From d8c1c103a159bce0effa041378541c40d9b38dc5 Mon Sep 17 00:00:00 2001 From: GitStart <1501599+gitstart@users.noreply.github.com> Date: Fri, 2 Dec 2022 18:08:12 +0800 Subject: [PATCH] [CAL-103] All Bookings show up under Today and Today should be uppercase (#5155) Co-authored-by: Nitesh Singh Co-authored-by: gitstart Co-authored-by: Thiago Nascimbeni Co-authored-by: Rafael Toledo <87545086+Toledodev@users.noreply.github.com> Co-authored-by: Matheus Benini Ferreira <88898100+MatheusBeniniF@users.noreply.github.com> Co-authored-by: Matheus Muniz <87545749+matheusmuniz03@users.noreply.github.com> Co-authored-by: Rafael Co-authored-by: gitstart Co-authored-by: niteshsingh1357 Co-authored-by: gitstart Co-authored-by: Nitesh Singh Co-authored-by: Thiago Nascimbeni Co-authored-by: Rafael Toledo <87545086+Toledodev@users.noreply.github.com> Co-authored-by: Matheus Benini Ferreira <88898100+MatheusBeniniF@users.noreply.github.com> Co-authored-by: Matheus Muniz <87545749+matheusmuniz03@users.noreply.github.com> Co-authored-by: Rafael Co-authored-by: gitstart Co-authored-by: niteshsingh1357 Co-authored-by: Peer Richelsen --- apps/web/pages/bookings/[status].tsx | 105 ++++++++++++++++++--------- 1 file changed, 72 insertions(+), 33 deletions(-) diff --git a/apps/web/pages/bookings/[status].tsx b/apps/web/pages/bookings/[status].tsx index 7b427e3ef5..fbd4c78c40 100644 --- a/apps/web/pages/bookings/[status].tsx +++ b/apps/web/pages/bookings/[status].tsx @@ -17,6 +17,13 @@ import SkeletonLoader from "@components/booking/SkeletonLoader"; type BookingListingStatus = RouterInputs["viewer"]["bookings"]["get"]["status"]; type BookingOutput = RouterOutputs["viewer"]["bookings"]["get"]["bookings"][0]; +type RecurringInfo = { + recurringEventId: string | null; + count: number; + firstDate: Date | null; + bookings: { [key: string]: Date[] }; +}; + const validStatuses = ["upcoming", "recurring", "past", "cancelled", "unconfirmed"] as const; const descriptionByStatus: Record = { @@ -73,6 +80,18 @@ export default function Bookings() { return true; }; + let recurringInfoToday: RecurringInfo | undefined; + + const bookingsToday = + query.data?.pages.map((page) => + page.bookings.filter((booking: BookingOutput) => { + recurringInfoToday = page.recurringInfo.find( + (info) => info.recurringEventId === booking.recurringEventId + ); + return new Date(booking.startTime).toDateString() === new Date().toDateString(); + }) + )[0] || []; + const [animationParentRef] = useAutoAnimate(); return ( @@ -83,45 +102,65 @@ export default function Bookings() { )} {(query.status === "loading" || query.isPaused) && } {query.status === "success" && !isEmpty && ( -
- - {/* TODO: add today only for the current day -

{t("today")}

- */} - -
- - - {query.data.pages.map((page, index) => ( - - {page.bookings.filter(filterBookings).map((booking: BookingOutput) => { - const recurringInfo = page.recurringInfo.find( - (info) => info.recurringEventId === booking.recurringEventId - ); - return ( + <> + {!!bookingsToday.length && status === "upcoming" && ( +
+ +

{t("today")}

+
+
+ + + {bookingsToday.map((booking: BookingOutput) => ( - ); - })} - - ))} - -
+ ))} + + + +
+
+ )} +
+

{t("all")}

+
+ + + {query.data.pages.map((page, index) => ( + + {page.bookings.filter(filterBookings).map((booking: BookingOutput) => { + const recurringInfo = page.recurringInfo.find( + (info) => info.recurringEventId === booking.recurringEventId + ); + return ( + + ); + })} + + ))} + +
+
+
+ +
-
- -
- + )} {query.status === "success" && isEmpty && (