MED-109: add doctor role and basic view (#45)
* MED-109: add doctor role and basic view * add role to accounts * remove old super admin and doctor sql
This commit is contained in:
@@ -1,5 +1,7 @@
|
||||
'use client';
|
||||
|
||||
import { useTransition } from 'react';
|
||||
|
||||
import Link from 'next/link';
|
||||
import { usePathname, useRouter } from 'next/navigation';
|
||||
|
||||
@@ -11,6 +13,7 @@ import { z } from 'zod';
|
||||
|
||||
import { Database } from '@kit/supabase/database';
|
||||
import { Button } from '@kit/ui/button';
|
||||
import { Checkbox } from '@kit/ui/checkbox';
|
||||
import {
|
||||
DropdownMenu,
|
||||
DropdownMenuContent,
|
||||
@@ -32,7 +35,10 @@ import {
|
||||
SelectTrigger,
|
||||
SelectValue,
|
||||
} from '@kit/ui/select';
|
||||
import { toast } from '@kit/ui/sonner';
|
||||
import { Trans } from '@kit/ui/trans';
|
||||
|
||||
import { updateRoleAction } from '../lib/server/admin-server-actions';
|
||||
import { AdminDeleteAccountDialog } from './admin-delete-account-dialog';
|
||||
import { AdminDeleteUserDialog } from './admin-delete-user-dialog';
|
||||
import { AdminImpersonateUserDialog } from './admin-impersonate-user-dialog';
|
||||
@@ -204,6 +210,39 @@ function getColumns(): ColumnDef<Account>[] {
|
||||
header: 'Updated At',
|
||||
accessorKey: 'updated_at',
|
||||
},
|
||||
{
|
||||
id: 'isDoctor',
|
||||
header: 'Doctor',
|
||||
cell: ({ row }) => {
|
||||
const [isPending, startTransition] = useTransition();
|
||||
|
||||
const handleToggle = () => {
|
||||
startTransition(async () => {
|
||||
const isDoctor = row.original.application_role === 'doctor';
|
||||
const newRole = isDoctor ? 'user' : 'doctor';
|
||||
|
||||
const promise = updateRoleAction({
|
||||
accountId: row.original.id,
|
||||
role: newRole,
|
||||
});
|
||||
|
||||
toast.promise(() => promise, {
|
||||
success: <Trans i18nKey={'account:updateRoleSuccess'} />,
|
||||
error: <Trans i18nKey={'account:updateRoleError'} />,
|
||||
loading: <Trans i18nKey={'account:updateRoleLoading'} />,
|
||||
});
|
||||
});
|
||||
};
|
||||
|
||||
return (
|
||||
<Checkbox
|
||||
checked={row.original.application_role === 'doctor'}
|
||||
onCheckedChange={handleToggle}
|
||||
disabled={isPending}
|
||||
/>
|
||||
);
|
||||
},
|
||||
},
|
||||
{
|
||||
id: 'actions',
|
||||
header: '',
|
||||
|
||||
Reference in New Issue
Block a user