2021-09-22 19:52:38 +00:00
|
|
|
import { GetServerSidePropsContext } from "next";
|
2022-07-28 19:58:26 +00:00
|
|
|
import { z } from "zod";
|
2021-09-22 19:52:38 +00:00
|
|
|
|
2022-07-28 19:58:26 +00:00
|
|
|
import { PaymentData } from "@calcom/app-store/stripepayment/lib/server";
|
|
|
|
import prisma from "@calcom/prisma";
|
2022-10-14 16:24:43 +00:00
|
|
|
import { EventTypeMetaDataSchema } from "@calcom/prisma/zod-utils";
|
2022-07-28 19:58:26 +00:00
|
|
|
import type { inferSSRProps } from "@calcom/types/inferSSRProps";
|
2021-09-22 18:36:13 +00:00
|
|
|
|
2022-10-10 08:11:47 +00:00
|
|
|
import { ssrInit } from "@server/lib/ssr";
|
|
|
|
|
2021-09-22 18:36:13 +00:00
|
|
|
export type PaymentPageProps = inferSSRProps<typeof getServerSideProps>;
|
|
|
|
|
2022-07-28 19:58:26 +00:00
|
|
|
const querySchema = z.object({
|
|
|
|
uid: z.string(),
|
|
|
|
});
|
|
|
|
|
2021-09-22 18:36:13 +00:00
|
|
|
export const getServerSideProps = async (context: GetServerSidePropsContext) => {
|
2022-10-10 08:11:47 +00:00
|
|
|
const ssr = await ssrInit(context);
|
|
|
|
|
2022-07-28 19:58:26 +00:00
|
|
|
const { uid } = querySchema.parse(context.query);
|
2021-09-22 18:36:13 +00:00
|
|
|
const rawPayment = await prisma.payment.findFirst({
|
|
|
|
where: {
|
2022-07-28 19:58:26 +00:00
|
|
|
uid,
|
2021-09-22 18:36:13 +00:00
|
|
|
},
|
|
|
|
select: {
|
|
|
|
data: true,
|
|
|
|
success: true,
|
|
|
|
uid: true,
|
|
|
|
refunded: true,
|
|
|
|
bookingId: true,
|
|
|
|
booking: {
|
|
|
|
select: {
|
2022-05-11 20:36:38 +00:00
|
|
|
id: true,
|
2022-11-15 19:00:02 +00:00
|
|
|
uid: true,
|
2021-09-22 18:36:13 +00:00
|
|
|
description: true,
|
|
|
|
title: true,
|
|
|
|
startTime: true,
|
|
|
|
attendees: {
|
|
|
|
select: {
|
|
|
|
email: true,
|
|
|
|
name: true,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
eventTypeId: true,
|
|
|
|
location: true,
|
|
|
|
eventType: {
|
|
|
|
select: {
|
|
|
|
id: true,
|
|
|
|
title: true,
|
|
|
|
description: true,
|
|
|
|
length: true,
|
|
|
|
eventName: true,
|
|
|
|
requiresConfirmation: true,
|
|
|
|
userId: true,
|
2022-10-14 16:24:43 +00:00
|
|
|
metadata: true,
|
2021-09-22 18:36:13 +00:00
|
|
|
users: {
|
|
|
|
select: {
|
|
|
|
name: true,
|
|
|
|
username: true,
|
|
|
|
hideBranding: true,
|
|
|
|
theme: true,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
team: {
|
|
|
|
select: {
|
|
|
|
name: true,
|
|
|
|
hideBranding: true,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
price: true,
|
|
|
|
currency: true,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
});
|
|
|
|
|
2022-05-31 13:40:12 +00:00
|
|
|
if (!rawPayment) return { notFound: true };
|
2021-09-22 18:36:13 +00:00
|
|
|
|
|
|
|
const { data, booking: _booking, ...restPayment } = rawPayment;
|
|
|
|
const payment = {
|
|
|
|
...restPayment,
|
|
|
|
data: data as unknown as PaymentData,
|
|
|
|
};
|
|
|
|
|
2022-05-31 13:40:12 +00:00
|
|
|
if (!_booking) return { notFound: true };
|
2021-09-22 18:36:13 +00:00
|
|
|
|
|
|
|
const { startTime, eventType, ...restBooking } = _booking;
|
|
|
|
const booking = {
|
|
|
|
...restBooking,
|
|
|
|
startTime: startTime.toString(),
|
|
|
|
};
|
|
|
|
|
2022-05-31 13:40:12 +00:00
|
|
|
if (!eventType) return { notFound: true };
|
2021-09-22 18:36:13 +00:00
|
|
|
|
|
|
|
const [user] = eventType.users;
|
|
|
|
if (!user) return { notFound: true };
|
|
|
|
|
|
|
|
const profile = {
|
|
|
|
name: eventType.team?.name || user?.name || null,
|
|
|
|
theme: (!eventType.team?.name && user?.theme) || null,
|
|
|
|
hideBranding: eventType.team?.hideBranding || user?.hideBranding || null,
|
|
|
|
};
|
|
|
|
|
|
|
|
return {
|
|
|
|
props: {
|
|
|
|
user,
|
2022-10-14 16:24:43 +00:00
|
|
|
eventType: {
|
|
|
|
...eventType,
|
|
|
|
metadata: EventTypeMetaDataSchema.parse(eventType.metadata),
|
|
|
|
},
|
2021-09-22 18:36:13 +00:00
|
|
|
booking,
|
2022-10-10 08:11:47 +00:00
|
|
|
trpcState: ssr.dehydrate(),
|
2021-09-22 18:36:13 +00:00
|
|
|
payment,
|
|
|
|
profile,
|
|
|
|
},
|
|
|
|
};
|
|
|
|
};
|