chore: [app-router-migration 17]: migrate payments page (#13039)

* chore: migrate payments page

* migrate page to WithLayout HOC, replace new ssrInit

* fix type error

* fix

* revert version changes

* fix

---------

Co-authored-by: Benny Joo <[email protected]>
This commit is contained in:
DmytroHryshynandBenny Joo authored and GitHub committed 2024-01-12 18:36:48 -03:00
1 parent abd90f6af8
commit a28b9cacd2
34 files changed
+748 -105

No files matched your search

@@ -597,7 +597,8 @@ async function handler(req: CustomRequest) {
// Posible to refactor TODO:
const paymentApp = (await appStore[
paymentAppCredential?.app?.dirName as keyof typeof appStore
]()) as PaymentApp;
]?.()) as PaymentApp;
if (!paymentApp?.lib?.PaymentService) {
console.warn(`payment App service of type ${paymentApp} is not implemented`);
return null;
@@ -1,3 +1,5 @@
"use client";
import classNames from "classnames";
import dynamic from "next/dynamic";
import Head from "next/head";
@@ -0,0 +1,21 @@
import type { Payment } from "@calcom/prisma/client";
function hasStringProp<T extends string>(x: unknown, key: T): x is { [key in T]: string } {
return !!x && typeof x === "object" && key in x;
}
export function getClientSecretFromPayment(
payment: Omit<Partial<Payment>, "data"> & { data: Record<string, unknown> }
) {
if (
payment.paymentOption === "HOLD" &&
hasStringProp(payment.data, "setupIntent") &&
hasStringProp(payment.data.setupIntent, "client_secret")
) {
return payment.data.setupIntent.client_secret;
}
if (hasStringProp(payment.data, "client_secret")) {
return payment.data.client_secret;
}
return "";
}
@@ -1,7 +1,7 @@
import type { Payment } from "@prisma/client";
import type { GetServerSidePropsContext } from "next";
import { z } from "zod";
import { getClientSecretFromPayment } from "@calcom/features/ee/payments/pages/getClientSecretFromPayment";
import prisma from "@calcom/prisma";
import { BookingStatus } from "@calcom/prisma/enums";
import { EventTypeMetaDataSchema } from "@calcom/prisma/zod-utils";
@@ -9,7 +9,7 @@ import type { inferSSRProps } from "@calcom/types/inferSSRProps";
import { ssrInit } from "../../../../../apps/web/server/lib/ssr";
export type PaymentPageProps = inferSSRProps<typeof getServerSideProps>;
export type PaymentPageProps = Omit<inferSSRProps<typeof getServerSideProps>, "trpcState">;
const querySchema = z.object({
uid: z.string(),
@@ -145,23 +145,3 @@ export const getServerSideProps = async (context: GetServerSidePropsContext) =>
},
};
};
function hasStringProp<T extends string>(x: unknown, key: T): x is { [key in T]: string } {
return !!x && typeof x === "object" && key in x;
}
function getClientSecretFromPayment(
payment: Omit<Partial<Payment>, "data"> & { data: Record<string, unknown> }
) {
if (
payment.paymentOption === "HOLD" &&
hasStringProp(payment.data, "setupIntent") &&
hasStringProp(payment.data.setupIntent, "client_secret")
) {
return payment.data.setupIntent.client_secret;
}
if (hasStringProp(payment.data, "client_secret")) {
return payment.data.client_secret;
}
return "";
}