Skip to content

Commit f7093b5

Browse files
committed
🛂(frontend) add access request modal on move modal
If a user tries to move a document for which they don't have the right to move, we now display a modal to request access to the owners of the document.
1 parent 9711538 commit f7093b5

File tree

4 files changed

+121
-6
lines changed

4 files changed

+121
-6
lines changed

src/frontend/apps/impress/src/components/modal/AlertModal.tsx

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,10 @@
1-
import { Button, Modal, ModalSize } from '@gouvfr-lasuite/cunningham-react';
1+
import {
2+
Button,
3+
ButtonProps,
4+
Modal,
5+
ModalProps,
6+
ModalSize,
7+
} from '@gouvfr-lasuite/cunningham-react';
28
import { ReactNode } from 'react';
39
import { useTranslation } from 'react-i18next';
410

@@ -10,10 +16,11 @@ export type AlertModalProps = {
1016
isOpen: boolean;
1117
onClose: () => void;
1218
onConfirm: () => void;
19+
themeCTA?: ButtonProps['color'];
1320
title: string;
1421
cancelLabel?: string;
1522
confirmLabel?: string;
16-
};
23+
} & Partial<ModalProps>;
1724

1825
export const AlertModal = ({
1926
cancelLabel,
@@ -23,6 +30,8 @@ export const AlertModal = ({
2330
onClose,
2431
onConfirm,
2532
title,
33+
themeCTA,
34+
...props
2635
}: AlertModalProps) => {
2736
const { t } = useTranslation();
2837
return (
@@ -46,7 +55,7 @@ export const AlertModal = ({
4655
<Box $direction="row-reverse" $gap="small">
4756
<Button
4857
aria-label={confirmLabel ?? t('Confirm')}
49-
color="error"
58+
color={themeCTA ?? 'error'}
5059
onClick={onConfirm}
5160
>
5261
{confirmLabel ?? t('Confirm')}
@@ -61,6 +70,7 @@ export const AlertModal = ({
6170
</Button>
6271
</Box>
6372
}
73+
{...props}
6474
>
6575
<Box className="--docs--alert-modal">
6676
<Box>
Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
1+
import { Button } from '@gouvfr-lasuite/cunningham-react';
2+
import { Trans, useTranslation } from 'react-i18next';
3+
4+
import { AlertModal, Box, Icon, Text } from '@/components';
5+
6+
import { useDocAccessRequests } from '../api/useDocAccessRequest';
7+
8+
import { ButtonAccessRequest } from './DocShareAccessRequest';
9+
10+
interface AlertModalRequestAccessProps {
11+
docId: string;
12+
isOpen: boolean;
13+
onClose: () => void;
14+
onConfirm: () => void;
15+
targetDocumentTitle: string;
16+
title: string;
17+
}
18+
19+
export const AlertModalRequestAccess = ({
20+
docId,
21+
isOpen,
22+
onClose,
23+
onConfirm,
24+
targetDocumentTitle,
25+
title,
26+
}: AlertModalRequestAccessProps) => {
27+
const { t } = useTranslation();
28+
const { data: requests } = useDocAccessRequests({
29+
docId,
30+
page: 1,
31+
});
32+
33+
const hasRequested = !!(
34+
requests && requests?.results.find((request) => request.document === docId)
35+
);
36+
37+
return (
38+
<AlertModal
39+
onClose={onClose}
40+
isOpen={isOpen}
41+
title={title}
42+
description={
43+
<>
44+
<Text $display="inline">
45+
<Trans
46+
i18nKey="You don't have permission to move this document to <strong>{{targetDocumentTitle}}</strong>. You need edit access to the destination. Request access, then try again."
47+
values={{
48+
targetDocumentTitle,
49+
}}
50+
components={{ strong: <strong /> }}
51+
/>
52+
</Text>
53+
{hasRequested && (
54+
<Text
55+
$weight="bold"
56+
$margin={{ top: 'sm' }}
57+
$direction="row"
58+
$align="center"
59+
>
60+
<Icon
61+
iconName="person_check"
62+
$margin={{ right: 'xxs' }}
63+
variant="symbols-outlined"
64+
/>
65+
{t('You have already requested access to this document.')}
66+
</Text>
67+
)}
68+
</>
69+
}
70+
confirmLabel={t('Request access')}
71+
onConfirm={onConfirm}
72+
rightActions={
73+
<Box $direction="row-reverse" $gap="small">
74+
<ButtonAccessRequest docId={docId} />
75+
<Button
76+
aria-label={t('Cancel')}
77+
variant="secondary"
78+
fullWidth
79+
onClick={() => onClose()}
80+
>
81+
{t('Cancel')}
82+
</Button>
83+
</Box>
84+
}
85+
/>
86+
);
87+
};
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
1+
export * from './AlertModalRequestAccess';
12
export * from './DocShareModal';
23
export * from './DocShareAccessRequest';

src/frontend/apps/impress/src/features/docs/docs-grid/components/DocMoveModal.tsx

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ import { QuickSearch } from '@/components/quick-search';
1616
import { Doc, useMoveDoc, useTrans } from '@/docs/doc-management';
1717
import { DocSearchContent, DocSearchTarget } from '@/docs/doc-search';
1818
import EmptySearchIcon from '@/docs/doc-search/assets/illustration-docs-empty.png';
19+
import { AlertModalRequestAccess } from '@/docs/doc-share';
1920
import { useResponsiveStore } from '@/stores';
2021

2122
import { DocsGridItemDate, DocsGridItemTitle } from './DocsGridItem';
@@ -75,6 +76,7 @@ export const DocMoveModal = ({
7576
const docTitle = doc.title || untitledDocument;
7677
const docTargetTitle = docSelected?.title || untitledDocument;
7778
const modalConfirmation = useModal();
79+
const modalRequest = useModal();
7880
const { mutate: moveDoc } = useMoveDoc(true);
7981
const [search, setSearch] = useState('');
8082
const { isDesktop } = useResponsiveStore();
@@ -113,6 +115,11 @@ export const DocMoveModal = ({
113115
variant="primary"
114116
fullWidth
115117
onClick={() => {
118+
if (!docSelected?.abilities.move) {
119+
modalRequest.open();
120+
return;
121+
}
122+
116123
if (doc.nb_accesses_direct > 1) {
117124
modalConfirmation.open();
118125
return;
@@ -210,9 +217,7 @@ export const DocMoveModal = ({
210217
<DocSearchContent
211218
search={search}
212219
filters={{ target: DocSearchTarget.ALL }}
213-
filterResults={(docResults) =>
214-
docResults.id !== doc.id && docResults.abilities.move
215-
}
220+
filterResults={(docResults) => docResults.id !== doc.id}
216221
onSelect={handleSelect}
217222
onLoadingChange={setLoading}
218223
renderSearchElement={(docSearch) => {
@@ -274,6 +279,18 @@ export const DocMoveModal = ({
274279
targetDocumentTitle={docTargetTitle}
275280
/>
276281
)}
282+
{modalRequest.isOpen && docSelected?.id && (
283+
<AlertModalRequestAccess
284+
docId={docSelected.id}
285+
isOpen={modalRequest.isOpen}
286+
onClose={modalRequest.onClose}
287+
onConfirm={() => {
288+
modalRequest.onClose();
289+
}}
290+
targetDocumentTitle={docTargetTitle}
291+
title={t('Move document')}
292+
/>
293+
)}
277294
</>
278295
);
279296
};

0 commit comments

Comments
 (0)