Skip to content

Commit

Permalink
front AgencyDtoWithoutEmails replaced by AgencyDtoForAgencyUsersAndAd…
Browse files Browse the repository at this point in the history
…mins
  • Loading branch information
bbohec committed Jan 10, 2025
1 parent 7c1e0db commit 890c0ec
Show file tree
Hide file tree
Showing 10 changed files with 144 additions and 110 deletions.
120 changes: 59 additions & 61 deletions front/src/app/components/agency/IcUserAgenciesToReview.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import { createPortal } from "react-dom";
import { SubmitHandler, useForm } from "react-hook-form";
import { useDispatch } from "react-redux";
import {
AgencyDtoWithoutEmails,
AgencyDtoForAgencyUsersAndAdmins,
AgencyId,
AgencyRight,
RejectIcUserRoleForAgencyParams,
Expand All @@ -32,85 +32,83 @@ type IcUserAgenciesToReviewModalProps = {
mode: "register" | "reject";
};

function AgencyReviewForm({
const AgencyReviewForm = ({
agency,
setSelectedAgency,
selectedUser,
setModalProps,
}: {
agency: AgencyDtoWithoutEmails;
agency: AgencyDtoForAgencyUsersAndAdmins;
selectedUser: User;
setSelectedAgency: (agency: AgencyDtoWithoutEmails) => void;
setSelectedAgency: (agency: AgencyDtoForAgencyUsersAndAdmins) => void;
setModalProps: (modalProps: IcUserAgenciesToReviewModalProps) => void;
}) {
return (
<div className={fr.cx("fr-col-4")}>
<div className={fr.cx("fr-card")}>
<div className={fr.cx("fr-card__body")}>
<div className={fr.cx("fr-card__content")}>
<h3 className={fr.cx("fr-card__title")}>{agency.name}</h3>
<p className={fr.cx("fr-card__desc")}>
{agency.address.streetNumberAndAddress} {agency.address.postcode}{" "}
{agency.address.city}
</p>
<p className={fr.cx("fr-card__desc")}>
<a
{...routes.adminAgencyDetail({ agencyId: agency.id }).link}
target="_blank"
>
Voir les détails de l'agence
</a>
</p>
</div>
<div className={fr.cx("fr-card__footer")}>
<ButtonsGroup
alignment="center"
inlineLayoutWhen="always"
buttonsSize="small"
buttons={[
{
type: "button",
priority: "primary",
id: `${domElementIds.admin.agencyTab.registerIcUserToAgencyButton}-${agency.id}-${selectedUser.id}`,
onClick: () => {
setModalProps({
title: "Rattacher cet utilisateur",
mode: "register",
});
setSelectedAgency(agency);
openIcUserRegistrationToAgencyModal();
},
children: "Valider",
}) => (
<div className={fr.cx("fr-col-4")}>
<div className={fr.cx("fr-card")}>
<div className={fr.cx("fr-card__body")}>
<div className={fr.cx("fr-card__content")}>
<h3 className={fr.cx("fr-card__title")}>{agency.name}</h3>
<p className={fr.cx("fr-card__desc")}>
{agency.address.streetNumberAndAddress} {agency.address.postcode}{" "}
{agency.address.city}
</p>
<p className={fr.cx("fr-card__desc")}>
<a
{...routes.adminAgencyDetail({ agencyId: agency.id }).link}
target="_blank"
>
Voir les détails de l'agence
</a>
</p>
</div>
<div className={fr.cx("fr-card__footer")}>
<ButtonsGroup
alignment="center"
inlineLayoutWhen="always"
buttonsSize="small"
buttons={[
{
type: "button",
priority: "primary",
id: `${domElementIds.admin.agencyTab.registerIcUserToAgencyButton}-${agency.id}-${selectedUser.id}`,
onClick: () => {
setModalProps({
title: "Rattacher cet utilisateur",
mode: "register",
});
setSelectedAgency(agency);
openIcUserRegistrationToAgencyModal();
},
{
type: "button",
priority: "secondary",
onClick: () => {
setModalProps({
title: "Refuser le rattachement",
mode: "reject",
});
setSelectedAgency(agency);
openIcUserRegistrationToAgencyModal();
},
children: "Refuser",
children: "Valider",
},
{
type: "button",
priority: "secondary",
onClick: () => {
setModalProps({
title: "Refuser le rattachement",
mode: "reject",
});
setSelectedAgency(agency);
openIcUserRegistrationToAgencyModal();
},
]}
/>
</div>
children: "Refuser",
},
]}
/>
</div>
</div>
</div>
);
}
</div>
);

export const IcUserAgenciesToReview = ({
agenciesNeedingReviewForUser,
selectedUser,
}: IcUserAgenciesToReviewProps) => {
const dispatch = useDispatch();
const [selectedAgency, setSelectedAgency] =
useState<AgencyDtoWithoutEmails>();
useState<AgencyDtoForAgencyUsersAndAdmins>();
const [modalProps, setModalProps] =
useState<IcUserAgenciesToReviewModalProps | null>(null);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -219,12 +219,9 @@ const makeAgencyAdminEmails = ({
agencyRight,
}: { agencyRight: AgencyRight }): ReactNode => (
<ul className={fr.cx("fr-raw-list")}>
{
// missing admin emails on agencyRight
["[email protected]", "[email protected]"].map((admin) => (
<li>{admin}</li>
))
}
{agencyRight.agency.admins.map((admin) => (
<li>{admin}</li>
))}
</ul>
);

Expand Down
54 changes: 35 additions & 19 deletions front/src/core-logic/adapters/AdminGateway/SimulatedAdminGateway.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,32 +17,42 @@ import {
UserInList,
UserParamsForAgency,
WithAgencyIdAndUserId,
toAgencyDtoForAgencyUsersAndAdmins,
} from "shared";
import { AdminGateway } from "src/core-logic/ports/AdminGateway";

const simulatedAgencyDtos: AgencyRight[] = [
const simulatedAgencyRights: AgencyRight[] = [
{
roles: ["to-review"],
agency: new AgencyDtoBuilder()
.withName("Agence de Bourg en Bresse")
.withId("fake-agency-id-1")
.build(),
agency: toAgencyDtoForAgencyUsersAndAdmins(
new AgencyDtoBuilder()
.withName("Agence de Bourg en Bresse")
.withId("fake-agency-id-1")
.build(),
[],
),
isNotifiedByEmail: true,
},
{
roles: ["validator"],
agency: new AgencyDtoBuilder()
.withName("Mission locale qu'on ne devrait pas voir")
.withId("fake-agency-id-not-shown")
.build(),
agency: toAgencyDtoForAgencyUsersAndAdmins(
new AgencyDtoBuilder()
.withName("Mission locale qu'on ne devrait pas voir")
.withId("fake-agency-id-not-shown")
.build(),
[],
),
isNotifiedByEmail: true,
},
{
roles: ["to-review"],
agency: new AgencyDtoBuilder()
.withName("CCI de Quimper")
.withId("fake-agency-id-3")
.build(),
agency: toAgencyDtoForAgencyUsersAndAdmins(
new AgencyDtoBuilder()
.withName("CCI de Quimper")
.withId("fake-agency-id-3")
.build(),
[],
),
isNotifiedByEmail: true,
},
];
Expand Down Expand Up @@ -114,7 +124,7 @@ export class SimulatedAdminGateway implements AdminGateway {
email: "[email protected]",
firstName: "Jean",
lastName: "Bon",
agencyRights: simulatedAgencyDtos,
agencyRights: simulatedAgencyRights,
dashboards: { agencies: {}, establishments: {} },
externalId: "fake-user-external-id-1",
createdAt: new Date().toISOString(),
Expand All @@ -137,10 +147,13 @@ export class SimulatedAdminGateway implements AdminGateway {
agencyRights: [
{
roles: ["to-review"],
agency: new AgencyDtoBuilder()
.withName("Mission locale qui plante")
.withId("non-existing-agency-id")
.build(),
agency: toAgencyDtoForAgencyUsersAndAdmins(
new AgencyDtoBuilder()
.withName("Mission locale qui plante")
.withId("non-existing-agency-id")
.build(),
[],
),
isNotifiedByEmail: true,
},
],
Expand Down Expand Up @@ -216,7 +229,10 @@ export class SimulatedAdminGateway implements AdminGateway {
...icUser,
agencyRights: [
{
agency: new AgencyDtoBuilder().build(),
agency: toAgencyDtoForAgencyUsersAndAdmins(
new AgencyDtoBuilder().build(),
[],
),
roles: ["validator"],
isNotifiedByEmail: true,
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import {
WithAgencyId,
WithAgencyIdAndUserId,
errors,
toAgencyDtoForAgencyUsersAndAdmins,
toAgencyPublicDisplayDto,
} from "shared";
import { AgencyGateway } from "src/core-logic/ports/AgencyGateway";
Expand Down Expand Up @@ -83,12 +84,15 @@ const simulatedUsers: InclusionConnectedUser[] = [
lastName: "Bon",
agencyRights: [
{
agency: MISSION_LOCAL_AGENCY_ACTIVE,
agency: toAgencyDtoForAgencyUsersAndAdmins(
MISSION_LOCAL_AGENCY_ACTIVE,
[],
),
isNotifiedByEmail: true,
roles: ["agency-admin"],
},
{
agency: PE_AGENCY_ACTIVE,
agency: toAgencyDtoForAgencyUsersAndAdmins(PE_AGENCY_ACTIVE, []),
isNotifiedByEmail: true,
roles: ["validator"],
},
Expand All @@ -114,7 +118,7 @@ const simulatedUsers: InclusionConnectedUser[] = [
lastName: "Jeplante",
agencyRights: [
{
agency: PE_AGENCY_ACTIVE,
agency: toAgencyDtoForAgencyUsersAndAdmins(PE_AGENCY_ACTIVE, []),
isNotifiedByEmail: true,
roles: ["agency-admin"],
},
Expand Down
5 changes: 3 additions & 2 deletions front/src/core-logic/domain/admin/fetchUser/fetchUser.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import {
InclusionConnectedUser,
InclusionConnectedUserBuilder,
expectToEqual,
toAgencyDtoForAgencyUsersAndAdmins,
} from "shared";
import { adminPreloadedState } from "src/core-logic/domain/admin/adminPreloadedState";
import { adminFetchUserSelectors } from "src/core-logic/domain/admin/fetchUser/fetchUser.selectors";
Expand Down Expand Up @@ -49,7 +50,7 @@ describe("Admin Users slice", () => {
it("if this other user is in the state, update this user rights successfully", () => {
const agency = new AgencyDtoBuilder().build();
const agencyRight: AgencyRight = {
agency,
agency: toAgencyDtoForAgencyUsersAndAdmins(agency, []),
roles: ["validator"],
isNotifiedByEmail: false,
};
Expand Down Expand Up @@ -102,7 +103,7 @@ describe("Admin Users slice", () => {
it("if it is not user in state, do nothing", () => {
const agency = new AgencyDtoBuilder().build();
const agencyRight: AgencyRight = {
agency,
agency: toAgencyDtoForAgencyUsersAndAdmins(agency, []),
roles: ["validator"],
isNotifiedByEmail: false,
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import {
UserParamsForAgency,
errors,
expectToEqual,
toAgencyDtoForAgencyUsersAndAdmins,
} from "shared";
import { adminPreloadedState } from "src/core-logic/domain/admin/adminPreloadedState";
import { icUsersAdminSelectors } from "src/core-logic/domain/admin/icUsersAdmin/icUsersAdmin.selectors";
Expand All @@ -36,12 +37,12 @@ const agency3 = new AgencyDtoBuilder().withId("agency-3").build();
const agency4 = new AgencyDtoBuilder().withId("agency-4").build();

const agency1Right: AgencyRight = {
agency: agency1,
agency: toAgencyDtoForAgencyUsersAndAdmins(agency1, []),
roles: ["to-review"],
isNotifiedByEmail: true,
};
const agency2Right: AgencyRight = {
agency: agency2,
agency: toAgencyDtoForAgencyUsersAndAdmins(agency2, []),
roles: ["validator"],
isNotifiedByEmail: true,
};
Expand All @@ -51,12 +52,12 @@ const user1AgencyRights: Record<AgencyId, AgencyRight> = {
};

const agency3Right: AgencyRight = {
agency: agency3,
agency: toAgencyDtoForAgencyUsersAndAdmins(agency3, []),
roles: ["to-review"],
isNotifiedByEmail: true,
};
const agency4Right: AgencyRight = {
agency: agency4,
agency: toAgencyDtoForAgencyUsersAndAdmins(agency4, []),
roles: ["to-review"],
isNotifiedByEmail: true,
};
Expand Down Expand Up @@ -597,7 +598,7 @@ describe("Agency registration for authenticated users", () => {
...userToCreate,
agencyRights: [
{
agency: agency2,
agency: toAgencyDtoForAgencyUsersAndAdmins(agency2, []),
roles: ["validator"],
isNotifiedByEmail: false,
},
Expand All @@ -612,7 +613,7 @@ describe("Agency registration for authenticated users", () => {
...icUser,
agencyRights: {
[agency2.id]: {
agency: agency2,
agency: toAgencyDtoForAgencyUsersAndAdmins(agency2, []),
roles: ["validator"],
isNotifiedByEmail: false,
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import {
InclusionConnectedUser,
errors,
expectToEqual,
toAgencyDtoForAgencyUsersAndAdmins,
} from "shared";
import { NormalizedInclusionConnectedUser } from "src/core-logic/domain/admin/icUsersAdmin/icUsersAdmin.slice";
import { agenciesPreloadedState } from "src/core-logic/domain/agencies/agenciesPreloadedState";
Expand Down Expand Up @@ -65,7 +66,7 @@ describe("CreateUserOnAgency", () => {
...userToCreate,
agencyRights: [
{
agency: agencyDto,
agency: toAgencyDtoForAgencyUsersAndAdmins(agencyDto, []),
roles: ["validator"],
isNotifiedByEmail: false,
},
Expand Down
Loading

0 comments on commit 890c0ec

Please sign in to comment.