Skip to content

Commit

Permalink
[WEB-1890] fix: issue creation by using appropriate stores (#5072)
Browse files Browse the repository at this point in the history
* fix issue creation by using appropriate stores

* add comments

* change useIssuesStore hook to use useIssueStoreType
  • Loading branch information
rahulramesha authored Jul 8, 2024
1 parent fb586c5 commit a623456
Show file tree
Hide file tree
Showing 6 changed files with 33 additions and 13 deletions.
8 changes: 3 additions & 5 deletions web/core/components/command-palette/command-palette.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand All @@ -49,7 +49,7 @@ export const CommandPalette: FC = observer(() => {
} = useUser();
const {
issues: { removeIssue },
} = useIssues(EIssuesStoreType.PROJECT);
} = useIssuesStore();
const {
toggleCommandPaletteModal,
isCreateIssueModalOpen,
Expand All @@ -71,7 +71,6 @@ export const CommandPalette: FC = observer(() => {
isDeleteIssueModalOpen,
toggleDeleteIssueModal,
isAnyModalOpen,
createIssueStoreType,
} = useCommandPalette();

const { data: issueDetails } = useSWR(
Expand Down Expand Up @@ -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}
/>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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} />
Expand Down
6 changes: 5 additions & 1 deletion web/core/components/issues/issue-modal/modal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down
3 changes: 1 addition & 2 deletions web/core/components/workspace/sidebar/quick-actions.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -90,7 +89,7 @@ export const SidebarQuickActions = observer(() => {
)}
onClick={() => {
setTrackElement("APP_SIDEBAR_QUICK_ACTIONS");
toggleCreateIssueModal(true, EIssuesStoreType.PROJECT);
toggleCreateIssueModal(true);
}}
disabled={disabled}
>
Expand Down
25 changes: 22 additions & 3 deletions web/core/hooks/use-issue-layout-store.ts
Original file line number Diff line number Diff line change
@@ -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);
};

0 comments on commit a623456

Please sign in to comment.