From 369d08ae6ed7069677abcf18a51a4684fe4683c2 Mon Sep 17 00:00:00 2001 From: nafees nazik Date: Sat, 2 Dec 2023 17:54:55 +0530 Subject: [PATCH] feat: refactor signin page --- apps/web/src/components/forms/signin.tsx | 210 ++++++++++++----------- 1 file changed, 109 insertions(+), 101 deletions(-) diff --git a/apps/web/src/components/forms/signin.tsx b/apps/web/src/components/forms/signin.tsx index 0d7dd723f..46173a97c 100644 --- a/apps/web/src/components/forms/signin.tsx +++ b/apps/web/src/components/forms/signin.tsx @@ -12,9 +12,16 @@ import { ErrorCode, isErrorCode } from '@documenso/lib/next-auth/error-codes'; import { cn } from '@documenso/ui/lib/utils'; import { Button } from '@documenso/ui/primitives/button'; import { Dialog, DialogContent, DialogHeader, DialogTitle } from '@documenso/ui/primitives/dialog'; -import { FormErrorMessage } from '@documenso/ui/primitives/form/form-error-message'; -import { Input, PasswordInput } from '@documenso/ui/primitives/input'; -import { Label } from '@documenso/ui/primitives/label'; +import { + Form, + FormControl, + FormField, + FormItem, + FormLabel, + FormMessage, +} from '@documenso/ui/primitives/form/form'; +import { Input } from '@documenso/ui/primitives/input'; +import { PasswordInput } from '@documenso/ui/primitives/password-input'; import { useToast } from '@documenso/ui/primitives/use-toast'; const ERROR_MESSAGES: Partial> = { @@ -52,12 +59,7 @@ export const SignInForm = ({ className }: SignInFormProps) => { 'totp' | 'backup' >('totp'); - const { - register, - handleSubmit, - setValue, - formState: { errors, isSubmitting }, - } = useForm({ + const form = useForm({ values: { email: '', password: '', @@ -67,9 +69,11 @@ export const SignInForm = ({ className }: SignInFormProps) => { resolver: zodResolver(ZSignInFormSchema), }); + const isSubmitting = form.formState.isSubmitting; + const onCloseTwoFactorAuthenticationDialog = () => { - setValue('totpCode', ''); - setValue('backupCode', ''); + form.setValue('totpCode', ''); + form.setValue('backupCode', ''); setIsTwoFactorAuthenticationDialogOpen(false); }; @@ -78,11 +82,11 @@ export const SignInForm = ({ className }: SignInFormProps) => { const method = twoFactorAuthenticationMethod === 'totp' ? 'backup' : 'totp'; if (method === 'totp') { - setValue('backupCode', ''); + form.setValue('backupCode', ''); } if (method === 'backup') { - setValue('totpCode', ''); + form.setValue('totpCode', ''); } setTwoFactorAuthenticationMethod(method); @@ -113,7 +117,6 @@ export const SignInForm = ({ className }: SignInFormProps) => { if (result?.error && isErrorCode(result.error)) { if (result.error === TwoFactorEnabledErrorCode) { setIsTwoFactorAuthenticationDialogOpen(true); - return; } @@ -156,64 +159,69 @@ export const SignInForm = ({ className }: SignInFormProps) => { }; return ( -
-
- - - - - -
- -
- - - - - -
- - +
+ ( + + Email + + + + + + )} + /> -
-
- Or continue with -
-
+ ( + + Password + + + + + + )} + /> +
- + +
+
+ Or continue with +
+
+ + + { Two-Factor Authentication -
- {twoFactorAuthenticationMethod === 'totp' && ( -
- - - +
+ {twoFactorAuthenticationMethod === 'totp' && ( + ( + + Authentication Token + + + + + + )} /> + )} - -
- )} - - {twoFactorAuthenticationMethod === 'backup' && ( -
- - - ( + + Backup Code + + + + + + )} /> - - -
- )} + )} +
-
- + ); };