Reduce booking page bundle size (#7131)
* AvailabilityPage Component loaded dynamically * update next/bundle-analyzer dependency * Load dynamically SlotPicker and TimezoneDropDown and make some imports refactoring * Gates functionality Returned * Replace crypto with md5 dependency to generate gravatar url * Refactor: AvailableTimes and SlotPicker * Update next.config.js * Update SlotPicker.tsx * Update getEventTypeAppData.ts --------- Co-authored-by: zomars <[email protected]>
This commit is contained in:
1 parent
602c813928
commit
fd76bc9cab
21 files changed
+533
-464
No files matched your search
@@ -0,0 +1,47 @@
|
||||
import type { z } from "zod";
|
||||
|
||||
import type { EventTypeModel } from "@calcom/prisma/zod";
|
||||
import type { EventTypeMetaDataSchema } from "@calcom/prisma/zod-utils";
|
||||
|
||||
export type EventTypeApps = NonNullable<NonNullable<z.infer<typeof EventTypeMetaDataSchema>>["apps"]>;
|
||||
export type EventTypeAppsList = keyof EventTypeApps;
|
||||
|
||||
export const getEventTypeAppData = <T extends EventTypeAppsList>(
|
||||
eventType: Pick<z.infer<typeof EventTypeModel>, "price" | "currency" | "metadata">,
|
||||
appId: T,
|
||||
forcedGet?: boolean
|
||||
): EventTypeApps[T] => {
|
||||
const metadata = eventType.metadata;
|
||||
const appMetadata = metadata?.apps && metadata.apps[appId];
|
||||
if (appMetadata) {
|
||||
const allowDataGet = forcedGet ? true : appMetadata.enabled;
|
||||
return allowDataGet ? appMetadata : null;
|
||||
}
|
||||
|
||||
// Backward compatibility for existing event types.
|
||||
// TODO: After the new AppStore EventType App flow is stable, write a migration to migrate metadata to new format which will let us remove this compatibility code
|
||||
// Migration isn't being done right now, to allow a revert if needed
|
||||
const legacyAppsData = {
|
||||
stripe: {
|
||||
enabled: eventType.price > 0,
|
||||
// Price default is 0 in DB. So, it would always be non nullish.
|
||||
price: eventType.price,
|
||||
// Currency default is "usd" in DB.So, it would also be available always
|
||||
currency: eventType.currency,
|
||||
},
|
||||
rainbow: {
|
||||
enabled: !!(eventType.metadata?.smartContractAddress && eventType.metadata?.blockchainId),
|
||||
smartContractAddress: eventType.metadata?.smartContractAddress || "",
|
||||
blockchainId: eventType.metadata?.blockchainId || 0,
|
||||
},
|
||||
giphy: {
|
||||
enabled: !!eventType.metadata?.giphyThankYouPage,
|
||||
thankYouPage: eventType.metadata?.giphyThankYouPage || "",
|
||||
},
|
||||
} as const;
|
||||
|
||||
// TODO: This assertion helps typescript hint that only one of the app's data can be returned
|
||||
const legacyAppData = legacyAppsData[appId as Extract<T, keyof typeof legacyAppsData>];
|
||||
const allowDataGet = forcedGet ? true : legacyAppData?.enabled;
|
||||
return allowDataGet ? legacyAppData : null;
|
||||
};
|
||||
Reference in new issue
Block a user