Skip to content

Commit

Permalink
Merge branch 'main' into pagination
Browse files Browse the repository at this point in the history
  • Loading branch information
alexzhang1618 authored Apr 13, 2024
2 parents 743bb2d + a92bb3f commit 904688c
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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({
Expand Down Expand Up @@ -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!', '', [
{
Expand All @@ -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);
}
Expand All @@ -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,

Expand All @@ -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);
}
Expand Down
10 changes: 7 additions & 3 deletions src/pages/admin/store/pickup/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -52,9 +52,13 @@ const AdminPickupPage = ({ futurePickupEvents, pastPickupEvents }: AdminPickupPa
</div>
</div>
<div className={styles.cardContainer}>
{displayPickupEvents.map(pickupEvent => (
<PickupEventCard pickupEvent={pickupEvent} key={pickupEvent.uuid} />
))}
{displayPickupEvents
.sort((x, y) => {
return Date.parse(x.start) - Date.parse(y.start);
})
.map(pickupEvent => (
<PickupEventCard pickupEvent={pickupEvent} key={pickupEvent.uuid} />
))}
</div>
</div>
);
Expand Down

0 comments on commit 904688c

Please sign in to comment.