Skip to content

Commit 44909fa

Browse files
PanchoutNathanAntoLC
authored andcommitted
✨(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 1c5270e commit 44909fa

File tree

20 files changed

+459
-392
lines changed

20 files changed

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

src/frontend/apps/impress/src/components/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
export * from './AlertModal';
12
export * from './Box';
23
export * from './BoxButton';
34
export * from './Card';

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

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -277,7 +277,11 @@ export const DocToolBox = ({ doc }: DocToolBoxProps) => {
277277
</Box>
278278

279279
{modalShare.isOpen && (
280-
<DocShareModal onClose={() => modalShare.close()} doc={doc} />
280+
<DocShareModal
281+
onClose={() => modalShare.close()}
282+
doc={doc}
283+
isRootDoc={treeContext?.root?.id === doc.id}
284+
/>
281285
)}
282286
{isModalExportOpen && ModalExport && (
283287
<ModalExport onClose={() => setIsModalExportOpen(false)} doc={doc} />

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

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,13 @@ import {
55
VariantType,
66
useToastProvider,
77
} from '@openfun/cunningham-react';
8-
import { t } from 'i18next';
98
import { usePathname } from 'next/navigation';
109
import { useRouter } from 'next/router';
10+
import { Trans, useTranslation } from 'react-i18next';
1111

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 {
@@ -27,10 +26,9 @@ export const ModalRemoveDoc = ({
2726
afterDelete,
2827
}: ModalRemoveDocProps) => {
2928
const { toast } = useToastProvider();
29+
const { t } = useTranslation();
3030
const { push } = useRouter();
3131
const pathname = usePathname();
32-
const { untitledDocument } = useTrans();
33-
3432
const {
3533
mutate: removeDoc,
3634
isError,
@@ -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,14 @@ 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" $display="inline-block">
103+
<Trans t={t} i18nKey="modal-remove-doc">
104+
This document and <strong>any sub-documents</strong> will be
105+
permanently deleted. This action is irreversible.
106+
</Trans>
107+
</Text>
108+
</>
108109
)}
109110

110111
{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)