From 5388ea0610900a5d226418476d58da06444624c5 Mon Sep 17 00:00:00 2001 From: Syed Ali Shahbaz Date: Tue, 3 Aug 2021 05:52:17 +0530 Subject: [PATCH 1/2] Added date and time to booking entries --- pages/bookings/index.tsx | 30 +++++++++++++++++++++--------- 1 file changed, 21 insertions(+), 9 deletions(-) diff --git a/pages/bookings/index.tsx b/pages/bookings/index.tsx index dbcaadf875..0880f37a04 100644 --- a/pages/bookings/index.tsx +++ b/pages/bookings/index.tsx @@ -3,6 +3,8 @@ import prisma from "../../lib/prisma"; import { getSession, useSession } from "next-auth/client"; import Shell from "../../components/Shell"; import { useRouter } from "next/router"; +import dayjs from "dayjs"; + export default function Bookings({ bookings }) { const [, loading] = useSession(); @@ -49,11 +51,12 @@ export default function Bookings({ bookings }) { className="px-6 py-3 text-left text-xs font-medium text-gray-500 uppercase tracking-wider"> Event - {/* Date - */} + + {console.log(bookings)} Actions @@ -86,11 +89,14 @@ export default function Bookings({ bookings }) {
{booking.title}
{booking.description}
- {/* -
- {dayjs(booking.startTime).format("D MMMM YYYY HH:mm")} -
- */} + +
+ {dayjs(booking.startTime).format("D MMMM YYYY")} +
+
+ {dayjs(booking.startTime).format("HH:mm")} - {dayjs(booking.endTime).format("HH:mm")} +
+ {!booking.confirmed && !booking.rejected && ( <> @@ -153,7 +159,7 @@ export async function getServerSideProps(context) { }, }); - const bookings = await prisma.booking.findMany({ + let b = await prisma.booking.findMany({ where: { userId: user.id, }, @@ -165,11 +171,17 @@ export async function getServerSideProps(context) { confirmed: true, rejected: true, id: true, + startTime: true, + endTime: true, }, orderBy: { - startTime: "desc", + startTime: "asc", }, }); + const bookings = b.map(booking=>{ + return ({...booking, startTime:booking.startTime.toISOString(), endTime:booking.endTime.toISOString(),}) + }); + return { props: { bookings } }; } From 4becb21d53a1b3561f11cb85d0db98e068956d25 Mon Sep 17 00:00:00 2001 From: Syed Ali Shahbaz Date: Tue, 3 Aug 2021 05:59:38 +0530 Subject: [PATCH 2/2] Cleaned up the code --- pages/bookings/index.tsx | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/pages/bookings/index.tsx b/pages/bookings/index.tsx index 0880f37a04..23b1082420 100644 --- a/pages/bookings/index.tsx +++ b/pages/bookings/index.tsx @@ -56,7 +56,6 @@ export default function Bookings({ bookings }) { className="px-6 py-3 text-left text-xs font-medium text-gray-500 uppercase tracking-wider"> Date - {console.log(bookings)} Actions @@ -159,7 +158,7 @@ export async function getServerSideProps(context) { }, }); - let b = await prisma.booking.findMany({ + const b = await prisma.booking.findMany({ where: { userId: user.id, },