2
0

Users.tsx 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. import { useMemo } from 'react';
  2. import { useNavigate, useLocation, useParams } from 'react-router-dom';
  3. import { useTranslation } from 'react-i18next';
  4. import { makeStyles, Theme } from '@material-ui/core';
  5. import { useNavigationHook } from '@/hooks/Navigation';
  6. import { ALL_ROUTER_TYPES } from '@/router/Types';
  7. import CustomTabList from '@/components/customTabList/CustomTabList';
  8. import { ITab } from '@/components/customTabList/Types';
  9. import { parseLocationSearch } from '@/utils/Format';
  10. import User from './User';
  11. import Roles from './Roles';
  12. import { TAB_EMUM } from './Types';
  13. const useStyles = makeStyles((theme: Theme) => ({
  14. wrapper: {
  15. flexDirection: 'row',
  16. gap: theme.spacing(4),
  17. },
  18. card: {
  19. boxShadow: 'none',
  20. flexBasis: theme.spacing(28),
  21. width: theme.spacing(28),
  22. flexGrow: 0,
  23. flexShrink: 0,
  24. },
  25. tab: {
  26. flexGrow: 1,
  27. flexShrink: 1,
  28. overflowX: 'auto',
  29. },
  30. }));
  31. const Users = () => {
  32. const classes = useStyles();
  33. useNavigationHook(ALL_ROUTER_TYPES.USER);
  34. const navigate = useNavigate();
  35. const location = useLocation();
  36. const { t: userTrans } = useTranslation('user');
  37. const activeTabIndex = useMemo(() => {
  38. const { activeIndex } = location.search
  39. ? parseLocationSearch(location.search)
  40. : { activeIndex: TAB_EMUM.schema };
  41. return Number(activeIndex);
  42. }, [location]);
  43. const handleTabChange = (activeIndex: number) => {
  44. const path = location.pathname;
  45. navigate(`${path}?activeIndex=${activeIndex}`);
  46. };
  47. const tabs: ITab[] = [
  48. {
  49. label: userTrans('users'),
  50. component: <User />,
  51. },
  52. {
  53. label: userTrans('roles'),
  54. component: <Roles />,
  55. },
  56. ];
  57. return (
  58. <section className={`page-wrapper ${classes.wrapper}`}>
  59. <CustomTabList
  60. tabs={tabs}
  61. wrapperClass={classes.tab}
  62. activeIndex={activeTabIndex}
  63. handleTabChange={handleTabChange}
  64. />
  65. </section>
  66. );
  67. };
  68. export default Users;