2023-08-02 09:35:48 +00:00
|
|
|
import { useRouter } from "next/navigation";
|
2022-06-01 17:24:41 +00:00
|
|
|
import { useState } from "react";
|
|
|
|
import { useForm } from "react-hook-form";
|
|
|
|
import { Toaster } from "react-hot-toast";
|
|
|
|
|
2022-12-05 21:24:09 +00:00
|
|
|
import { APP_NAME } from "@calcom/lib/constants";
|
2022-06-01 17:24:41 +00:00
|
|
|
import { useLocale } from "@calcom/lib/hooks/useLocale";
|
2022-11-23 02:55:25 +00:00
|
|
|
import { Alert, Button, Form, TextField } from "@calcom/ui";
|
2022-06-01 17:24:41 +00:00
|
|
|
|
|
|
|
export default function AppleCalendarSetup() {
|
|
|
|
const { t } = useLocale();
|
|
|
|
const router = useRouter();
|
|
|
|
const form = useForm({
|
|
|
|
defaultValues: {
|
|
|
|
username: "",
|
|
|
|
password: "",
|
|
|
|
},
|
|
|
|
});
|
|
|
|
|
|
|
|
const [errorMessage, setErrorMessage] = useState("");
|
|
|
|
|
|
|
|
return (
|
2023-04-05 18:14:46 +00:00
|
|
|
<div className="bg-emphasis flex h-screen">
|
|
|
|
<div className="bg-default m-auto rounded p-5 md:w-[560px] md:p-10">
|
2023-06-22 22:25:37 +00:00
|
|
|
<div className="flex flex-col space-y-5 md:flex-row md:space-x-5 md:space-y-0">
|
2022-06-01 17:24:41 +00:00
|
|
|
<div>
|
|
|
|
{/* eslint-disable @next/next/no-img-element */}
|
|
|
|
<img
|
|
|
|
src="/api/app-store/applecalendar/icon.svg"
|
|
|
|
alt="Apple Calendar"
|
|
|
|
className="h-12 w-12 max-w-2xl"
|
|
|
|
/>
|
|
|
|
</div>
|
|
|
|
<div>
|
2023-04-05 18:14:46 +00:00
|
|
|
<h1 className="text-default">{t("connect_apple_server")}</h1>
|
2022-06-01 17:24:41 +00:00
|
|
|
|
|
|
|
<div className="mt-1 text-sm">
|
2022-12-05 21:24:09 +00:00
|
|
|
{t("apple_server_generate_password", { appName: APP_NAME })}{" "}
|
2022-06-01 17:24:41 +00:00
|
|
|
<a
|
|
|
|
className="text-indigo-400"
|
|
|
|
href="https://appleid.apple.com/account/manage"
|
|
|
|
target="_blank"
|
|
|
|
rel="noopener noreferrer">
|
|
|
|
https://appleid.apple.com/account/manage
|
|
|
|
</a>
|
2022-06-11 17:33:04 +00:00
|
|
|
. {t("credentials_stored_encrypted")}
|
2022-06-01 17:24:41 +00:00
|
|
|
</div>
|
|
|
|
<div className="my-2 mt-3">
|
|
|
|
<Form
|
|
|
|
form={form}
|
|
|
|
handleSubmit={async (values) => {
|
|
|
|
setErrorMessage("");
|
|
|
|
const res = await fetch("/api/integrations/applecalendar/add", {
|
|
|
|
method: "POST",
|
|
|
|
body: JSON.stringify(values),
|
|
|
|
headers: {
|
|
|
|
"Content-Type": "application/json",
|
|
|
|
},
|
|
|
|
});
|
|
|
|
const json = await res.json();
|
|
|
|
if (!res.ok) {
|
2022-06-11 17:33:04 +00:00
|
|
|
setErrorMessage(json?.message || t("something_went_wrong"));
|
2022-06-01 17:24:41 +00:00
|
|
|
} else {
|
|
|
|
router.push(json.url);
|
|
|
|
}
|
|
|
|
}}>
|
2023-08-16 19:49:10 +00:00
|
|
|
<fieldset
|
|
|
|
className="space-y-2"
|
|
|
|
disabled={form.formState.isSubmitting}
|
|
|
|
data-testid="apple-calendar-form">
|
2022-06-01 17:24:41 +00:00
|
|
|
<TextField
|
|
|
|
required
|
|
|
|
type="text"
|
|
|
|
{...form.register("username")}
|
2022-08-26 22:49:38 +00:00
|
|
|
label="Apple ID"
|
|
|
|
placeholder="appleid@domain.com"
|
2023-08-16 19:49:10 +00:00
|
|
|
data-testid="apple-calendar-email"
|
2022-06-01 17:24:41 +00:00
|
|
|
/>
|
|
|
|
<TextField
|
|
|
|
required
|
|
|
|
type="password"
|
|
|
|
{...form.register("password")}
|
2022-06-11 17:33:04 +00:00
|
|
|
label={t("password")}
|
2022-06-01 17:24:41 +00:00
|
|
|
placeholder="•••••••••••••"
|
|
|
|
autoComplete="password"
|
2023-08-16 19:49:10 +00:00
|
|
|
data-testid="apple-calendar-password"
|
2022-06-01 17:24:41 +00:00
|
|
|
/>
|
|
|
|
</fieldset>
|
|
|
|
|
|
|
|
{errorMessage && <Alert severity="error" title={errorMessage} className="my-4" />}
|
2023-01-04 07:38:45 +00:00
|
|
|
<div className="mt-5 justify-end space-x-2 rtl:space-x-reverse sm:mt-4 sm:flex">
|
2022-06-11 17:33:04 +00:00
|
|
|
<Button type="button" color="secondary" onClick={() => router.back()}>
|
|
|
|
{t("cancel")}
|
|
|
|
</Button>
|
2023-08-16 19:49:10 +00:00
|
|
|
<Button
|
|
|
|
type="submit"
|
|
|
|
loading={form.formState.isSubmitting}
|
|
|
|
data-testid="apple-calendar-login-button">
|
2022-06-11 17:33:04 +00:00
|
|
|
{t("save")}
|
2022-06-01 17:24:41 +00:00
|
|
|
</Button>
|
|
|
|
</div>
|
|
|
|
</Form>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
<Toaster position="bottom-right" />
|
|
|
|
</div>
|
|
|
|
);
|
|
|
|
}
|