You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

Navbar.jsx 5.7KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217
  1. import AppBar from '@mui/material/AppBar';
  2. import Box from '@mui/material/Box';
  3. import Typography from '@mui/material/Typography';
  4. import { signOut, useSession } from 'next-auth/react';
  5. import Image from 'next/image';
  6. import Link from 'next/link';
  7. import { useRouter } from 'next/router';
  8. import {
  9. BASE_PAGE,
  10. CART_PAGE,
  11. PRODUCTS_PAGE,
  12. PROFILE_PAGE,
  13. } from '../../../constants/pages';
  14. import { useStore } from '../../../store/cart-context';
  15. const Navbar = () => {
  16. const router = useRouter();
  17. const { totalQuantity } = useStore();
  18. const { data: session } = useSession();
  19. const signOutHandler = async () => {
  20. const data = await signOut({ redirect: false, callbackUrl: '/' });
  21. router.push(data.url);
  22. };
  23. return (
  24. <AppBar
  25. position="absolute"
  26. sx={{
  27. zIndex: 100,
  28. top: 20,
  29. width: '100%',
  30. backgroundColor: 'transparent',
  31. boxShadow: 'none',
  32. height: 40,
  33. }}
  34. >
  35. <Box sx={{ display: 'flex', width: '100%' }}>
  36. <Box
  37. sx={{
  38. flexGrow: 1,
  39. maxWidth: '50%',
  40. height: 30,
  41. display: 'flex',
  42. px: 10,
  43. }}
  44. >
  45. <Link key="home" href={BASE_PAGE}>
  46. <Typography
  47. textAlign="center"
  48. sx={{
  49. mx: 'auto',
  50. fontSize: { md: 20, xs: 17 },
  51. fontWeight: 500,
  52. mr: { lg: 0, xs: 2 },
  53. color: router.pathname === '/' ? 'white' : 'black',
  54. textDecoration: 'none',
  55. cursor: 'pointer',
  56. }}
  57. >
  58. Home
  59. </Typography>
  60. </Link>
  61. <Link key="menu" href={BASE_PAGE}>
  62. <Typography
  63. textAlign="center"
  64. sx={{
  65. mx: 'auto',
  66. fontSize: { md: 20, xs: 17 },
  67. fontWeight: 500,
  68. mr: { lg: 0, xs: 2 },
  69. color: router.pathname === '/' ? 'white' : 'black',
  70. textDecoration: 'none',
  71. cursor: 'pointer',
  72. }}
  73. >
  74. Menu
  75. </Typography>
  76. </Link>
  77. <Link key="about" href={BASE_PAGE}>
  78. <Typography
  79. textAlign="center"
  80. sx={{
  81. mx: 'auto',
  82. fontSize: { md: 20, xs: 17 },
  83. fontWeight: 500,
  84. mr: { lg: 0, xs: 2 },
  85. color: router.pathname === '/' ? 'white' : 'black',
  86. textDecoration: 'none',
  87. cursor: 'pointer',
  88. }}
  89. >
  90. About
  91. </Typography>
  92. </Link>
  93. <Link key="store" href={PRODUCTS_PAGE}>
  94. <Typography
  95. textAlign="center"
  96. sx={{
  97. mx: 'auto',
  98. fontSize: { md: 20, xs: 17 },
  99. fontWeight: 500,
  100. mr: { lg: 0, xs: 2 },
  101. color: router.pathname === '/' ? 'white' : 'black',
  102. textDecoration: 'none',
  103. cursor: 'pointer',
  104. }}
  105. >
  106. Store
  107. </Typography>
  108. </Link>
  109. <Link key="contact" href={BASE_PAGE}>
  110. <Typography
  111. textAlign="center"
  112. sx={{
  113. mx: 'auto',
  114. fontSize: { md: 20, xs: 17 },
  115. fontWeight: 500,
  116. color: router.pathname === '/' ? 'white' : 'black',
  117. textDecoration: 'none',
  118. cursor: 'pointer',
  119. }}
  120. >
  121. Contact
  122. </Typography>
  123. </Link>
  124. </Box>
  125. <Box
  126. sx={{
  127. flexGrow: 1,
  128. maxWidth: '50%',
  129. height: 30,
  130. display: 'flex',
  131. justifyContent: 'right',
  132. pt: 0.5,
  133. mr: 4,
  134. }}
  135. >
  136. {session?.user?._id && (
  137. <Box
  138. sx={{
  139. mx: 2,
  140. mt: 0.1,
  141. cursor: 'pointer',
  142. }}
  143. onClick={signOutHandler}
  144. >
  145. <Image
  146. src="/images/logout.svg"
  147. alt="profile"
  148. width={18}
  149. height={20}
  150. />
  151. </Box>
  152. )}
  153. <Box
  154. sx={{
  155. mx: 2,
  156. cursor: 'pointer',
  157. }}
  158. >
  159. <Link key="home" href={PROFILE_PAGE}>
  160. <Image
  161. src="/images/profile.svg"
  162. alt="profile"
  163. width={24}
  164. height={24}
  165. />
  166. </Link>
  167. </Box>
  168. <Box
  169. sx={{
  170. mr: 6,
  171. ml: 2,
  172. cursor: 'pointer',
  173. }}
  174. >
  175. <Link key="home" href={CART_PAGE}>
  176. <Box>
  177. <Box
  178. sx={{
  179. color: 'white',
  180. zIndex: 3,
  181. width: 20,
  182. height: 20,
  183. borderRadius: 20,
  184. textAlign: 'center',
  185. px: 0.5,
  186. ml: 2.2,
  187. mt: -1,
  188. fontSize: 16,
  189. position: 'absolute',
  190. backgroundColor: 'primary.main',
  191. }}
  192. >
  193. {totalQuantity}
  194. </Box>
  195. <Image
  196. src="/images/cart.svg"
  197. alt="cart"
  198. width={24}
  199. height={24}
  200. />
  201. </Box>
  202. </Link>
  203. </Box>
  204. </Box>
  205. </Box>
  206. </AppBar>
  207. );
  208. };
  209. export default Navbar;