import React, { useState } from "react"; import { useForm } from "react-hook-form"; import { Dialog, DialogClose, DialogContent, DialogFooter, DialogHeader, DialogProps, } from "@components/Dialog"; import { Form, TextField } from "@components/form/fields"; import { Alert } from "@components/ui/Alert"; import Button from "@components/ui/Button"; export const ADD_APPLE_INTEGRATION_FORM_TITLE = "addAppleIntegration"; export function AddAppleIntegrationModal(props: DialogProps) { const form = useForm({ defaultValues: { username: "", password: "", }, }); const [errorMessage, setErrorMessage] = useState(""); return ( Generate an app specific password to use with Cal.com at{" "} https://appleid.apple.com/account/manage . Your credentials will be stored and encrypted. } />
{ setErrorMessage(""); const res = await fetch("/api/integrations/apple/add", { method: "POST", body: JSON.stringify(values), headers: { "Content-Type": "application/json", }, }); const json = await res.json(); if (!res.ok) { setErrorMessage(json?.message || "Something went wrong"); } else { props.onOpenChange?.(false); } }}>
{errorMessage && } { props.onOpenChange?.(false); }} asChild>
); }