AdminPage.jsx 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153
  1. import {
  2. Avatar,
  3. BottomNavigationAction,
  4. Button, Card, CardContent, CardHeader, Checkbox, CircularProgress, Collapse,
  5. Container, Divider,
  6. FormControl,
  7. Grid,
  8. InputLabel, MenuItem, Pagination, Select, Switch,
  9. TextField,
  10. useMediaQuery
  11. } from "@mui/material";
  12. import Breadcrumb from "../../components/Breadcrumbs";
  13. import PropTypes from 'prop-types';
  14. import SwipeableViews from 'react-swipeable-views';
  15. import { useTheme } from '@mui/material/styles';
  16. import AppBar from '@mui/material/AppBar';
  17. import Tabs from '@mui/material/Tabs';
  18. import Tab from '@mui/material/Tab';
  19. import Typography from '@mui/material/Typography';
  20. import Box from '@mui/material/Box';
  21. import {useState} from "react";
  22. import PersonIcon from '@mui/icons-material/Person';
  23. import CategoryIcon from '@mui/icons-material/Category';
  24. import AutoAwesomeIcon from '@mui/icons-material/AutoAwesome';
  25. import BottomNavigation from '@mui/material/BottomNavigation';
  26. import AddCircleOutlineIcon from '@mui/icons-material/AddCircleOutline';
  27. import EditIcon from '@mui/icons-material/Edit';
  28. import {CFindGoodEdit, CGoodEdit, FindGoodEdit} from "./GoodTab";
  29. import {CClients} from "./ClientsTab";
  30. import {CCategoryEdit, CCategoryEditTree} from "./CateforyTab";
  31. const defaultTabs = [{icon: PersonIcon, text: 'clients'}, {icon: CategoryIcon, text: 'categories'}, {icon: AutoAwesomeIcon, text: 'products'}]
  32. const IconHeader = ({Icon}) => {
  33. return <Icon style={{marginRight: '10px'}} />
  34. }
  35. function TabPanel(props) {
  36. const { children, value, index, ...other } = props;
  37. return (
  38. <div
  39. role="tabpanel"
  40. hidden={value !== index}
  41. id={`full-width-tabpanel-${index}`}
  42. aria-labelledby={`full-width-tab-${index}`}
  43. {...other}
  44. >
  45. {value === index && (
  46. <Box sx={{ p: 3 }}>
  47. <Typography>{children}</Typography>
  48. </Box>
  49. )}
  50. </div>
  51. );
  52. }
  53. TabPanel.propTypes = {
  54. children: PropTypes.node,
  55. index: PropTypes.number.isRequired,
  56. value: PropTypes.number.isRequired,
  57. };
  58. function a11yProps(index) {
  59. return {
  60. id: `full-width-tab-${index}`,
  61. 'aria-controls': `full-width-tabpanel-${index}`,
  62. };
  63. }
  64. const SelectBlock = ({Block, FindBlock}) => {
  65. const [value, setValue] = useState('create');
  66. return (
  67. <>
  68. <Box sx={{width: '100%', display:'flex', justifyContent: 'center', alignItems: 'center', marginBottom: '20px'}}>
  69. <BottomNavigation
  70. showLabels
  71. sx={{width: '100%'}}
  72. value={value}
  73. onChange={(event, newValue) => {
  74. setValue(newValue);
  75. }}
  76. >
  77. <BottomNavigationAction value={'create'} label="Create" icon={<AddCircleOutlineIcon />} />
  78. <BottomNavigationAction value={'edit'} label="Edit" icon={<EditIcon />} />
  79. </BottomNavigation>
  80. </Box>
  81. {value === 'create' ?
  82. <Block/> : <FindBlock/>
  83. }
  84. </>
  85. )
  86. }
  87. const FullWidthTabs = () => {
  88. const theme = useTheme();
  89. const [value, setValue] = useState(0);
  90. const handleChange = (event, newValue) => {
  91. setValue(newValue);
  92. };
  93. const handleChangeIndex = (index) => {
  94. setValue(index);
  95. };
  96. return (
  97. <Box sx={{ bgcolor: '#fff', width: '100%', borderRadius: '20px', borderTopLeftRadius: '20px', borderTopRightRadius: '20px', overflow: 'hidden'}}>
  98. <AppBar position="static" sx={{boxShadow: 'none'}}>
  99. <Tabs
  100. value={value}
  101. onChange={handleChange}
  102. TabIndicatorProps={{style: {background:'#616161', height: '1px'}}}
  103. textColor="inherit"
  104. sx={{backgroundColor:'#fff', color: '#000'}}
  105. variant="fullWidth"
  106. aria-label="full width tabs example"
  107. >
  108. {defaultTabs.map((item, index) =>
  109. <Tab key={index} icon={<IconHeader Icon={item.icon}/>} iconPosition="start" label={item.text} sx={{borderBottom: '1px solid #dedede'}} {...a11yProps(index)}/>
  110. )}
  111. </Tabs>
  112. </AppBar>
  113. <SwipeableViews
  114. axis={theme.direction === 'rtl' ? 'x-reverse' : 'x'}
  115. index={value}
  116. onChangeIndex={handleChangeIndex}
  117. >
  118. <TabPanel value={value} index={0} dir={theme.direction}>
  119. <CClients/>
  120. </TabPanel>
  121. <TabPanel value={value} index={1} dir={theme.direction}>
  122. <SelectBlock Block={CCategoryEdit} FindBlock={CCategoryEditTree}/>
  123. </TabPanel>
  124. <TabPanel value={value} index={2} dir={theme.direction}>
  125. <SelectBlock Block={CGoodEdit} FindBlock={CFindGoodEdit}/>
  126. </TabPanel>
  127. </SwipeableViews>
  128. </Box>
  129. );
  130. }
  131. const AdminPage = () => {
  132. const matches = useMediaQuery('(max-width:768px)')
  133. return(
  134. <>
  135. <Breadcrumb links={['admin']} title={'Dashboard'}/>
  136. <main style={{backgroundColor: "#f3f3f3", padding: matches ? "20px 0" : "50px 0", minHeight:'300px'}}>
  137. <Container maxWidth="lg">
  138. <FullWidthTabs/>
  139. </Container>
  140. </main>
  141. </>
  142. )
  143. }
  144. export default AdminPage