AdminPage.jsx 6.0 KB

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