mirror of
https://github.com/makeplane/plane
synced 2025-08-07 19:59:33 +00:00
[WEB-1890] fix: issue creation by using appropriate stores (#5072)
* fix issue creation by using appropriate stores * add comments * change useIssuesStore hook to use useIssueStoreType
This commit is contained in:
@@ -17,14 +17,14 @@ import { CreateProjectModal } from "@/components/project";
|
||||
import { CreateUpdateProjectViewModal } from "@/components/views";
|
||||
// constants
|
||||
import { ISSUE_DETAILS } from "@/constants/fetch-keys";
|
||||
import { EIssuesStoreType } from "@/constants/issue";
|
||||
import { EUserProjectRoles } from "@/constants/project";
|
||||
import { EUserWorkspaceRoles } from "@/constants/workspace";
|
||||
// helpers
|
||||
import { copyTextToClipboard } from "@/helpers/string.helper";
|
||||
// hooks
|
||||
import { useEventTracker, useIssues, useUser, useAppTheme, useCommandPalette } from "@/hooks/store";
|
||||
import { useEventTracker, useUser, useAppTheme, useCommandPalette } from "@/hooks/store";
|
||||
import { useAppRouter } from "@/hooks/use-app-router";
|
||||
import { useIssuesStore } from "@/hooks/use-issue-layout-store";
|
||||
import { usePlatformOS } from "@/hooks/use-platform-os";
|
||||
// services
|
||||
import { IssueService } from "@/services/issue";
|
||||
@@ -49,7 +49,7 @@ export const CommandPalette: FC = observer(() => {
|
||||
} = useUser();
|
||||
const {
|
||||
issues: { removeIssue },
|
||||
} = useIssues(EIssuesStoreType.PROJECT);
|
||||
} = useIssuesStore();
|
||||
const {
|
||||
toggleCommandPaletteModal,
|
||||
isCreateIssueModalOpen,
|
||||
@@ -71,7 +71,6 @@ export const CommandPalette: FC = observer(() => {
|
||||
isDeleteIssueModalOpen,
|
||||
toggleDeleteIssueModal,
|
||||
isAnyModalOpen,
|
||||
createIssueStoreType,
|
||||
} = useCommandPalette();
|
||||
|
||||
const { data: issueDetails } = useSWR(
|
||||
@@ -317,7 +316,6 @@ export const CommandPalette: FC = observer(() => {
|
||||
isOpen={isCreateIssueModalOpen}
|
||||
onClose={() => toggleCreateIssueModal(false)}
|
||||
data={cycleId ? { cycle_id: cycleId.toString() } : moduleId ? { module_ids: [moduleId.toString()] } : undefined}
|
||||
storeType={createIssueStoreType}
|
||||
isDraft={isDraftIssue}
|
||||
/>
|
||||
|
||||
|
||||
@@ -152,7 +152,7 @@ export const AllIssueQuickActions: React.FC<IQuickActionProps> = observer((props
|
||||
onSubmit={async (data) => {
|
||||
if (issueToEdit && handleUpdate) await handleUpdate(data);
|
||||
}}
|
||||
storeType={EIssuesStoreType.PROJECT}
|
||||
storeType={EIssuesStoreType.GLOBAL}
|
||||
/>
|
||||
<ContextMenu parentRef={parentRef} items={MENU_ITEMS} />
|
||||
<CustomMenu
|
||||
|
||||
@@ -104,7 +104,7 @@ export const DraftIssueQuickActions: React.FC<IQuickActionProps> = observer((pro
|
||||
onSubmit={async (data) => {
|
||||
if (issueToEdit && handleUpdate) await handleUpdate(data);
|
||||
}}
|
||||
storeType={EIssuesStoreType.PROJECT}
|
||||
storeType={EIssuesStoreType.DRAFT}
|
||||
isDraft
|
||||
/>
|
||||
<ContextMenu parentRef={parentRef} items={MENU_ITEMS} />
|
||||
|
||||
@@ -13,6 +13,7 @@ import { ISSUE_CREATED, ISSUE_UPDATED } from "@/constants/event-tracker";
|
||||
import { EIssuesStoreType } from "@/constants/issue";
|
||||
// hooks
|
||||
import { useEventTracker, useCycle, useIssues, useModule, useProject, useIssueDetail } from "@/hooks/store";
|
||||
import { useIssueStoreType } from "@/hooks/use-issue-layout-store";
|
||||
import { useIssuesActions } from "@/hooks/use-issues-actions";
|
||||
import useLocalStorage from "@/hooks/use-local-storage";
|
||||
// components
|
||||
@@ -36,9 +37,12 @@ export const CreateUpdateIssueModal: React.FC<IssuesModalProps> = observer((prop
|
||||
onClose,
|
||||
onSubmit,
|
||||
withDraftIssueWrapper = true,
|
||||
storeType = EIssuesStoreType.PROJECT,
|
||||
storeType: issueStoreFromProps,
|
||||
isDraft = false,
|
||||
} = props;
|
||||
const issueStoreType = useIssueStoreType();
|
||||
|
||||
const storeType = issueStoreFromProps ?? issueStoreType;
|
||||
// ref
|
||||
const issueTitleRef = useRef<HTMLInputElement>(null);
|
||||
// states
|
||||
|
||||
@@ -7,7 +7,6 @@ import { TIssue } from "@plane/types";
|
||||
// components
|
||||
import { CreateUpdateIssueModal } from "@/components/issues";
|
||||
// constants
|
||||
import { EIssuesStoreType } from "@/constants/issue";
|
||||
// helpers
|
||||
import { cn } from "@/helpers/common.helper";
|
||||
// hooks
|
||||
@@ -90,7 +89,7 @@ export const SidebarQuickActions = observer(() => {
|
||||
)}
|
||||
onClick={() => {
|
||||
setTrackElement("APP_SIDEBAR_QUICK_ACTIONS");
|
||||
toggleCreateIssueModal(true, EIssuesStoreType.PROJECT);
|
||||
toggleCreateIssueModal(true);
|
||||
}}
|
||||
disabled={disabled}
|
||||
>
|
||||
|
||||
@@ -1,17 +1,36 @@
|
||||
import { createContext, useContext } from "react";
|
||||
import { useParams } from "next/navigation";
|
||||
import { EIssuesStoreType } from "@/constants/issue";
|
||||
import { useIssues } from "./store";
|
||||
|
||||
export const IssuesStoreContext = createContext<EIssuesStoreType>(EIssuesStoreType.PROJECT);
|
||||
export const IssuesStoreContext = createContext<EIssuesStoreType | undefined>(undefined);
|
||||
|
||||
export const useIssueStoreType = () => {
|
||||
const storeType = useContext(IssuesStoreContext);
|
||||
|
||||
return storeType;
|
||||
const { globalViewId, viewId, projectId, cycleId, moduleId, userId } = useParams();
|
||||
|
||||
// If store type exists in context, use that store type
|
||||
if (storeType) return storeType;
|
||||
|
||||
// else check the router params to determine the issue store
|
||||
if (globalViewId) return EIssuesStoreType.GLOBAL;
|
||||
|
||||
if (userId) return EIssuesStoreType.PROFILE;
|
||||
|
||||
if (viewId) return EIssuesStoreType.PROJECT_VIEW;
|
||||
|
||||
if (cycleId) return EIssuesStoreType.CYCLE;
|
||||
|
||||
if (moduleId) return EIssuesStoreType.MODULE;
|
||||
|
||||
if (projectId) return EIssuesStoreType.PROJECT;
|
||||
|
||||
return EIssuesStoreType.PROJECT;
|
||||
};
|
||||
|
||||
export const useIssuesStore = () => {
|
||||
const storeType = useContext(IssuesStoreContext);
|
||||
const storeType = useIssueStoreType();
|
||||
|
||||
return useIssues(storeType);
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user