@@ -10,68 +10,68 @@ import { toast } from "@/components/toast";
1010import { type RegisterActionState , register } from "../actions" ;
1111
1212export default function Page ( ) {
13- const router = useRouter ( ) ;
13+ const router = useRouter ( ) ;
1414
15- const [ email , setEmail ] = useState ( "" ) ;
16- const [ isSuccessful , setIsSuccessful ] = useState ( false ) ;
15+ const [ email , setEmail ] = useState ( "" ) ;
16+ const [ isSuccessful , setIsSuccessful ] = useState ( false ) ;
1717
18- const [ state , formAction ] = useActionState < RegisterActionState , FormData > (
19- register ,
20- {
21- status : "idle" ,
22- } ,
23- ) ;
18+ const [ state , formAction ] = useActionState < RegisterActionState , FormData > (
19+ register ,
20+ {
21+ status : "idle" ,
22+ }
23+ ) ;
2424
25- const { update : updateSession } = useSession ( ) ;
25+ const { update : updateSession } = useSession ( ) ;
2626
27- useEffect ( ( ) => {
28- if ( state . status === "user_exists" ) {
29- toast ( { type : "error" , description : "Account already exists!" } ) ;
30- } else if ( state . status === "failed" ) {
31- toast ( { type : "error" , description : "Failed to create account!" } ) ;
32- } else if ( state . status === "invalid_data" ) {
33- toast ( {
34- type : "error" ,
35- description : "Failed validating your submission!" ,
36- } ) ;
37- } else if ( state . status === "success" ) {
38- toast ( { type : "success" , description : "Account created successfully!" } ) ;
27+ useEffect ( ( ) => {
28+ if ( state . status === "user_exists" ) {
29+ toast ( { type : "error" , description : "Account already exists!" } ) ;
30+ } else if ( state . status === "failed" ) {
31+ toast ( { type : "error" , description : "Failed to create account!" } ) ;
32+ } else if ( state . status === "invalid_data" ) {
33+ toast ( {
34+ type : "error" ,
35+ description : "Failed validating your submission!" ,
36+ } ) ;
37+ } else if ( state . status === "success" ) {
38+ toast ( { type : "success" , description : "Account created successfully!" } ) ;
3939
40- setIsSuccessful ( true ) ;
41- updateSession ( ) ;
42- router . refresh ( ) ;
43- }
44- // eslint-disable-next-line react-hooks/exhaustive-deps
45- } , [ state . status ] ) ;
40+ setIsSuccessful ( true ) ;
41+ updateSession ( ) ;
42+ router . refresh ( ) ;
43+ }
44+ // eslint-disable-next-line react-hooks/exhaustive-deps
45+ } , [ state . status ] ) ;
4646
47- const handleSubmit = ( formData : FormData ) => {
48- setEmail ( formData . get ( "email" ) as string ) ;
49- formAction ( formData ) ;
50- } ;
47+ const handleSubmit = ( formData : FormData ) => {
48+ setEmail ( formData . get ( "email" ) as string ) ;
49+ formAction ( formData ) ;
50+ } ;
5151
52- return (
53- < div className = "flex h-dvh w-screen items-start justify-center bg-background pt-12 md:items-center md:pt-0" >
54- < div className = "flex w-full max-w-md flex-col gap-12 overflow-hidden rounded-2xl" >
55- < div className = "flex flex-col items-center justify-center gap-2 px-4 text-center sm:px-16" >
56- < h3 className = "font-semibold text-xl dark:text-zinc-50" > Sign Up</ h3 >
57- < p className = "text-gray-500 text-sm dark:text-zinc-400" >
58- Create an account with your email and password
59- </ p >
60- </ div >
61- < AuthForm action = { handleSubmit } defaultEmail = { email } >
62- < SubmitButton isSuccessful = { isSuccessful } > Sign Up</ SubmitButton >
63- < p className = "mt-4 text-center text-gray-600 text-sm dark:text-zinc-400" >
64- { "Already have an account? " }
65- < Link
66- className = "font-semibold text-gray-800 hover:underline dark:text-zinc-200"
67- href = "/login"
68- >
69- Sign in
70- </ Link >
71- { " instead." }
72- </ p >
73- </ AuthForm >
74- </ div >
75- </ div >
76- ) ;
52+ return (
53+ < div className = "flex h-dvh w-screen items-start justify-center bg-background pt-12 md:items-center md:pt-0" >
54+ < div className = "flex w-full max-w-md flex-col gap-12 overflow-hidden rounded-2xl" >
55+ < div className = "flex flex-col items-center justify-center gap-2 px-4 text-center sm:px-16" >
56+ < h3 className = "font-semibold text-xl dark:text-zinc-50" > Sign Up</ h3 >
57+ < p className = "text-gray-500 text-sm dark:text-zinc-400" >
58+ Create an account with your email and password
59+ </ p >
60+ </ div >
61+ < AuthForm action = { handleSubmit } defaultEmail = { email } >
62+ < SubmitButton isSuccessful = { isSuccessful } > Sign Up</ SubmitButton >
63+ < p className = "mt-4 text-center text-gray-600 text-sm dark:text-zinc-400" >
64+ { "Already have an account? " }
65+ < Link
66+ className = "font-semibold text-gray-800 hover:underline dark:text-zinc-200"
67+ href = "/login"
68+ >
69+ Sign in
70+ </ Link >
71+ { " instead." }
72+ </ p >
73+ </ AuthForm >
74+ </ div >
75+ </ div >
76+ ) ;
7777}
0 commit comments