Vous ne pouvez pas sélectionner plus de 25 sujets Les noms de sujets doivent commencer par une lettre ou un nombre, peuvent contenir des tirets ('-') et peuvent comporter jusqu'à 35 caractères.

Navbar.jsx 5.8KB

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