ProfilePage.jsx 6.4 KB

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