| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218 |
- import AppBar from '@mui/material/AppBar';
- import Box from '@mui/material/Box';
- import Typography from '@mui/material/Typography';
- import { signOut, useSession } from 'next-auth/react';
- import Image from 'next/image';
- import Link from 'next/link';
- import { useRouter } from 'next/router';
- import {
- BASE_PAGE,
- CART_PAGE,
- CONTACT_PAGE,
- PRODUCTS_PAGE,
- PROFILE_PAGE,
- } from '../../../constants/pages';
- import { useStore } from '../../../store/cart-context';
-
- const Navbar = () => {
- const router = useRouter();
- const { totalQuantity } = useStore();
- const { data: session } = useSession();
-
- const signOutHandler = async () => {
- const data = await signOut({ redirect: false, callbackUrl: '/' });
- router.push(data.url);
- };
-
- return (
- <AppBar
- position="absolute"
- sx={{
- zIndex: 100,
- top: 20,
- width: '100%',
- backgroundColor: 'transparent',
- boxShadow: 'none',
- height: 40,
- }}
- >
- <Box sx={{ display: 'flex', width: '100%' }}>
- <Box
- sx={{
- flexGrow: 1,
- maxWidth: '50%',
- height: 30,
- display: 'flex',
- px: 10,
- }}
- >
- <Link key="home" href={BASE_PAGE}>
- <Typography
- textAlign="center"
- sx={{
- mx: 'auto',
- fontSize: { md: 20, xs: 17 },
- fontWeight: 500,
- mr: { lg: 0, xs: 2 },
- color: router.pathname === '/' ? 'white' : 'black',
- textDecoration: 'none',
- cursor: 'pointer',
- }}
- >
- Home
- </Typography>
- </Link>
-
- <Link key="menu" href={BASE_PAGE}>
- <Typography
- textAlign="center"
- sx={{
- mx: 'auto',
- fontSize: { md: 20, xs: 17 },
- fontWeight: 500,
- mr: { lg: 0, xs: 2 },
- color: router.pathname === '/' ? 'white' : 'black',
- textDecoration: 'none',
- cursor: 'pointer',
- }}
- >
- Menu
- </Typography>
- </Link>
-
- <Link key="about" href={BASE_PAGE}>
- <Typography
- textAlign="center"
- sx={{
- mx: 'auto',
- fontSize: { md: 20, xs: 17 },
- fontWeight: 500,
- mr: { lg: 0, xs: 2 },
- color: router.pathname === '/' ? 'white' : 'black',
- textDecoration: 'none',
- cursor: 'pointer',
- }}
- >
- About
- </Typography>
- </Link>
-
- <Link key="store" href={PRODUCTS_PAGE}>
- <Typography
- textAlign="center"
- sx={{
- mx: 'auto',
- fontSize: { md: 20, xs: 17 },
- fontWeight: 500,
- mr: { lg: 0, xs: 2 },
- color: router.pathname === '/' ? 'white' : 'black',
- textDecoration: 'none',
- cursor: 'pointer',
- }}
- >
- Store
- </Typography>
- </Link>
-
- <Link key="contact" href={CONTACT_PAGE}>
- <Typography
- textAlign="center"
- sx={{
- mx: 'auto',
- fontSize: { md: 20, xs: 17 },
- fontWeight: 500,
- color: router.pathname === '/' ? 'white' : 'black',
- textDecoration: 'none',
- cursor: 'pointer',
- }}
- >
- Contact
- </Typography>
- </Link>
- </Box>
- <Box
- sx={{
- flexGrow: 1,
- maxWidth: '50%',
- height: 30,
- display: 'flex',
- justifyContent: 'right',
- pt: 0.5,
- mr: 4,
- }}
- >
- {session?.user?._id && (
- <Box
- sx={{
- mx: 2,
- mt: 0.1,
- cursor: 'pointer',
- }}
- onClick={signOutHandler}
- >
- <Image
- src="/images/logout.svg"
- alt="profile"
- width={18}
- height={20}
- />
- </Box>
- )}
- <Box
- sx={{
- mx: 2,
- cursor: 'pointer',
- }}
- >
- <Link key="home" href={PROFILE_PAGE}>
- <Image
- src="/images/profile.svg"
- alt="profile"
- width={24}
- height={24}
- />
- </Link>
- </Box>
- <Box
- sx={{
- mr: 6,
- ml: 2,
- cursor: 'pointer',
- }}
- >
- <Link key="home" href={CART_PAGE}>
- <Box>
- <Box
- sx={{
- color: 'white',
- zIndex: 3,
- width: 20,
- height: 20,
- borderRadius: 20,
- textAlign: 'center',
- px: 0.5,
- ml: 2.2,
- mt: -1,
- fontSize: 16,
- position: 'absolute',
- backgroundColor: 'primary.main',
- }}
- >
- {totalQuantity}
- </Box>
- <Image
- src="/images/cart.svg"
- alt="cart"
- width={24}
- height={24}
- />
- </Box>
- </Link>
- </Box>
- </Box>
- </Box>
- </AppBar>
- );
- };
-
- export default Navbar;
|