File tree Expand file tree Collapse file tree 1 file changed +21
-2
lines changed Expand file tree Collapse file tree 1 file changed +21
-2
lines changed Original file line number Diff line number Diff line change 11import React , { Fragment } from 'react' ;
2- import { Form , Link , useSearchParams } from 'react-router-dom' ;
2+ import {
3+ Form ,
4+ Link ,
5+ useActionData ,
6+ useNavigation ,
7+ useSearchParams ,
8+ } from 'react-router-dom' ;
39
410import classes from './AuthForm.module.css' ;
511
612function AuthForm ( ) {
713 const [ searchParams ] = useSearchParams ( ) ;
14+ const navigation = useNavigation ( ) ;
15+ const data = useActionData ( ) ;
816
917 const isLogin = searchParams . get ( 'mode' ) === 'login' ;
18+ const isSubmitting = navigation . state === 'submitting' ;
1019
1120 return (
1221 < Fragment >
1322 < Form method = "post" className = { classes . form } >
1423 < h1 > { isLogin ? 'Log in' : 'Create a new user' } </ h1 >
24+ { data && data . errors && (
25+ < ul >
26+ { Object . values ( data . errors ) . map ( error => (
27+ < li key = { error } > { error } </ li >
28+ ) ) }
29+ </ ul >
30+ ) }
31+ { data && data . message && < p > { data . message } </ p > }
1532 < p >
1633 < label htmlFor = "email" > Email</ label >
1734 < input id = "email" type = "email" name = "email" required />
@@ -24,7 +41,9 @@ function AuthForm() {
2441 < Link to = { `?mode=${ isLogin ? 'signup' : 'login' } ` } >
2542 { isLogin ? 'Create new user' : 'Login' }
2643 </ Link >
27- < button > { isLogin ? 'Login' : 'Save' } </ button >
44+ < button disabled = { isSubmitting } >
45+ { isSubmitting ? 'Submitting...' : isLogin ? 'Login' : 'Save' }
46+ </ button >
2847 </ div >
2948 </ Form >
3049 </ Fragment >
You can’t perform that action at this time.
0 commit comments