AdminPage.jsx 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200
  1. import {
  2. BottomNavigationAction,
  3. Container,
  4. useMediaQuery
  5. } from "@mui/material";
  6. import Breadcrumb from "../../components/Breadcrumbs";
  7. import PropTypes from 'prop-types';
  8. import SwipeableViews from 'react-swipeable-views';
  9. import { useTheme } from '@mui/material/styles';
  10. import AppBar from '@mui/material/AppBar';
  11. import Tabs from '@mui/material/Tabs';
  12. import Tab from '@mui/material/Tab';
  13. import Box from '@mui/material/Box';
  14. import {useEffect, useState} from "react";
  15. import PersonIcon from '@mui/icons-material/Person';
  16. import CategoryIcon from '@mui/icons-material/Category';
  17. import AutoAwesomeIcon from '@mui/icons-material/AutoAwesome';
  18. import BottomNavigation from '@mui/material/BottomNavigation';
  19. import AddCircleOutlineIcon from '@mui/icons-material/AddCircleOutline';
  20. import EditIcon from '@mui/icons-material/Edit';
  21. import {CClients} from "./ClientsTab/ClientsTab";
  22. import {CGoodEdit} from "./GoodsTab/GoodEdit";
  23. import {CFindGoodEdit} from "./GoodsTab/FindGoodEdit";
  24. import {CCategoryEdit} from "./CategoriesTab/CategoryEdit";
  25. import {CCategoryEditTree, CCCategoryEditTree} from "./CategoriesTab/CCategoryEditTree";
  26. import {actionClearPromise} from "../../reducers/PromiseReducer";
  27. import {connect} from "react-redux";
  28. const defaultTabs = [
  29. {icon: PersonIcon, text: 'clients'},
  30. {icon: CategoryIcon, text: 'categories'},
  31. {icon: AutoAwesomeIcon, text: 'products'}
  32. ]
  33. const IconHeader = ({Icon}) => {
  34. return <Icon style={{marginRight: '10px'}} />
  35. }
  36. function TabPanel(props) {
  37. const { children, value, index, ...other } = props;
  38. return (
  39. <div
  40. role="tabpanel"
  41. hidden={value !== index}
  42. id={`full-width-tabpanel-${index}`}
  43. aria-labelledby={`full-width-tab-${index}`}
  44. {...other}
  45. >
  46. {value === index && (
  47. <Box sx={{ p: 3 }}>
  48. <Box>{children}</Box>
  49. </Box>
  50. )}
  51. </div>
  52. );
  53. }
  54. TabPanel.propTypes = {
  55. children: PropTypes.node,
  56. index: PropTypes.number.isRequired,
  57. value: PropTypes.number.isRequired,
  58. };
  59. function a11yProps(index) {
  60. return {
  61. id: `full-width-tab-${index}`,
  62. 'aria-controls': `full-width-tabpanel-${index}`,
  63. };
  64. }
  65. const SelectBlock = ({Block, FindBlock, actionClear}) => {
  66. const [value, setValue] = useState('create');
  67. useEffect(()=>{
  68. actionClear('uploadFile')
  69. }, [value])
  70. return (
  71. <>
  72. <Box
  73. sx={{
  74. width: '100%',
  75. display:'flex',
  76. justifyContent: 'center',
  77. alignItems: 'center',
  78. marginBottom: '20px'
  79. }}
  80. >
  81. <BottomNavigation
  82. showLabels
  83. sx={{width: '100%'}}
  84. value={value}
  85. onChange={(event, newValue) => {
  86. setValue(newValue);
  87. }}
  88. >
  89. <BottomNavigationAction
  90. value={'create'}
  91. label="Create"
  92. icon={<AddCircleOutlineIcon />}
  93. />
  94. <BottomNavigationAction
  95. value={'edit'}
  96. label="Edit"
  97. icon={<EditIcon />}
  98. />
  99. </BottomNavigation>
  100. </Box>
  101. {value === 'create' ?
  102. <Block/> : <FindBlock/>
  103. }
  104. </>
  105. )
  106. }
  107. const CSelectBlock = connect(null, {actionClear: actionClearPromise})(SelectBlock)
  108. const FullWidthTabs = () => {
  109. const theme = useTheme();
  110. const [value, setValue] = useState(0);
  111. const handleChange = (event, newValue) => {
  112. setValue(newValue);
  113. };
  114. const handleChangeIndex = (index) => {
  115. setValue(index);
  116. };
  117. return (
  118. <Box
  119. sx={{
  120. bgcolor: '#fff',
  121. width: '100%',
  122. borderRadius: '20px',
  123. borderTopLeftRadius: '20px',
  124. borderTopRightRadius: '20px',
  125. overflow: 'hidden'
  126. }}
  127. >
  128. <AppBar
  129. position="static"
  130. sx={{boxShadow: 'none'}}
  131. >
  132. <Tabs
  133. value={value}
  134. onChange={handleChange}
  135. TabIndicatorProps={{style: {background:'#616161', height: '1px'}}}
  136. textColor="inherit"
  137. sx={{backgroundColor:'#fff', color: '#000'}}
  138. variant="fullWidth"
  139. aria-label="full width tabs example"
  140. >
  141. {defaultTabs.map((item, index) =>
  142. <Tab
  143. key={index}
  144. icon={<IconHeader Icon={item.icon}/>}
  145. iconPosition="start"
  146. label={item.text}
  147. sx={{borderBottom: '1px solid #dedede'}}
  148. {...a11yProps(index)}
  149. />
  150. )}
  151. </Tabs>
  152. </AppBar>
  153. <SwipeableViews
  154. axis={theme.direction === 'rtl' ? 'x-reverse' : 'x'}
  155. index={value}
  156. onChangeIndex={handleChangeIndex}
  157. >
  158. <TabPanel value={value} index={0} dir={theme.direction}>
  159. {/*<CClients/>*/}
  160. </TabPanel>
  161. <TabPanel value={value} index={1} dir={theme.direction}>
  162. <CSelectBlock Block={CCategoryEdit} FindBlock={CCCategoryEditTree}/>
  163. </TabPanel>
  164. <TabPanel value={value} index={2} dir={theme.direction}>
  165. {/*<CSelectBlock Block={CGoodEdit} FindBlock={CFindGoodEdit}/>*/}
  166. </TabPanel>
  167. </SwipeableViews>
  168. </Box>
  169. );
  170. }
  171. const AdminPage = () => {
  172. const matches = useMediaQuery('(max-width:768px)')
  173. return(
  174. <>
  175. <Breadcrumb links={['admin']} title={'Dashboard'}/>
  176. <main
  177. style={{
  178. backgroundColor: "#f3f3f3",
  179. padding: matches ? "20px 0" : "50px 0",
  180. minHeight:'300px'
  181. }}
  182. >
  183. <Container maxWidth="lg">
  184. <FullWidthTabs/>
  185. </Container>
  186. </main>
  187. </>
  188. )
  189. }
  190. export default AdminPage