Skip to content

Commit

Permalink
show action column only for IF admin on MyProfile
Browse files Browse the repository at this point in the history
  • Loading branch information
JeromeBu committed Nov 21, 2024
1 parent 6a7cb57 commit e70ef34
Showing 1 changed file with 65 additions and 47 deletions.
112 changes: 65 additions & 47 deletions front/src/app/components/UserDetail.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -57,12 +57,19 @@ export const UserDetail = ({
agencyRights={[...userWithRights.agencyRights].sort((a, b) =>
a.agency.name.localeCompare(b.agency.name),
)}
isAdmin={userWithRights.isBackofficeAdmin}
/>
</div>
);
};

const AgenciesTable = ({ agencyRights }: { agencyRights: AgencyRight[] }) => {
const AgenciesTable = ({
agencyRights,
isAdmin,
}: {
agencyRights: AgencyRight[];
isAdmin?: boolean;
}) => {
if (!agencyRights.length)
return <p>Cet utilisateur n'est lié à aucune agence</p>;

Expand All @@ -78,56 +85,67 @@ const AgenciesTable = ({ agencyRights }: { agencyRights: AgencyRight[] }) => {
"Carractéristiques de l'agence",
"Roles",
"Reçoit les notifications",
"Actions",
...(isAdmin ? ["Actions"] : []),
]}
data={agencyRights.map((agencyRight) => {
const viewAgencyProps = !agencyRight.roles.includes("agency-admin")
? {
disabled: true,
title:
"Vous n'êtes pas administrateur de cette agence. Seuls les administrateurs de l'agence peuvent voir le détail.",
}
: {
linkProps: routes.adminAgencyDetail({
agencyId: agencyRight.agency.id,
}).link,
};
data={agencyRights.map((agencyRight) => [
<>
{agencyRight.agency.name}
<span className={fr.cx("fr-hint-text")}>
{addressDtoToString(agencyRight.agency.address)}
</span>

return [
<>
{agencyRight.agency.name}
<span className={fr.cx("fr-hint-text")}>
{addressDtoToString(agencyRight.agency.address)}
</span>
</>,
<ul className={fr.cx("fr-raw-list")}>
<li>
<AgencyTag
refersToAgencyName={agencyRight.agency.refersToAgencyName}
/>
</li>
{!activeAgencyStatuses.includes(agencyRight.agency.status) && (
<li>
<AgencyStatusBadge status={agencyRight.agency.status} />
</li>
)}
{agencyRight.roles.includes("agency-admin") && isAdmin && (
<a
className={fr.cx(
"fr-link",
"fr-text--sm",
"fr-icon-arrow-right-line",
"fr-link--icon-right",
)}
{...routes.adminAgencyDetail({
// this should be changed to agencyDashboardAgency/:agencyId, when it is ready
agencyId: agencyRight.agency.id,
}).link}
>
Voir l'agence
</a>
)}
</>,
<ul className={fr.cx("fr-raw-list")}>
<li>
<AgencyTag
refersToAgencyName={agencyRight.agency.refersToAgencyName}
/>
</li>
{!activeAgencyStatuses.includes(agencyRight.agency.status) && (
<li>
Type : {agencyKindToLabelIncludingIF[agencyRight.agency.kind]}
<AgencyStatusBadge status={agencyRight.agency.status} />
</li>
</ul>,
agencyRight.roles
.map((role) => agencyRoleToDisplay[role].label)
.join(", "),
agencyRight.isNotifiedByEmail ? "Oui" : "Non",
<Button
priority="tertiary no outline"
size="small"
{...viewAgencyProps}
>
Voir l'agence
</Button>,
];
})}
)}
<li>
Type : {agencyKindToLabelIncludingIF[agencyRight.agency.kind]}
</li>
</ul>,
agencyRight.roles
.map((role) => agencyRoleToDisplay[role].label)
.join(", "),
agencyRight.isNotifiedByEmail ? "Oui" : "Non",
...(isAdmin
? [
<Button
priority="tertiary no outline"
size="small"
linkProps={
routes.adminAgencyDetail({
agencyId: agencyRight.agency.id,
}).link
}
>
Voir l'agence comme admin IF
</Button>,
]
: []),
])}
/>
</>
);
Expand Down

0 comments on commit e70ef34

Please sign in to comment.