import type { InferGetStaticPropsType } from "next"; import { Trans } from "next-i18next"; import Link from "next/link"; import { useState } from "react"; import { Toaster } from "react-hot-toast"; import { useLocale } from "@calcom/lib/hooks/useLocale"; import { trpc } from "@calcom/trpc/react"; import { Button, Tooltip, showToast } from "@calcom/ui"; import { Clipboard } from "@calcom/ui/components/icon"; import type { getStaticProps } from "./_getStaticProps"; const MAKE = "make"; export default function MakeSetup({ inviteLink }: InferGetStaticPropsType) { const [newApiKeys, setNewApiKeys] = useState>({}); const { t } = useLocale(); const utils = trpc.useContext(); const integrations = trpc.viewer.integrations.useQuery({ variant: "automation" }); const oldApiKey = trpc.viewer.apiKeys.findKeyOfType.useQuery({ appId: MAKE }); const teamsList = trpc.viewer.teams.listOwnedTeams.useQuery(undefined, { refetchOnWindowFocus: false, }); const teams = teamsList.data?.map((team) => ({ id: team.id, name: team.name })); const deleteApiKey = trpc.viewer.apiKeys.delete.useMutation({ onSuccess: () => { utils.viewer.apiKeys.findKeyOfType.invalidate(); }, }); const makeCredentials: { userCredentialIds: number[] } | undefined = integrations.data?.items.find( (item: { type: string }) => item.type === "make_automation" ); const [credentialId] = makeCredentials?.userCredentialIds || [false]; const showContent = integrations.data && integrations.isSuccess && credentialId; async function createApiKey(teamId?: number) { const event = { note: "Make", expiresAt: null, appId: MAKE, teamId }; const apiKey = await utils.client.viewer.apiKeys.create.mutate(event); if (oldApiKey.data) { const oldKey = teamId ? oldApiKey.data.find((key) => key.teamId === teamId) : oldApiKey.data.find((key) => !key.teamId); if (oldKey) { deleteApiKey.mutate({ id: oldKey.id, }); } } return apiKey; } async function generateApiKey(teamId?: number) { const apiKey = await createApiKey(teamId); setNewApiKeys({ ...newApiKeys, [teamId || ""]: apiKey }); } if (integrations.isLoading) { return
; } return (
{showContent ? (
Make Logo
{t("setting_up_make")}
<>
{t("generate_api_key")}:
{!teams ? ( ) : ( <>
Your event types:
{!newApiKeys[""] ? ( ) : ( )} {teams.map((team) => { return (
{team.name}:
{!newApiKeys[team.id] ? ( ) : ( )}
); })} )}
  1. Go to Make Invite Link and install the Cal.com app.
  2. Log into your Make account and create a new Scenario.
  3. Select Cal.com as your Trigger app. Also choose a Trigger event.
  4. Choose your account and then enter your Unique API Key.
  5. Test your Trigger.
  6. You're set!
) : (
{t("install_make_app")}
)}
); } const CopyApiKey = ({ apiKey }: { apiKey: string }) => { const { t } = useLocale(); return (
{apiKey}
{t("copy_somewhere_safe")}
); };