From 25138c378a7fc69fd05200cda34827228a8ea028 Mon Sep 17 00:00:00 2001 From: silentoplayz Date: Tue, 4 Aug 2026 22:53:50 -0400 Subject: [PATCH] fix(calendar): require a date and render validation errors as text --- src/lib/apis/calendar/index.ts | 32 ++++++++++++------- .../calendar/CalendarEventModal.svelte | 5 +++ src/lib/i18n/locales/en-US/translation.json | 1 + 3 files changed, 26 insertions(+), 12 deletions(-) diff --git a/src/lib/apis/calendar/index.ts b/src/lib/apis/calendar/index.ts index eb02b184d6..3cbe3b3f87 100644 --- a/src/lib/apis/calendar/index.ts +++ b/src/lib/apis/calendar/index.ts @@ -69,6 +69,14 @@ export type CalendarForm = { access_grants?: { target_type: string; target_id: string; permission: string }[]; }; +const getErrorDetail = (err: any) => { + if (Array.isArray(err?.detail)) { + return err.detail.map((e: { msg?: string }) => e.msg || JSON.stringify(e)).join(', '); + } + + return err?.detail; +}; + // ── Calendars ───────────────────────────────── export const getCalendars = async (token: string): Promise => { @@ -87,7 +95,7 @@ export const getCalendars = async (token: string): Promise => { return res.json(); }) .catch((err) => { - error = err.detail; + error = getErrorDetail(err); console.error(err); return null; }); @@ -116,7 +124,7 @@ export const createCalendar = async (token: string, form: CalendarForm): Promise return res.json(); }) .catch((err) => { - error = err.detail; + error = getErrorDetail(err); console.error(err); return null; }); @@ -149,7 +157,7 @@ export const updateCalendar = async ( return res.json(); }) .catch((err) => { - error = err.detail; + error = getErrorDetail(err); console.error(err); return null; }); @@ -177,7 +185,7 @@ export const deleteCalendar = async (token: string, calendarId: string): Promise return res.json(); }) .catch((err) => { - error = err.detail; + error = getErrorDetail(err); console.error(err); return null; }); @@ -208,7 +216,7 @@ export const setDefaultCalendar = async ( return res.json(); }) .catch((err) => { - error = err.detail; + error = getErrorDetail(err); console.error(err); return null; }); @@ -250,7 +258,7 @@ export const getCalendarEvents = async ( return res.json(); }) .catch((err) => { - error = err.detail; + error = getErrorDetail(err); console.error(err); return null; }); @@ -282,7 +290,7 @@ export const createCalendarEvent = async ( return res.json(); }) .catch((err) => { - error = err.detail; + error = getErrorDetail(err); console.error(err); return null; }); @@ -313,7 +321,7 @@ export const getCalendarEventById = async ( return res.json(); }) .catch((err) => { - error = err.detail; + error = getErrorDetail(err); console.error(err); return null; }); @@ -346,7 +354,7 @@ export const updateCalendarEvent = async ( return res.json(); }) .catch((err) => { - error = err.detail; + error = getErrorDetail(err); console.error(err); return null; }); @@ -374,7 +382,7 @@ export const deleteCalendarEvent = async (token: string, eventId: string): Promi return res.json(); }) .catch((err) => { - error = err.detail; + error = getErrorDetail(err); console.error(err); return null; }); @@ -407,7 +415,7 @@ export const rsvpCalendarEvent = async ( return res.json(); }) .catch((err) => { - error = err.detail; + error = getErrorDetail(err); console.error(err); return null; }); @@ -445,7 +453,7 @@ export const searchCalendarEvents = async ( return res.json(); }) .catch((err) => { - error = err.detail; + error = getErrorDetail(err); console.error(err); return null; }); diff --git a/src/lib/components/calendar/CalendarEventModal.svelte b/src/lib/components/calendar/CalendarEventModal.svelte index e95c30d6e6..c5eddac82d 100644 --- a/src/lib/components/calendar/CalendarEventModal.svelte +++ b/src/lib/components/calendar/CalendarEventModal.svelte @@ -121,6 +121,11 @@ return; } + if (!startDate) { + toast.error($i18n.t('Date is required')); + return; + } + loading = true; try { const startNs = dateTimeToNs(startDate, allDay ? '00:00' : startTime); diff --git a/src/lib/i18n/locales/en-US/translation.json b/src/lib/i18n/locales/en-US/translation.json index da7da2fb01..b064bdbf8b 100644 --- a/src/lib/i18n/locales/en-US/translation.json +++ b/src/lib/i18n/locales/en-US/translation.json @@ -708,6 +708,7 @@ "Database": "", "Datalab Marker API": "", "Datalab Marker service endpoint used for document parsing.": "", + "Date is required": "", "Date Modified": "", "Day": "", "DD/MM/YYYY": "",