@@ -7,7 +7,7 @@ import classes from "./index.module.css";
7
7
import { toast } from "react-toastify" ;
8
8
9
9
const EmailVerification : React . FC = ( ) => {
10
- const { userId } = useParams < { userId : string } > ( ) ;
10
+ const { userId } = useParams < { userId ? : string } > ( ) ;
11
11
const [ token , setToken ] = useState ( "" ) ;
12
12
const [ email , setEmail ] = useState ( "" ) ;
13
13
const navigate = useNavigate ( ) ;
@@ -19,16 +19,17 @@ const EmailVerification: React.FC = () => {
19
19
setEmail ( res . data . data . email ) ;
20
20
} )
21
21
. catch ( ( err ) => console . error ( err ) ) ;
22
+ // eslint-disable-next-line react-hooks/exhaustive-deps
22
23
} , [ ] ) ;
23
24
24
- const handleResend = ( ) => {
25
+ const handleSendEmail = ( ) => {
25
26
userClient
26
27
. post ( `/users/send-verification-email` , { email } )
28
+ . then ( ( res ) => toast . success ( res . data . message ) )
27
29
. catch ( ( err ) => console . error ( err ) ) ;
28
30
} ;
29
31
30
- const handleVerify = ( e : React . FormEvent < HTMLFormElement > ) => {
31
- e . preventDefault ( ) ;
32
+ const handleVerifyAcc = ( ) => {
32
33
userClient
33
34
. get ( `/users/verify-email/${ email } /${ token } ` )
34
35
. then ( ( res ) => {
@@ -59,35 +60,51 @@ const EmailVerification: React.FC = () => {
59
60
} ) }
60
61
>
61
62
< Typography variant = "h5" > Verify your email address</ Typography >
62
- < Typography sx = { ( theme ) => ( { margin : theme . spacing ( 2 , 0 ) } ) } >
63
- An account verification token has been sent to your email.
64
- </ Typography >
65
- < form onSubmit = { handleVerify } >
66
- < TextField
63
+ { userId ? (
64
+ < Typography sx = { ( theme ) => ( { margin : theme . spacing ( 2 , 0 ) } ) } >
65
+ An account verification token has been sent to your email.
66
+ </ Typography >
67
+ ) : (
68
+ < Typography sx = { ( theme ) => ( { margin : theme . spacing ( 2 , 0 ) } ) } >
69
+ An account verification token will be sent to your email.
70
+ </ Typography >
71
+ ) }
72
+ < TextField
73
+ fullWidth
74
+ margin = "normal"
75
+ label = "Email"
76
+ value = { email }
77
+ onChange = { ( e ) => setEmail ( e . target . value ) }
78
+ slotProps = { {
79
+ input : {
80
+ endAdornment : < Button onClick = { handleSendEmail } > Send</ Button > ,
81
+ } ,
82
+ } }
83
+ />
84
+ < TextField
85
+ fullWidth
86
+ margin = "normal"
87
+ label = "Token"
88
+ value = { token }
89
+ onChange = { ( e ) => setToken ( e . target . value ) }
90
+ />
91
+ < Stack
92
+ direction = "row"
93
+ spacing = { 2 }
94
+ sx = { ( theme ) => ( { marginTop : theme . spacing ( 4 ) } ) }
95
+ >
96
+ < Button
67
97
fullWidth
68
- margin = "normal"
69
- label = "Token"
70
- value = { token }
71
- onChange = { ( e ) => setToken ( e . target . value ) }
72
- />
73
- < Stack
74
- direction = "row"
75
- spacing = { 2 }
76
- sx = { ( theme ) => ( { marginTop : theme . spacing ( 4 ) } ) }
98
+ variant = "contained"
99
+ color = "secondary"
100
+ onClick = { handleSendEmail }
77
101
>
78
- < Button
79
- fullWidth
80
- variant = "contained"
81
- color = "secondary"
82
- onClick = { handleResend }
83
- >
84
- Resend
85
- </ Button >
86
- < Button fullWidth variant = "contained" type = "submit" >
87
- Verify
88
- </ Button >
89
- </ Stack >
90
- </ form >
102
+ Resend
103
+ </ Button >
104
+ < Button fullWidth variant = "contained" onClick = { handleVerifyAcc } >
105
+ Verify
106
+ </ Button >
107
+ </ Stack >
91
108
</ Box >
92
109
</ AppMargin >
93
110
</ Box >
0 commit comments