Skip to content

Commit

Permalink
Added checks to make weird dates not break code
Browse files Browse the repository at this point in the history
added a popup instead
  • Loading branch information
WishingWell13 committed Apr 12, 2024
1 parent 4eda486 commit c745347
Showing 1 changed file with 18 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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);
}
Expand All @@ -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,
Expand Down Expand Up @@ -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);
}
Expand Down

0 comments on commit c745347

Please sign in to comment.