🚚(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.
This commit is contained in:
@@ -12,19 +12,18 @@ import {
|
||||
useDeleteFavoriteDoc,
|
||||
useDuplicateDoc,
|
||||
} from '@/docs/doc-management';
|
||||
import { DocShareModal } from '@/docs/doc-share';
|
||||
|
||||
interface DocsGridActionsProps {
|
||||
doc: Doc;
|
||||
openShareModal?: () => void;
|
||||
}
|
||||
|
||||
export const DocsGridActions = ({
|
||||
doc,
|
||||
openShareModal,
|
||||
}: DocsGridActionsProps) => {
|
||||
export const DocsGridActions = ({ doc }: DocsGridActionsProps) => {
|
||||
const { t } = useTranslation();
|
||||
|
||||
const deleteModal = useModal();
|
||||
const shareModal = useModal();
|
||||
|
||||
const { mutate: duplicateDoc } = useDuplicateDoc();
|
||||
|
||||
const removeFavoriteDoc = useDeleteFavoriteDoc({
|
||||
@@ -52,7 +51,7 @@ export const DocsGridActions = ({
|
||||
label: t('Share'),
|
||||
icon: 'group',
|
||||
callback: () => {
|
||||
openShareModal?.();
|
||||
shareModal.open();
|
||||
},
|
||||
|
||||
testId: `docs-grid-actions-share-${doc.id}`,
|
||||
@@ -114,6 +113,9 @@ export const DocsGridActions = ({
|
||||
{deleteModal.isOpen && (
|
||||
<ModalRemoveDoc onClose={deleteModal.onClose} doc={doc} />
|
||||
)}
|
||||
{shareModal.isOpen && (
|
||||
<DocShareModal doc={doc} onClose={shareModal.close} />
|
||||
)}
|
||||
</>
|
||||
);
|
||||
};
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { Tooltip, useModal } from '@gouvfr-lasuite/cunningham-react';
|
||||
import { Tooltip } from '@gouvfr-lasuite/cunningham-react';
|
||||
import { useSearchParams } from 'next/navigation';
|
||||
import { KeyboardEvent } from 'react';
|
||||
import { useTranslation } from 'react-i18next';
|
||||
@@ -8,7 +8,6 @@ import { Box, Icon, StyledLink, Text } from '@/components';
|
||||
import { useConfig } from '@/core';
|
||||
import { useCunninghamTheme } from '@/cunningham';
|
||||
import { Doc, LinkReach, SimpleDocItem } from '@/docs/doc-management';
|
||||
import { DocShareModal } from '@/docs/doc-share';
|
||||
import { useDate } from '@/hooks';
|
||||
import { useResponsiveStore } from '@/stores';
|
||||
|
||||
@@ -32,15 +31,10 @@ export const DocsGridItem = ({ doc, dragMode = false }: DocsGridItemProps) => {
|
||||
const { isDesktop } = useResponsiveStore();
|
||||
const { flexLeft, flexRight } = useResponsiveDocGrid();
|
||||
const { spacingsTokens } = useCunninghamTheme();
|
||||
const shareModal = useModal();
|
||||
const isPublic = doc.link_reach === LinkReach.PUBLIC;
|
||||
const isAuthenticated = doc.link_reach === LinkReach.AUTHENTICATED;
|
||||
const isShared = isPublic || isAuthenticated;
|
||||
|
||||
const handleShareClick = () => {
|
||||
shareModal.open();
|
||||
};
|
||||
|
||||
const handleKeyDown = (e: KeyboardEvent) => {
|
||||
if (e.key === 'Enter' || e.key === ' ') {
|
||||
e.preventDefault();
|
||||
@@ -173,23 +167,16 @@ export const DocsGridItem = ({ doc, dragMode = false }: DocsGridItemProps) => {
|
||||
|
||||
<Box $direction="row" $align="center" $gap={spacingsTokens.lg}>
|
||||
{isDesktop && (
|
||||
<DocsGridItemSharedButton
|
||||
doc={doc}
|
||||
handleClick={handleShareClick}
|
||||
disabled={isInTrashbin}
|
||||
/>
|
||||
<DocsGridItemSharedButton doc={doc} disabled={isInTrashbin} />
|
||||
)}
|
||||
{isInTrashbin ? (
|
||||
<DocsGridTrashbinActions doc={doc} />
|
||||
) : (
|
||||
<DocsGridActions doc={doc} openShareModal={handleShareClick} />
|
||||
<DocsGridActions doc={doc} />
|
||||
)}
|
||||
</Box>
|
||||
</Box>
|
||||
</Box>
|
||||
{shareModal.isOpen && (
|
||||
<DocShareModal doc={doc} onClose={shareModal.close} />
|
||||
)}
|
||||
</>
|
||||
);
|
||||
};
|
||||
|
||||
@@ -1,28 +1,26 @@
|
||||
import { Button, Tooltip } from '@gouvfr-lasuite/cunningham-react';
|
||||
import { Button, Tooltip, useModal } from '@gouvfr-lasuite/cunningham-react';
|
||||
import { useTranslation } from 'react-i18next';
|
||||
|
||||
import { Box, Icon, Text } from '@/components';
|
||||
import { Doc } from '@/docs/doc-management';
|
||||
import { DocShareModal } from '@/docs/doc-share';
|
||||
|
||||
type Props = {
|
||||
doc: Doc;
|
||||
handleClick: () => void;
|
||||
disabled: boolean;
|
||||
};
|
||||
export const DocsGridItemSharedButton = ({
|
||||
doc,
|
||||
handleClick,
|
||||
disabled,
|
||||
}: Props) => {
|
||||
export const DocsGridItemSharedButton = ({ doc, disabled }: Props) => {
|
||||
const { t } = useTranslation();
|
||||
const sharedCount = doc.nb_accesses_direct;
|
||||
const isShared = sharedCount - 1 > 0;
|
||||
const shareModal = useModal();
|
||||
|
||||
if (!isShared) {
|
||||
return <Box $minWidth="50px"> </Box>;
|
||||
}
|
||||
|
||||
return (
|
||||
<>
|
||||
<Tooltip
|
||||
content={
|
||||
<Text $textAlign="center">
|
||||
@@ -42,7 +40,7 @@ export const DocsGridItemSharedButton = ({
|
||||
onClick={(event) => {
|
||||
event.preventDefault();
|
||||
event.stopPropagation();
|
||||
handleClick();
|
||||
shareModal.open();
|
||||
}}
|
||||
color="brand"
|
||||
variant="secondary"
|
||||
@@ -61,5 +59,9 @@ export const DocsGridItemSharedButton = ({
|
||||
{sharedCount}
|
||||
</Button>
|
||||
</Tooltip>
|
||||
{shareModal.isOpen && (
|
||||
<DocShareModal doc={doc} onClose={shareModal.close} />
|
||||
)}
|
||||
</>
|
||||
);
|
||||
};
|
||||
|
||||
@@ -1,4 +1,3 @@
|
||||
import { useModal } from '@gouvfr-lasuite/cunningham-react';
|
||||
import { t } from 'i18next';
|
||||
import { DateTime } from 'luxon';
|
||||
import { css } from 'styled-components';
|
||||
@@ -6,7 +5,6 @@ import { css } from 'styled-components';
|
||||
import { Box, StyledLink } from '@/components';
|
||||
import { useCunninghamTheme } from '@/cunningham';
|
||||
import { Doc, SimpleDocItem } from '@/docs/doc-management';
|
||||
import { DocShareModal } from '@/docs/doc-share';
|
||||
import { DocsGridActions } from '@/docs/docs-grid';
|
||||
import { useResponsiveStore } from '@/stores';
|
||||
|
||||
@@ -15,7 +13,6 @@ type LeftPanelFavoriteItemProps = {
|
||||
};
|
||||
|
||||
export const LeftPanelFavoriteItem = ({ doc }: LeftPanelFavoriteItemProps) => {
|
||||
const shareModal = useModal();
|
||||
const { colorsTokens, spacingsTokens } = useCunninghamTheme();
|
||||
const { isDesktop } = useResponsiveStore();
|
||||
|
||||
@@ -61,11 +58,8 @@ export const LeftPanelFavoriteItem = ({ doc }: LeftPanelFavoriteItemProps) => {
|
||||
<SimpleDocItem showAccesses doc={doc} />
|
||||
</StyledLink>
|
||||
<Box className="pinned-actions" $align="center">
|
||||
<DocsGridActions doc={doc} openShareModal={shareModal.open} />
|
||||
<DocsGridActions doc={doc} />
|
||||
</Box>
|
||||
{shareModal.isOpen && (
|
||||
<DocShareModal doc={doc} onClose={shareModal.close} />
|
||||
)}
|
||||
</Box>
|
||||
);
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user