forked from github/plane
chore: archived issue update status
This commit is contained in:
parent
42f2d346bf
commit
aecb9d8619
@ -2,10 +2,13 @@ import { useCallback, useEffect, useState, ReactElement } from "react";
|
|||||||
import { useRouter } from "next/router";
|
import { useRouter } from "next/router";
|
||||||
import useSWR, { mutate } from "swr";
|
import useSWR, { mutate } from "swr";
|
||||||
import { useForm } from "react-hook-form";
|
import { useForm } from "react-hook-form";
|
||||||
|
import { useMobxStore } from "lib/mobx/store-provider";
|
||||||
|
import { observer } from "mobx-react-lite";
|
||||||
// services
|
// services
|
||||||
import { IssueService, IssueArchiveService } from "services/issue";
|
import { IssueService, IssueArchiveService } from "services/issue";
|
||||||
// hooks
|
// hooks
|
||||||
import useToast from "hooks/use-toast";
|
import useToast from "hooks/use-toast";
|
||||||
|
import useReloadConfirmations from "hooks/use-reload-confirmation";
|
||||||
// layouts
|
// layouts
|
||||||
import { AppLayout } from "layouts/app-layout";
|
import { AppLayout } from "layouts/app-layout";
|
||||||
// components
|
// components
|
||||||
@ -37,7 +40,7 @@ const defaultValues: Partial<IIssue> = {
|
|||||||
const issueService = new IssueService();
|
const issueService = new IssueService();
|
||||||
const issueArchiveService = new IssueArchiveService();
|
const issueArchiveService = new IssueArchiveService();
|
||||||
|
|
||||||
const ArchivedIssueDetailsPage: NextPageWithLayout = () => {
|
const ArchivedIssueDetailsPage: NextPageWithLayout = observer(() => {
|
||||||
// router
|
// router
|
||||||
const router = useRouter();
|
const router = useRouter();
|
||||||
const { workspaceSlug, projectId, archivedIssueId } = router.query;
|
const { workspaceSlug, projectId, archivedIssueId } = router.query;
|
||||||
@ -45,6 +48,11 @@ const ArchivedIssueDetailsPage: NextPageWithLayout = () => {
|
|||||||
const [isRestoring, setIsRestoring] = useState(false);
|
const [isRestoring, setIsRestoring] = useState(false);
|
||||||
// hooks
|
// hooks
|
||||||
const { setToastAlert } = useToast();
|
const { setToastAlert } = useToast();
|
||||||
|
const { setShowAlert } = useReloadConfirmations();
|
||||||
|
// mobx stores
|
||||||
|
const {
|
||||||
|
projectIssues: { isSubmitting, setIsSubmitting },
|
||||||
|
} = useMobxStore();
|
||||||
|
|
||||||
const { data: issueDetails, mutate: mutateIssueDetails } = useSWR<IIssue | undefined>(
|
const { data: issueDetails, mutate: mutateIssueDetails } = useSWR<IIssue | undefined>(
|
||||||
workspaceSlug && projectId && archivedIssueId ? ISSUE_DETAILS(archivedIssueId as string) : null,
|
workspaceSlug && projectId && archivedIssueId ? ISSUE_DETAILS(archivedIssueId as string) : null,
|
||||||
@ -65,7 +73,7 @@ const ArchivedIssueDetailsPage: NextPageWithLayout = () => {
|
|||||||
const submitChanges = useCallback(
|
const submitChanges = useCallback(
|
||||||
async (formData: Partial<IIssue>) => {
|
async (formData: Partial<IIssue>) => {
|
||||||
if (!workspaceSlug || !projectId || !archivedIssueId) return;
|
if (!workspaceSlug || !projectId || !archivedIssueId) return;
|
||||||
|
setIsSubmitting("submitting");
|
||||||
mutate<IIssue>(
|
mutate<IIssue>(
|
||||||
ISSUE_DETAILS(archivedIssueId as string),
|
ISSUE_DETAILS(archivedIssueId as string),
|
||||||
(prevData) => {
|
(prevData) => {
|
||||||
@ -88,6 +96,7 @@ const ArchivedIssueDetailsPage: NextPageWithLayout = () => {
|
|||||||
.then(() => {
|
.then(() => {
|
||||||
mutateIssueDetails();
|
mutateIssueDetails();
|
||||||
mutate(PROJECT_ISSUES_ACTIVITY(archivedIssueId as string));
|
mutate(PROJECT_ISSUES_ACTIVITY(archivedIssueId as string));
|
||||||
|
setIsSubmitting("submitted");
|
||||||
})
|
})
|
||||||
.catch((e) => {
|
.catch((e) => {
|
||||||
console.error(e);
|
console.error(e);
|
||||||
@ -130,6 +139,17 @@ const ArchivedIssueDetailsPage: NextPageWithLayout = () => {
|
|||||||
.finally(() => setIsRestoring(false));
|
.finally(() => setIsRestoring(false));
|
||||||
};
|
};
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
if (isSubmitting === "submitted") {
|
||||||
|
setShowAlert(false);
|
||||||
|
setTimeout(async () => {
|
||||||
|
setIsSubmitting("saved");
|
||||||
|
}, 2000);
|
||||||
|
} else if (isSubmitting === "submitting") {
|
||||||
|
setShowAlert(true);
|
||||||
|
}
|
||||||
|
}, [isSubmitting, setShowAlert]);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
{issueDetails && projectId ? (
|
{issueDetails && projectId ? (
|
||||||
@ -153,7 +173,12 @@ const ArchivedIssueDetailsPage: NextPageWithLayout = () => {
|
|||||||
</div>
|
</div>
|
||||||
)}
|
)}
|
||||||
<div className="space-y-5 divide-y-2 divide-custom-border-200 opacity-60 pointer-events-none">
|
<div className="space-y-5 divide-y-2 divide-custom-border-200 opacity-60 pointer-events-none">
|
||||||
<IssueMainContent issueDetails={issueDetails} submitChanges={submitChanges} uneditable />
|
<IssueMainContent
|
||||||
|
setShowAlert={(value) => setShowAlert(value)}
|
||||||
|
issueDetails={issueDetails}
|
||||||
|
submitChanges={submitChanges}
|
||||||
|
uneditable
|
||||||
|
/>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div className="w-1/3 h-full space-y-5 border-l border-custom-border-300 p-5 overflow-hidden">
|
<div className="w-1/3 h-full space-y-5 border-l border-custom-border-300 p-5 overflow-hidden">
|
||||||
@ -184,7 +209,7 @@ const ArchivedIssueDetailsPage: NextPageWithLayout = () => {
|
|||||||
)}
|
)}
|
||||||
</>
|
</>
|
||||||
);
|
);
|
||||||
};
|
});
|
||||||
|
|
||||||
ArchivedIssueDetailsPage.getLayout = function getLayout(page: ReactElement) {
|
ArchivedIssueDetailsPage.getLayout = function getLayout(page: ReactElement) {
|
||||||
return (
|
return (
|
||||||
|
Loading…
Reference in New Issue
Block a user