Skip to content

Commit 79bf7d4

Browse files
authored
fix: hydration error and draft issue workflow (#2199)
* fix: hydration error and draft issue workflow * fix: build error
1 parent 5d33147 commit 79bf7d4

File tree

11 files changed

+240
-47
lines changed

11 files changed

+240
-47
lines changed

web/components/command-palette/command-pallette.tsx

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ export const CommandPalette: React.FC = observer(() => {
4141
const [isCreateUpdatePageModalOpen, setIsCreateUpdatePageModalOpen] = useState(false);
4242

4343
const router = useRouter();
44-
const { workspaceSlug, projectId, issueId, inboxId } = router.query;
44+
const { workspaceSlug, projectId, issueId, inboxId, cycleId, moduleId } = router.query;
4545

4646
const { user } = useUser();
4747

@@ -183,6 +183,13 @@ export const CommandPalette: React.FC = observer(() => {
183183
isOpen={isIssueModalOpen}
184184
handleClose={() => setIsIssueModalOpen(false)}
185185
fieldsToShow={inboxId ? ["name", "description", "priority"] : ["all"]}
186+
prePopulateData={
187+
cycleId
188+
? { cycle: cycleId.toString() }
189+
: moduleId
190+
? { module: moduleId.toString() }
191+
: undefined
192+
}
186193
/>
187194
<BulkDeleteIssuesModal
188195
isOpen={isBulkDeleteIssuesModalOpen}

web/components/core/views/issues-view.tsx

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@ import {
2323
CreateUpdateIssueModal,
2424
DeleteIssueModal,
2525
DeleteDraftIssueModal,
26-
IssuePeekOverview,
2726
CreateUpdateDraftIssueModal,
2827
} from "components/issues";
2928
import { CreateUpdateViewModal } from "components/views";
@@ -484,15 +483,7 @@ export const IssuesView: React.FC<Props> = ({
484483
}
485484
: null
486485
}
487-
fieldsToShow={[
488-
"name",
489-
"description",
490-
"label",
491-
"assignee",
492-
"priority",
493-
"dueDate",
494-
"priority",
495-
]}
486+
fieldsToShow={["all"]}
496487
/>
497488
<CreateUpdateIssueModal
498489
isOpen={editIssueModal && issueToEdit?.actionType !== "delete"}

web/components/issues/delete-draft-issue-modal.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,12 +50,12 @@ export const DeleteDraftIssueModal: React.FC<Props> = (props) => {
5050
};
5151

5252
const handleDeletion = async () => {
53-
if (!workspaceSlug || !data) return;
53+
if (!workspaceSlug || !data || !user) return;
5454

5555
setIsDeleteLoading(true);
5656

5757
await issueServices
58-
.deleteDraftIssue(workspaceSlug as string, data.project, data.id)
58+
.deleteDraftIssue(workspaceSlug as string, data.project, data.id, user)
5959
.then(() => {
6060
setIsDeleteLoading(false);
6161
handleClose();

web/components/issues/draft-issue-modal.tsx

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ import useIssuesView from "hooks/use-issues-view";
1414
import useCalendarIssuesView from "hooks/use-calendar-issues-view";
1515
import useToast from "hooks/use-toast";
1616
import useSpreadsheetIssuesView from "hooks/use-spreadsheet-issues-view";
17+
import useLocalStorage from "hooks/use-local-storage";
1718
import useProjects from "hooks/use-projects";
1819
import useMyIssues from "hooks/my-issues/use-my-issues";
1920
// components
@@ -79,6 +80,8 @@ export const CreateUpdateDraftIssueModal: React.FC<IssuesModalProps> = ({
7980
const { user } = useUser();
8081
const { projects } = useProjects();
8182

83+
const { clearValue: clearDraftIssueLocalStorage } = useLocalStorage("draftedIssue", {});
84+
8285
const { groupedIssues, mutateMyIssues } = useMyIssues(workspaceSlug?.toString());
8386

8487
const { setToastAlert } = useToast();
@@ -111,11 +114,14 @@ export const CreateUpdateDraftIssueModal: React.FC<IssuesModalProps> = ({
111114
return;
112115
}
113116

117+
if (prePopulateData && prePopulateData.project)
118+
return setActiveProject(prePopulateData.project);
119+
114120
// if data is not present, set active project to the project
115121
// in the url. This has the least priority.
116122
if (projects && projects.length > 0 && !activeProject)
117123
setActiveProject(projects?.find((p) => p.id === projectId)?.id ?? projects?.[0].id ?? null);
118-
}, [activeProject, data, projectId, projects, isOpen]);
124+
}, [activeProject, data, projectId, projects, isOpen, prePopulateData]);
119125

120126
const calendarFetchKey = cycleId
121127
? CYCLE_ISSUES_WITH_PARAMS(cycleId.toString(), calendarParams)
@@ -228,6 +234,8 @@ export const CreateUpdateDraftIssueModal: React.FC<IssuesModalProps> = ({
228234
if (!data) await createIssue(payload);
229235
else await updateIssue(payload);
230236

237+
clearDraftIssueLocalStorage();
238+
231239
if (onSubmit) await onSubmit(payload);
232240
};
233241

web/components/issues/form.tsx

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ import { Controller, useForm } from "react-hook-form";
88
import aiService from "services/ai.service";
99
// hooks
1010
import useToast from "hooks/use-toast";
11-
import useLocalStorage from "hooks/use-local-storage";
1211
// components
1312
import { GptAssistantModal } from "components/core";
1413
import { ParentIssuesListModal } from "components/issues";
@@ -62,11 +61,9 @@ export interface IssueFormProps {
6261
setActiveProject: React.Dispatch<React.SetStateAction<string | null>>;
6362
createMore: boolean;
6463
setCreateMore: React.Dispatch<React.SetStateAction<boolean>>;
65-
handleClose: () => void;
6664
handleDiscardClose: () => void;
6765
status: boolean;
6866
user: ICurrentUserResponse | undefined;
69-
setIsConfirmDiscardOpen: React.Dispatch<React.SetStateAction<boolean>>;
7067
handleFormDirty: (payload: Partial<IIssue> | null) => void;
7168
fieldsToShow: (
7269
| "project"
@@ -107,8 +104,6 @@ export const IssueForm: FC<IssueFormProps> = (props) => {
107104
const [gptAssistantModal, setGptAssistantModal] = useState(false);
108105
const [iAmFeelingLucky, setIAmFeelingLucky] = useState(false);
109106

110-
const { setValue: setValueInLocalStorage } = useLocalStorage<any>("draftedIssue", null);
111-
112107
const editorRef = useRef<any>(null);
113108

114109
const router = useRouter();
@@ -139,9 +134,11 @@ export const IssueForm: FC<IssueFormProps> = (props) => {
139134
state: getValues("state"),
140135
priority: getValues("priority"),
141136
assignees: getValues("assignees"),
142-
target_date: getValues("target_date"),
143137
labels: getValues("labels"),
138+
start_date: getValues("start_date"),
139+
target_date: getValues("target_date"),
144140
project: getValues("project"),
141+
parent: getValues("parent"),
145142
};
146143

147144
useEffect(() => {
@@ -571,8 +568,6 @@ export const IssueForm: FC<IssueFormProps> = (props) => {
571568
<div className="flex items-center gap-2">
572569
<SecondaryButton
573570
onClick={() => {
574-
const data = JSON.stringify(getValues());
575-
setValueInLocalStorage(data);
576571
handleDiscardClose();
577572
}}
578573
>

web/components/issues/modal.tsx

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ import useInboxView from "hooks/use-inbox-view";
1919
import useSpreadsheetIssuesView from "hooks/use-spreadsheet-issues-view";
2020
import useProjects from "hooks/use-projects";
2121
import useMyIssues from "hooks/my-issues/use-my-issues";
22+
import useLocalStorage from "hooks/use-local-storage";
2223
// components
2324
import { IssueForm, ConfirmIssueDiscard } from "components/issues";
2425
// types
@@ -92,17 +93,25 @@ export const CreateUpdateIssueModal: React.FC<IssuesModalProps> = ({
9293

9394
const { groupedIssues, mutateMyIssues } = useMyIssues(workspaceSlug?.toString());
9495

96+
const { setValue: setValueInLocalStorage, clearValue: clearLocalStorageValue } =
97+
useLocalStorage<any>("draftedIssue", {});
98+
9599
const { setToastAlert } = useToast();
96100

97-
if (cycleId) prePopulateData = { ...prePopulateData, cycle: cycleId as string };
98-
if (moduleId) prePopulateData = { ...prePopulateData, module: moduleId as string };
99101
if (router.asPath.includes("my-issues") || router.asPath.includes("assigned"))
100102
prePopulateData = {
101103
...prePopulateData,
102104
assignees: [...(prePopulateData?.assignees ?? []), user?.id ?? ""],
103105
};
104106

105107
const onClose = () => {
108+
if (!showConfirmDiscard) handleClose();
109+
if (formDirtyState === null) return setActiveProject(null);
110+
const data = JSON.stringify(formDirtyState);
111+
setValueInLocalStorage(data);
112+
};
113+
114+
const onDiscardClose = () => {
106115
if (formDirtyState !== null) {
107116
setShowConfirmDiscard(true);
108117
} else {
@@ -111,11 +120,6 @@ export const CreateUpdateIssueModal: React.FC<IssuesModalProps> = ({
111120
}
112121
};
113122

114-
const onDiscardClose = () => {
115-
handleClose();
116-
setActiveProject(null);
117-
};
118-
119123
const handleFormDirty = (data: any) => {
120124
setFormDirtyState(data);
121125
};
@@ -397,6 +401,7 @@ export const CreateUpdateIssueModal: React.FC<IssuesModalProps> = ({
397401
setActiveProject(null);
398402
setFormDirtyState(null);
399403
setShowConfirmDiscard(false);
404+
clearLocalStorageValue();
400405
}}
401406
/>
402407

@@ -431,9 +436,7 @@ export const CreateUpdateIssueModal: React.FC<IssuesModalProps> = ({
431436
initialData={data ?? prePopulateData}
432437
createMore={createMore}
433438
setCreateMore={setCreateMore}
434-
handleClose={onClose}
435439
handleDiscardClose={onDiscardClose}
436-
setIsConfirmDiscardOpen={setShowConfirmDiscard}
437440
projectId={activeProject ?? ""}
438441
setActiveProject={setActiveProject}
439442
status={data ? true : false}

web/components/ui/buttons/type.d.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
export type ButtonProps = {
22
children: React.ReactNode;
33
className?: string;
4-
onClick?: () => void;
4+
onClick?: (e: any) => void;
55
type?: "button" | "submit" | "reset";
66
disabled?: boolean;
77
loading?: boolean;

web/components/workspace/sidebar-quick-action.tsx

Lines changed: 6 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,10 @@ export const WorkspaceSidebarQuickAction = () => {
1717

1818
const [isDraftIssueModalOpen, setIsDraftIssueModalOpen] = useState(false);
1919

20-
const { storedValue, clearValue } = useLocalStorage<any>("draftedIssue", null);
20+
const { storedValue, clearValue } = useLocalStorage<any>(
21+
"draftedIssue",
22+
JSON.stringify(undefined)
23+
);
2124

2225
return (
2326
<>
@@ -30,18 +33,7 @@ export const WorkspaceSidebarQuickAction = () => {
3033
clearValue();
3134
setIsDraftIssueModalOpen(false);
3235
}}
33-
fieldsToShow={[
34-
"name",
35-
"description",
36-
"label",
37-
"assignee",
38-
"priority",
39-
"dueDate",
40-
"priority",
41-
"state",
42-
"startDate",
43-
"project",
44-
]}
36+
fieldsToShow={["all"]}
4537
/>
4638

4739
<div
@@ -50,7 +42,7 @@ export const WorkspaceSidebarQuickAction = () => {
5042
}`}
5143
>
5244
<div
53-
className={`flex items-center justify-between w-full rounded cursor-pointer px-2 gap-1 ${
45+
className={`flex items-center justify-between w-full rounded cursor-pointer px-2 gap-1 group ${
5446
store?.theme?.sidebarCollapsed
5547
? "px-2 hover:bg-custom-sidebar-background-80"
5648
: "px-3 shadow border-[0.5px] border-custom-border-300"

web/services/issues.service.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -658,7 +658,12 @@ class ProjectIssuesServices extends APIService {
658658
});
659659
}
660660

661-
async deleteDraftIssue(workspaceSlug: string, projectId: string, issueId: string): Promise<any> {
661+
async deleteDraftIssue(
662+
workspaceSlug: string,
663+
projectId: string,
664+
issueId: string,
665+
user: ICurrentUserResponse
666+
): Promise<any> {
662667
return this.delete(
663668
`/api/workspaces/${workspaceSlug}/projects/${projectId}/issue-drafts/${issueId}/`
664669
)

0 commit comments

Comments
 (0)