-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
front AgencyDtoWithoutEmails replaced by AgencyDtoForAgencyUsersAndAd…
…mins
- Loading branch information
Showing
18 changed files
with
428 additions
and
370 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
58 changes: 58 additions & 0 deletions
58
front/src/app/components/agency/agencies-table/ActiveAgencyRightsTable.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
import { fr } from "@codegouvfr/react-dsfr"; | ||
import Table from "@codegouvfr/react-dsfr/Table"; | ||
import { ReactNode } from "react"; | ||
import { AgencyRight } from "shared"; | ||
import { agencyRoleToDisplay } from "../AgencyUsers"; | ||
import { AgencyLineAdminEmails } from "./agency-line/AgencyLineAdminEmails"; | ||
import { AgencyLineAgencyName } from "./agency-line/AgencyLineAgencyName"; | ||
import { AgencyLineCaracteristics } from "./agency-line/AgencyLineCaracteristics"; | ||
import { AgencyLineRightsCTAs } from "./agency-line/AgencyLineRightsCTAs"; | ||
|
||
export const ActiveAgencyRightsTable = ({ | ||
agenciesWithoutToReviewRights, | ||
onUpdateClicked, | ||
isBackofficeAdmin, | ||
}: { | ||
agenciesWithoutToReviewRights: AgencyRight[]; | ||
onUpdateClicked: (agencyRight: AgencyRight) => void; | ||
isBackofficeAdmin?: boolean; | ||
}) => ( | ||
<> | ||
<h2 className={fr.cx("fr-h4")}> | ||
Organismes rattachés au profil ({agenciesWithoutToReviewRights.length}{" "} | ||
{agenciesWithoutToReviewRights.length === 1 ? "agence" : "agences"}) | ||
</h2> | ||
|
||
<Table | ||
headers={[ | ||
"Organisme", | ||
"Caractéristiques de l'agence", | ||
"Administrateurs", | ||
"Roles", | ||
"Reçoit les notifications", | ||
"Actions", | ||
]} | ||
data={agenciesWithoutToReviewRights | ||
.sort((a, b) => a.agency.name.localeCompare(b.agency.name)) | ||
.map(makeAgencyRightLine(onUpdateClicked, isBackofficeAdmin))} | ||
/> | ||
</> | ||
); | ||
|
||
const makeAgencyRightLine = | ||
( | ||
onUpdateClicked: (agencyRight: AgencyRight) => void, | ||
isBackofficeAdmin?: boolean, | ||
) => | ||
(agencyRight: AgencyRight): ReactNode[] => [ | ||
AgencyLineAgencyName({ agencyRight }), | ||
AgencyLineCaracteristics({ agencyRight }), | ||
AgencyLineAdminEmails({ agencyRight }), | ||
agencyRight.roles.map((role) => agencyRoleToDisplay[role].label).join(", "), | ||
agencyRight.isNotifiedByEmail ? "Oui" : "Non", | ||
AgencyLineRightsCTAs({ | ||
agencyRight, | ||
onUpdateClicked, | ||
isBackofficeAdmin, | ||
}), | ||
]; |
87 changes: 87 additions & 0 deletions
87
front/src/app/components/agency/agencies-table/AgenciesTablesSection.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,87 @@ | ||
import { createModal } from "@codegouvfr/react-dsfr/Modal"; | ||
import { useState } from "react"; | ||
import { createPortal } from "react-dom"; | ||
import { AgencyRight, User, UserParamsForAgency, domElementIds } from "shared"; | ||
import { Feedback } from "../../feedback/Feedback"; | ||
import { AgencyUserModificationForm } from "../AgencyUserModificationForm"; | ||
import { ActiveAgencyRightsTable } from "./ActiveAgencyRightsTable"; | ||
import { OnGoingAgencyRightsTable } from "./OnGoingAgencyRightsTable"; | ||
|
||
const manageUserModal = createModal({ | ||
isOpenedByDefault: false, | ||
id: domElementIds.admin.agencyTab.editAgencyManageUserModal, | ||
}); | ||
|
||
export const AgenciesTablesSection = ({ | ||
user, | ||
agencyRights, | ||
isBackofficeAdmin, | ||
onUserUpdateRequested, | ||
}: { | ||
user: User; | ||
agencyRights: AgencyRight[]; | ||
isBackofficeAdmin?: boolean; | ||
onUserUpdateRequested: (userParamsForAgency: UserParamsForAgency) => void; | ||
}) => { | ||
if (!agencyRights.length) | ||
return <p>Cet utilisateur n'est lié à aucune agence</p>; | ||
|
||
const [selectedAgencyRight, setSelectedAgencyRight] = | ||
useState<AgencyRight | null>(null); | ||
|
||
const onUpdateClicked = (agencyRight: AgencyRight) => { | ||
setSelectedAgencyRight(agencyRight); | ||
manageUserModal.open(); | ||
}; | ||
|
||
const toReviewAgencyRights = agencyRights.filter((agencyRight) => | ||
agencyRight.roles.includes("to-review"), | ||
); | ||
const activeAgencyRights = agencyRights.filter( | ||
(agencyRight) => !agencyRight.roles.includes("to-review"), | ||
); | ||
|
||
return ( | ||
<> | ||
<Feedback topic="user" /> | ||
{toReviewAgencyRights.length > 0 && ( | ||
<OnGoingAgencyRightsTable | ||
agenciesWithToReviewRights={toReviewAgencyRights} | ||
/> | ||
)} | ||
{activeAgencyRights.length > 0 && ( | ||
<ActiveAgencyRightsTable | ||
agenciesWithoutToReviewRights={activeAgencyRights} | ||
onUpdateClicked={onUpdateClicked} | ||
isBackofficeAdmin={isBackofficeAdmin} | ||
/> | ||
)} | ||
{createPortal( | ||
<manageUserModal.Component title={"Modifier le rôle de l'utilisateur"}> | ||
{selectedAgencyRight && ( | ||
<AgencyUserModificationForm | ||
agencyUser={{ | ||
agencyId: selectedAgencyRight.agency.id, | ||
userId: user.id, | ||
roles: selectedAgencyRight.roles, | ||
email: user.email, | ||
isNotifiedByEmail: selectedAgencyRight.isNotifiedByEmail, | ||
isIcUser: !!user.externalId, | ||
}} | ||
closeModal={() => manageUserModal.close()} | ||
agencyHasRefersTo={!!selectedAgencyRight.agency.refersToAgencyId} | ||
isEmailDisabled={true} | ||
areRolesDisabled={ | ||
!isBackofficeAdmin && | ||
!selectedAgencyRight.roles.includes("agency-admin") | ||
} | ||
onSubmit={onUserUpdateRequested} | ||
routeName="myProfile" | ||
/> | ||
)} | ||
</manageUserModal.Component>, | ||
document.body, | ||
)} | ||
</> | ||
); | ||
}; |
32 changes: 32 additions & 0 deletions
32
front/src/app/components/agency/agencies-table/OnGoingAgencyRightsTable.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
import { fr } from "@codegouvfr/react-dsfr"; | ||
import Table from "@codegouvfr/react-dsfr/Table"; | ||
import { ReactNode } from "react"; | ||
import { AgencyRight } from "shared"; | ||
import { AgencyLineAdminEmails } from "./agency-line/AgencyLineAdminEmails"; | ||
import { AgencyLineAgencyName } from "./agency-line/AgencyLineAgencyName"; | ||
import { AgencyLineCaracteristics } from "./agency-line/AgencyLineCaracteristics"; | ||
|
||
export const OnGoingAgencyRightsTable = ({ | ||
agenciesWithToReviewRights, | ||
}: { agenciesWithToReviewRights: AgencyRight[] }) => ( | ||
<> | ||
<h2 className={fr.cx("fr-h4")}> | ||
Demandes d'accès en cours ({agenciesWithToReviewRights.length}{" "} | ||
{agenciesWithToReviewRights.length === 1 ? "agence" : "agences"}) | ||
</h2> | ||
<Table | ||
headers={["Organisme", "Caractéristiques de l'agence", "Administrateurs"]} | ||
data={agenciesWithToReviewRights | ||
.sort((a, b) => a.agency.name.localeCompare(b.agency.name)) | ||
.map(makeAgencyWithToReviewRightLine())} | ||
/> | ||
</> | ||
); | ||
|
||
const makeAgencyWithToReviewRightLine = | ||
() => | ||
(agencyRight: AgencyRight): ReactNode[] => [ | ||
AgencyLineAgencyName({ agencyRight }), | ||
AgencyLineCaracteristics({ agencyRight }), | ||
AgencyLineAdminEmails({ agencyRight }), | ||
]; |
13 changes: 13 additions & 0 deletions
13
front/src/app/components/agency/agencies-table/agency-line/AgencyLineAdminEmails.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
import { fr } from "@codegouvfr/react-dsfr"; | ||
import { ReactNode } from "react"; | ||
import { AgencyRight } from "shared"; | ||
|
||
export const AgencyLineAdminEmails = ({ | ||
agencyRight, | ||
}: { agencyRight: AgencyRight }): ReactNode => ( | ||
<ul className={fr.cx("fr-raw-list")}> | ||
{agencyRight.agency.admins.map((admin) => ( | ||
<li>{admin}</li> | ||
))} | ||
</ul> | ||
); |
31 changes: 31 additions & 0 deletions
31
front/src/app/components/agency/agencies-table/agency-line/AgencyLineAgencyName.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
import { fr } from "@codegouvfr/react-dsfr"; | ||
import { ReactNode } from "react"; | ||
import { AgencyRight, addressDtoToString } from "shared"; | ||
import { routes } from "src/app/routes/routes"; | ||
|
||
export const AgencyLineAgencyName = ({ | ||
agencyRight, | ||
}: { agencyRight: AgencyRight }): ReactNode => ( | ||
<div key={agencyRight.agency.id}> | ||
{agencyRight.agency.name} | ||
<span className={fr.cx("fr-hint-text")}> | ||
{addressDtoToString(agencyRight.agency.address)} | ||
</span> | ||
|
||
{agencyRight.roles.includes("agency-admin") && ( | ||
<a | ||
className={fr.cx( | ||
"fr-link", | ||
"fr-text--sm", | ||
"fr-icon-arrow-right-line", | ||
"fr-link--icon-right", | ||
)} | ||
{...routes.agencyDashboardAgencyDetails({ | ||
agencyId: agencyRight.agency.id, | ||
}).link} | ||
> | ||
Voir l'agence | ||
</a> | ||
)} | ||
</div> | ||
); |
Oops, something went wrong.