From 01acb4c941fc883dfbd7b0beb5ed58d19165a80a Mon Sep 17 00:00:00 2001 From: americano98 Date: Fri, 29 Nov 2024 14:18:35 +0300 Subject: [PATCH] chore: states update, fix styles --- packages/ui/src/components/card.tsx | 2 +- packages/ui/src/components/input-otp.tsx | 4 +- packages/ui/src/components/input.tsx | 2 +- packages/ui/src/components/label.tsx | 2 +- .../src/views/auth/components/agreements.tsx | 6 +- .../auth/components/animated-harness-logo.tsx | 10 +-- .../src/views/auth/forgot-password-page.tsx | 20 ++++-- .../ui/src/views/auth/new-password-page.tsx | 24 +++++-- packages/ui/src/views/auth/otp-page.tsx | 31 ++++---- packages/ui/src/views/auth/signin-page.tsx | 28 +++++--- packages/ui/src/views/auth/signup-page.tsx | 72 ++++++++++++------- .../views/layouts/Floating1ColumnLayout.tsx | 4 +- 12 files changed, 130 insertions(+), 75 deletions(-) diff --git a/packages/ui/src/components/card.tsx b/packages/ui/src/components/card.tsx index 60345a0377..52e260a694 100644 --- a/packages/ui/src/components/card.tsx +++ b/packages/ui/src/components/card.tsx @@ -3,7 +3,7 @@ import * as React from 'react' import { cn } from '@utils/cn' import { cva, type VariantProps } from 'class-variance-authority' -const cardVariants = cva('bg-card text-card-foreground rounded-lg border shadow', { +const cardVariants = cva('rounded-lg border bg-card text-card-foreground shadow', { variants: { variant: { default: '', diff --git a/packages/ui/src/components/input-otp.tsx b/packages/ui/src/components/input-otp.tsx index 3f667d43ff..43b9560f1f 100644 --- a/packages/ui/src/components/input-otp.tsx +++ b/packages/ui/src/components/input-otp.tsx @@ -40,7 +40,7 @@ const InputOTPSlot = React.forwardRef(({ inde
(({ inde {char} {hasFakeCaret && (
-
+
)}
diff --git a/packages/ui/src/components/input.tsx b/packages/ui/src/components/input.tsx index c1b4cc8ce8..be666162d9 100644 --- a/packages/ui/src/components/input.tsx +++ b/packages/ui/src/components/input.tsx @@ -25,7 +25,7 @@ const BaseInput = React.forwardRef( {error && ( diff --git a/packages/ui/src/components/label.tsx b/packages/ui/src/components/label.tsx index 6a758b35eb..d4dc2c32de 100644 --- a/packages/ui/src/components/label.tsx +++ b/packages/ui/src/components/label.tsx @@ -6,7 +6,7 @@ import * as LabelPrimitive from '@radix-ui/react-label' import { cn } from '@utils/cn' import { cva, type VariantProps } from 'class-variance-authority' -const labelVariants = cva('leading-none block peer-disabled:cursor-not-allowed peer-disabled:opacity-70', { +const labelVariants = cva('block leading-none peer-disabled:cursor-not-allowed peer-disabled:opacity-70', { variants: { variant: { default: 'text-sm leading-none', diff --git a/packages/ui/src/views/auth/components/agreements.tsx b/packages/ui/src/views/auth/components/agreements.tsx index 490eebfcd2..52d093c407 100644 --- a/packages/ui/src/views/auth/components/agreements.tsx +++ b/packages/ui/src/views/auth/components/agreements.tsx @@ -4,17 +4,17 @@ import { Text } from '../../../components' export function Agreements() { return ( - + By joining, you agree to{' '} Terms of Service {' '} and  Privacy Policy diff --git a/packages/ui/src/views/auth/components/animated-harness-logo.tsx b/packages/ui/src/views/auth/components/animated-harness-logo.tsx index 233f9507eb..5d66e70051 100644 --- a/packages/ui/src/views/auth/components/animated-harness-logo.tsx +++ b/packages/ui/src/views/auth/components/animated-harness-logo.tsx @@ -29,7 +29,7 @@ export function AnimatedHarnessLogo({ theme }: AnimatedHarnessLogoProps) { const isError = theme === 'error' return ( -
+
-
+
- + - +
- +
) } diff --git a/packages/ui/src/views/auth/forgot-password-page.tsx b/packages/ui/src/views/auth/forgot-password-page.tsx index 5bbcf9033b..bea1a2c505 100644 --- a/packages/ui/src/views/auth/forgot-password-page.tsx +++ b/packages/ui/src/views/auth/forgot-password-page.tsx @@ -1,4 +1,4 @@ -import { useEffect } from 'react' +import { useEffect, useState } from 'react' import { SubmitHandler, useForm } from 'react-hook-form' import { Link } from 'react-router-dom' @@ -25,11 +25,13 @@ const forgotPasswordSchema = z.object({ }) export function ForgotPasswordPage({ isLoading, onSubmit, error }: PageProps) { + const [serverError, setServerError] = useState(null) const { register, handleSubmit, setError, clearErrors, + trigger, formState: { errors } } = useForm({ resolver: zodResolver(forgotPasswordSchema) @@ -42,19 +44,29 @@ export function ForgotPasswordPage({ isLoading, onSubmit, error }: PageProps) { } } - const hasError = Object.keys(errors).length > 0 || !!error + const handleInputChange = async () => { + if (serverError) { + setServerError(null) + clearErrors(['email']) + await trigger() + } + } useEffect(() => { if (error) { + setServerError(error) setError('email', { type: 'manual', message: error }) } else { + setServerError(null) clearErrors(['email']) } }, [error, setError, clearErrors]) + const hasError = Object.keys(errors).length > 0 || !!serverError + return (
@@ -141,6 +137,7 @@ export function OTPPage({ handleResend, isLoading, handleFormSubmit, error }: Pa type="submit" size="md" loading={isLoading} + disabled={hasError} > {isLoading ? 'Verifying...' : 'Verify'} @@ -148,7 +145,7 @@ export function OTPPage({ handleResend, isLoading, handleFormSubmit, error }: Pa Didn't receive the code?{' '} - diff --git a/packages/ui/src/views/auth/signin-page.tsx b/packages/ui/src/views/auth/signin-page.tsx index 6aa5c2d4d6..9594fb0211 100644 --- a/packages/ui/src/views/auth/signin-page.tsx +++ b/packages/ui/src/views/auth/signin-page.tsx @@ -1,4 +1,4 @@ -import { useEffect } from 'react' +import { useEffect, useState } from 'react' import { useForm } from 'react-hook-form' import { Link } from 'react-router-dom' @@ -27,12 +27,14 @@ const signInSchema = z.object({ }) export function SignInPage({ handleSignIn, isLoading, error }: PageProps) { + const [serverError, setServerError] = useState(null) const { register, handleSubmit, setError, clearErrors, - formState: { errors } + formState: { errors }, + trigger } = useForm({ resolver: zodResolver(signInSchema) }) @@ -41,8 +43,17 @@ export function SignInPage({ handleSignIn, isLoading, error }: PageProps) { handleSignIn(data) } + const handleInputChange = async () => { + if (serverError) { + setServerError(null) + clearErrors(['password']) + await trigger() + } + } + useEffect(() => { if (error) { + setServerError(error) setError('email', { type: 'manual', message: ' ' @@ -52,15 +63,16 @@ export function SignInPage({ handleSignIn, isLoading, error }: PageProps) { message: error }) } else { + setServerError(null) clearErrors(['email', 'password']) } }, [error, setError, clearErrors]) - const hasError = Object.keys(errors).length > 0 || !!error + const hasError = Object.keys(errors).length > 0 || !!serverError return ( @@ -84,9 +96,9 @@ export function SignInPage({ handleSignIn, isLoading, error }: PageProps) { id="email" type="email" placeholder="Your email" - {...register('email')} - autoFocus + {...register('email', { onChange: handleInputChange })} error={errors.email?.message?.toString()} + autoFocus />