diff --git a/src/components/Header.tsx b/src/components/Header.tsx index 86fea0f76..b4abef080 100644 --- a/src/components/Header.tsx +++ b/src/components/Header.tsx @@ -9,25 +9,18 @@ import Menu from '@mui/material/Menu'; import MenuItem from '@mui/material/MenuItem'; import AccessControl from './AccessControl'; +import { VillageSelect } from './VillageSelect'; import { UserContext } from 'src/contexts/userContext'; -import { VillageContext } from 'src/contexts/villageContext'; -import { secondaryColor } from 'src/styles/variables.const'; import Logo from 'src/svg/logo.svg'; import { UserType } from 'types/user.type'; export const Header = () => { const router = useRouter(); const { user, logout } = React.useContext(UserContext); - - const { village, showSelectVillageModal } = React.useContext(VillageContext); - const [anchorEl, setAnchorEl] = React.useState(null); const open = Boolean(anchorEl); - //* NOTE: might be interesting to make a hook for this below - const isPelico = user?.type === UserType.MEDIATOR || user?.type === UserType.ADMIN || user?.type === UserType.SUPER_ADMIN; - const handleMenu = (event: React.MouseEvent) => { if (open) { setAnchorEl(null); @@ -58,26 +51,10 @@ export const Header = () => { {user && (
- {isPelico ? ( -
- - {village ? village.name : 'Village non choisi !'} - - -
- ) : null} - {user.type === UserType.ADMIN || user.type === UserType.SUPER_ADMIN || user.type === UserType.MEDIATOR ? ( - - - - ) : null} +
{ user.type === UserType.OBSERVATOR ? ( ) : null} diff --git a/src/components/VillageSelect.tsx b/src/components/VillageSelect.tsx new file mode 100644 index 000000000..cf704bace --- /dev/null +++ b/src/components/VillageSelect.tsx @@ -0,0 +1,36 @@ +import React from 'react'; + +import { Button, Grid } from '@mui/material'; + +import { UserContext } from 'src/contexts/userContext'; +import { VillageContext } from 'src/contexts/villageContext'; +import { secondaryColor } from 'src/styles/variables.const'; +import { UserType } from 'types/user.type'; + +export const VillageSelect = () => { + const { user } = React.useContext(UserContext); + const { village, showSelectVillageModal } = React.useContext(VillageContext); + const isPelico = user && (user?.type === UserType.MEDIATOR || user?.type === UserType.ADMIN || user?.type === UserType.SUPER_ADMIN); + + return ( + + {isPelico ? ( +
+ + {village ? village.name : 'Village non choisi !'} + + +
+ ) : null} +
+ ); +};