diff --git a/apps/web/src/views/card/components/AttachmentThumbnails.tsx b/apps/web/src/views/card/components/AttachmentThumbnails.tsx index 2ee0afad..228966fd 100644 --- a/apps/web/src/views/card/components/AttachmentThumbnails.tsx +++ b/apps/web/src/views/card/components/AttachmentThumbnails.tsx @@ -26,9 +26,11 @@ interface Attachment { export function AttachmentThumbnails({ attachments, cardPublicId, + isReadOnly = false, }: { attachments?: Attachment[]; cardPublicId: string; + isReadOnly?: boolean; }) { const { showPopup } = usePopup(); const utils = api.useUtils(); @@ -48,6 +50,8 @@ export function AttachmentThumbnails({ const deleteAttachment = api.attachment.delete.useMutation({ onMutate: async (args) => { + if (isReadOnly) return; + await utils.card.byId.cancel({ cardPublicId }); const currentState = utils.card.byId.getData({ cardPublicId }); @@ -62,6 +66,7 @@ export function AttachmentThumbnails({ return { previousState: currentState }; }, onError: (_error, _args, context) => { + if (isReadOnly) return; utils.card.byId.setData({ cardPublicId }, context?.previousState); showPopup({ header: t`Unable to delete attachment`, @@ -70,10 +75,12 @@ export function AttachmentThumbnails({ }); }, onSuccess: () => { + if (isReadOnly) return; // Close viewer if the deleted image was being viewed setSelectedIndex(null); }, onSettled: async () => { + if (isReadOnly) return; await utils.card.byId.invalidate({ cardPublicId }); }, }); @@ -152,7 +159,7 @@ export function AttachmentThumbnails({ return ( <> -
+
{imageAttachments.map((attachment, index) => { if (!attachment.url) return null; return ( @@ -180,11 +187,15 @@ export function AttachmentThumbnails({ key={attachment.publicId} attachment={attachment} onDownload={() => handleDownload(attachment)} - onDelete={() => { - deleteAttachment.mutate({ - attachmentPublicId: attachment.publicId, - }); - }} + onDelete={ + isReadOnly + ? undefined + : () => { + deleteAttachment.mutate({ + attachmentPublicId: attachment.publicId, + }); + } + } /> ); })} @@ -221,13 +232,13 @@ export function AttachmentThumbnails({
-
e.stopPropagation()} - onClick={(e) => e.stopPropagation()} - > - {selectedIndex !== null && selectedAttachment && ( - <> + {selectedIndex !== null && selectedAttachment && ( +
e.stopPropagation()} + onClick={(e) => e.stopPropagation()} + > + {!isReadOnly && ( - - - )} -
+ )} + +
+ )}
{imageAttachments.length > 1 && selectedIndex !== null && ( @@ -405,7 +416,7 @@ function FileListItem({ }: { attachment: Attachment; onDownload: () => void; - onDelete: () => void; + onDelete?: () => void; }) { return (
@@ -432,16 +443,18 @@ function FileListItem({ > - + {onDelete && ( + + )}
diff --git a/apps/web/src/views/public/board/CardModal.tsx b/apps/web/src/views/public/board/CardModal.tsx index f6fa3f80..b5cf1902 100644 --- a/apps/web/src/views/public/board/CardModal.tsx +++ b/apps/web/src/views/public/board/CardModal.tsx @@ -9,6 +9,7 @@ import LabelIcon from "~/components/LabelIcon"; import { useModal } from "~/providers/modal"; import { api } from "~/utils/api"; import ActivityList from "~/views/card/components/ActivityList"; +import { AttachmentThumbnails } from "~/views/card/components/AttachmentThumbnails"; import Checklists from "~/views/card/components/Checklists"; export function CardModal({ @@ -126,11 +127,24 @@ export function CardModal({
)} + {data?.attachments && + data.attachments.length > 0 && + cardPublicId && ( +
+ +
+ )} {data?.checklists && data.checklists.length > 0 && ( ))}