diff --git a/apps/app/components/issues/attachment-upload.tsx b/apps/app/components/issues/attachment-upload.tsx index a9fb0e13777..c684f9afd4b 100644 --- a/apps/app/components/issues/attachment-upload.tsx +++ b/apps/app/components/issues/attachment-upload.tsx @@ -38,6 +38,7 @@ export const IssueAttachmentUpload = () => { }) ); setIsLoading(true); + issuesService .uploadIssueAttachment( workspaceSlug as string, @@ -46,7 +47,11 @@ export const IssueAttachmentUpload = () => { formData ) .then((res) => { - mutate(ISSUE_ATTACHMENTS(issueId as string)); + mutate( + ISSUE_ATTACHMENTS(issueId as string), + (prevData) => [res, ...(prevData ?? [])], + false + ); setToastAlert({ type: "success", title: "Success!", diff --git a/apps/app/components/issues/delete-attachment-modal.tsx b/apps/app/components/issues/delete-attachment-modal.tsx index 92906244aae..645b4ba5d47 100644 --- a/apps/app/components/issues/delete-attachment-modal.tsx +++ b/apps/app/components/issues/delete-attachment-modal.tsx @@ -1,4 +1,4 @@ -import React, { useState } from "react"; +import React from "react"; import { useRouter } from "next/router"; @@ -28,8 +28,6 @@ type Props = { }; export const DeleteAttachmentModal: React.FC = ({ isOpen, setIsOpen, data }) => { - const [isDeleteLoading, setIsDeleteLoading] = useState(false); - const router = useRouter(); const { workspaceSlug, projectId, issueId } = router.query; @@ -37,15 +35,16 @@ export const DeleteAttachmentModal: React.FC = ({ isOpen, setIsOpen, data const handleClose = () => { setIsOpen(false); - setIsDeleteLoading(false); }; const handleDeletion = async (assetId: string) => { - setIsDeleteLoading(true); - if (!workspaceSlug || !projectId || !data) return; - mutate(ISSUE_ATTACHMENTS(issueId as string)); + mutate( + ISSUE_ATTACHMENTS(issueId as string), + (prevData) => (prevData ?? [])?.filter((p) => p.id !== assetId), + false + ); await issuesService .deleteIssueAttachment( @@ -54,22 +53,12 @@ export const DeleteAttachmentModal: React.FC = ({ isOpen, setIsOpen, data issueId as string, assetId as string ) - .then((res) => { - mutate(ISSUE_ATTACHMENTS(issueId as string)); - setToastAlert({ - type: "success", - title: "Success!", - message: "File removed successfully.", - }); - handleClose(); - }) - .catch((err) => { + .catch(() => { setToastAlert({ type: "error", title: "error!", message: "Something went wrong please try again.", }); - setIsDeleteLoading(false); }); }; @@ -129,8 +118,13 @@ export const DeleteAttachmentModal: React.FC = ({ isOpen, setIsOpen, data
Cancel - handleDeletion(data.id)} loading={isDeleteLoading}> - {isDeleteLoading ? "Deleting..." : "Delete"} + { + handleDeletion(data.id); + handleClose(); + }} + > + Delete