Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: draft issue delete not working #2249

Merged
merged 4 commits into from
Sep 25, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 14 additions & 2 deletions web/components/core/views/inline-issue-create-wrapper.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ import {
CYCLE_DETAILS,
MODULE_DETAILS,
PROJECT_ISSUES_LIST_WITH_PARAMS,
PROJECT_DRAFT_ISSUES_LIST_WITH_PARAMS,
} from "constants/fetch-keys";

// types
Expand Down Expand Up @@ -119,6 +120,8 @@ export const InlineCreateIssueFormWrapper: React.FC<Props> = (props) => {
const router = useRouter();
const { workspaceSlug, projectId, cycleId, moduleId, viewId } = router.query;

const isDraftIssues = router.pathname?.split("/")?.[4] === "draft-issues";

const { user } = useUser();

const { setToastAlert } = useToast();
Expand Down Expand Up @@ -193,8 +196,15 @@ export const InlineCreateIssueFormWrapper: React.FC<Props> = (props) => {

reset({ ...defaultValues });

await issuesService
.createIssues(workspaceSlug.toString(), projectId.toString(), formData, user)
await (!isDraftIssues
? issuesService.createIssues(workspaceSlug.toString(), projectId.toString(), formData, user)
: issuesService.createDraftIssue(
workspaceSlug.toString(),
projectId.toString(),
formData,
user
)
)
.then(async (res) => {
mutate(PROJECT_ISSUES_LIST_WITH_PARAMS(projectId.toString(), params));
if (formData.cycle && formData.cycle !== "")
Expand All @@ -216,6 +226,8 @@ export const InlineCreateIssueFormWrapper: React.FC<Props> = (props) => {
params
);

if (isDraftIssues)
mutate(PROJECT_DRAFT_ISSUES_LIST_WITH_PARAMS(projectId.toString() ?? "", params));
if (displayFilters.layout === "calendar") mutate(calendarFetchKey);
if (displayFilters.layout === "gantt_chart") mutate(ganttFetchKey);
if (displayFilters.layout === "spreadsheet") mutate(spreadsheetFetchKey);
Expand Down
9 changes: 6 additions & 3 deletions web/components/issues/delete-draft-issue-modal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ import { useRouter } from "next/router";

import { mutate } from "swr";

import useUser from "hooks/use-user";

// headless ui
import { Dialog, Transition } from "@headlessui/react";
// services
Expand All @@ -16,20 +18,19 @@ import { ExclamationTriangleIcon } from "@heroicons/react/24/outline";
// ui
import { SecondaryButton, DangerButton } from "components/ui";
// types
import type { IIssue, ICurrentUserResponse } from "types";
import type { IIssue } from "types";
// fetch-keys
import { PROJECT_DRAFT_ISSUES_LIST_WITH_PARAMS } from "constants/fetch-keys";

type Props = {
isOpen: boolean;
handleClose: () => void;
data: IIssue | null;
user?: ICurrentUserResponse;
onSubmit?: () => Promise<void> | void;
};

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);

Expand All @@ -40,6 +41,8 @@ export const DeleteDraftIssueModal: React.FC<Props> = (props) => {

const { setToastAlert } = useToast();

const { user } = useUser();

useEffect(() => {
setIsDeleteLoading(false);
}, [isOpen]);
Expand Down
4 changes: 3 additions & 1 deletion web/components/issues/draft-issue-form.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ interface IssueFormProps {
createMore: boolean;
setCreateMore: React.Dispatch<React.SetStateAction<boolean>>;
handleClose: () => void;
handleDiscard: () => void;
status: boolean;
user: ICurrentUserResponse | undefined;
fieldsToShow: (
Expand Down Expand Up @@ -97,6 +98,7 @@ export const DraftIssueForm: FC<IssueFormProps> = (props) => {
status,
user,
fieldsToShow,
handleDiscard,
} = props;

const [stateModal, setStateModal] = useState(false);
Expand Down Expand Up @@ -569,7 +571,7 @@ export const DraftIssueForm: FC<IssueFormProps> = (props) => {
<ToggleSwitch value={createMore} onChange={() => {}} size="md" />
</div>
<div className="flex items-center gap-2">
<SecondaryButton onClick={onClose}>Discard</SecondaryButton>
<SecondaryButton onClick={handleDiscard}>Discard</SecondaryButton>
<SecondaryButton
loading={isSubmitting}
onClick={handleSubmit((formData) =>
Expand Down
18 changes: 7 additions & 11 deletions web/components/issues/draft-issue-modal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,11 @@ export const CreateUpdateDraftIssueModal: React.FC<IssuesModalProps> = (props) =
setActiveProject(null);
};

const onDiscard = () => {
clearDraftIssueLocalStorage();
onClose();
};

useEffect(() => {
setPreloadedData(prePopulateDataProps ?? {});

Expand Down Expand Up @@ -141,7 +146,7 @@ export const CreateUpdateDraftIssueModal: React.FC<IssuesModalProps> = (props) =
if (prePopulateData && prePopulateData.project && !activeProject)
return setActiveProject(prePopulateData.project);

if (prePopulateData && prePopulateData.project)
if (prePopulateData && prePopulateData.project && !activeProject)
return setActiveProject(prePopulateData.project);

// if data is not present, set active project to the project
Expand Down Expand Up @@ -180,16 +185,8 @@ export const CreateUpdateDraftIssueModal: React.FC<IssuesModalProps> = (props) =
await issuesService
.createDraftIssue(workspaceSlug as string, activeProject ?? "", payload, user)
.then(async () => {
mutate(PROJECT_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();

setToastAlert({
Expand All @@ -200,8 +197,6 @@ export const CreateUpdateDraftIssueModal: React.FC<IssuesModalProps> = (props) =

if (payload.assignees_list?.some((assignee) => assignee === user?.id))
mutate(USER_ISSUE(workspaceSlug as string));

if (payload.parent && payload.parent !== "") mutate(SUB_ISSUES(payload.parent));
})
.catch(() => {
setToastAlert({
Expand Down Expand Up @@ -396,6 +391,7 @@ export const CreateUpdateDraftIssueModal: React.FC<IssuesModalProps> = (props) =
createMore={createMore}
setCreateMore={setCreateMore}
handleClose={onClose}
handleDiscard={onDiscard}
projectId={activeProject ?? ""}
setActiveProject={setActiveProject}
status={data ? true : false}
Expand Down