simplify /bookings/[status]
logic (#845)
This commit is contained in:
parent
342ea3e5d2
commit
eb93e778bd
2 changed files with 10 additions and 14 deletions
|
@ -11,7 +11,7 @@ import BookingListItem from "@components/booking/BookingListItem";
|
||||||
|
|
||||||
type BookingListingStatus = inferQueryInput<"viewer.bookings">["status"];
|
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.",
|
upcoming: "As soon as someone books a time with you it will show up here.",
|
||||||
past: "Your past bookings will show up here.",
|
past: "Your past bookings will show up here.",
|
||||||
cancelled: "Your cancelled bookings will show up here.",
|
cancelled: "Your cancelled bookings will show up here.",
|
||||||
|
@ -41,17 +41,13 @@ export default function Bookings() {
|
||||||
</table>
|
</table>
|
||||||
</div>
|
</div>
|
||||||
)}
|
)}
|
||||||
empty={
|
empty={() => (
|
||||||
status
|
<EmptyScreen
|
||||||
? () => (
|
Icon={CalendarIcon}
|
||||||
<EmptyScreen
|
headline={`No ${status} bookings, yet`}
|
||||||
Icon={CalendarIcon}
|
description={`You have no ${status} bookings. ${descriptionByStatus[status]}`}
|
||||||
headline={`No ${status} bookings, yet`}
|
/>
|
||||||
description={`You have no ${status} bookings. ${descriptionByStatus[status]}`}
|
)}
|
||||||
/>
|
|
||||||
)
|
|
||||||
: undefined
|
|
||||||
}
|
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
|
@ -22,11 +22,11 @@ export const viewerRouter = createProtectedRouter()
|
||||||
})
|
})
|
||||||
.query("bookings", {
|
.query("bookings", {
|
||||||
input: z.object({
|
input: z.object({
|
||||||
status: z.enum(["upcoming", "past", "cancelled"]).optional(),
|
status: z.enum(["upcoming", "past", "cancelled"]),
|
||||||
}),
|
}),
|
||||||
async resolve({ ctx, input }) {
|
async resolve({ ctx, input }) {
|
||||||
const { prisma, user } = ctx;
|
const { prisma, user } = ctx;
|
||||||
const bookingListingByStatus = input.status || "upcoming";
|
const bookingListingByStatus = input.status;
|
||||||
const bookingListingFilters: Record<typeof bookingListingByStatus, Prisma.BookingWhereInput[]> = {
|
const bookingListingFilters: Record<typeof bookingListingByStatus, Prisma.BookingWhereInput[]> = {
|
||||||
upcoming: [{ endTime: { gte: new Date() } }],
|
upcoming: [{ endTime: { gte: new Date() } }],
|
||||||
past: [{ endTime: { lte: new Date() } }],
|
past: [{ endTime: { lte: new Date() } }],
|
||||||
|
|
Loading…
Reference in a new issue