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:
Efraín Rochínandzomars authored and GitHub committed 2023-02-17 12:53:31 -07:00
1 parent 602c813928
commit fd76bc9cab
21 files changed
+533 -464

No files matched your search

+1 -1
View File
@@ -1,7 +1,7 @@
import Script from "next/script";
import { getEventTypeAppData } from "@calcom/app-store/_utils/getEventTypeAppData";
import { appStoreMetadata } from "@calcom/app-store/appStoreMetaData";
import { getEventTypeAppData } from "@calcom/app-store/utils";
import type { appDataSchemas } from "./apps.schemas.generated";
@@ -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;
};
+2 -46
View File
@@ -1,16 +1,15 @@
import { Prisma } from "@prisma/client";
import type { TFunction } from "next-i18next";
import type { z } from "zod";
// If you import this file on any app it should produce circular dependency
// import appStore from "./index";
import { appStoreMetadata } from "@calcom/app-store/appStoreMetaData";
import type { EventLocationType } from "@calcom/app-store/locations";
import { defaultLocations } from "@calcom/app-store/locations";
import type { EventTypeModel } from "@calcom/prisma/zod";
import type { EventTypeMetaDataSchema } from "@calcom/prisma/zod-utils";
import type { App, AppMeta } from "@calcom/types/App";
export * from "./_utils/getEventTypeAppData";
type LocationOption = {
label: string;
value: EventLocationType["type"];
@@ -18,9 +17,6 @@ type LocationOption = {
disabled?: boolean;
};
export type EventTypeApps = NonNullable<NonNullable<z.infer<typeof EventTypeMetaDataSchema>>["apps"]>;
export type EventTypeAppsList = keyof EventTypeApps;
const ALL_APPS_MAP = Object.keys(appStoreMetadata).reduce((store, key) => {
const metadata = appStoreMetadata[key as keyof typeof appStoreMetadata] as AppMeta;
if (metadata.logo && !metadata.logo.includes("/")) {
@@ -193,44 +189,4 @@ export function getAppFromSlug(slug: string | undefined): AppMeta | undefined {
return ALL_APPS.find((app) => app.slug === slug);
}
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;
};
export default getApps;
+1 -7
View File
@@ -8,14 +8,8 @@ import { getEventLocationTypeFromApp } from "@calcom/app-store/locations";
import { MeetLocationType } from "@calcom/app-store/locations";
import getApps from "@calcom/app-store/utils";
import prisma from "@calcom/prisma";
import { Attendee } from "@calcom/prisma/client";
import { createdEventSchema } from "@calcom/prisma/zod-utils";
import type {
AdditionalInformation,
CalendarEvent,
NewCalendarEventType,
Person,
} from "@calcom/types/Calendar";
import type { AdditionalInformation, CalendarEvent, NewCalendarEventType } from "@calcom/types/Calendar";
import { CredentialPayload, CredentialWithAppName } from "@calcom/types/Credential";
import type { Event } from "@calcom/types/Event";
import type {
+1 -1
View File
@@ -1,4 +1,4 @@
import { BookingStatus, Credential, SelectedCalendar } from "@prisma/client";
import { BookingStatus, Credential } from "@prisma/client";
import { getBusyCalendarTimes } from "@calcom/core/CalendarManager";
import dayjs from "@calcom/dayjs";
@@ -1,5 +1,4 @@
import type { TFunction } from "next-i18next";
import { ReactNode } from "react";
import { APP_NAME, WEBAPP_URL, IS_PRODUCTION } from "@calcom/lib/constants";
@@ -3,7 +3,7 @@ import { useState } from "react";
import { useLocale } from "@calcom/lib/hooks/useLocale";
import { RouterOutputs, trpc } from "@calcom/trpc/react";
import { Card, showToast } from "@calcom/ui";
import { FiUserPlus, FiUsers, FiUnlock, FiEdit } from "@calcom/ui/components/icon";
import { FiUserPlus, FiUsers, FiEdit } from "@calcom/ui/components/icon";
import TeamListItem from "./TeamListItem";
@@ -10,7 +10,6 @@ import dayjs from "@calcom/dayjs";
import prisma from "@calcom/prisma";
import { Prisma } from "@calcom/prisma/client";
import { bookingMetadataSchema } from "@calcom/prisma/zod-utils";
import { Person } from "@calcom/types/Calendar";
import { getSenderId } from "../alphanumericSenderIdSupport";
import * as twilio from "./smsProviders/twilioProvider";
@@ -32,7 +32,7 @@ import {
TextAreaField,
TextField,
} from "@calcom/ui";
import { FiPlus, FiChevronDown } from "@calcom/ui/components/icon";
import { FiPlus } from "@calcom/ui/components/icon";
import { DuplicateDialog } from "./DuplicateDialog";
@@ -32,7 +32,6 @@ import {
FiChevronRight,
FiPlus,
FiMenu,
FiExternalLink,
} from "@calcom/ui/components/icon";
const tabs: VerticalTabItemProps[] = [
+2 -2
View File
@@ -1,10 +1,10 @@
import crypto from "crypto";
import md5Parser from "md5";
export const defaultAvatarSrc = function ({ email, md5 }: { md5?: string; email?: string }) {
if (!email && !md5) return "";
if (email && !md5) {
md5 = crypto.createHash("md5").update(email).digest("hex");
md5 = md5Parser(email);
}
return `https://www.gravatar.com/avatar/${md5}?s=160&d=mp&r=PG`;
+1 -1
View File
@@ -1,9 +1,9 @@
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 } from "@calcom/app-store/stripepayment/zod";
import type { EventTypeAppsList } from "@calcom/app-store/utils";
import { getEventTypeAppData } from "@calcom/app-store/utils";
export default function getPaymentAppData(
eventType: Parameters<typeof getEventTypeAppData>[0],
@@ -40,7 +40,7 @@ import { WorkflowStep } from "@calcom/prisma/client";
import { TRPCError } from "@trpc/server";
import { router, authedProcedure, authedRateLimitedProcedure } from "../../trpc";
import { router, authedProcedure } from "../../trpc";
import { viewerTeamsRouter } from "./teams";
function getSender(