forked from ahmod001/grocery
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
14 changed files
with
265 additions
and
20 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,10 @@ | ||
import { Visibility, VisibilityOff } from '@mui/icons-material'; | ||
import { Button, Container, Fade, IconButton, InputAdornment, TextField } from '@mui/material'; | ||
import { useState } from 'react'; | ||
import { Alert, Button, Collapse, Container, Fade, IconButton, InputAdornment, TextField } from '@mui/material'; | ||
import { useContext, useState } from 'react'; | ||
import { useForm } from "react-hook-form"; | ||
import animation from '../../../assets/animations/loginAnimation.gif'; | ||
import { groceryContext } from '../../Layout/Layout'; | ||
import { useLocation, useNavigate } from 'react-router-dom'; | ||
|
||
const Login = () => { | ||
const { register, handleSubmit, formState: { errors } } = useForm(); | ||
|
@@ -12,19 +14,28 @@ const Login = () => { | |
// Scrolling Bug Fixed | ||
window.scroll({ top: 0 }); | ||
|
||
const navigate = useNavigate(); | ||
const location = useLocation(); | ||
const { from } = location.state || { from: { pathname: '/' } } | ||
|
||
const { userLoggedInState } = useContext(groceryContext); | ||
// Login handler | ||
const onSubmit = data => { | ||
const defaultUser = { | ||
email: '[email protected]', | ||
password: 'User1234' | ||
} | ||
const [isUserLoggedIn, setIsUserLoggedIn] = userLoggedInState; | ||
|
||
if (defaultUser.email !== data.email) { | ||
setLogInError("You entered wrong email") | ||
setLogInError("Invalid email") | ||
} else if (defaultUser.password !== data.password) { | ||
setLogInError('You entered the password') | ||
setLogInError('Invalid password') | ||
} else { | ||
setLogInError('') | ||
sessionStorage.setItem('userLoggedIn', JSON.stringify(true)) | ||
setIsUserLoggedIn(true) | ||
navigate(from) | ||
} | ||
}; | ||
|
||
|
@@ -103,6 +114,10 @@ const Login = () => { | |
}} | ||
/> | ||
|
||
{/* Display the alert only if there is a login error */} | ||
{logInError && | ||
<></> | ||
} | ||
{/* Submit-btn */} | ||
<Button | ||
sx={{ textTransform: 'capitalize' }} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
import { useNavigate } from "react-router-dom"; | ||
import EmptyCart from './EmptyCart/EmptyCart'; | ||
import { Container, Fade } from "@mui/material"; | ||
import { useState } from "react"; | ||
import OrderSummary from "./OrderSummary/OrderSummary"; | ||
import CartItems from "./CartItems/CartItems"; | ||
|
||
const Cart = () => { | ||
// Scrolling Bug Fixed | ||
window.scroll({ top: 0 }); | ||
const [isCartEmpty, setIsCartEmpty] = useState(false) | ||
const navigate = useNavigate(); | ||
|
||
return ( | ||
<section className='h-screen pt-16'> | ||
|
||
{ | ||
!isCartEmpty ? | ||
// Main Layout | ||
<Container sx={{ display: 'flex', justifyContent: 'center', alignItems: 'center', height: '100%' }}> | ||
<section className="grid gap-8 w-full lg:grid-cols-3 md:grid-cols-2 "> | ||
<CartItems /> | ||
<OrderSummary /> | ||
</section> | ||
</Container> | ||
|
||
// If the cart is empty this component will show | ||
: <EmptyCart /> | ||
} | ||
</section> | ||
); | ||
}; | ||
|
||
export default Cart; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
import { Fade, IconButton, Tooltip } from '@mui/material'; | ||
import {Close} from '@mui/icons-material'; | ||
|
||
const CartItemCard = () => { | ||
return ( | ||
<Fade in={true}> | ||
<div className='grid grid-cols-3 gap-x-2.5 rounded-xl w-full bg-gray-100'> | ||
{/* Meal Img */} | ||
<div className='col py-2 pl-1.5 '> | ||
<img src={''} className='cursor-pointer' alt={''} /> | ||
</div> | ||
|
||
{/* Meal Name & Price*/} | ||
<div className='col py-2 flex'> | ||
<div className='my-auto overflow-hidden space-y-1'> | ||
<h4 className='font-semibold text-xs'>{'nam'}</h4> | ||
<h4 className='text-lg font-bold text-red-600'>${'price'}</h4> | ||
<h6 className='text-xs text-gray-400'>Best in quality</h6> | ||
</div> | ||
</div> | ||
|
||
{/* Actions */} | ||
<div className='space-y-3.5 lg:py-0.5 lg:pr-0.5 py-2 pr-1.5'> | ||
|
||
{/* Remove_from_cart Btn */} | ||
<div className='flex justify-end'> | ||
<Tooltip | ||
placement='top-end' | ||
title={'Remove'}> | ||
<IconButton | ||
// onClick={handleRemove} | ||
size='small'> | ||
<Close fontSize='inherit' /> | ||
</IconButton> | ||
</Tooltip> | ||
</div> | ||
|
||
{/* set Quantity */} | ||
<div className='flex align-middle'> | ||
{/* <QuantityController | ||
cartItemCard={true} | ||
meal={meal} | ||
mealQuantity={mealQuantity} | ||
setMealQuantity={setMealQuantity} /> */} | ||
</div> | ||
</div> | ||
</div> | ||
</Fade> | ||
); | ||
}; | ||
|
||
export default CartItemCard; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
import React from 'react'; | ||
import CartItemCard from '../CartItemCard/CartItemCard'; | ||
|
||
const CartItems = () => { | ||
return ( | ||
<div className='col lg:col-span-2 space-y-3.5 '> | ||
{/* Title */} | ||
<h2 className='sm:text-2xl text-lg sm:font-semibold font-bold '>Selected Items</h2> | ||
<CartItemCard /> | ||
</div> | ||
); | ||
}; | ||
|
||
export default CartItems; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
import { Button, Container, Fade } from '@mui/material'; | ||
import React from 'react'; | ||
import { useNavigate } from 'react-router-dom'; | ||
|
||
const EmptyCart = () => { | ||
const navigate = useNavigate(); | ||
|
||
return ( | ||
<Fade in={true}> | ||
<Container sx={{ display: 'flex', justifyContent: 'center', alignItems: 'center', height: '100%' }}> | ||
<div className='text-center md:space-y-4 space-y-3.5 text-gray-500'> | ||
<h6 className='text-sm'>There are no items in this cart</h6> | ||
<Button | ||
onClick={() => navigate('/products')} | ||
size='large' | ||
color='success' | ||
sx={{ textTransform: 'capitalize' }} | ||
variant='outlined'> | ||
Continue Shopping | ||
</Button> | ||
</div> | ||
</Container> | ||
</Fade> | ||
); | ||
}; | ||
|
||
export default EmptyCart; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
import { Button } from '@mui/material'; | ||
|
||
const OrderSummary = () => { | ||
return ( | ||
<div className='flex justify-center'> | ||
<div className='sm:space-y-5 w-full max-w-[25rem] space-y-4'> | ||
{/* Title */} | ||
<h3 className='sm:text-xl text-lg sm:font-semibold font-bold tracking-wide'>Order Summary</h3> | ||
|
||
{/* Total Bill */} | ||
<table className='table-auto h-28 text-sm w-full'> | ||
<tbody> | ||
{/* Subtotal */} | ||
<tr className='font-medium text-gray-800'> | ||
<td>Subtotal</td> | ||
<td>$ 1200 USD</td> | ||
</tr> | ||
{/* Delivery Charge */} | ||
<tr className='font-medium text-gray-800'> | ||
<td>Delivery charge</td> | ||
<td>$ 12 USD</td> | ||
</tr> | ||
{/* Total */} | ||
<tr className='font-medium text-lg'> | ||
<td>Total</td> | ||
<td style={{color: 'green'}}>$ 1212 USD</td> | ||
</tr> | ||
</tbody> | ||
</table> | ||
|
||
{/* Proceed to checkout */} | ||
<Button | ||
fullWidth | ||
// onClick={handlePlaceOrder} | ||
sx={{ textTransform: 'capitalize', display: 'block' }} | ||
variant='contained' | ||
color='success'> | ||
Proceed to checkout | ||
</Button> | ||
</div> | ||
</div> | ||
); | ||
}; | ||
|
||
export default OrderSummary; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.