diff --git a/web/pages/[workspaceSlug]/projects/[projectId]/archived-issues/[archivedIssueId].tsx b/web/pages/[workspaceSlug]/projects/[projectId]/archived-issues/[archivedIssueId].tsx index b02585182..eae24c1f7 100644 --- a/web/pages/[workspaceSlug]/projects/[projectId]/archived-issues/[archivedIssueId].tsx +++ b/web/pages/[workspaceSlug]/projects/[projectId]/archived-issues/[archivedIssueId].tsx @@ -2,10 +2,13 @@ import { useCallback, useEffect, useState, ReactElement } from "react"; import { useRouter } from "next/router"; import useSWR, { mutate } from "swr"; import { useForm } from "react-hook-form"; +import { useMobxStore } from "lib/mobx/store-provider"; +import { observer } from "mobx-react-lite"; // services import { IssueService, IssueArchiveService } from "services/issue"; // hooks import useToast from "hooks/use-toast"; +import useReloadConfirmations from "hooks/use-reload-confirmation"; // layouts import { AppLayout } from "layouts/app-layout"; // components @@ -37,7 +40,7 @@ const defaultValues: Partial = { const issueService = new IssueService(); const issueArchiveService = new IssueArchiveService(); -const ArchivedIssueDetailsPage: NextPageWithLayout = () => { +const ArchivedIssueDetailsPage: NextPageWithLayout = observer(() => { // router const router = useRouter(); const { workspaceSlug, projectId, archivedIssueId } = router.query; @@ -45,6 +48,11 @@ const ArchivedIssueDetailsPage: NextPageWithLayout = () => { const [isRestoring, setIsRestoring] = useState(false); // hooks const { setToastAlert } = useToast(); + const { setShowAlert } = useReloadConfirmations(); + // mobx stores + const { + projectIssues: { isSubmitting, setIsSubmitting }, + } = useMobxStore(); const { data: issueDetails, mutate: mutateIssueDetails } = useSWR( workspaceSlug && projectId && archivedIssueId ? ISSUE_DETAILS(archivedIssueId as string) : null, @@ -65,7 +73,7 @@ const ArchivedIssueDetailsPage: NextPageWithLayout = () => { const submitChanges = useCallback( async (formData: Partial) => { if (!workspaceSlug || !projectId || !archivedIssueId) return; - + setIsSubmitting("submitting"); mutate( ISSUE_DETAILS(archivedIssueId as string), (prevData) => { @@ -88,6 +96,7 @@ const ArchivedIssueDetailsPage: NextPageWithLayout = () => { .then(() => { mutateIssueDetails(); mutate(PROJECT_ISSUES_ACTIVITY(archivedIssueId as string)); + setIsSubmitting("submitted"); }) .catch((e) => { console.error(e); @@ -130,6 +139,17 @@ const ArchivedIssueDetailsPage: NextPageWithLayout = () => { .finally(() => setIsRestoring(false)); }; + useEffect(() => { + if (isSubmitting === "submitted") { + setShowAlert(false); + setTimeout(async () => { + setIsSubmitting("saved"); + }, 2000); + } else if (isSubmitting === "submitting") { + setShowAlert(true); + } + }, [isSubmitting, setShowAlert]); + return ( <> {issueDetails && projectId ? ( @@ -153,7 +173,12 @@ const ArchivedIssueDetailsPage: NextPageWithLayout = () => { )}
- + setShowAlert(value)} + issueDetails={issueDetails} + submitChanges={submitChanges} + uneditable + />
@@ -184,7 +209,7 @@ const ArchivedIssueDetailsPage: NextPageWithLayout = () => { )} ); -}; +}); ArchivedIssueDetailsPage.getLayout = function getLayout(page: ReactElement) { return (