{/* Don't show project selection if editing an issue */}
@@ -670,7 +672,40 @@ export const IssueFormRoot: FC = observer((props) => {
-
diff --git a/web/components/issues/issue-modal/modal.tsx b/web/components/issues/issue-modal/modal.tsx
index 3b5b35cea..02a087314 100644
--- a/web/components/issues/issue-modal/modal.tsx
+++ b/web/components/issues/issue-modal/modal.tsx
@@ -20,10 +20,19 @@ export interface IssuesModalProps {
onSubmit?: (res: TIssue) => Promise
;
withDraftIssueWrapper?: boolean;
storeType?: TCreateModalStoreTypes;
+ isDraft?: boolean;
}
export const CreateUpdateIssueModal: React.FC = observer((props) => {
- const { data, isOpen, onClose, onSubmit, withDraftIssueWrapper = true, storeType = EIssuesStoreType.PROJECT } = props;
+ const {
+ data,
+ isOpen,
+ onClose,
+ onSubmit,
+ withDraftIssueWrapper = true,
+ storeType = EIssuesStoreType.PROJECT,
+ isDraft = false,
+ } = props;
// states
const [changesMade, setChangesMade] = useState | null>(null);
const [createMore, setCreateMore] = useState(false);
@@ -42,6 +51,7 @@ export const CreateUpdateIssueModal: React.FC = observer((prop
const { issues: cycleIssues } = useIssues(EIssuesStoreType.CYCLE);
const { issues: viewIssues } = useIssues(EIssuesStoreType.PROJECT_VIEW);
const { issues: profileIssues } = useIssues(EIssuesStoreType.PROFILE);
+ const { issues: draftIssueStore } = useIssues(EIssuesStoreType.DRAFT);
// store mapping based on current store
const issueStores = {
[EIssuesStoreType.PROJECT]: {
@@ -122,11 +132,16 @@ export const CreateUpdateIssueModal: React.FC = observer((prop
onClose();
};
- const handleCreateIssue = async (payload: Partial): Promise => {
+ const handleCreateIssue = async (
+ payload: Partial,
+ is_draft_issue: boolean = false
+ ): Promise => {
if (!workspaceSlug || !payload.project_id) return;
try {
- const response = await currentIssueStore.createIssue(workspaceSlug, payload.project_id, payload, viewId);
+ const response = is_draft_issue
+ ? await draftIssueStore.createIssue(workspaceSlug, payload.project_id, payload)
+ : await currentIssueStore.createIssue(workspaceSlug, payload.project_id, payload, viewId);
if (!response) throw new Error();
currentIssueStore.fetchIssues(workspaceSlug, payload.project_id, "mutation", viewId);
@@ -213,7 +228,7 @@ export const CreateUpdateIssueModal: React.FC = observer((prop
}
};
- const handleFormSubmit = async (formData: Partial) => {
+ const handleFormSubmit = async (formData: Partial, is_draft_issue: boolean = false) => {
if (!workspaceSlug || !formData.project_id || !storeType) return;
const payload: Partial = {
@@ -222,7 +237,7 @@ export const CreateUpdateIssueModal: React.FC = observer((prop
};
let response: TIssue | undefined = undefined;
- if (!data?.id) response = await handleCreateIssue(payload);
+ if (!data?.id) response = await handleCreateIssue(payload, is_draft_issue);
else response = await handleUpdateIssue(payload);
if (response != undefined && onSubmit) await onSubmit(response);
@@ -274,6 +289,7 @@ export const CreateUpdateIssueModal: React.FC = observer((prop
projectId={activeProjectId}
isCreateMoreToggleEnabled={createMore}
onCreateMoreToggleChange={handleCreateMoreToggleChange}
+ isDraft={isDraft}
/>
) : (
= observer((prop
onCreateMoreToggleChange={handleCreateMoreToggleChange}
onSubmit={handleFormSubmit}
projectId={activeProjectId}
+ isDraft={isDraft}
/>
)}
diff --git a/web/store/issue/draft/issue.store.ts b/web/store/issue/draft/issue.store.ts
index 13d14484a..dc0f601eb 100644
--- a/web/store/issue/draft/issue.store.ts
+++ b/web/store/issue/draft/issue.store.ts
@@ -1,5 +1,9 @@
import { action, observable, makeObservable, computed, runInAction } from "mobx";
import set from "lodash/set";
+import update from "lodash/update";
+import uniq from "lodash/uniq";
+import concat from "lodash/concat";
+import pull from "lodash/pull";
// base class
import { IssueHelperStore } from "../helpers/issue-helper.store";
// services
@@ -123,7 +127,7 @@ export class DraftIssues extends IssueHelperStore implements IDraftIssues {
const response = await this.issueDraftService.createDraftIssue(workspaceSlug, projectId, data);
runInAction(() => {
- this.issues[projectId].push(response.id);
+ update(this.issues, [projectId], (issueIds = []) => uniq(concat(issueIds, response.id)));
});
this.rootStore.issues.addIssue([response]);
@@ -136,8 +140,17 @@ export class DraftIssues extends IssueHelperStore implements IDraftIssues {
updateIssue = async (workspaceSlug: string, projectId: string, issueId: string, data: Partial) => {
try {
- this.rootStore.issues.updateIssue(issueId, data);
- const response = await this.issueDraftService.updateDraftIssue(workspaceSlug, projectId, issueId, data);
+ const response = await this.rootIssueStore.projectIssues.updateIssue(workspaceSlug, projectId, issueId, data);
+
+ if (data.hasOwnProperty("is_draft") && data?.is_draft === false) {
+ runInAction(() => {
+ update(this.issues, [projectId], (issueIds = []) => {
+ if (issueIds.includes(issueId)) pull(issueIds, issueId);
+ return issueIds;
+ });
+ });
+ }
+
return response;
} catch (error) {
this.fetchIssues(workspaceSlug, projectId, "mutation");
@@ -147,15 +160,14 @@ export class DraftIssues extends IssueHelperStore implements IDraftIssues {
removeIssue = async (workspaceSlug: string, projectId: string, issueId: string) => {
try {
- const response = await this.issueDraftService.deleteDraftIssue(workspaceSlug, projectId, issueId);
+ const response = await this.rootIssueStore.projectIssues.removeIssue(workspaceSlug, projectId, issueId);
- const issueIndex = this.issues[projectId].findIndex((_issueId) => _issueId === issueId);
- if (issueIndex >= 0)
- runInAction(() => {
- this.issues[projectId].splice(issueIndex, 1);
+ runInAction(() => {
+ update(this.issues, [projectId], (issueIds = []) => {
+ if (issueIds.includes(issueId)) pull(issueIds, issueId);
+ return issueIds;
});
-
- this.rootStore.issues.removeIssue(issueId);
+ });
return response;
} catch (error) {