Files
multica/apps/web/features/issues/stores/draft-store.ts
Naiyuan Qing bf379b2e76 feat(issues): persist create-issue draft with sidebar indicator
- Add zustand draft store with localStorage persistence
- Restore draft fields when reopening create-issue modal
- Clear draft only on successful submission
- Show brand-colored dot on sidebar new-issue button when draft exists

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-03-30 14:57:29 +08:00

47 lines
1.1 KiB
TypeScript

import { create } from "zustand";
import { persist } from "zustand/middleware";
import type { IssueStatus, IssuePriority, IssueAssigneeType } from "@/shared/types";
interface IssueDraft {
title: string;
description: string;
status: IssueStatus;
priority: IssuePriority;
assigneeType?: IssueAssigneeType;
assigneeId?: string;
dueDate: string | null;
}
const EMPTY_DRAFT: IssueDraft = {
title: "",
description: "",
status: "todo",
priority: "none",
assigneeType: undefined,
assigneeId: undefined,
dueDate: null,
};
interface IssueDraftStore {
draft: IssueDraft;
setDraft: (patch: Partial<IssueDraft>) => void;
clearDraft: () => void;
hasDraft: () => boolean;
}
export const useIssueDraftStore = create<IssueDraftStore>()(
persist(
(set, get) => ({
draft: { ...EMPTY_DRAFT },
setDraft: (patch) =>
set((s) => ({ draft: { ...s.draft, ...patch } })),
clearDraft: () => set({ draft: { ...EMPTY_DRAFT } }),
hasDraft: () => {
const { draft } = get();
return !!(draft.title || draft.description);
},
}),
{ name: "multica_issue_draft" },
),
);