Nevar pievienot vairāk kā 25 tēmas Tēmai ir jāsākas ar burtu vai ciparu, tā var saturēt domu zīmes ('-') un var būt līdz 35 simboliem gara.

Navbar.jsx 5.7KB

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