@@ -20,10 +20,24 @@ function App() {
2020 const [ sortOption , setSortOption ] = useState ( 'recommended' ) ;
2121 const [ activeNav , setActiveNav ] = useState ( 'MEN' ) ;
2222 const [ sneakersView , setSneakersView ] = useState ( false ) ;
23- const [ loggedInUser , setLoggedInUser ] = useState ( null ) ;
23+ const [ loggedInUser , setLoggedInUser ] = useState ( ( ) => {
24+ try { return JSON . parse ( localStorage . getItem ( 'zappify_user' ) ) || null ; } catch { return null ; }
25+ } ) ;
2426 const [ showCheckout , setShowCheckout ] = useState ( false ) ;
2527 const [ showAccount , setShowAccount ] = useState ( false ) ;
26- const [ placedOrders , setPlacedOrders ] = useState ( [ ] ) ;
28+ const [ placedOrders , setPlacedOrders ] = useState ( ( ) => {
29+ try { return JSON . parse ( localStorage . getItem ( 'zappify_orders' ) ) || [ ] ; } catch { return [ ] ; }
30+ } ) ;
31+
32+ const handleLogin = ( user ) => {
33+ setLoggedInUser ( user ) ;
34+ localStorage . setItem ( 'zappify_user' , JSON . stringify ( user ) ) ;
35+ } ;
36+
37+ const handleLogout = ( ) => {
38+ setLoggedInUser ( null ) ;
39+ localStorage . removeItem ( 'zappify_user' ) ;
40+ } ;
2741
2842 const toggleFilter = ( item , type ) => {
2943 if ( type === 'category' ) {
@@ -97,7 +111,7 @@ function App() {
97111 wishlistCount = { wishlistItems . length }
98112 activeNav = { activeNav }
99113 loggedInUser = { loggedInUser }
100- onLogout = { ( ) => setLoggedInUser ( null ) }
114+ onLogout = { handleLogout }
101115 onOpenAccount = { ( ) => setShowAccount ( true ) }
102116 />
103117
@@ -168,7 +182,7 @@ function App() {
168182 wishlistItems = { wishlistItems }
169183 onRemoveFromCart = { removeFromCart }
170184 onToggleWishlist = { toggleWishlist }
171- onLoginSuccess = { setLoggedInUser }
185+ onLoginSuccess = { handleLogin }
172186 onCheckout = { ( ) => { setActiveOverlay ( null ) ; setShowCheckout ( true ) ; } }
173187 />
174188 ) }
@@ -179,7 +193,12 @@ function App() {
179193 cartItems = { cartItems }
180194 onClose = { ( ) => setShowCheckout ( false ) }
181195 onRemoveFromCart = { removeFromCart }
182- onOrderPlaced = { ( items ) => setPlacedOrders ( prev => [ ...prev , ...items ] ) }
196+ onOrderPlaced = { ( items ) => {
197+ const updated = [ ...placedOrders , ...items ] ;
198+ setPlacedOrders ( updated ) ;
199+ localStorage . setItem ( 'zappify_orders' , JSON . stringify ( updated ) ) ;
200+ setCartItems ( [ ] ) ;
201+ } }
183202 />
184203 ) }
185204
@@ -188,7 +207,7 @@ function App() {
188207 user = { loggedInUser }
189208 orders = { placedOrders }
190209 onClose = { ( ) => setShowAccount ( false ) }
191- onLogout = { ( ) => { setLoggedInUser ( null ) ; setShowAccount ( false ) ; } }
210+ onLogout = { ( ) => { handleLogout ( ) ; setShowAccount ( false ) ; } }
192211 />
193212 ) }
194213 </ div >
@@ -197,9 +216,32 @@ function App() {
197216
198217const Overlay = ( { type, onClose, cartItems, wishlistItems, onRemoveFromCart, onToggleWishlist, onLoginSuccess, onCheckout } ) => {
199218 const [ isSignUp , setIsSignUp ] = useState ( false ) ;
219+ const [ formData , setFormData ] = useState ( { name : '' , email : '' , password : '' , confirm : '' } ) ;
220+ const [ error , setError ] = useState ( '' ) ;
200221 const isDrawer = type === 'cart' || type === 'wishlist' ;
201222 const cartTotal = cartItems . reduce ( ( sum , i ) => sum + i . price * i . qty , 0 ) ;
202223
224+ const handleAuth = ( ) => {
225+ setError ( '' ) ;
226+ if ( ! formData . email || ! formData . password ) { setError ( 'Please fill all fields' ) ; return ; }
227+ if ( isSignUp ) {
228+ if ( ! formData . name ) { setError ( 'Please enter your name' ) ; return ; }
229+ if ( formData . password !== formData . confirm ) { setError ( 'Passwords do not match' ) ; return ; }
230+ if ( formData . password . length < 6 ) { setError ( 'Password must be at least 6 characters' ) ; return ; }
231+ const user = { name : formData . name , email : formData . email , picture : `https://ui-avatars.com/api/?name=${ encodeURIComponent ( formData . name ) } &background=e85d04&color=fff` } ;
232+ onLoginSuccess ( user ) ;
233+ onClose ( ) ;
234+ } else {
235+ const saved = JSON . parse ( localStorage . getItem ( 'zappify_user' ) ) ;
236+ if ( saved && saved . email === formData . email ) {
237+ onLoginSuccess ( saved ) ;
238+ onClose ( ) ;
239+ } else {
240+ setError ( 'Account not found. Please sign up first.' ) ;
241+ }
242+ }
243+ } ;
244+
203245 return (
204246 < div className = "overlay-system" >
205247 < motion . div
@@ -300,11 +342,12 @@ const Overlay = ({ type, onClose, cartItems, wishlistItems, onRemoveFromCart, on
300342 < p > { isSignUp ? 'Join Zappify today' : 'Login to your Zappify account' } </ p >
301343
302344 < div className = "auth-form" >
303- { isSignUp && < input type = "text" placeholder = "Full Name" /> }
304- < input type = "email" placeholder = "Email Address" />
305- < input type = "password" placeholder = "Password" />
306- { isSignUp && < input type = "password" placeholder = "Confirm Password" /> }
307- < button className = "btn-primary auth-btn" > { isSignUp ? 'CREATE ACCOUNT' : 'SIGN IN' } </ button >
345+ { isSignUp && < input type = "text" placeholder = "Full Name" value = { formData . name } onChange = { e => setFormData ( { ...formData , name : e . target . value } ) } /> }
346+ < input type = "email" placeholder = "Email Address" value = { formData . email } onChange = { e => setFormData ( { ...formData , email : e . target . value } ) } />
347+ < input type = "password" placeholder = "Password" value = { formData . password } onChange = { e => setFormData ( { ...formData , password : e . target . value } ) } />
348+ { isSignUp && < input type = "password" placeholder = "Confirm Password" value = { formData . confirm } onChange = { e => setFormData ( { ...formData , confirm : e . target . value } ) } /> }
349+ { error && < p className = "auth-error" > { error } </ p > }
350+ < button className = "btn-primary auth-btn" onClick = { handleAuth } > { isSignUp ? 'CREATE ACCOUNT' : 'SIGN IN' } </ button >
308351 < div className = "separator" > < span > OR CONTINUE WITH</ span > </ div >
309352 < div className = "google-btn-wrap" >
310353 < GoogleLogin
0 commit comments