Introduce EventTypeAppCard in app-store and make it super easy to add it through CLI - Also adds Fathom app (#4727)

* Add OmniInstall button

* Make AppCards configurable by the app itself

* Make OmniInstallAppButton not redirect

* Fixes

* Add extendsFeature support to CLI

* Move to automatic file generation approach as dynamic import checking doesnt work correctly

* Use zod everywhere consistenly for metadata and fix all TS issues

* Fix viewer.eventTypes endpoint. Make prisma base select and _ prefixed models consistent in expecting scalars only

* Remove unnecessary zod parsing of event-types as it is making the scope of the PR huge

* Fix UI TS errors

* wip

* Add zod types support in EventTypeAppCard.tsx

* Fixes during PR review and other failing tests

* Remove unused app

* Fix stripe installation flow

* More fixes

* Fix apps and active apps count

* self review

* Add loading attribute to OmniInsall button

* Handle empty state

* Improve types

* Fix stripe app installation bug

* added fathom app (#4804)

* added fathom app wrapper, needs script injection to public booking page

* new logo

* Add Fathom script support on booking pages and add it as an eventTypeapp

* Add automation and analytics apps

* Add missing pieces for analytics category

* Rename BookingPageScripts to BookingPageTagManager

Co-authored-by: Hariom Balhara <[email protected]>

* Fix lint error

* Fix runtime error with legayAppData being undefined

* Remove duplicate automation key

Co-authored-by: Peer Richelsen <[email protected]>
This commit is contained in:
Hariom BalharaandPeer Richelsen authored and GitHub committed 2022-10-14 10:24:43 -06:00
1 parent 215e3c93d6
commit 271d4319b9
79 files changed
+1324 -1466

No files matched your search

@@ -8,6 +8,7 @@ import { v5 as uuidv5 } from "uuid";
import { getLocationValueForDB, LocationObject } from "@calcom/app-store/locations";
import { handleEthSignature } from "@calcom/app-store/rainbow/utils/ethereum";
import { handlePayment } from "@calcom/app-store/stripepayment/lib/server";
import { getEventTypeAppData } from "@calcom/app-store/utils";
import { cancelScheduledJobs, scheduleTrigger } from "@calcom/app-store/zapier/lib/nodeScheduler";
import EventManager from "@calcom/core/EventManager";
import { getEventName } from "@calcom/core/event";
@@ -25,6 +26,7 @@ import getWebhooks from "@calcom/features/webhooks/lib/getWebhooks";
import { isPrismaObjOrUndefined, parseRecurringEvent } from "@calcom/lib";
import { getDefaultEvent, getGroupName, getUsernameList } from "@calcom/lib/defaultEvents";
import { getErrorFromUnknown } from "@calcom/lib/errors";
import getStripeAppData from "@calcom/lib/getStripeAppData";
import { HttpError } from "@calcom/lib/http-error";
import isOutOfBounds, { BookingDateInPastError } from "@calcom/lib/isOutOfBounds";
import logger from "@calcom/lib/logger";
@@ -32,6 +34,7 @@ import { checkBookingLimits, getLuckyUser } from "@calcom/lib/server";
import { getTranslation } from "@calcom/lib/server/i18n";
import { updateWebUser as syncServicesUpdateWebUser } from "@calcom/lib/sync/SyncServiceManager";
import prisma, { userSelect } from "@calcom/prisma";
import { EventTypeMetaDataSchema } from "@calcom/prisma/zod-utils";
import { extendedBookingCreateBody, requiredCustomInputSchema } from "@calcom/prisma/zod-utils";
import type { BufferedBusyTime } from "@calcom/types/BufferedBusyTime";
import type { AdditionalInformation, CalendarEvent } from "@calcom/types/Calendar";
@@ -173,6 +176,7 @@ const getEventTypesFromDB = async (eventTypeId: number) => {
return {
...eventType,
metadata: EventTypeMetaDataSchema.parse(eventType.metadata),
recurringEvent: parseRecurringEvent(eventType.recurringEvent),
locations: (eventType.locations ?? []) as LocationObject[],
};
@@ -252,6 +256,8 @@ async function handler(req: NextApiRequest & { userId?: number }) {
if (!eventType) throw new HttpError({ statusCode: 404, message: "eventType.notFound" });
const stripeAppData = getStripeAppData(eventType);
// Check if required custom inputs exist
if (eventType.customInputs) {
eventType.customInputs.forEach((customInput) => {
@@ -354,12 +360,12 @@ async function handler(req: NextApiRequest & { userId?: number }) {
users = availableUsers;
}
}
console.log("available users", users);
const rainbowAppData = getEventTypeAppData(eventType, "rainbow") || {};
// @TODO: use the returned address somewhere in booking creation?
// const address: string | undefined = await ...
await handleEthSignature(eventType.metadata, reqBody.ethSignature);
await handleEthSignature(rainbowAppData, reqBody.ethSignature);
const [organizerUser] = users;
const tOrganizer = await getTranslation(organizerUser.locale ?? "en", "common");
@@ -587,7 +593,7 @@ async function handler(req: NextApiRequest & { userId?: number }) {
// Otherwise, an owner rescheduling should be always accepted.
const userReschedulingIsOwner = originalRescheduledBooking?.user?.id === userId;
const isConfirmedByDefault =
(!eventType.requiresConfirmation && !eventType.price) || userReschedulingIsOwner;
(!eventType.requiresConfirmation && !stripeAppData.price) || userReschedulingIsOwner;
const newBookingData: Prisma.BookingCreateInput = {
uid,
title: evt.title,
@@ -661,7 +667,7 @@ async function handler(req: NextApiRequest & { userId?: number }) {
}
}
if (typeof eventType.price === "number" && eventType.price > 0) {
if (typeof stripeAppData.price === "number" && stripeAppData.price > 0) {
/* Validate if there is any stripe_payment credential for this user */
/* note: removes custom error message about stripe */
await prisma.credential.findFirstOrThrow({
@@ -753,7 +759,7 @@ async function handler(req: NextApiRequest & { userId?: number }) {
}
// If it's not a reschedule, doesn't require confirmation and there's no price,
// Create a booking
} else if (!eventType.requiresConfirmation && !eventType.price) {
} else if (!eventType.requiresConfirmation && !stripeAppData.price) {
// Use EventManager to conditionally use all needed integrations.
const createManager = await eventManager.create(evt);
@@ -796,8 +802,8 @@ async function handler(req: NextApiRequest & { userId?: number }) {
}
if (
!Number.isNaN(eventType.price) &&
eventType.price > 0 &&
!Number.isNaN(stripeAppData.price) &&
stripeAppData.price > 0 &&
!originalRescheduledBooking?.paid &&
!!booking
) {
@@ -853,7 +859,7 @@ async function handler(req: NextApiRequest & { userId?: number }) {
eventTitle: eventType.title,
eventDescription: eventType.description,
requiresConfirmation: eventType.requiresConfirmation || null,
price: eventType.price,
price: stripeAppData.price,
currency: eventType.currency,
length: eventType.length,
};
@@ -9,6 +9,7 @@ import getStripe from "@calcom/app-store/stripepayment/lib/client";
import dayjs from "@calcom/dayjs";
import { sdkActionManager, useIsEmbed } from "@calcom/embed-core/embed-iframe";
import { WEBSITE_URL } from "@calcom/lib/constants";
import getStripeAppData from "@calcom/lib/getStripeAppData";
import { useLocale } from "@calcom/lib/hooks/useLocale";
import useTheme from "@calcom/lib/hooks/useTheme";
import { getIs24hClockFromLocalStorage, isBrowserLocale24h } from "@calcom/lib/timeFormat";
@@ -25,6 +26,7 @@ const PaymentPage: FC<PaymentPageProps> = (props) => {
const [timezone, setTimezone] = useState<string | null>(null);
useTheme(props.profile.theme);
const isEmbed = useIsEmbed();
const stripeAppData = getStripeAppData(props.eventType);
useEffect(() => {
let embedIframeWidth = 0;
const _timezone = localStorage.getItem("timeOption.preferredTimeZone") || dayjs.tz.guess();
@@ -113,9 +115,9 @@ const PaymentPage: FC<PaymentPageProps> = (props) => {
<div className="col-span-2 mb-6">
<IntlProvider locale="en">
<FormattedNumber
value={props.eventType.price / 100.0}
value={stripeAppData.price / 100.0}
style="currency"
currency={props.eventType.currency.toUpperCase()}
currency={stripeAppData.currency.toUpperCase()}
/>
</IntlProvider>
</div>
@@ -3,6 +3,7 @@ import { z } from "zod";
import { PaymentData } from "@calcom/app-store/stripepayment/lib/server";
import prisma from "@calcom/prisma";
import { EventTypeMetaDataSchema } from "@calcom/prisma/zod-utils";
import type { inferSSRProps } from "@calcom/types/inferSSRProps";
import { ssrInit } from "@server/lib/ssr";
@@ -50,6 +51,7 @@ export const getServerSideProps = async (context: GetServerSidePropsContext) =>
eventName: true,
requiresConfirmation: true,
userId: true,
metadata: true,
users: {
select: {
name: true,
@@ -104,7 +106,10 @@ export const getServerSideProps = async (context: GetServerSidePropsContext) =>
return {
props: {
user,
eventType,
eventType: {
...eventType,
metadata: EventTypeMetaDataSchema.parse(eventType.metadata),
},
booking,
trpcState: ssr.dehydrate(),
payment,