Skip to content

Commit

Permalink
feat: integrate panierId into Header and navigation items to make lin…
Browse files Browse the repository at this point in the history
…k to panier work properly
  • Loading branch information
elisfainstein committed Jan 8, 2025
1 parent 5642b00 commit e530b66
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ export const MenuPrincipal = (props: HeaderPropsWithModalState) => {
const {
currentCollectivite,
ownedCollectivites,
panierId,
modalOpened,
setOpenedId,
auth,
Expand All @@ -47,7 +48,7 @@ export const MenuPrincipal = (props: HeaderPropsWithModalState) => {
let secondaryItems = [] as TNavItemsList;
if (currentCollectivite) {
// récupère la liste des items à afficher dans le menu
items = makeNavItems(currentCollectivite, auth.user);
items = makeNavItems(currentCollectivite, auth.user, panierId);
secondaryItems = makeSecondaryNavItems(currentCollectivite);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import { useAuth } from '@/app/core-logic/api/auth/AuthProvider';
import { useCurrentCollectivite } from '@/app/core-logic/hooks/useCurrentCollectivite';
import { useMaintenance } from '../useMaintenance';
import { useNbActionsDansPanier } from './AccesPanierAction';
import { Header as HeaderBase } from './Header';

/**
Expand All @@ -11,13 +12,17 @@ import { Header as HeaderBase } from './Header';
const Header = () => {
const auth = useAuth();
const currentCollectivite = useCurrentCollectivite();
const { data: panier } = useNbActionsDansPanier(
currentCollectivite?.collectivite_id!
);
const maintenance = useMaintenance();

return (
<HeaderBase
auth={auth}
ownedCollectivites={auth.user?.collectivites ?? []}
currentCollectivite={currentCollectivite}
panierId={panier?.panierId}
maintenance={maintenance}
/>
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,10 @@ import { TNavDropdown, TNavItem, TNavItemsList } from './types';
/** Génère les liens de navigation pour une collectivité donnée */
export const makeNavItems = (
collectivite: CurrentCollectivite,
user: UserData | null
user: UserData | null,
panierId: string | undefined
): TNavItemsList => {
return filtreItems(makeNavItemsBase(collectivite, user));
return filtreItems(makeNavItemsBase(collectivite, user, panierId));
};

const isVisiteur = ({
Expand All @@ -43,7 +44,8 @@ const isVisiteur = ({

const makeNavItemsBase = (
collectivite: CurrentCollectivite,
user: UserData | null
user: UserData | null,
panierId: string | undefined
): TNavItemsList => {
const collectiviteId = collectivite.collectivite_id;
const confidentiel =
Expand All @@ -58,10 +60,11 @@ const makeNavItemsBase = (
dataTest: 'nav-home',
},
{
confidentiel,
label: 'Actions à Impact',
dataTest: 'pa-actions-impact',
to: makeCollectivitePanierUrl({
collectiviteId,
panierId,
}),
},
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ export type HeaderProps = {
auth: TAuthContext;
currentCollectivite: CurrentCollectivite | null;
ownedCollectivites: TMesCollectivites;
panierId: string | undefined;
maintenance: Maintenance;
};

Expand Down

0 comments on commit e530b66

Please sign in to comment.