Skip to content

Commit 8285121

Browse files
✨(frontend) add AlertModal and enhance document sharing features
- Introduced a new `AlertModal` component for confirmation dialogs. - Updated `DocToolBoxLicenceAGPL` and `DocToolBoxLicenceMIT` to include `isRootDoc` prop for better document management. - Enhanced `DocShareModal` to conditionally render content based on the root document status. - Improved `DocInheritedShareContent` to display inherited access information more effectively. - Refactored `DocRoleDropdown` to handle access removal actions and improve role management. - Updated `DocShareMemberItem` to accommodate new access management features.
1 parent 98c8b46 commit 8285121

File tree

21 files changed

+488
-503
lines changed

21 files changed

+488
-503
lines changed
Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
import { Button, Modal, ModalSize } from '@openfun/cunningham-react';
2+
import { useTranslation } from 'react-i18next';
3+
4+
import { Box } from '../Box';
5+
import { Text } from '../Text';
6+
7+
export type AlertModalProps = {
8+
isOpen: boolean;
9+
onClose: () => void;
10+
title: string;
11+
description: string | React.ReactNode;
12+
onConfirm: () => void;
13+
confirmLabel?: string;
14+
cancelLabel?: string;
15+
};
16+
17+
export const AlertModal = ({
18+
isOpen,
19+
onClose,
20+
title,
21+
description,
22+
onConfirm,
23+
confirmLabel,
24+
cancelLabel,
25+
}: AlertModalProps) => {
26+
const { t } = useTranslation();
27+
return (
28+
<Modal
29+
isOpen={isOpen}
30+
size={ModalSize.MEDIUM}
31+
onClose={onClose}
32+
title={
33+
<Text $size="h6" $align="flex-start" $variation="1000">
34+
{title}
35+
</Text>
36+
}
37+
rightActions={
38+
<>
39+
<Button
40+
aria-label={t('Close the modal')}
41+
color="secondary"
42+
fullWidth
43+
onClick={() => onClose()}
44+
>
45+
{cancelLabel ?? t('Cancel')}
46+
</Button>
47+
<Button
48+
aria-label={confirmLabel ?? t('Confirm')}
49+
color="danger"
50+
onClick={onConfirm}
51+
>
52+
{confirmLabel ?? t('Confirm')}
53+
</Button>
54+
</>
55+
}
56+
>
57+
<Box
58+
aria-label={t('Confirmation button')}
59+
className="--docs--alert-modal"
60+
>
61+
<Box>
62+
<Text $variation="600">{description}</Text>
63+
</Box>
64+
</Box>
65+
</Modal>
66+
);
67+
};

src/frontend/apps/impress/src/features/docs/doc-header/components/DocToolBox.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,7 @@ export const DocToolBox = ({ doc }: DocToolBoxProps) => {
117117
doc={doc}
118118
modalHistory={modalHistory}
119119
modalShare={modalShare}
120+
isRootDoc={treeContext?.root?.id === doc.id}
120121
/>
121122
</Box>
122123
</Box>

src/frontend/apps/impress/src/features/docs/doc-header/components/DocToolBoxLicenceAGPL.tsx

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,12 +37,14 @@ interface DocToolBoxLicenceProps {
3737
doc: Doc;
3838
modalHistory: ModalType;
3939
modalShare: ModalType;
40+
isRootDoc?: boolean;
4041
}
4142

4243
export const DocToolBoxLicenceAGPL = ({
4344
doc,
4445
modalHistory,
4546
modalShare,
47+
isRootDoc = true,
4648
}: DocToolBoxLicenceProps) => {
4749
const { t } = useTranslation();
4850
const queryClient = useQueryClient();
@@ -176,7 +178,11 @@ export const DocToolBoxLicenceAGPL = ({
176178
</DropdownMenu>
177179

178180
{modalShare.isOpen && (
179-
<DocShareModal onClose={() => modalShare.close()} doc={doc} />
181+
<DocShareModal
182+
onClose={() => modalShare.close()}
183+
doc={doc}
184+
isRootDoc={isRootDoc}
185+
/>
180186
)}
181187
{isModalExportOpen && (
182188
<ModalExport onClose={() => setIsModalExportOpen(false)} doc={doc} />

src/frontend/apps/impress/src/features/docs/doc-header/components/DocToolBoxLicenceMIT.tsx

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,12 +31,14 @@ interface DocToolBoxLicenceProps {
3131
doc: Doc;
3232
modalHistory: ModalType;
3333
modalShare: ModalType;
34+
isRootDoc?: boolean;
3435
}
3536

3637
export const DocToolBoxLicenceMIT = ({
3738
doc,
3839
modalHistory,
3940
modalShare,
41+
isRootDoc = true,
4042
}: DocToolBoxLicenceProps) => {
4143
const { t } = useTranslation();
4244
const queryClient = useQueryClient();
@@ -152,7 +154,11 @@ export const DocToolBoxLicenceMIT = ({
152154
</DropdownMenu>
153155

154156
{modalShare.isOpen && (
155-
<DocShareModal onClose={() => modalShare.close()} doc={doc} />
157+
<DocShareModal
158+
onClose={() => modalShare.close()}
159+
doc={doc}
160+
isRootDoc={isRootDoc}
161+
/>
156162
)}
157163
{isModalRemoveOpen && (
158164
<ModalRemoveDoc onClose={() => setIsModalRemoveOpen(false)} doc={doc} />

src/frontend/apps/impress/src/features/docs/doc-management/components/ModalRemoveDoc.tsx

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@ import { useRouter } from 'next/router';
1212
import { Box, Text, TextErrors } from '@/components';
1313

1414
import { useRemoveDoc } from '../api/useRemoveDoc';
15-
import { useTrans } from '../hooks';
1615
import { Doc } from '../types';
1716

1817
interface ModalRemoveDocProps {
@@ -29,7 +28,6 @@ export const ModalRemoveDoc = ({
2928
const { toast } = useToastProvider();
3029
const { push } = useRouter();
3130
const pathname = usePathname();
32-
const { untitledDocument } = useTrans(doc);
3331

3432
const {
3533
mutate: removeDoc,
@@ -82,7 +80,7 @@ export const ModalRemoveDoc = ({
8280
</Button>
8381
</>
8482
}
85-
size={ModalSize.SMALL}
83+
size={ModalSize.MEDIUM}
8684
title={
8785
<Text
8886
$size="h6"
@@ -100,11 +98,13 @@ export const ModalRemoveDoc = ({
10098
className="--docs--modal-remove-doc"
10199
>
102100
{!isError && (
103-
<Text $size="sm" $variation="600">
104-
{t('Are you sure you want to delete the document "{{title}}"?', {
105-
title: doc.title ?? untitledDocument,
106-
})}
107-
</Text>
101+
<>
102+
<Text $size="sm" $variation="600">
103+
{t(
104+
'This document will be permanently deleted. This action is irreversible.',
105+
)}
106+
</Text>
107+
</>
108108
)}
109109

110110
{isError && <TextErrors causes={error.cause} />}

src/frontend/apps/impress/src/features/docs/doc-search/components/DocSearchModal.tsx

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,10 @@ export const DocSearchModal = ({
7474
loading={loading}
7575
onFilter={handleInputSearch}
7676
>
77-
<Box $height={isDesktop ? '500px' : 'calc(100vh - 68px - 1rem)'}>
77+
<Box
78+
$padding={{ horizontal: '10px' }}
79+
$height={isDesktop ? '500px' : 'calc(100vh - 68px - 1rem)'}
80+
>
7881
{showFilters && (
7982
<DocSearchFilters
8083
values={filters}

src/frontend/apps/impress/src/features/docs/doc-share/api/useDocAccesses.tsx

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,17 @@
11
import { UseQueryOptions, useQuery } from '@tanstack/react-query';
22

33
import { APIError, errorCauses, fetchAPI } from '@/api';
4-
54
import { Access } from '@/docs/doc-management';
65

76
export type DocAccessesParams = {
87
docId: string;
98
ordering?: string;
109
};
1110

12-
export type DocAccessesAPIParams = DocAccessesParams & {};
13-
1411
export const getDocAccesses = async ({
1512
docId,
1613
ordering,
17-
}: DocAccessesAPIParams): Promise<Access[]> => {
14+
}: DocAccessesParams): Promise<Access[]> => {
1815
let url = `documents/${docId}/accesses/`;
1916

2017
if (ordering) {
@@ -36,7 +33,7 @@ export const getDocAccesses = async ({
3633
export const KEY_LIST_DOC_ACCESSES = 'docs-accesses';
3734

3835
export function useDocAccesses(
39-
params: DocAccessesAPIParams,
36+
params: DocAccessesParams,
4037
queryConfig?: UseQueryOptions<Access[], APIError, Access[]>,
4138
) {
4239
return useQuery<Access[], APIError, Access[]>({

0 commit comments

Comments
 (0)