mirror of
https://github.com/makeplane/plane
synced 2024-06-14 14:31:34 +00:00
fix: issue attachments mutation (#743)
* fix: dashboard workspace activity mutation * fix: attachment mutation for create and delete
This commit is contained in:
parent
98e6d3de22
commit
c21fb6e942
@ -38,6 +38,7 @@ export const IssueAttachmentUpload = () => {
|
|||||||
})
|
})
|
||||||
);
|
);
|
||||||
setIsLoading(true);
|
setIsLoading(true);
|
||||||
|
|
||||||
issuesService
|
issuesService
|
||||||
.uploadIssueAttachment(
|
.uploadIssueAttachment(
|
||||||
workspaceSlug as string,
|
workspaceSlug as string,
|
||||||
@ -46,7 +47,11 @@ export const IssueAttachmentUpload = () => {
|
|||||||
formData
|
formData
|
||||||
)
|
)
|
||||||
.then((res) => {
|
.then((res) => {
|
||||||
mutate<IIssueAttachment[]>(ISSUE_ATTACHMENTS(issueId as string));
|
mutate<IIssueAttachment[]>(
|
||||||
|
ISSUE_ATTACHMENTS(issueId as string),
|
||||||
|
(prevData) => [res, ...(prevData ?? [])],
|
||||||
|
false
|
||||||
|
);
|
||||||
setToastAlert({
|
setToastAlert({
|
||||||
type: "success",
|
type: "success",
|
||||||
title: "Success!",
|
title: "Success!",
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
import React, { useState } from "react";
|
import React from "react";
|
||||||
|
|
||||||
import { useRouter } from "next/router";
|
import { useRouter } from "next/router";
|
||||||
|
|
||||||
@ -28,8 +28,6 @@ type Props = {
|
|||||||
};
|
};
|
||||||
|
|
||||||
export const DeleteAttachmentModal: React.FC<Props> = ({ isOpen, setIsOpen, data }) => {
|
export const DeleteAttachmentModal: React.FC<Props> = ({ isOpen, setIsOpen, data }) => {
|
||||||
const [isDeleteLoading, setIsDeleteLoading] = useState(false);
|
|
||||||
|
|
||||||
const router = useRouter();
|
const router = useRouter();
|
||||||
const { workspaceSlug, projectId, issueId } = router.query;
|
const { workspaceSlug, projectId, issueId } = router.query;
|
||||||
|
|
||||||
@ -37,15 +35,16 @@ export const DeleteAttachmentModal: React.FC<Props> = ({ isOpen, setIsOpen, data
|
|||||||
|
|
||||||
const handleClose = () => {
|
const handleClose = () => {
|
||||||
setIsOpen(false);
|
setIsOpen(false);
|
||||||
setIsDeleteLoading(false);
|
|
||||||
};
|
};
|
||||||
|
|
||||||
const handleDeletion = async (assetId: string) => {
|
const handleDeletion = async (assetId: string) => {
|
||||||
setIsDeleteLoading(true);
|
|
||||||
|
|
||||||
if (!workspaceSlug || !projectId || !data) return;
|
if (!workspaceSlug || !projectId || !data) return;
|
||||||
|
|
||||||
mutate<IIssueAttachment[]>(ISSUE_ATTACHMENTS(issueId as string));
|
mutate<IIssueAttachment[]>(
|
||||||
|
ISSUE_ATTACHMENTS(issueId as string),
|
||||||
|
(prevData) => (prevData ?? [])?.filter((p) => p.id !== assetId),
|
||||||
|
false
|
||||||
|
);
|
||||||
|
|
||||||
await issuesService
|
await issuesService
|
||||||
.deleteIssueAttachment(
|
.deleteIssueAttachment(
|
||||||
@ -54,22 +53,12 @@ export const DeleteAttachmentModal: React.FC<Props> = ({ isOpen, setIsOpen, data
|
|||||||
issueId as string,
|
issueId as string,
|
||||||
assetId as string
|
assetId as string
|
||||||
)
|
)
|
||||||
.then((res) => {
|
.catch(() => {
|
||||||
mutate(ISSUE_ATTACHMENTS(issueId as string));
|
|
||||||
setToastAlert({
|
|
||||||
type: "success",
|
|
||||||
title: "Success!",
|
|
||||||
message: "File removed successfully.",
|
|
||||||
});
|
|
||||||
handleClose();
|
|
||||||
})
|
|
||||||
.catch((err) => {
|
|
||||||
setToastAlert({
|
setToastAlert({
|
||||||
type: "error",
|
type: "error",
|
||||||
title: "error!",
|
title: "error!",
|
||||||
message: "Something went wrong please try again.",
|
message: "Something went wrong please try again.",
|
||||||
});
|
});
|
||||||
setIsDeleteLoading(false);
|
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -129,8 +118,13 @@ export const DeleteAttachmentModal: React.FC<Props> = ({ isOpen, setIsOpen, data
|
|||||||
</div>
|
</div>
|
||||||
<div className="flex justify-end gap-2 bg-gray-50 p-4 sm:px-6">
|
<div className="flex justify-end gap-2 bg-gray-50 p-4 sm:px-6">
|
||||||
<SecondaryButton onClick={handleClose}>Cancel</SecondaryButton>
|
<SecondaryButton onClick={handleClose}>Cancel</SecondaryButton>
|
||||||
<DangerButton onClick={() => handleDeletion(data.id)} loading={isDeleteLoading}>
|
<DangerButton
|
||||||
{isDeleteLoading ? "Deleting..." : "Delete"}
|
onClick={() => {
|
||||||
|
handleDeletion(data.id);
|
||||||
|
handleClose();
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
Delete
|
||||||
</DangerButton>
|
</DangerButton>
|
||||||
</div>
|
</div>
|
||||||
</Dialog.Panel>
|
</Dialog.Panel>
|
||||||
|
Loading…
Reference in New Issue
Block a user