AdminPage.jsx 6.4 KB

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