* refactor: UserAvatarGroupWithOrg.tsx remove unecessary profile prop * chore: define event-type types in platform/types * feat: event-type transformes in lib and re-exported through platform-libraries * chore: define user types in platform/types * chore: add users endpoint to platform-constants * refactor: app-store use narrowed down booker event type * chore: version old event-types module * fix: old event-types e2e test * fix: libraries add missing export * fix: reset libraries version to 0 * feat: new event-types module and users endpoints * feat: make booker atom work with v2 event-types * updating event type * refactor: remove guard for get event-types * refactor: move private hook to public * Revert "refactor: remove guard for get event-types" This reverts commit d41204069f1d5bb1305b388ce53399f9175f4249. * Revert "refactor: move private hook to public" This reverts commit 09322e8fba102e57104959f79ed6bfa9a677dc9d. * refactor: get by username and slug in /event-types * remove console log * feat: locations handle displayEventPublicly * test e2e event-types * revert: user output from types * refactor: event-types hooks have private and public folders * refactor: require event-type.slug in input * refactor: demand that all labels of booking fields are unique * refactor: remove unused import * refactor: only have email and name by default in booker * refactor: add booking field slug * fix: display event-type location publicly / hide it in booker * fix: display event-type location publicly / hide it in booker * fix: packages/lib tests * fix: typescript in e2e test * fix: dynamic event types input * refactor: use IsIn instead of IsEnum * refactor: simplify getEventTypes * fix: use ApiAuthGuard instead of AccessTokenGuard * chore: export more stuff from libraries * refactor: SchedulingTypeEnum and Type --------- Co-authored-by: Morgan <33722304+ThyMinimalDev@users.noreply.github.com>
56 lines
2.0 KiB
TypeScript
56 lines
2.0 KiB
TypeScript
import type { z } from "zod";
|
|
|
|
import { getEventTypeAppData } from "@calcom/app-store/_utils/getEventTypeAppData";
|
|
import type { appDataSchemas } from "@calcom/app-store/apps.schemas.generated";
|
|
import type { appDataSchema, paymentOptionEnum } from "@calcom/app-store/stripepayment/zod";
|
|
import type { EventTypeAppsList } from "@calcom/app-store/utils";
|
|
import type { BookerEvent } from "@calcom/features/bookings/types";
|
|
|
|
export default function getPaymentAppData(
|
|
eventType: Pick<BookerEvent, "price" | "currency" | "metadata">,
|
|
forcedGet?: boolean
|
|
) {
|
|
const metadataApps = eventType?.metadata?.apps as unknown as EventTypeAppsList;
|
|
if (!metadataApps) {
|
|
return { enabled: false, price: 0, currency: "usd", appId: null };
|
|
}
|
|
type appId = keyof typeof metadataApps;
|
|
// @TODO: a lot of unknowns types here can be improved later
|
|
const paymentAppIds = (Object.keys(metadataApps) as Array<keyof typeof appDataSchemas>).filter(
|
|
(app) =>
|
|
(metadataApps[app as appId] as unknown as z.infer<typeof appDataSchema>)?.price &&
|
|
(metadataApps[app as appId] as unknown as z.infer<typeof appDataSchema>)?.enabled
|
|
);
|
|
|
|
// Event type should only have one payment app data
|
|
let paymentAppData: {
|
|
enabled: boolean;
|
|
price: number;
|
|
currency: string;
|
|
appId: EventTypeAppsList | null;
|
|
paymentOption: typeof paymentOptionEnum;
|
|
credentialId?: number;
|
|
} | null = null;
|
|
for (const appId of paymentAppIds) {
|
|
const appData = getEventTypeAppData(eventType, appId, forcedGet);
|
|
if (appData && paymentAppData === null) {
|
|
paymentAppData = {
|
|
...appData,
|
|
appId,
|
|
};
|
|
}
|
|
}
|
|
// This is the current expectation of system to have price and currency set always(using DB Level defaults).
|
|
// Newly added apps code should assume that their app data might not be set.
|
|
return (
|
|
paymentAppData || {
|
|
enabled: false,
|
|
price: 0,
|
|
currency: "usd",
|
|
appId: null,
|
|
paymentOption: "ON_BOOKING",
|
|
credentialId: undefined,
|
|
}
|
|
);
|
|
}
|