import { EventTypeSetupProps, FormValues } from "pages/event-types/[type]"; import { useFormContext } from "react-hook-form"; import { GetAppData, SetAppData } from "@calcom/app-store/EventTypeAppContext"; import { EventTypeAppCard } from "@calcom/app-store/_components/EventTypeAppCardInterface"; import { EventTypeAppCardComponentProps } from "@calcom/app-store/types"; import { EventTypeAppsList } from "@calcom/app-store/utils"; import { useLocale } from "@calcom/lib/hooks/useLocale"; import { trpc } from "@calcom/trpc/react"; import { Button, EmptyScreen } from "@calcom/ui"; import { FiGrid } from "@calcom/ui/components/icon"; export type EventType = Pick["eventType"] & EventTypeAppCardComponentProps["eventType"]; export const EventAppsTab = ({ eventType }: { eventType: EventType }) => { const { t } = useLocale(); const { data: eventTypeApps, isLoading } = trpc.viewer.apps.useQuery({ extendsFeature: "EventType", }); const methods = useFormContext(); const installedApps = eventTypeApps?.filter((app) => app.credentials.length); const notInstalledApps = eventTypeApps?.filter((app) => !app.credentials.length); const allAppsData = methods.watch("metadata")?.apps || {}; const setAllAppsData = (_allAppsData: typeof allAppsData) => { methods.setValue("metadata", { ...methods.getValues("metadata"), apps: _allAppsData, }); }; const getAppDataGetter = (appId: EventTypeAppsList): GetAppData => { return function (key) { const appData = allAppsData[appId as keyof typeof allAppsData] || {}; if (key) { return appData[key as keyof typeof appData]; } return appData; }; }; const getAppDataSetter = (appId: EventTypeAppsList): SetAppData => { return function (key, value) { // Always get latest data available in Form because consequent calls to setData would update the Form but not allAppsData(it would update during next render) const allAppsDataFromForm = methods.getValues("metadata")?.apps || {}; const appData = allAppsDataFromForm[appId]; setAllAppsData({ ...allAppsDataFromForm, [appId]: { ...appData, [key]: value, }, }); }; }; return ( <>
{!isLoading && !installedApps?.length ? ( {t("empty_installed_apps_button")}{" "} } /> ) : null} {installedApps?.map((app) => ( ))}
{!isLoading && notInstalledApps?.length ? (

Available Apps

) : null}
{notInstalledApps?.map((app) => ( ))}
); };