feat(03-05): add write client calls and eventForm Zustand keys
- createEvent(payload): POST /api/events/create, credentials:include, returns {uid}
- updateEvent(uid, payload): PATCH /api/events/:uid/edit
- fetchWritableCalendars(): GET /api/events/writable-calendars, returns calendars array (D-03 server-authoritative)
- Exported interfaces: CreateEventPayload, CreateEventResponse, WritableCalendar, RecurrencePreset
- calendarStore: eventFormOpen (bool), eventFormMode ('create'|'edit'), eventFormUid (string|null)
- setEventForm(open, mode?, uid?) setter with correct defaults
This commit is contained in:
@@ -35,10 +35,27 @@ export interface CalendarStore {
|
||||
openEventId: string | null
|
||||
calendarRange: { start: string; end: string }
|
||||
|
||||
// ── EventForm UI state (Plan 03-05) ──────────────────────────────────────
|
||||
// Server state (events, calendars) lives in TanStack Query. These are pure
|
||||
// UI-shape keys: whether the form is open, what mode it is in, and which
|
||||
// event UID to pre-populate in edit mode.
|
||||
eventFormOpen: boolean
|
||||
eventFormMode: 'create' | 'edit'
|
||||
eventFormUid: string | null
|
||||
|
||||
setSelectedView: (view: string) => void
|
||||
setSelectedDate: (date: string) => void
|
||||
setOpenEventId: (id: string | null) => void
|
||||
setCalendarRange: (range: { start: string; end: string }) => void
|
||||
|
||||
/**
|
||||
* Open or close the EventForm.
|
||||
*
|
||||
* @param open true to open, false to close
|
||||
* @param mode 'create' (default) or 'edit'
|
||||
* @param uid UID of the event to pre-populate in edit mode (null otherwise)
|
||||
*/
|
||||
setEventForm: (open: boolean, mode?: 'create' | 'edit', uid?: string | null) => void
|
||||
}
|
||||
|
||||
// ── Helpers ────────────────────────────────────────────────────────────────
|
||||
@@ -93,6 +110,11 @@ export const useCalendarStore = create<CalendarStore>((set) => ({
|
||||
openEventId: null,
|
||||
calendarRange: initialCalendarRange(),
|
||||
|
||||
// EventForm UI state — closed by default, create mode, no pre-fill UID
|
||||
eventFormOpen: false,
|
||||
eventFormMode: 'create',
|
||||
eventFormUid: null,
|
||||
|
||||
setSelectedView: (view: string) => {
|
||||
set({ selectedView: view })
|
||||
// Persist to localStorage keyed by breakpoint group
|
||||
@@ -110,4 +132,7 @@ export const useCalendarStore = create<CalendarStore>((set) => ({
|
||||
|
||||
setCalendarRange: (range: { start: string; end: string }) =>
|
||||
set({ calendarRange: range }),
|
||||
|
||||
setEventForm: (open: boolean, mode: 'create' | 'edit' = 'create', uid: string | null = null) =>
|
||||
set({ eventFormOpen: open, eventFormMode: mode, eventFormUid: uid }),
|
||||
}))
|
||||
|
||||
Reference in New Issue
Block a user