|
1 | 1 | import Button from "@codegouvfr/react-dsfr/Button"; |
2 | 2 | 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 | +}; |
4 | 19 |
|
5 | 20 | export const AgencyLineRightsCTAs = ({ |
| 21 | + removeAgencyRightIdPrefix, |
6 | 22 | agencyRight, |
7 | | - isBackofficeAdmin, |
| 23 | + user, |
8 | 24 | onUpdateClicked, |
9 | 25 | 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 | +}; |
0 commit comments