Skip to content

Commit c9decda

Browse files
committed
add remove agency rights button & modal on AgencyLineRightsCTAs
Signed-off-by: Benjamin Bohec <bbohec.pro@gmail.com>
1 parent 0d252d6 commit c9decda

7 files changed

Lines changed: 133 additions & 59 deletions

File tree

front/src/app/components/agency/agencies-table/AgenciesTablesSection.tsx

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,9 @@ export const AgenciesTablesSection = ({
6868

6969
<AgencyRightsTable
7070
agencyRights={toReviewAgencyRights}
71+
removeAgencyRightIdPrefix={
72+
domElementIds.admin.agencyTab.removeAgencyRight
73+
}
7174
user={user}
7275
onUserRegistrationCancelledRequested={onUserRegistrationCancelledRequested(
7376
"user",
@@ -79,6 +82,9 @@ export const AgenciesTablesSection = ({
7982
<AgencyRightsTable
8083
agencyRights={activeAgencyRights}
8184
user={user}
85+
removeAgencyRightIdPrefix={
86+
domElementIds.admin.agencyTab.removeAgencyRight
87+
}
8288
modalId={domElementIds.admin.agencyTab.editAgencyManageUserModal}
8389
onUserUpdateRequested={onUserUpdateRequested("user")}
8490
/>

front/src/app/components/agency/agencies-table/AgencyRightsTable.tsx

Lines changed: 25 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ import { AgencyLineAdminEmails } from "./agency-line/AgencyLineAdminEmails";
2929
type AgencyRightsTableProps = {
3030
agencyRights: AgencyRight[];
3131
user: User;
32+
removeAgencyRightIdPrefix: string;
3233
title?: string;
3334
onUserRegistrationCancelledRequested?: (agencyRight: AgencyRight) => void;
3435
} & (
@@ -43,6 +44,7 @@ export const AgencyRightsTable = ({
4344
agencyRights,
4445
user,
4546
modalId,
47+
removeAgencyRightIdPrefix,
4648
onUserUpdateRequested,
4749
onUserRegistrationCancelledRequested,
4850
title,
@@ -106,12 +108,15 @@ export const AgencyRightsTable = ({
106108
return a.agency.name.localeCompare(b.agency.name);
107109
})
108110
.map((agencyRight) =>
109-
AgencyRightLine(
111+
AgencyRightLine({
110112
agencyRight,
111-
onUserUpdateRequested && onUpdateClicked,
112-
onUserRegistrationCancelledRequested,
113+
user,
114+
removeAgencyRightIdPrefix,
115+
onUpdateClicked: onUserUpdateRequested && onUpdateClicked,
116+
onRegistrationCancelledClicked:
117+
onUserRegistrationCancelledRequested,
113118
isBackofficeAdmin,
114-
),
119+
}),
115120
)}
116121
/>
117122
{onUserUpdateRequested &&
@@ -159,12 +164,20 @@ export const AgencyRightsTable = ({
159164
);
160165
};
161166

162-
const AgencyRightLine = (
163-
agencyRight: AgencyRight,
164-
onUpdateClicked?: (agencyRight: AgencyRight) => void,
165-
onRegistrationCancelledClicked?: (agencyRight: AgencyRight) => void,
166-
isBackofficeAdmin?: boolean,
167-
) => [
167+
const AgencyRightLine = ({
168+
agencyRight,
169+
user,
170+
onUpdateClicked,
171+
onRegistrationCancelledClicked,
172+
isBackofficeAdmin,
173+
}: {
174+
agencyRight: AgencyRight;
175+
user: User;
176+
removeAgencyRightIdPrefix: string;
177+
onUpdateClicked?: (agencyRight: AgencyRight) => void;
178+
onRegistrationCancelledClicked?: (agencyRight: AgencyRight) => void;
179+
isBackofficeAdmin?: boolean;
180+
}) => [
168181
<Fragment key={`${agencyRight.agency.id}-agency-infos`}>
169182
<AgencyTag refersToAgencyName={agencyRight.agency.refersToAgencyName} />
170183
<AgencyStatusBadge status={agencyRight.agency.status} />
@@ -211,6 +224,8 @@ const AgencyRightLine = (
211224
agencyRight={agencyRight}
212225
onUpdateClicked={onUpdateClicked}
213226
onRegistrationCancelledClicked={onRegistrationCancelledClicked}
227+
removeAgencyRightIdPrefix=""
228+
user={user}
214229
isBackofficeAdmin={isBackofficeAdmin}
215230
/>
216231
</Fragment>,
Lines changed: 76 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -1,56 +1,83 @@
11
import Button from "@codegouvfr/react-dsfr/Button";
22
import type { ReactNode } from "react";
3-
import { type AgencyRight, domElementIds, frontRoutes } from "shared";
3+
import {
4+
type AgencyRight,
5+
domElementIds,
6+
frontRoutes,
7+
type User,
8+
} from "shared";
9+
import { makeRemoveUserAgencyRightsButtonPropsWithConfirmationModal } from "../../makeRemoveUserAgencyRightsButtonPropsWithConfirmationModal";
10+
11+
type AgencyLineRightsCTAsProps = {
12+
agencyRight: AgencyRight;
13+
onUpdateClicked?: (agencyRight: AgencyRight) => void;
14+
onRegistrationCancelledClicked?: (agencyRight: AgencyRight) => void;
15+
user: User;
16+
removeAgencyRightIdPrefix: string;
17+
isBackofficeAdmin: boolean | undefined;
18+
};
419

520
export const AgencyLineRightsCTAs = ({
21+
removeAgencyRightIdPrefix,
622
agencyRight,
7-
isBackofficeAdmin,
23+
user,
824
onUpdateClicked,
925
onRegistrationCancelledClicked,
10-
}: {
11-
agencyRight: AgencyRight;
12-
onUpdateClicked?: (agencyRight: AgencyRight) => void;
13-
onRegistrationCancelledClicked?: (agencyRight: AgencyRight) => void;
14-
isBackofficeAdmin?: boolean | undefined;
15-
}): ReactNode => (
16-
<>
17-
{onUpdateClicked && (
18-
<Button
19-
size="small"
20-
priority="secondary"
21-
id={`${domElementIds.myAccount.editRoleButton}-${agencyRight.agency.id}`}
22-
onClick={() => {
23-
onUpdateClicked(agencyRight);
24-
}}
25-
>
26-
Modifier
27-
</Button>
28-
)}
29-
{isBackofficeAdmin && (
30-
<Button
31-
priority="tertiary no outline"
32-
id={`${domElementIds.myAccount.adminAgencyLink}-${agencyRight.agency.id}`}
33-
size="small"
34-
linkProps={
35-
frontRoutes.adminAgencyDetail({
36-
agencyId: agencyRight.agency.id,
37-
}).link
38-
}
39-
>
40-
Voir l'agence comme admin IF
41-
</Button>
42-
)}
43-
{onRegistrationCancelledClicked && (
44-
<Button
45-
priority="secondary"
46-
id={`${domElementIds.myAccount.cancelRegistrationButton}-${agencyRight.agency.id}`}
47-
size="small"
48-
onClick={() => {
49-
onRegistrationCancelledClicked(agencyRight);
50-
}}
51-
>
52-
Annuler la demande
53-
</Button>
54-
)}
55-
</>
56-
);
26+
isBackofficeAdmin,
27+
}: AgencyLineRightsCTAsProps): ReactNode => {
28+
const {
29+
RemoveUserAgencyRightsPortalWithModal,
30+
removeUserAgencyRightsButtonProps,
31+
} = makeRemoveUserAgencyRightsButtonPropsWithConfirmationModal({
32+
agencyRight,
33+
feedbackTopic: "agency-user",
34+
removeUserButtonId: `${removeAgencyRightIdPrefix}-${agencyRight.agency.id}-button`,
35+
removeUserModalId: `${removeAgencyRightIdPrefix}-${agencyRight.agency.id}-${user.id}-modal`,
36+
userEmail: user.email,
37+
userId: user.id,
38+
});
39+
return (
40+
<>
41+
{onUpdateClicked && (
42+
<Button
43+
size="small"
44+
priority="secondary"
45+
id={`${domElementIds.myAccount.editRoleButton}-${agencyRight.agency.id}`}
46+
onClick={() => {
47+
onUpdateClicked(agencyRight);
48+
}}
49+
>
50+
Modifier
51+
</Button>
52+
)}
53+
<Button {...removeUserAgencyRightsButtonProps} />
54+
{isBackofficeAdmin && (
55+
<Button
56+
priority="tertiary no outline"
57+
id={`${domElementIds.myAccount.adminAgencyLink}-${agencyRight.agency.id}`}
58+
size="small"
59+
linkProps={
60+
frontRoutes.adminAgencyDetail({
61+
agencyId: agencyRight.agency.id,
62+
}).link
63+
}
64+
>
65+
Voir l'agence comme admin IF
66+
</Button>
67+
)}
68+
{onRegistrationCancelledClicked && (
69+
<Button
70+
priority="secondary"
71+
id={`${domElementIds.myAccount.cancelRegistrationButton}-${agencyRight.agency.id}`}
72+
size="small"
73+
onClick={() => {
74+
onRegistrationCancelledClicked(agencyRight);
75+
}}
76+
>
77+
Annuler la demande
78+
</Button>
79+
)}
80+
{RemoveUserAgencyRightsPortalWithModal}
81+
</>
82+
);
83+
};

front/src/app/components/agency/agency-dashboard/NoActiveAgencyRights.tsx

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,9 @@ export function NoActiveAgencyRights({
5353
agencyRights={toReviewAgencyRights}
5454
user={currentUser}
5555
title={`Demandes d'accès en cours (${toReviewAgencyRights.length})`}
56+
removeAgencyRightIdPrefix={
57+
domElementIds.agencyDashboard.registerAgencies.removeAgencyRight
58+
}
5659
onUserRegistrationCancelledRequested={
5760
onUserRegistrationCancelledRequested
5861
}

front/src/app/components/agency/agency-dashboard/tabs/AgencyAdminTabContent.tsx

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,9 @@ export const AgencyAdminTabContent = ({
8181
agencyRights={agenciesUserIsAdminOn}
8282
user={currentUser}
8383
title={`Organismes sur lesquels vous êtes administrateur (${agenciesUserIsAdminOn.length} organismes)`}
84+
removeAgencyRightIdPrefix={
85+
domElementIds.agencyDashboard.agencyTab.removeAgencyRight
86+
}
8487
modalId={domElementIds.agencyDashboard.agencyTab.adminRightsModal}
8588
onUserUpdateRequested={onUserUpdateRequested(
8689
"agency-user-for-dashboard",
@@ -93,6 +96,9 @@ export const AgencyAdminTabContent = ({
9396
agencyRights={agenciesUserIsNotAdminOn}
9497
user={currentUser}
9598
title={`Organismes auxquels vous êtes rattaché (${agenciesUserIsNotAdminOn.length} organismes)`}
99+
removeAgencyRightIdPrefix={
100+
domElementIds.agencyDashboard.agencyTab.removeAgencyRight
101+
}
96102
modalId={domElementIds.agencyDashboard.agencyTab.userRightsModal}
97103
onUserUpdateRequested={onUserUpdateRequested(
98104
"agency-user-for-dashboard",

front/src/core-logic/domain/feedback/feedback.content.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -341,6 +341,18 @@ export const feedbacks: Record<
341341
title: "Problème lors de la création de l'utilisateur",
342342
message: "Une erreur est survenue lors de la création de l'utilisateur",
343343
},
344+
"delete.success": {
345+
action: removeUserFromAgencySlice.actions.removeUserFromAgencySucceeded,
346+
title: "L'utilisateur n'est plus rattaché à cette agence",
347+
message: "Les données de l'utilisateur (rôles) ont été mises à jour.",
348+
},
349+
"delete.error": {
350+
action: removeUserFromAgencySlice.actions.removeUserFromAgencyFailed,
351+
title:
352+
"Problème lors de la suppression du rattachement l'utilisateur à cette agence",
353+
message:
354+
"Une erreur est survenue lors de la suppression du rattachement de l'utilisateur.",
355+
},
344356
},
345357
"dashboard-agency-register-user": {
346358
"fetch.error": {

shared/src/domElementIds.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -882,6 +882,7 @@ export const domElementIds = {
882882
"im-reject-agency-modal__justification-input",
883883
rejectAgencyModalSubmitButton: "im-reject-agency-modal__submit-button",
884884
rejectAgencyModalCancelButton: "im-reject-agency-modal__cancel-button",
885+
removeAgencyRight: "im-remove-agency-right__button",
885886
userRegistrationToAgencyModal:
886887
"im-register-user-to-agency__user-registration-modal",
887888
closeAgencyAndTransferConventionsModal:
@@ -931,6 +932,7 @@ export const domElementIds = {
931932
adminAgencyLink: "im-profile__admin-agency-link",
932933
adminEstablishmentLink: "im-profile__admin-establishment-link",
933934
cancelRegistrationButton: "im-profile__cancel-registration-button",
935+
removeAgencyRight: "im-profile__remove-agency-right-button",
934936
updateOwnInfosLink: "im-profile__update-own-infos-link",
935937
editAgencyUserEmail: "im-profile-edit-agency-user__email",
936938
editAgencyManageUserCheckbox:
@@ -992,6 +994,7 @@ export const domElementIds = {
992994
},
993995
registerAgencies: {
994996
newAgencyButton: "im-register-agencies__new-agency-button",
997+
removeAgencyRight: "im-register-agencies__remove-agency-right-button",
995998
showRegistrationFormButton:
996999
"im-register-agencies__show-registration-form-button",
9971000
table: "im-register-agencies-table",
@@ -1014,6 +1017,8 @@ export const domElementIds = {
10141017
agencyTab: {
10151018
adminRightsModal: "im-agency-dashboard__agency-tab-admin-rights-modal",
10161019
userRightsModal: "im-agency-dashboard__agency-tab-user-rights-modal",
1020+
removeAgencyRight:
1021+
"im-agency-dashboard__agency-tab-remove-user-agency-right",
10171022
},
10181023
agencyDetails: {
10191024
editAgencyForm: "im-agency-dashboard-form-edit-agency",

0 commit comments

Comments
 (0)