mirror of
https://github.com/makeplane/plane
synced 2024-06-14 14:31:34 +00:00
fix: draft issue delete not working (#2249)
* fix: draft issue not deleting, project can't be changed in draft issue modal * fix: removed mutation for view where draft issues are not shown * fix: inline create issue for draft issue * fix: clearing data from localstorage on discard click
This commit is contained in:
parent
5e8d523ed4
commit
7db78594dc
@ -39,6 +39,7 @@ import {
|
|||||||
CYCLE_DETAILS,
|
CYCLE_DETAILS,
|
||||||
MODULE_DETAILS,
|
MODULE_DETAILS,
|
||||||
PROJECT_ISSUES_LIST_WITH_PARAMS,
|
PROJECT_ISSUES_LIST_WITH_PARAMS,
|
||||||
|
PROJECT_DRAFT_ISSUES_LIST_WITH_PARAMS,
|
||||||
} from "constants/fetch-keys";
|
} from "constants/fetch-keys";
|
||||||
|
|
||||||
// types
|
// types
|
||||||
@ -119,6 +120,8 @@ export const InlineCreateIssueFormWrapper: React.FC<Props> = (props) => {
|
|||||||
const router = useRouter();
|
const router = useRouter();
|
||||||
const { workspaceSlug, projectId, cycleId, moduleId, viewId } = router.query;
|
const { workspaceSlug, projectId, cycleId, moduleId, viewId } = router.query;
|
||||||
|
|
||||||
|
const isDraftIssues = router.pathname?.split("/")?.[4] === "draft-issues";
|
||||||
|
|
||||||
const { user } = useUser();
|
const { user } = useUser();
|
||||||
|
|
||||||
const { setToastAlert } = useToast();
|
const { setToastAlert } = useToast();
|
||||||
@ -184,8 +187,15 @@ export const InlineCreateIssueFormWrapper: React.FC<Props> = (props) => {
|
|||||||
|
|
||||||
reset({ ...defaultValues });
|
reset({ ...defaultValues });
|
||||||
|
|
||||||
await issuesService
|
await (!isDraftIssues
|
||||||
.createIssues(workspaceSlug.toString(), projectId.toString(), formData, user)
|
? issuesService.createIssues(workspaceSlug.toString(), projectId.toString(), formData, user)
|
||||||
|
: issuesService.createDraftIssue(
|
||||||
|
workspaceSlug.toString(),
|
||||||
|
projectId.toString(),
|
||||||
|
formData,
|
||||||
|
user
|
||||||
|
)
|
||||||
|
)
|
||||||
.then(async (res) => {
|
.then(async (res) => {
|
||||||
mutate(PROJECT_ISSUES_LIST_WITH_PARAMS(projectId.toString(), params));
|
mutate(PROJECT_ISSUES_LIST_WITH_PARAMS(projectId.toString(), params));
|
||||||
if (formData.cycle && formData.cycle !== "")
|
if (formData.cycle && formData.cycle !== "")
|
||||||
@ -207,6 +217,8 @@ export const InlineCreateIssueFormWrapper: React.FC<Props> = (props) => {
|
|||||||
params
|
params
|
||||||
);
|
);
|
||||||
|
|
||||||
|
if (isDraftIssues)
|
||||||
|
mutate(PROJECT_DRAFT_ISSUES_LIST_WITH_PARAMS(projectId.toString() ?? "", params));
|
||||||
if (displayFilters.layout === "calendar") mutate(calendarFetchKey);
|
if (displayFilters.layout === "calendar") mutate(calendarFetchKey);
|
||||||
if (displayFilters.layout === "gantt_chart") mutate(ganttFetchKey);
|
if (displayFilters.layout === "gantt_chart") mutate(ganttFetchKey);
|
||||||
if (displayFilters.layout === "spreadsheet") mutate(spreadsheetFetchKey);
|
if (displayFilters.layout === "spreadsheet") mutate(spreadsheetFetchKey);
|
||||||
|
@ -4,6 +4,8 @@ import { useRouter } from "next/router";
|
|||||||
|
|
||||||
import { mutate } from "swr";
|
import { mutate } from "swr";
|
||||||
|
|
||||||
|
import useUser from "hooks/use-user";
|
||||||
|
|
||||||
// headless ui
|
// headless ui
|
||||||
import { Dialog, Transition } from "@headlessui/react";
|
import { Dialog, Transition } from "@headlessui/react";
|
||||||
// services
|
// services
|
||||||
@ -16,7 +18,7 @@ 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 { IIssue, ICurrentUserResponse } from "types";
|
import type { IIssue } from "types";
|
||||||
// fetch-keys
|
// fetch-keys
|
||||||
import { PROJECT_DRAFT_ISSUES_LIST_WITH_PARAMS } from "constants/fetch-keys";
|
import { PROJECT_DRAFT_ISSUES_LIST_WITH_PARAMS } from "constants/fetch-keys";
|
||||||
|
|
||||||
@ -24,12 +26,11 @@ type Props = {
|
|||||||
isOpen: boolean;
|
isOpen: boolean;
|
||||||
handleClose: () => void;
|
handleClose: () => void;
|
||||||
data: IIssue | null;
|
data: IIssue | null;
|
||||||
user?: ICurrentUserResponse;
|
|
||||||
onSubmit?: () => Promise<void> | void;
|
onSubmit?: () => Promise<void> | void;
|
||||||
};
|
};
|
||||||
|
|
||||||
export const DeleteDraftIssueModal: React.FC<Props> = (props) => {
|
export const DeleteDraftIssueModal: React.FC<Props> = (props) => {
|
||||||
const { isOpen, handleClose, data, user, onSubmit } = props;
|
const { isOpen, handleClose, data, onSubmit } = props;
|
||||||
|
|
||||||
const [isDeleteLoading, setIsDeleteLoading] = useState(false);
|
const [isDeleteLoading, setIsDeleteLoading] = useState(false);
|
||||||
|
|
||||||
@ -40,6 +41,8 @@ export const DeleteDraftIssueModal: React.FC<Props> = (props) => {
|
|||||||
|
|
||||||
const { setToastAlert } = useToast();
|
const { setToastAlert } = useToast();
|
||||||
|
|
||||||
|
const { user } = useUser();
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
setIsDeleteLoading(false);
|
setIsDeleteLoading(false);
|
||||||
}, [isOpen]);
|
}, [isOpen]);
|
||||||
|
@ -66,6 +66,7 @@ interface IssueFormProps {
|
|||||||
createMore: boolean;
|
createMore: boolean;
|
||||||
setCreateMore: React.Dispatch<React.SetStateAction<boolean>>;
|
setCreateMore: React.Dispatch<React.SetStateAction<boolean>>;
|
||||||
handleClose: () => void;
|
handleClose: () => void;
|
||||||
|
handleDiscard: () => void;
|
||||||
status: boolean;
|
status: boolean;
|
||||||
user: ICurrentUserResponse | undefined;
|
user: ICurrentUserResponse | undefined;
|
||||||
fieldsToShow: (
|
fieldsToShow: (
|
||||||
@ -97,6 +98,7 @@ export const DraftIssueForm: FC<IssueFormProps> = (props) => {
|
|||||||
status,
|
status,
|
||||||
user,
|
user,
|
||||||
fieldsToShow,
|
fieldsToShow,
|
||||||
|
handleDiscard,
|
||||||
} = props;
|
} = props;
|
||||||
|
|
||||||
const [stateModal, setStateModal] = useState(false);
|
const [stateModal, setStateModal] = useState(false);
|
||||||
@ -569,7 +571,7 @@ export const DraftIssueForm: FC<IssueFormProps> = (props) => {
|
|||||||
<ToggleSwitch value={createMore} onChange={() => {}} size="md" />
|
<ToggleSwitch value={createMore} onChange={() => {}} size="md" />
|
||||||
</div>
|
</div>
|
||||||
<div className="flex items-center gap-2">
|
<div className="flex items-center gap-2">
|
||||||
<SecondaryButton onClick={onClose}>Discard</SecondaryButton>
|
<SecondaryButton onClick={handleDiscard}>Discard</SecondaryButton>
|
||||||
<SecondaryButton
|
<SecondaryButton
|
||||||
loading={isSubmitting}
|
loading={isSubmitting}
|
||||||
onClick={handleSubmit((formData) =>
|
onClick={handleSubmit((formData) =>
|
||||||
|
@ -97,6 +97,11 @@ export const CreateUpdateDraftIssueModal: React.FC<IssuesModalProps> = (props) =
|
|||||||
setActiveProject(null);
|
setActiveProject(null);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const onDiscard = () => {
|
||||||
|
clearDraftIssueLocalStorage();
|
||||||
|
onClose();
|
||||||
|
};
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
setPreloadedData(prePopulateDataProps ?? {});
|
setPreloadedData(prePopulateDataProps ?? {});
|
||||||
|
|
||||||
@ -141,7 +146,7 @@ export const CreateUpdateDraftIssueModal: React.FC<IssuesModalProps> = (props) =
|
|||||||
if (prePopulateData && prePopulateData.project && !activeProject)
|
if (prePopulateData && prePopulateData.project && !activeProject)
|
||||||
return setActiveProject(prePopulateData.project);
|
return setActiveProject(prePopulateData.project);
|
||||||
|
|
||||||
if (prePopulateData && prePopulateData.project)
|
if (prePopulateData && prePopulateData.project && !activeProject)
|
||||||
return setActiveProject(prePopulateData.project);
|
return setActiveProject(prePopulateData.project);
|
||||||
|
|
||||||
// if data is not present, set active project to the project
|
// if data is not present, set active project to the project
|
||||||
@ -180,16 +185,8 @@ export const CreateUpdateDraftIssueModal: React.FC<IssuesModalProps> = (props) =
|
|||||||
await issuesService
|
await issuesService
|
||||||
.createDraftIssue(workspaceSlug as string, activeProject ?? "", payload, user)
|
.createDraftIssue(workspaceSlug as string, activeProject ?? "", payload, user)
|
||||||
.then(async () => {
|
.then(async () => {
|
||||||
mutate(PROJECT_ISSUES_LIST_WITH_PARAMS(activeProject ?? "", params));
|
|
||||||
mutate(PROJECT_DRAFT_ISSUES_LIST_WITH_PARAMS(activeProject ?? "", params));
|
mutate(PROJECT_DRAFT_ISSUES_LIST_WITH_PARAMS(activeProject ?? "", params));
|
||||||
|
|
||||||
if (displayFilters.layout === "calendar") mutate(calendarFetchKey);
|
|
||||||
if (displayFilters.layout === "gantt_chart")
|
|
||||||
mutate(ganttFetchKey, {
|
|
||||||
start_target_date: true,
|
|
||||||
order_by: "sort_order",
|
|
||||||
});
|
|
||||||
if (displayFilters.layout === "spreadsheet") mutate(spreadsheetFetchKey);
|
|
||||||
if (groupedIssues) mutateMyIssues();
|
if (groupedIssues) mutateMyIssues();
|
||||||
|
|
||||||
setToastAlert({
|
setToastAlert({
|
||||||
@ -200,8 +197,6 @@ export const CreateUpdateDraftIssueModal: React.FC<IssuesModalProps> = (props) =
|
|||||||
|
|
||||||
if (payload.assignees_list?.some((assignee) => assignee === user?.id))
|
if (payload.assignees_list?.some((assignee) => assignee === user?.id))
|
||||||
mutate(USER_ISSUE(workspaceSlug as string));
|
mutate(USER_ISSUE(workspaceSlug as string));
|
||||||
|
|
||||||
if (payload.parent && payload.parent !== "") mutate(SUB_ISSUES(payload.parent));
|
|
||||||
})
|
})
|
||||||
.catch(() => {
|
.catch(() => {
|
||||||
setToastAlert({
|
setToastAlert({
|
||||||
@ -396,6 +391,7 @@ export const CreateUpdateDraftIssueModal: React.FC<IssuesModalProps> = (props) =
|
|||||||
createMore={createMore}
|
createMore={createMore}
|
||||||
setCreateMore={setCreateMore}
|
setCreateMore={setCreateMore}
|
||||||
handleClose={onClose}
|
handleClose={onClose}
|
||||||
|
handleDiscard={onDiscard}
|
||||||
projectId={activeProject ?? ""}
|
projectId={activeProject ?? ""}
|
||||||
setActiveProject={setActiveProject}
|
setActiveProject={setActiveProject}
|
||||||
status={data ? true : false}
|
status={data ? true : false}
|
||||||
|
Loading…
Reference in New Issue
Block a user