Skip to content

Commit

Permalink
simplify /bookings/[status] logic (calcom#845)
Browse files Browse the repository at this point in the history
  • Loading branch information
KATT authored Oct 2, 2021
1 parent 342ea3e commit eb93e77
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 14 deletions.
20 changes: 8 additions & 12 deletions pages/bookings/[status].tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import BookingListItem from "@components/booking/BookingListItem";

type BookingListingStatus = inferQueryInput<"viewer.bookings">["status"];

const descriptionByStatus = {
const descriptionByStatus: Record<BookingListingStatus, string> = {
upcoming: "As soon as someone books a time with you it will show up here.",
past: "Your past bookings will show up here.",
cancelled: "Your cancelled bookings will show up here.",
Expand Down Expand Up @@ -41,17 +41,13 @@ export default function Bookings() {
</table>
</div>
)}
empty={
status
? () => (
<EmptyScreen
Icon={CalendarIcon}
headline={`No ${status} bookings, yet`}
description={`You have no ${status} bookings. ${descriptionByStatus[status]}`}
/>
)
: undefined
}
empty={() => (
<EmptyScreen
Icon={CalendarIcon}
headline={`No ${status} bookings, yet`}
description={`You have no ${status} bookings. ${descriptionByStatus[status]}`}
/>
)}
/>
</div>
</div>
Expand Down
4 changes: 2 additions & 2 deletions server/routers/viewer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,11 @@ export const viewerRouter = createProtectedRouter()
})
.query("bookings", {
input: z.object({
status: z.enum(["upcoming", "past", "cancelled"]).optional(),
status: z.enum(["upcoming", "past", "cancelled"]),
}),
async resolve({ ctx, input }) {
const { prisma, user } = ctx;
const bookingListingByStatus = input.status || "upcoming";
const bookingListingByStatus = input.status;
const bookingListingFilters: Record<typeof bookingListingByStatus, Prisma.BookingWhereInput[]> = {
upcoming: [{ endTime: { gte: new Date() } }],
past: [{ endTime: { lte: new Date() } }],
Expand Down

0 comments on commit eb93e77

Please sign in to comment.