diff --git a/public/assets/icons/arrow-left.svg b/public/assets/icons/arrow-left.svg index 52dc05c6..f8ff17a2 100644 --- a/public/assets/icons/arrow-left.svg +++ b/public/assets/icons/arrow-left.svg @@ -1,3 +1,3 @@ - + diff --git a/public/assets/icons/arrow-right.svg b/public/assets/icons/arrow-right.svg index b25599ae..820e9c21 100644 --- a/public/assets/icons/arrow-right.svg +++ b/public/assets/icons/arrow-right.svg @@ -1,3 +1,3 @@ - + diff --git a/src/components/admin/event/AdminPickupEvent/AdminPickupEventForm.tsx b/src/components/admin/event/AdminPickupEvent/AdminPickupEventForm.tsx index d53ba189..5fb61cf0 100644 --- a/src/components/admin/event/AdminPickupEvent/AdminPickupEventForm.tsx +++ b/src/components/admin/event/AdminPickupEvent/AdminPickupEventForm.tsx @@ -25,6 +25,13 @@ interface IProps { upcomingEvents: PublicEvent[]; } +const parseProps = (isoStart: string, isoEnd: string, rawOrderLimit: string) => { + const start = new Date(isoStart).toISOString(); + const end = new Date(isoEnd).toISOString(); + const orderLimit = parseInt(`${rawOrderLimit}`, 10); + return { start, end, orderLimit }; +}; + export const completePickupEvent = async (uuid: UUID, token: string) => { try { await AdminEventManager.completePickupEvent({ @@ -89,18 +96,16 @@ 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, end, orderLimit } = parseProps(isoStart, isoEnd, `${rawOrderLimit}`); + const uuid = await AdminEventManager.createPickupEvent(token, { title, start, end, description, orderLimit, - linkedEventUuid, + linkedEventUuid: linkedEventUuid || null, }); showToast('Pickup Event created successfully!', '', [ { @@ -110,7 +115,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 instanceof RangeError) { + reportError('Invalid date, could not create pickup event', error); + } else { + reportError('Could not create pickup event', error); + } } finally { setLoading(false); } @@ -128,13 +137,18 @@ 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, end, orderLimit } = parseProps(isoStart, isoEnd, `${rawOrderLimit}`); + await AdminEventManager.editPickupEvent({ - pickupEvent: { title, start, end, description, orderLimit, linkedEventUuid }, + pickupEvent: { + title, + start, + end, + description, + orderLimit, + linkedEventUuid: linkedEventUuid || null, + }, uuid: defaultData.uuid ?? '', token: token, @@ -153,7 +167,11 @@ const AdminPickupEventForm = ({ mode, defaultData = {}, token, upcomingEvents }: }, }); } catch (error) { - reportError('Could not save changes', error); + if (error instanceof RangeError) { + reportError("Invalid date, can't save changes", error); + } else { + reportError('Could not save changes', error); + } } finally { setLoading(false); } diff --git a/src/components/common/PaginationControls/index.tsx b/src/components/common/PaginationControls/index.tsx index 3e0ca0bf..ea1ffd05 100644 --- a/src/components/common/PaginationControls/index.tsx +++ b/src/components/common/PaginationControls/index.tsx @@ -1,5 +1,5 @@ -import LeftArrowIcon from '@/public/assets/icons/page-left-icon.svg'; -import RightArrowIcon from '@/public/assets/icons/page-right-icon.svg'; +import LeftArrowIcon from '@/public/assets/icons/arrow-left.svg'; +import RightArrowIcon from '@/public/assets/icons/arrow-right.svg'; import { useEffect, useState } from 'react'; import style from './style.module.scss'; @@ -54,7 +54,7 @@ const PaginationControls = ({ page, onPage, pages }: PaginationControlsProps) => } }} /> - of + / {pages}