Skip to content

Commit 5491179

Browse files
committed
🚚(frontend) move modal Share directly to concern component
To keep consistency with the other modals, we move the share modal directly to the DocsGridActions component. This way, we avoid having to pass down the openShareModal function from parent components and keep the logic related to sharing a doc encapsulated within the concern component.
1 parent 4680316 commit 5491179

File tree

4 files changed

+57
-72
lines changed

4 files changed

+57
-72
lines changed

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

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,19 +12,18 @@ import {
1212
useDeleteFavoriteDoc,
1313
useDuplicateDoc,
1414
} from '@/docs/doc-management';
15+
import { DocShareModal } from '@/docs/doc-share';
1516

1617
interface DocsGridActionsProps {
1718
doc: Doc;
18-
openShareModal?: () => void;
1919
}
2020

21-
export const DocsGridActions = ({
22-
doc,
23-
openShareModal,
24-
}: DocsGridActionsProps) => {
21+
export const DocsGridActions = ({ doc }: DocsGridActionsProps) => {
2522
const { t } = useTranslation();
2623

2724
const deleteModal = useModal();
25+
const shareModal = useModal();
26+
2827
const { mutate: duplicateDoc } = useDuplicateDoc();
2928

3029
const removeFavoriteDoc = useDeleteFavoriteDoc({
@@ -52,7 +51,7 @@ export const DocsGridActions = ({
5251
label: t('Share'),
5352
icon: 'group',
5453
callback: () => {
55-
openShareModal?.();
54+
shareModal.open();
5655
},
5756

5857
testId: `docs-grid-actions-share-${doc.id}`,
@@ -114,6 +113,9 @@ export const DocsGridActions = ({
114113
{deleteModal.isOpen && (
115114
<ModalRemoveDoc onClose={deleteModal.onClose} doc={doc} />
116115
)}
116+
{shareModal.isOpen && (
117+
<DocShareModal doc={doc} onClose={shareModal.close} />
118+
)}
117119
</>
118120
);
119121
};

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

Lines changed: 3 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { Tooltip, useModal } from '@gouvfr-lasuite/cunningham-react';
1+
import { Tooltip } from '@gouvfr-lasuite/cunningham-react';
22
import { useSearchParams } from 'next/navigation';
33
import { KeyboardEvent } from 'react';
44
import { useTranslation } from 'react-i18next';
@@ -8,7 +8,6 @@ import { Box, Icon, StyledLink, Text } from '@/components';
88
import { useConfig } from '@/core';
99
import { useCunninghamTheme } from '@/cunningham';
1010
import { Doc, LinkReach, SimpleDocItem } from '@/docs/doc-management';
11-
import { DocShareModal } from '@/docs/doc-share';
1211
import { useDate } from '@/hooks';
1312
import { useResponsiveStore } from '@/stores';
1413

@@ -32,15 +31,10 @@ export const DocsGridItem = ({ doc, dragMode = false }: DocsGridItemProps) => {
3231
const { isDesktop } = useResponsiveStore();
3332
const { flexLeft, flexRight } = useResponsiveDocGrid();
3433
const { spacingsTokens } = useCunninghamTheme();
35-
const shareModal = useModal();
3634
const isPublic = doc.link_reach === LinkReach.PUBLIC;
3735
const isAuthenticated = doc.link_reach === LinkReach.AUTHENTICATED;
3836
const isShared = isPublic || isAuthenticated;
3937

40-
const handleShareClick = () => {
41-
shareModal.open();
42-
};
43-
4438
const handleKeyDown = (e: KeyboardEvent) => {
4539
if (e.key === 'Enter' || e.key === ' ') {
4640
e.preventDefault();
@@ -173,23 +167,16 @@ export const DocsGridItem = ({ doc, dragMode = false }: DocsGridItemProps) => {
173167

174168
<Box $direction="row" $align="center" $gap={spacingsTokens.lg}>
175169
{isDesktop && (
176-
<DocsGridItemSharedButton
177-
doc={doc}
178-
handleClick={handleShareClick}
179-
disabled={isInTrashbin}
180-
/>
170+
<DocsGridItemSharedButton doc={doc} disabled={isInTrashbin} />
181171
)}
182172
{isInTrashbin ? (
183173
<DocsGridTrashbinActions doc={doc} />
184174
) : (
185-
<DocsGridActions doc={doc} openShareModal={handleShareClick} />
175+
<DocsGridActions doc={doc} />
186176
)}
187177
</Box>
188178
</Box>
189179
</Box>
190-
{shareModal.isOpen && (
191-
<DocShareModal doc={doc} onClose={shareModal.close} />
192-
)}
193180
</>
194181
);
195182
};
Lines changed: 45 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -1,65 +1,67 @@
1-
import { Button, Tooltip } from '@gouvfr-lasuite/cunningham-react';
1+
import { Button, Tooltip, useModal } from '@gouvfr-lasuite/cunningham-react';
22
import { useTranslation } from 'react-i18next';
33

44
import { Box, Icon, Text } from '@/components';
55
import { Doc } from '@/docs/doc-management';
6+
import { DocShareModal } from '@/docs/doc-share';
67

78
type Props = {
89
doc: Doc;
9-
handleClick: () => void;
1010
disabled: boolean;
1111
};
12-
export const DocsGridItemSharedButton = ({
13-
doc,
14-
handleClick,
15-
disabled,
16-
}: Props) => {
12+
export const DocsGridItemSharedButton = ({ doc, disabled }: Props) => {
1713
const { t } = useTranslation();
1814
const sharedCount = doc.nb_accesses_direct;
1915
const isShared = sharedCount - 1 > 0;
16+
const shareModal = useModal();
2017

2118
if (!isShared) {
2219
return <Box $minWidth="50px">&nbsp;</Box>;
2320
}
2421

2522
return (
26-
<Tooltip
27-
content={
28-
<Text $textAlign="center">
29-
{t('Shared with {{count}} users', { count: sharedCount })}
30-
</Text>
31-
}
32-
placement="top"
33-
className="--docs--doc-tooltip-grid-item-shared-button"
34-
>
35-
<Button
36-
className="--docs--doc-grid-item-shared-button"
37-
aria-label={t('Open the sharing settings for the document')}
38-
data-testid={`docs-grid-item-shared-button-${doc.id}`}
39-
style={{
40-
padding: `0 var(--c--globals--spacings--xxxs) 0 var(--c--globals--spacings--xxxs)`,
41-
}}
42-
onClick={(event) => {
43-
event.preventDefault();
44-
event.stopPropagation();
45-
handleClick();
46-
}}
47-
color="brand"
48-
variant="secondary"
49-
size="nano"
50-
icon={
51-
<Icon
52-
$theme="brand"
53-
$variation="secondary"
54-
iconName="group"
55-
disabled={disabled}
56-
variant="filled"
57-
/>
23+
<>
24+
<Tooltip
25+
content={
26+
<Text $textAlign="center">
27+
{t('Shared with {{count}} users', { count: sharedCount })}
28+
</Text>
5829
}
59-
disabled={disabled}
30+
placement="top"
31+
className="--docs--doc-tooltip-grid-item-shared-button"
6032
>
61-
{sharedCount}
62-
</Button>
63-
</Tooltip>
33+
<Button
34+
className="--docs--doc-grid-item-shared-button"
35+
aria-label={t('Open the sharing settings for the document')}
36+
data-testid={`docs-grid-item-shared-button-${doc.id}`}
37+
style={{
38+
padding: `0 var(--c--globals--spacings--xxxs) 0 var(--c--globals--spacings--xxxs)`,
39+
}}
40+
onClick={(event) => {
41+
event.preventDefault();
42+
event.stopPropagation();
43+
shareModal.open();
44+
}}
45+
color="brand"
46+
variant="secondary"
47+
size="nano"
48+
icon={
49+
<Icon
50+
$theme="brand"
51+
$variation="secondary"
52+
iconName="group"
53+
disabled={disabled}
54+
variant="filled"
55+
/>
56+
}
57+
disabled={disabled}
58+
>
59+
{sharedCount}
60+
</Button>
61+
</Tooltip>
62+
{shareModal.isOpen && (
63+
<DocShareModal doc={doc} onClose={shareModal.close} />
64+
)}
65+
</>
6466
);
6567
};

src/frontend/apps/impress/src/features/left-panel/components/LeftPanelFavoriteItem.tsx

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,10 @@
1-
import { useModal } from '@gouvfr-lasuite/cunningham-react';
21
import { t } from 'i18next';
32
import { DateTime } from 'luxon';
43
import { css } from 'styled-components';
54

65
import { Box, StyledLink } from '@/components';
76
import { useCunninghamTheme } from '@/cunningham';
87
import { Doc, SimpleDocItem } from '@/docs/doc-management';
9-
import { DocShareModal } from '@/docs/doc-share';
108
import { DocsGridActions } from '@/docs/docs-grid';
119
import { useResponsiveStore } from '@/stores';
1210

@@ -15,7 +13,6 @@ type LeftPanelFavoriteItemProps = {
1513
};
1614

1715
export const LeftPanelFavoriteItem = ({ doc }: LeftPanelFavoriteItemProps) => {
18-
const shareModal = useModal();
1916
const { colorsTokens, spacingsTokens } = useCunninghamTheme();
2017
const { isDesktop } = useResponsiveStore();
2118

@@ -61,11 +58,8 @@ export const LeftPanelFavoriteItem = ({ doc }: LeftPanelFavoriteItemProps) => {
6158
<SimpleDocItem showAccesses doc={doc} />
6259
</StyledLink>
6360
<Box className="pinned-actions" $align="center">
64-
<DocsGridActions doc={doc} openShareModal={shareModal.open} />
61+
<DocsGridActions doc={doc} />
6562
</Box>
66-
{shareModal.isOpen && (
67-
<DocShareModal doc={doc} onClose={shareModal.close} />
68-
)}
6963
</Box>
7064
);
7165
};

0 commit comments

Comments
 (0)