@@ -9,6 +9,7 @@ import Link from "next/link";
99export default function Login ( ) {
1010 const [ user , { mutate } ] = useUser ( ) ;
1111 const [ errorMsg , setErrorMsg ] = useState ( "" ) ;
12+ const [ loading , isLoading ] = useState ( false ) ;
1213
1314 useEffect ( ( ) => {
1415 // redirect to home if user is authenticated
@@ -20,6 +21,7 @@ export default function Login() {
2021 if ( e . currentTarget . password . value !== e . currentTarget . cpassword . value ) {
2122 setErrorMsg ( "Passwords does not match" )
2223 } else {
24+ isLoading ( true ) ;
2325 const body = {
2426 email : e . currentTarget . email . value ,
2527 name : e . currentTarget . name . value ,
@@ -34,92 +36,102 @@ export default function Login() {
3436 const userObj = await res . json ( ) ;
3537 // writing our user object to the state
3638 mutate ( userObj ) ;
37- M . toast ( { html : 'Signed up' , classes :'blue' } )
39+ M . toast ( { html : 'Signed up' , classes : 'blue' } )
3840 } else {
41+ isLoading ( false ) ;
3942 setErrorMsg ( await res . text ( ) ) ;
4043 }
4144 }
4245 } ;
4346 return (
44- < div className = "row" >
45- < div className = "col s12 m12" >
46- < div className = "card z-depth-0" >
47- < h4 style = { { fontWeight :'bolder' } } > Create account</ h4 >
48- < div className = "container" >
49- < div className = "card-container" >
50- < div className = "row" >
51- < div className = "card-content" >
52- < form onSubmit = { handleSubmit } >
53- { errorMsg ? (
54- < p style = { { color : "red" } } > { errorMsg } </ p >
55- ) : null }
56- < div className = "input-field col s12" >
57- < i className = "prefix" >
58- < FaUserCircle />
59- </ i >
60- < input
61- id = "name"
62- type = "text"
63- className = "validate"
64- name = "name"
65- required
66- />
67- < label htmlFor = "name" > Name</ label >
68- </ div >
69- < div className = "input-field col s12" >
70- < i className = "prefix" >
71- < MdEmail />
72- </ i >
73- < input
74- id = "email"
75- type = "text"
76- className = "validate "
77- name = "email"
78- required
79- />
80- < label htmlFor = "email" > Email</ label >
81- </ div >
82- < div class = "input-field col s12" >
83- < i className = "prefix" >
84- < RiLockPasswordFill />
85- </ i >
86- < input
87- id = "password"
88- type = "password"
89- class = "validate"
90- name = "password"
91- required
92- />
93- < label htmlFor = "password" > Password</ label >
94- </ div >
95- < div class = "input-field col s12" >
96- < i className = "prefix" >
97- < RiLockPasswordLine />
98- </ i >
99- < input
100- id = "cpassword"
101- type = "password"
102- class = "validate"
103- name = "cpassword"
104- required
105- />
106- < label htmlFor = "cpassword" > Confirm Password</ label >
107- </ div >
108- < div className = "col s12" style = { { marginBottom : '1rem' } } >
109- < button class = "waves-effect waves-light btn col s12" type = "submit" >
110- sign up
47+ < >
48+ < div className = "card-stacked center-align" >
49+ { loading ? < div class = "progress" style = { { margin : 0 } } >
50+ < div class = "indeterminate" > </ div >
51+ </ div > : null }
52+ < div className = "card-content" >
53+ < div className = "row" >
54+ < div className = "col s12 m12" >
55+ < div className = "card z-depth-0" >
56+ < h4 style = { { fontWeight : 'bolder' } } > Create account</ h4 >
57+ < div className = "container" >
58+ < div className = "card-container" >
59+ < div className = "row" >
60+ < div className = "card-content" >
61+ < form onSubmit = { handleSubmit } >
62+ { errorMsg ? (
63+ < p style = { { color : "red" } } > { errorMsg } </ p >
64+ ) : null }
65+ < div className = "input-field col s12" >
66+ < i className = "prefix" >
67+ < FaUserCircle />
68+ </ i >
69+ < input
70+ id = "name"
71+ type = "text"
72+ className = "validate"
73+ name = "name"
74+ required
75+ />
76+ < label htmlFor = "name" > Name</ label >
77+ </ div >
78+ < div className = "input-field col s12" >
79+ < i className = "prefix" >
80+ < MdEmail />
81+ </ i >
82+ < input
83+ id = "email"
84+ type = "text"
85+ className = "validate "
86+ name = "email"
87+ required
88+ />
89+ < label htmlFor = "email" > Email</ label >
90+ </ div >
91+ < div class = "input-field col s12" >
92+ < i className = "prefix" >
93+ < RiLockPasswordFill />
94+ </ i >
95+ < input
96+ id = "password"
97+ type = "password"
98+ class = "validate"
99+ name = "password"
100+ required
101+ />
102+ < label htmlFor = "password" > Password</ label >
103+ </ div >
104+ < div class = "input-field col s12" >
105+ < i className = "prefix" >
106+ < RiLockPasswordLine />
107+ </ i >
108+ < input
109+ id = "cpassword"
110+ type = "password"
111+ class = "validate"
112+ name = "cpassword"
113+ required
114+ />
115+ < label htmlFor = "cpassword" > Confirm Password</ label >
116+ </ div >
117+ < div className = "col s12" style = { { marginBottom : '1rem' } } >
118+ < button class = "waves-effect waves-light btn col s12" type = "submit" >
119+ sign up
111120 </ button >
121+ </ div >
122+ </ form >
123+ </ div >
124+ < div className = "card-action col s12" >
125+ < p > Already have an account< Link href = "/login" > Login here.</ Link > </ p >
126+ </ div >
112127 </ div >
113- </ form >
114- </ div >
115- < div className = "card-action col s12" >
116- < p > Already have an account< Link href = "/login" > Login here.</ Link > </ p >
128+ </ div >
117129 </ div >
118130 </ div >
119131 </ div >
120132 </ div >
121133 </ div >
122134 </ div >
123- </ div >
135+ </ >
124136 ) ;
125137}
0 commit comments