Files
myeasycms-v2/packages/features/admin/src/components/admin-ban-user-dialog.tsx
gbuomprisco 0935ecd90f Update ESLint and Supabase dependencies
Upgraded `@typescript-eslint` plugins and parser from ^7.17.0 to ^7.18.0 and `supabase` from ^1.187.8 to ^1.187.10. These updates incorporate recent improvements and bug fixes. Updated the pnpm-lock.yaml file to reflect these changes and ensure compatibility.
2024-07-30 12:18:37 +02:00

104 lines
2.6 KiB
TypeScript

'use client';
import { zodResolver } from '@hookform/resolvers/zod';
import { useForm } from 'react-hook-form';
import {
AlertDialog,
AlertDialogCancel,
AlertDialogContent,
AlertDialogDescription,
AlertDialogFooter,
AlertDialogHeader,
AlertDialogTitle,
AlertDialogTrigger,
} from '@kit/ui/alert-dialog';
import { Button } from '@kit/ui/button';
import {
Form,
FormControl,
FormDescription,
FormField,
FormItem,
FormLabel,
FormMessage,
} from '@kit/ui/form';
import { Input } from '@kit/ui/input';
import { banUserAction } from '../lib/server/admin-server-actions';
import { BanUserSchema } from '../lib/server/schema/admin-actions.schema';
export function AdminBanUserDialog(
props: React.PropsWithChildren<{
userId: string;
}>,
) {
const form = useForm({
resolver: zodResolver(BanUserSchema),
defaultValues: {
userId: props.userId,
confirmation: '',
},
});
return (
<AlertDialog>
<AlertDialogTrigger asChild>{props.children}</AlertDialogTrigger>
<AlertDialogContent>
<AlertDialogHeader>
<AlertDialogTitle>Ban User</AlertDialogTitle>
<AlertDialogDescription>
Are you sure you want to ban this user? Please note that the user
will stay logged in until their session expires.
</AlertDialogDescription>
</AlertDialogHeader>
<Form {...form}>
<form
className={'flex flex-col space-y-8'}
onSubmit={form.handleSubmit((data) => {
return banUserAction(data);
})}
>
<FormField
name={'confirmation'}
render={({ field }) => (
<FormItem>
<FormLabel>
Type <b>CONFIRM</b> to confirm
</FormLabel>
<FormControl>
<Input
required
pattern={'CONFIRM'}
placeholder={'Type CONFIRM to confirm'}
{...field}
/>
</FormControl>
<FormDescription>
Are you sure you want to do this?
</FormDescription>
<FormMessage />
</FormItem>
)}
/>
<AlertDialogFooter>
<AlertDialogCancel>Cancel</AlertDialogCancel>
<Button type={'submit'} variant={'destructive'}>
Ban User
</Button>
</AlertDialogFooter>
</form>
</Form>
</AlertDialogContent>
</AlertDialog>
);
}