1
1
import { cn } from "@follow/utils/utils"
2
2
import { lazy , Suspense , useEffect , useState } from "react"
3
+ import { useTranslation } from "react-i18next"
3
4
import { toast } from "sonner"
4
5
5
6
import { useWhoami } from "~/atoms/user"
@@ -21,7 +22,9 @@ export function NewUserGuide() {
21
22
useEffect ( ( ) => {
22
23
if ( user ?. email && ! user . emailVerified ) {
23
24
toast . error ( < EmailVerificationToast user = { user } /> , {
25
+ id : "email-verification" ,
24
26
duration : Infinity ,
27
+ closeButton : true ,
25
28
} )
26
29
}
27
30
} , [ user ?. emailVerified ] )
@@ -40,10 +43,15 @@ function EmailVerificationToast({
40
43
email : string
41
44
}
42
45
} ) {
46
+ const { t } = useTranslation ( "settings" )
43
47
const [ isEmailVerificationSent , setIsEmailVerificationSent ] = useState ( false )
44
48
return (
45
49
< div data-content className = "flex w-full flex-col gap-2" >
46
- < div data-title > Please verify your email ({ user . email } ) to continue</ div >
50
+ < div data-title >
51
+ { t ( "profile.email.verify_email" , {
52
+ email_address : user . email ,
53
+ } ) }
54
+ </ div >
47
55
< button
48
56
type = "button"
49
57
data-button = "true"
@@ -53,15 +61,21 @@ function EmailVerificationToast({
53
61
isEmailVerificationSent && "!cursor-progress opacity-50" ,
54
62
) }
55
63
disabled = { isEmailVerificationSent }
56
- onClick = { ( ) => {
57
- sendVerificationEmail ( {
64
+ onClick = { async ( ) => {
65
+ setIsEmailVerificationSent ( true )
66
+ await sendVerificationEmail ( {
58
67
email : user . email ,
59
68
callbackURL : `${ WEB_URL } /login` ,
60
69
} )
61
- setIsEmailVerificationSent ( true )
70
+ toast . dismiss ( "email-verification" )
71
+ // Wait for the toast to dismiss before showing the success toast
72
+ // To have a better user experience
73
+ setTimeout ( ( ) => {
74
+ toast . success ( t ( "profile.email.verification_sent" ) )
75
+ } , 800 )
62
76
} }
63
77
>
64
- Send verification email
78
+ { t ( "profile. email.send_verification" ) }
65
79
</ button >
66
80
</ div >
67
81
)
0 commit comments