mirror of
https://github.com/makeplane/plane
synced 2024-06-14 14:31:34 +00:00
chore: decline issue mutation (#1354)
This commit is contained in:
parent
a0ae569a68
commit
2cef6e67d4
@ -1,102 +1,33 @@
|
|||||||
import React, { useEffect, useState } from "react";
|
import React, { useState } from "react";
|
||||||
|
|
||||||
import { useRouter } from "next/router";
|
|
||||||
|
|
||||||
import { mutate } from "swr";
|
|
||||||
|
|
||||||
// headless ui
|
// headless ui
|
||||||
import { Dialog, Transition } from "@headlessui/react";
|
import { Dialog, Transition } from "@headlessui/react";
|
||||||
// services
|
|
||||||
import inboxServices from "services/inbox.service";
|
|
||||||
// hooks
|
|
||||||
import useToast from "hooks/use-toast";
|
|
||||||
import useInboxView from "hooks/use-inbox-view";
|
|
||||||
import useUser from "hooks/use-user";
|
|
||||||
// icons
|
// icons
|
||||||
import { ExclamationTriangleIcon } from "@heroicons/react/24/outline";
|
import { ExclamationTriangleIcon } from "@heroicons/react/24/outline";
|
||||||
// ui
|
// ui
|
||||||
import { SecondaryButton, DangerButton } from "components/ui";
|
import { SecondaryButton, DangerButton } from "components/ui";
|
||||||
// types
|
// types
|
||||||
import type { IInboxIssue, ICurrentUserResponse, IInboxIssueDetail } from "types";
|
import type { IInboxIssue } from "types";
|
||||||
// fetch-keys
|
|
||||||
import { INBOX_ISSUES, INBOX_ISSUE_DETAILS } from "constants/fetch-keys";
|
|
||||||
|
|
||||||
type Props = {
|
type Props = {
|
||||||
isOpen: boolean;
|
isOpen: boolean;
|
||||||
handleClose: () => void;
|
handleClose: () => void;
|
||||||
data: IInboxIssue | undefined;
|
data: IInboxIssue | undefined;
|
||||||
|
onSubmit: () => Promise<void>;
|
||||||
};
|
};
|
||||||
|
|
||||||
export const DeclineIssueModal: React.FC<Props> = ({ isOpen, handleClose, data }) => {
|
export const DeclineIssueModal: React.FC<Props> = ({ isOpen, handleClose, data, onSubmit }) => {
|
||||||
const [isDeclining, setIsDeclining] = useState(false);
|
const [isDeclining, setIsDeclining] = useState(false);
|
||||||
|
|
||||||
const router = useRouter();
|
|
||||||
const { workspaceSlug, projectId, inboxId } = router.query;
|
|
||||||
|
|
||||||
const { user } = useUser();
|
|
||||||
const { setToastAlert } = useToast();
|
|
||||||
const { params } = useInboxView();
|
|
||||||
|
|
||||||
const onClose = () => {
|
const onClose = () => {
|
||||||
setIsDeclining(false);
|
setIsDeclining(false);
|
||||||
handleClose();
|
handleClose();
|
||||||
};
|
};
|
||||||
|
|
||||||
const handleDecline = () => {
|
const handleDecline = () => {
|
||||||
if (!workspaceSlug || !projectId || !inboxId || !data) return;
|
|
||||||
|
|
||||||
setIsDeclining(true);
|
setIsDeclining(true);
|
||||||
|
|
||||||
inboxServices
|
onSubmit().finally(() => setIsDeclining(false));
|
||||||
.markInboxStatus(
|
|
||||||
workspaceSlug.toString(),
|
|
||||||
projectId.toString(),
|
|
||||||
inboxId.toString(),
|
|
||||||
data.bridge_id,
|
|
||||||
{
|
|
||||||
status: -1,
|
|
||||||
},
|
|
||||||
user
|
|
||||||
)
|
|
||||||
.then(() => {
|
|
||||||
mutate<IInboxIssueDetail>(
|
|
||||||
INBOX_ISSUE_DETAILS(inboxId.toString(), data.bridge_id),
|
|
||||||
(prevData) => {
|
|
||||||
if (!prevData) return prevData;
|
|
||||||
|
|
||||||
return {
|
|
||||||
...prevData,
|
|
||||||
issue_inbox: [{ ...prevData.issue_inbox[0], status: -1 }],
|
|
||||||
};
|
|
||||||
},
|
|
||||||
false
|
|
||||||
);
|
|
||||||
mutate<IInboxIssue[]>(
|
|
||||||
INBOX_ISSUES(inboxId.toString(), params),
|
|
||||||
(prevData) =>
|
|
||||||
prevData?.map((i) =>
|
|
||||||
i.bridge_id === data.bridge_id
|
|
||||||
? { ...i, issue_inbox: [{ ...i.issue_inbox[0], status: -1 }] }
|
|
||||||
: i
|
|
||||||
),
|
|
||||||
false
|
|
||||||
);
|
|
||||||
|
|
||||||
setToastAlert({
|
|
||||||
type: "success",
|
|
||||||
title: "Success!",
|
|
||||||
message: "Issue declined successfully.",
|
|
||||||
});
|
|
||||||
onClose();
|
|
||||||
})
|
|
||||||
.catch(() =>
|
|
||||||
setToastAlert({
|
|
||||||
type: "error",
|
|
||||||
title: "Error!",
|
|
||||||
message: "Issue could not be declined. Please try again.",
|
|
||||||
})
|
|
||||||
)
|
|
||||||
.finally(() => setIsDeclining(false));
|
|
||||||
};
|
};
|
||||||
|
|
||||||
return (
|
return (
|
||||||
|
@ -194,6 +194,11 @@ const ProjectInbox: NextPage = () => {
|
|||||||
isOpen={declineIssueModal}
|
isOpen={declineIssueModal}
|
||||||
handleClose={() => setDeclineIssueModal(false)}
|
handleClose={() => setDeclineIssueModal(false)}
|
||||||
data={inboxIssues?.find((i) => i.bridge_id === inboxIssueId)}
|
data={inboxIssues?.find((i) => i.bridge_id === inboxIssueId)}
|
||||||
|
onSubmit={async () => {
|
||||||
|
await markInboxStatus({
|
||||||
|
status: -1,
|
||||||
|
}).finally(() => setDeclineIssueModal(false));
|
||||||
|
}}
|
||||||
/>
|
/>
|
||||||
<DeleteIssueModal
|
<DeleteIssueModal
|
||||||
isOpen={deleteIssueModal}
|
isOpen={deleteIssueModal}
|
||||||
|
Loading…
Reference in New Issue
Block a user