Skip to content

Commit f251e66

Browse files
fix: UI fixes for sign up page (#1031)
* fix: UI fixes for sign up page Signed-off-by: pranalidhanavade <pranali.dhanavade@ayanworks.com> * fix: sonarlint issues Signed-off-by: pranalidhanavade <pranali.dhanavade@ayanworks.com> * fix: ellips suggestions on PR Signed-off-by: pranalidhanavade <pranali.dhanavade@ayanworks.com> --------- Signed-off-by: pranalidhanavade <pranali.dhanavade@ayanworks.com>
1 parent ae145c0 commit f251e66

File tree

4 files changed

+45
-68
lines changed

4 files changed

+45
-68
lines changed

nextjs/src/features/auth/components/EmailVerificationForm.tsx

Lines changed: 39 additions & 61 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22

33
import * as Yup from 'yup'
44

5-
import { Alert, AlertDescription } from '@/components/ui/alert'
65
import { Formik, Form as FormikForm } from 'formik'
76
import React, { useState } from 'react'
87
import { apiStatusCodes, emailRegex } from '@/config/CommonConstant'
@@ -12,6 +11,7 @@ import {
1211
sendVerificationMail,
1312
} from '@/app/api/Auth'
1413

14+
import { AlertComponent } from '@/components/AlertComponent'
1515
import { AxiosResponse } from 'axios'
1616
import { Button } from '@/components/ui/button'
1717
import { Input } from '@/components/ui/input'
@@ -30,12 +30,8 @@ export default function EmailVerificationForm({
3030
}: StepEmailProps): React.ReactElement {
3131
const [loading, setLoading] = useState(false)
3232
const [verifyLoader, setVerifyLoader] = useState(false)
33-
34-
const [showEmailVerification, setShowEmailVerification] = useState<{
35-
message: string
36-
isError: boolean
37-
type: string
38-
}>({ message: '', isError: false, type: '' })
33+
const [emailSuccess, setEmailSuccess] = useState<string | null>(null)
34+
const [addFailure, setAddFailure] = useState<string | null>(null)
3935

4036
const validationSchema = Yup.object().shape({
4137
email: Yup.string()
@@ -58,34 +54,26 @@ export default function EmailVerificationForm({
5854
const { data } = userRsp as AxiosResponse
5955

6056
if (data?.statusCode === apiStatusCodes.API_STATUS_CREATED) {
61-
setShowEmailVerification({
62-
message: data?.message,
63-
isError: false,
64-
type: 'success',
65-
})
57+
setEmailSuccess(data?.message)
58+
setAddFailure(null)
6659
} else {
67-
setShowEmailVerification({
68-
message: data?.message,
69-
isError: true,
70-
type: 'danger',
71-
})
60+
setAddFailure(userRsp as string)
61+
setEmailSuccess(null)
7262
}
7363
} catch (err) {
7464
// eslint-disable-next-line no-console
7565
console.error('Error during sending verification email:', err)
76-
setShowEmailVerification({
77-
message: 'An error occurred while sending verification email.',
78-
isError: true,
79-
type: 'danger',
80-
})
66+
setAddFailure('An error occurred while sending verification email.')
67+
setEmailSuccess(null)
8168
} finally {
8269
setVerifyLoader(false)
8370
}
8471
}
8572

8673
const handleVerifyEmail = async (emailValue: string): Promise<void> => {
8774
setLoading(true)
88-
setShowEmailVerification({ message: '', isError: false, type: '' })
75+
setEmailSuccess(null)
76+
setAddFailure(null)
8977

9078
try {
9179
const userRsp = await checkUserExist(emailValue)
@@ -95,11 +83,7 @@ export default function EmailVerificationForm({
9583
if (data?.statusCode === apiStatusCodes.API_STATUS_SUCCESS) {
9684
if (isEmailVerified) {
9785
if (isRegistrationCompleted) {
98-
setShowEmailVerification({
99-
message: 'Email is already registered.',
100-
isError: true,
101-
type: 'danger',
102-
})
86+
setAddFailure(data?.data?.message)
10387
} else {
10488
setEmail(emailValue)
10589
goToNext()
@@ -108,20 +92,12 @@ export default function EmailVerificationForm({
10892
await handleSendVerificationEmail(emailValue)
10993
}
11094
} else {
111-
setShowEmailVerification({
112-
message: data?.data?.message ?? 'Something went wrong.',
113-
isError: true,
114-
type: 'danger',
115-
})
95+
setAddFailure(data?.data?.message ?? 'Something went wrong.')
11696
}
11797
} catch (err) {
11898
// eslint-disable-next-line no-console
11999
console.error('Unexpected error during email verification:', err)
120-
setShowEmailVerification({
121-
message: 'An unexpected error occurred. Please try again.',
122-
isError: true,
123-
type: 'danger',
124-
})
100+
setAddFailure('An unexpected error occurred. Please try again.')
125101
} finally {
126102
setLoading(false)
127103
}
@@ -147,29 +123,31 @@ export default function EmailVerificationForm({
147123

148124
return (
149125
<FormikForm className="space-y-4">
150-
{showEmailVerification.message && (
151-
<Alert
152-
variant={
153-
showEmailVerification.type === 'success'
154-
? 'default'
155-
: 'destructive'
156-
}
157-
className={`mb-4 ${
158-
showEmailVerification.type === 'success'
159-
? 'bg-success'
160-
: 'bg-error'
161-
}`}
162-
>
163-
<AlertDescription
164-
className={
165-
showEmailVerification.type === 'success'
166-
? 'text-success'
167-
: 'text-error'
168-
}
169-
>
170-
{showEmailVerification.message}
171-
</AlertDescription>
172-
</Alert>
126+
{emailSuccess && (
127+
<div className="w-full" role="alert">
128+
<AlertComponent
129+
message={emailSuccess}
130+
type={'success'}
131+
onAlertClose={() => {
132+
if (emailSuccess) {
133+
setEmailSuccess(null)
134+
}
135+
}}
136+
/>
137+
</div>
138+
)}
139+
{addFailure && (
140+
<div className="w-full" role="alert">
141+
<AlertComponent
142+
message={addFailure}
143+
type={'failure'}
144+
onAlertClose={() => {
145+
if (addFailure) {
146+
setAddFailure(null)
147+
}
148+
}}
149+
/>
150+
</div>
173151
)}
174152

175153
<div className="h-12">

nextjs/src/features/auth/components/SignUpUser.tsx

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,9 @@ export default function SignUpUser(): React.JSX.Element {
5757
<div className="text-muted-foreground mt-4 text-center text-sm">
5858
Already have an account?{' '}
5959
<Link href="/auth/sign-in">
60-
<span className="text-secondary hover:underline">Sign in</span>
60+
<span className="text-muted-foreground hover:text-foreground hover:underline">
61+
Sign in
62+
</span>
6163
</Link>
6264
</div>
6365
</div>

nextjs/src/features/auth/components/user-auth-form.tsx

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -323,7 +323,9 @@ export default function SignInViewPage(): React.JSX.Element {
323323
name="email"
324324
render={({ field }) => (
325325
<FormItem>
326-
<FormLabel>Email</FormLabel>
326+
<FormLabel className="data-[error=true]:text-foreground">
327+
Email
328+
</FormLabel>
327329
<FormControl>
328330
<div className="relative">
329331
<Mail className="text-muted-foreground absolute top-2.5 left-3 h-4 w-4" />

nextjs/src/features/passkey/AddPasskey.tsx

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -269,11 +269,6 @@ const AddPasskey = ({
269269
/>
270270
</div>
271271
)}
272-
<Alert variant={addSuccess ? 'default' : 'destructive'}>
273-
<AlertDescription>
274-
{addSuccess || addFailure || error}
275-
</AlertDescription>
276-
</Alert>
277272
</div>
278273
)}
279274
<div className="relative flex h-full flex-auto flex-col p-3 sm:p-4">

0 commit comments

Comments
 (0)