import { ClipboardCopyIcon } from "@heroicons/react/solid"; import { Trans } from "next-i18next"; import Link from "next/link"; import { useState } from "react"; import { useLocale } from "@calcom/lib/hooks/useLocale"; import showToast from "@calcom/lib/notification"; import { Button } from "@calcom/ui"; import { Tooltip } from "@calcom/ui/Tooltip"; import Loader from "@calcom/web/components/Loader"; import Icon from "./icon"; interface IZapierSetupProps { trpc: any; } const ZAPIER = "zapier"; export default function ZapierSetup(props: IZapierSetupProps) { const { trpc } = props; const [newApiKey, setNewApiKey] = useState(""); const { t } = useLocale(); const utils = trpc.useContext(); const integrations = trpc.useQuery(["viewer.integrations"]); const oldApiKey = trpc.useQuery(["viewer.apiKeys.findKeyOfType", { appId: ZAPIER }]); const deleteApiKey = trpc.useMutation("viewer.apiKeys.delete"); const zapierCredentials: { credentialIds: number[] } | undefined = integrations.data?.other?.items.find( (item: { type: string }) => item.type === "zapier_other" ); const [credentialId] = zapierCredentials?.credentialIds || [false]; const showContent = integrations.data && integrations.isSuccess && credentialId; async function createApiKey() { const event = { note: "Zapier", expiresAt: null, appId: ZAPIER }; const apiKey = await utils.client.mutation("viewer.apiKeys.create", event); if (oldApiKey.data) { deleteApiKey.mutate({ id: oldApiKey.data.id, }); } setNewApiKey(apiKey); } if (integrations.isLoading) { return (
); } return (
{showContent ? (
{t("setting_up_zapier")}
{!newApiKey ? ( <>
{t("generate_api_key")}:
) : ( <>
{t("your_unique_api_key")}
{newApiKey}
{t("copy_safe_api_key")}
)}
  1. Log into your Zapier account and create a new Zap.
  2. Select Cal.com as your Trigger app. Also choose a Trigger event.
  3. Choose your account and then enter your Unique API Key.
  4. Test your Trigger.
  5. You're set!
) : (
{t("install_zapier_app")}
)}
); }