import { zodResolver } from "@hookform/resolvers/zod"; import { useRouter } from "next/router"; import { useState } from "react"; import { Controller, useForm } from "react-hook-form"; import { Toaster } from "react-hot-toast"; import z from "zod"; import { useLocale } from "@calcom/lib/hooks/useLocale"; import { Alert, Button, EmailField, Form, PasswordField, SelectField, Switch, TextField } from "@calcom/ui"; import { ExchangeAuthentication, ExchangeVersion } from "../../enums"; interface IFormData { url: string; username: string; password: string; authenticationMethod: ExchangeAuthentication; exchangeVersion: ExchangeVersion; useCompression: boolean; } const schema = z .object({ url: z.string().url(), username: z.string().email(), password: z.string(), authenticationMethod: z.number().default(ExchangeAuthentication.STANDARD), exchangeVersion: z.number().default(ExchangeVersion.Exchange2016), useCompression: z.boolean().default(false), }) .strict(); export default function ExchangeSetup() { const { t } = useLocale(); const router = useRouter(); const [errorMessage, setErrorMessage] = useState(""); const form = useForm({ defaultValues: { authenticationMethod: ExchangeAuthentication.STANDARD, exchangeVersion: ExchangeVersion.Exchange2016, }, resolver: zodResolver(schema), }); const authenticationMethods = [ { value: ExchangeAuthentication.STANDARD, label: t("exchange_authentication_standard") }, { value: ExchangeAuthentication.NTLM, label: t("exchange_authentication_ntlm") }, ]; const exchangeVersions = [ { value: ExchangeVersion.Exchange2007_SP1, label: t("exchange_version_2007_SP1") }, { value: ExchangeVersion.Exchange2010, label: t("exchange_version_2010") }, { value: ExchangeVersion.Exchange2010_SP1, label: t("exchange_version_2010_SP1") }, { value: ExchangeVersion.Exchange2010_SP2, label: t("exchange_version_2010_SP2") }, { value: ExchangeVersion.Exchange2013, label: t("exchange_version_2013") }, { value: ExchangeVersion.Exchange2013_SP1, label: t("exchange_version_2013_SP1") }, { value: ExchangeVersion.Exchange2015, label: t("exchange_version_2015") }, { value: ExchangeVersion.Exchange2016, label: t("exchange_version_2016") }, ]; return ( <>
{/* eslint-disable @next/next/no-img-element */} Microsoft Exchange

{t("exchange_add")}

{t("credentials_stored_encrypted")}
{ setErrorMessage(""); const res = await fetch("/api/integrations/exchangecalendar/add", { method: "POST", body: JSON.stringify(values), headers: { "Content-Type": "application/json", }, }); const json = await res.json(); if (!res.ok) { setErrorMessage(json?.message || t("something_went_wrong")); } else { router.push(json.url); } }}>
( { onChange(authentication?.value); form.setValue("authenticationMethod", authentication!.value); }} /> )} /> ( { onChange(version?.value); form.setValue("exchangeVersion", version!.value); }} /> )} /> { form.setValue("useCompression", alt); }} />
{errorMessage && }
); }