fix: create issue modal project select (#3549)

This commit is contained in:
Anmol Singh Bhatia 2024-02-02 14:29:59 +05:30 committed by GitHub
parent 67cf1785b8
commit 662b497082
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -2,7 +2,7 @@ import React, { useEffect, useState } from "react";
import { observer } from "mobx-react-lite"; import { observer } from "mobx-react-lite";
import { Dialog, Transition } from "@headlessui/react"; import { Dialog, Transition } from "@headlessui/react";
// hooks // hooks
import { useApplication, useCycle, useIssues, useModule, useProject, useUser, useWorkspace } from "hooks/store"; import { useApplication, useCycle, useIssues, useModule, useProject, useWorkspace } from "hooks/store";
import useToast from "hooks/use-toast"; import useToast from "hooks/use-toast";
import useLocalStorage from "hooks/use-local-storage"; import useLocalStorage from "hooks/use-local-storage";
// components // components
@ -32,7 +32,6 @@ export const CreateUpdateIssueModal: React.FC<IssuesModalProps> = observer((prop
const { const {
eventTracker: { postHogEventTracker }, eventTracker: { postHogEventTracker },
} = useApplication(); } = useApplication();
const { currentUser } = useUser();
const { const {
router: { workspaceSlug, projectId, cycleId, moduleId, viewId: projectViewId }, router: { workspaceSlug, projectId, cycleId, moduleId, viewId: projectViewId },
} = useApplication(); } = useApplication();
@ -49,27 +48,22 @@ export const CreateUpdateIssueModal: React.FC<IssuesModalProps> = observer((prop
const issueStores = { const issueStores = {
[EIssuesStoreType.PROJECT]: { [EIssuesStoreType.PROJECT]: {
store: projectIssues, store: projectIssues,
dataIdToUpdate: activeProjectId,
viewId: undefined, viewId: undefined,
}, },
[EIssuesStoreType.PROJECT_VIEW]: { [EIssuesStoreType.PROJECT_VIEW]: {
store: viewIssues, store: viewIssues,
dataIdToUpdate: activeProjectId,
viewId: projectViewId, viewId: projectViewId,
}, },
[EIssuesStoreType.PROFILE]: { [EIssuesStoreType.PROFILE]: {
store: profileIssues, store: profileIssues,
dataIdToUpdate: currentUser?.id || undefined,
viewId: undefined, viewId: undefined,
}, },
[EIssuesStoreType.CYCLE]: { [EIssuesStoreType.CYCLE]: {
store: cycleIssues, store: cycleIssues,
dataIdToUpdate: activeProjectId,
viewId: cycleId, viewId: cycleId,
}, },
[EIssuesStoreType.MODULE]: { [EIssuesStoreType.MODULE]: {
store: moduleIssues, store: moduleIssues,
dataIdToUpdate: activeProjectId,
viewId: moduleId, viewId: moduleId,
}, },
}; };
@ -78,7 +72,7 @@ export const CreateUpdateIssueModal: React.FC<IssuesModalProps> = observer((prop
// local storage // local storage
const { setValue: setLocalStorageDraftIssue } = useLocalStorage<any>("draftedIssue", {}); const { setValue: setLocalStorageDraftIssue } = useLocalStorage<any>("draftedIssue", {});
// current store details // current store details
const { store: currentIssueStore, viewId, dataIdToUpdate } = issueStores[storeType]; const { store: currentIssueStore, viewId } = issueStores[storeType];
useEffect(() => { useEffect(() => {
// if modal is closed, reset active project to null // if modal is closed, reset active project to null
@ -129,13 +123,13 @@ export const CreateUpdateIssueModal: React.FC<IssuesModalProps> = observer((prop
}; };
const handleCreateIssue = async (payload: Partial<TIssue>): Promise<TIssue | undefined> => { const handleCreateIssue = async (payload: Partial<TIssue>): Promise<TIssue | undefined> => {
if (!workspaceSlug || !dataIdToUpdate) return; if (!workspaceSlug || !payload.project_id) return;
try { try {
const response = await currentIssueStore.createIssue(workspaceSlug, dataIdToUpdate, payload, viewId); const response = await currentIssueStore.createIssue(workspaceSlug, payload.project_id, payload, viewId);
if (!response) throw new Error(); if (!response) throw new Error();
currentIssueStore.fetchIssues(workspaceSlug, dataIdToUpdate, "mutation", viewId); currentIssueStore.fetchIssues(workspaceSlug, payload.project_id, "mutation", viewId);
if (payload.cycle_id && payload.cycle_id !== "" && storeType !== EIssuesStoreType.CYCLE) if (payload.cycle_id && payload.cycle_id !== "" && storeType !== EIssuesStoreType.CYCLE)
await addIssueToCycle(response, payload.cycle_id); await addIssueToCycle(response, payload.cycle_id);
@ -182,10 +176,10 @@ export const CreateUpdateIssueModal: React.FC<IssuesModalProps> = observer((prop
}; };
const handleUpdateIssue = async (payload: Partial<TIssue>): Promise<TIssue | undefined> => { const handleUpdateIssue = async (payload: Partial<TIssue>): Promise<TIssue | undefined> => {
if (!workspaceSlug || !dataIdToUpdate || !data?.id) return; if (!workspaceSlug || !payload.project_id || !data?.id) return;
try { try {
const response = await currentIssueStore.updateIssue(workspaceSlug, dataIdToUpdate, data.id, payload, viewId); const response = await currentIssueStore.updateIssue(workspaceSlug, payload.project_id, data.id, payload, viewId);
setToastAlert({ setToastAlert({
type: "success", type: "success",
title: "Success!", title: "Success!",
@ -226,7 +220,7 @@ export const CreateUpdateIssueModal: React.FC<IssuesModalProps> = observer((prop
}; };
const handleFormSubmit = async (formData: Partial<TIssue>) => { const handleFormSubmit = async (formData: Partial<TIssue>) => {
if (!workspaceSlug || !dataIdToUpdate || !storeType) return; if (!workspaceSlug || !formData.project_id || !storeType) return;
const payload: Partial<TIssue> = { const payload: Partial<TIssue> = {
...formData, ...formData,