From c74534792ee160c682c0c42867e85e3bb7ca7d0b Mon Sep 17 00:00:00 2001 From: Andrew Smithwick Date: Thu, 11 Apr 2024 18:48:21 -0700 Subject: [PATCH] Added checks to make weird dates not break code added a popup instead --- .../AdminPickupEvent/AdminPickupEventForm.tsx | 28 ++++++++++++------- 1 file changed, 18 insertions(+), 10 deletions(-) diff --git a/src/components/admin/event/AdminPickupEvent/AdminPickupEventForm.tsx b/src/components/admin/event/AdminPickupEvent/AdminPickupEventForm.tsx index d57699d6..7c7b1a66 100644 --- a/src/components/admin/event/AdminPickupEvent/AdminPickupEventForm.tsx +++ b/src/components/admin/event/AdminPickupEvent/AdminPickupEventForm.tsx @@ -89,11 +89,11 @@ const AdminPickupEventForm = ({ mode, defaultData = {}, token, upcomingEvents }: orderLimit: rawOrderLimit, } = formData; - const start = new Date(isoStart).toISOString(); - const end = new Date(isoEnd).toISOString(); - const orderLimit = parseInt(`${rawOrderLimit}`, 10); - try { + const start = new Date(isoStart).toISOString(); + const end = new Date(isoEnd).toISOString(); + const orderLimit = parseInt(`${rawOrderLimit}`, 10); + const uuid = await AdminEventManager.createPickupEvent(token, { title, start, @@ -110,7 +110,11 @@ const AdminPickupEventForm = ({ mode, defaultData = {}, token, upcomingEvents }: ]); router.push(`${config.admin.store.pickup}/${uuid}`); } catch (error) { - reportError('Could not create pickup event', error); + if (error === RangeError) { + reportError('Invalid date, could not create pickup event', error); + } else { + reportError('Could not create pickup event', error); + } } finally { setLoading(false); } @@ -128,11 +132,11 @@ const AdminPickupEventForm = ({ mode, defaultData = {}, token, upcomingEvents }: orderLimit: rawOrderLimit, } = formData; - const start = new Date(isoStart).toISOString(); - const end = new Date(isoEnd).toISOString(); - const orderLimit = parseInt(`${rawOrderLimit}`, 10); - try { + const start = new Date(isoStart).toISOString(); + const end = new Date(isoEnd).toISOString(); + const orderLimit = parseInt(`${rawOrderLimit}`, 10); + await AdminEventManager.editPickupEvent({ pickupEvent: { title, @@ -160,7 +164,11 @@ const AdminPickupEventForm = ({ mode, defaultData = {}, token, upcomingEvents }: }, }); } catch (error) { - reportError('Could not save changes', error); + if (error === RangeError) { + reportError("Invalid date, can't save changes", error); + } else { + reportError('Could not save changes', error); + } } finally { setLoading(false); }