ProfilePage.jsx 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186
  1. import React from 'react';
  2. import {Box, Container, Typography, useMediaQuery} from "@mui/material";
  3. import PropTypes from "prop-types";
  4. import {useState} from "react";
  5. import {timeCalc} from "../ProductPage/timeCalc";
  6. import Breadcrumb from "../../components/Breadcrumbs";
  7. import Tabs from "@mui/material/Tabs";
  8. import Tab from "@mui/material/Tab";
  9. import {CMainOrders} from "../MyOrdersPage/MainOrders";
  10. import {CMainWishList} from "../WishListPage/MainWishList";
  11. import {connect} from "react-redux";
  12. import {actionAuthLogout} from "../../reducers/AuthReducer";
  13. import {actionUserRemove} from "../../reducers/UserReducer";
  14. import {AccountDetails} from "./AccountDetails";
  15. function TabPanel(props) {
  16. const { children, value, index, ...other } = props;
  17. return (
  18. <div
  19. role="tabpanel"
  20. hidden={value !== index}
  21. id={`vertical-tabpanel-${index}`}
  22. aria-labelledby={`vertical-tab-${index}`}
  23. style={{width: '100%'}}
  24. {...other}
  25. >
  26. {value === index && (
  27. <Box sx={{ p: 3}}>
  28. <Box>
  29. {children}
  30. </Box>
  31. </Box>
  32. )}
  33. </div>
  34. );
  35. }
  36. TabPanel.propTypes = {
  37. children: PropTypes.node,
  38. index: PropTypes.number.isRequired,
  39. value: PropTypes.number.isRequired,
  40. };
  41. function a11yProps(index) {
  42. return {
  43. id: `vertical-tab-${index}`,
  44. 'aria-controls': `vertical-tabpanel-${index}`,
  45. };
  46. }
  47. const ProfilePage = ({user = {}, promise, authLogOut, userLogOut}) => {
  48. const matches = useMediaQuery('(max-width:899px)')
  49. const matches2 = useMediaQuery('(max-width:768px)')
  50. const [value, setValue] = useState(0)
  51. const handleChange = (event, newValue) => {
  52. setValue(newValue);
  53. };
  54. let formattedTime = 0;
  55. if (Object.keys(user).length !== 0) {
  56. formattedTime = timeCalc(+user.createdAt);
  57. }
  58. const handleLogOut = () => {
  59. authLogOut();
  60. userLogOut();
  61. }
  62. return (
  63. Object.keys(user).length > 1 &&
  64. <>
  65. <Breadcrumb links={['Profile']}/>
  66. <main
  67. style={{
  68. backgroundColor: "#f3f3f3",
  69. padding: matches ? "20px 0" : "50px 0",
  70. minHeight:'300px'
  71. }}
  72. >
  73. <Container maxWidth="lg">
  74. <Box>
  75. <Typography
  76. variant='h5'
  77. textAlign='center'
  78. fontFamily='sarif'
  79. marginBottom={matches ? '20px':'40px'}
  80. >
  81. LOGGED IN AS
  82. <strong>
  83. { ` ${user?.login.toUpperCase()}` || 'login' }
  84. </strong>
  85. </Typography>
  86. </Box>
  87. <Box
  88. sx={{
  89. flexGrow: 1,
  90. bgcolor: '#fff',
  91. display: 'flex',
  92. height: '100%',
  93. alignItems: 'center'
  94. }}
  95. flexDirection={matches2 ? 'column': "row"}
  96. >
  97. <Tabs
  98. orientation={matches2 ? 'horizontal': "vertical"}
  99. variant="scrollable"
  100. value={value}
  101. onChange={handleChange}
  102. aria-label="Profile settings"
  103. sx={{
  104. borderRight: 1,
  105. borderColor: 'divider',
  106. padding: '50px 0',
  107. height: '100%'
  108. }}
  109. >
  110. <Tab
  111. sx={{
  112. padding: '0 50px',
  113. textAlign: 'center'
  114. }}
  115. label={'ACCOUNT DETAILS'}
  116. {...a11yProps(0)}
  117. />
  118. <Tab
  119. sx={{
  120. padding: '0 50px',
  121. textAlign: 'center'
  122. }}
  123. label={'my orders'}
  124. {...a11yProps(1)}
  125. />
  126. <Tab
  127. sx={{
  128. padding: '0 50px',
  129. textAlign: 'center'
  130. }}
  131. label={'wish list'}
  132. {...a11yProps(2)}
  133. />
  134. <Tab
  135. sx={{
  136. padding: '0 50px',
  137. textAlign: 'center'
  138. }}
  139. label={'Logout'}
  140. onClick={handleLogOut}
  141. {...a11yProps(2)}
  142. />
  143. </Tabs>
  144. <TabPanel
  145. value={value}
  146. index={0}
  147. >
  148. <AccountDetails
  149. user={user}
  150. promise={promise}
  151. time={formattedTime}
  152. />
  153. </TabPanel>
  154. <TabPanel
  155. value={value}
  156. index={1}
  157. >
  158. <CMainOrders itemsPerPage={5} />
  159. </TabPanel>
  160. <TabPanel
  161. value={value}
  162. index={2}
  163. >
  164. <CMainWishList color={'#fff'}/>
  165. </TabPanel>
  166. </Box>
  167. </Container>
  168. </main>
  169. </>
  170. )
  171. }
  172. export const CProfilePage = connect(state => ({
  173. user: state.user,
  174. promise: state.promise}),
  175. {
  176. authLogOut: actionAuthLogout,
  177. userLogOut: actionUserRemove})
  178. (ProfilePage)