2021-10-12 19:43:22 +00:00
|
|
|
import { InformationCircleIcon } from "@heroicons/react/outline";
|
2022-01-14 13:49:15 +00:00
|
|
|
import { TrashIcon } from "@heroicons/react/solid";
|
2021-09-22 19:52:38 +00:00
|
|
|
import crypto from "crypto";
|
2021-09-13 09:48:55 +00:00
|
|
|
import { GetServerSidePropsContext } from "next";
|
2022-01-14 13:49:15 +00:00
|
|
|
import { signOut } from "next-auth/react";
|
2022-01-29 00:46:35 +00:00
|
|
|
import { Trans } from "next-i18next";
|
2021-10-28 22:45:58 +00:00
|
|
|
import { useRouter } from "next/router";
|
2021-12-09 23:51:30 +00:00
|
|
|
import { ComponentProps, FormEvent, RefObject, useEffect, useMemo, useRef, useState } from "react";
|
|
|
|
import Select from "react-select";
|
2021-10-28 22:45:58 +00:00
|
|
|
import TimezoneSelect, { ITimezone } from "react-timezone-select";
|
2021-09-22 19:52:38 +00:00
|
|
|
|
2021-10-15 11:32:09 +00:00
|
|
|
import { QueryCell } from "@lib/QueryCell";
|
2021-10-02 20:16:51 +00:00
|
|
|
import { asStringOrNull, asStringOrUndefined } from "@lib/asStringOrNull";
|
2021-09-22 19:52:38 +00:00
|
|
|
import { getSession } from "@lib/auth";
|
2021-10-15 11:32:09 +00:00
|
|
|
import { nameOfDay } from "@lib/core/i18n/weekday";
|
2021-10-13 09:34:55 +00:00
|
|
|
import { useLocale } from "@lib/hooks/useLocale";
|
2021-09-22 19:52:38 +00:00
|
|
|
import { isBrandingHidden } from "@lib/isBrandingHidden";
|
2021-10-12 19:43:22 +00:00
|
|
|
import showToast from "@lib/notification";
|
2021-08-22 13:16:42 +00:00
|
|
|
import prisma from "@lib/prisma";
|
2021-09-28 08:57:30 +00:00
|
|
|
import { trpc } from "@lib/trpc";
|
2021-09-22 19:52:38 +00:00
|
|
|
import { inferSSRProps } from "@lib/types/inferSSRProps";
|
|
|
|
|
2022-01-14 13:49:15 +00:00
|
|
|
import { Dialog, DialogClose, DialogContent, DialogTrigger } from "@components/Dialog";
|
2021-09-22 19:52:38 +00:00
|
|
|
import ImageUploader from "@components/ImageUploader";
|
2021-09-29 21:33:18 +00:00
|
|
|
import SettingsShell from "@components/SettingsShell";
|
2021-09-22 19:52:38 +00:00
|
|
|
import Shell from "@components/Shell";
|
2022-01-14 13:49:15 +00:00
|
|
|
import ConfirmationDialogContent from "@components/dialog/ConfirmationDialogContent";
|
2021-12-09 23:51:30 +00:00
|
|
|
import { TextField } from "@components/form/fields";
|
2021-09-28 08:57:30 +00:00
|
|
|
import { Alert } from "@components/ui/Alert";
|
2021-09-14 08:45:28 +00:00
|
|
|
import Avatar from "@components/ui/Avatar";
|
2021-09-13 09:48:55 +00:00
|
|
|
import Badge from "@components/ui/Badge";
|
|
|
|
import Button from "@components/ui/Button";
|
2022-02-08 16:13:42 +00:00
|
|
|
import ColorPicker from "@components/ui/colorpicker";
|
2021-04-07 15:03:02 +00:00
|
|
|
|
2021-09-13 09:48:55 +00:00
|
|
|
type Props = inferSSRProps<typeof getServerSideProps>;
|
2021-10-15 11:32:09 +00:00
|
|
|
|
2021-10-13 09:34:55 +00:00
|
|
|
function HideBrandingInput(props: { hideBrandingRef: RefObject<HTMLInputElement>; user: Props["user"] }) {
|
|
|
|
const { t } = useLocale();
|
2021-09-13 09:48:55 +00:00
|
|
|
const [modelOpen, setModalOpen] = useState(false);
|
2021-10-28 22:45:58 +00:00
|
|
|
|
2021-09-13 09:48:55 +00:00
|
|
|
return (
|
|
|
|
<>
|
|
|
|
<input
|
|
|
|
id="hide-branding"
|
|
|
|
name="hide-branding"
|
|
|
|
type="checkbox"
|
|
|
|
ref={props.hideBrandingRef}
|
|
|
|
defaultChecked={isBrandingHidden(props.user)}
|
|
|
|
className={
|
2022-02-09 00:05:13 +00:00
|
|
|
"h-4 w-4 rounded-sm border-gray-300 text-neutral-900 focus:ring-neutral-800 disabled:opacity-50"
|
2021-09-13 09:48:55 +00:00
|
|
|
}
|
|
|
|
onClick={(e) => {
|
|
|
|
if (!e.currentTarget.checked || props.user.plan !== "FREE") {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// prevent checking the input
|
|
|
|
e.preventDefault();
|
|
|
|
|
|
|
|
setModalOpen(true);
|
|
|
|
}}
|
|
|
|
/>
|
2021-10-12 19:43:22 +00:00
|
|
|
<Dialog open={modelOpen}>
|
|
|
|
<DialogContent>
|
2022-02-09 00:05:13 +00:00
|
|
|
<div className="mx-auto mb-4 flex h-12 w-12 items-center justify-center rounded-full bg-yellow-100">
|
|
|
|
<InformationCircleIcon className="h-6 w-6 text-yellow-400" aria-hidden="true" />
|
2021-10-12 19:43:22 +00:00
|
|
|
</div>
|
2021-10-15 11:32:09 +00:00
|
|
|
<div className="mb-4 sm:flex sm:items-start">
|
2021-10-12 19:43:22 +00:00
|
|
|
<div className="mt-3 sm:mt-0 sm:text-left">
|
2022-02-09 00:05:13 +00:00
|
|
|
<h3 className="font-cal text-lg font-bold leading-6 text-gray-900" id="modal-title">
|
2021-10-13 09:34:55 +00:00
|
|
|
{t("only_available_on_pro_plan")}
|
2021-10-12 19:43:22 +00:00
|
|
|
</h3>
|
|
|
|
</div>
|
|
|
|
</div>
|
2021-09-13 09:48:55 +00:00
|
|
|
<div className="flex flex-col space-y-3">
|
2021-10-13 09:34:55 +00:00
|
|
|
<p>{t("remove_cal_branding_description")}</p>
|
2021-09-13 09:48:55 +00:00
|
|
|
<p>
|
2022-01-29 00:46:35 +00:00
|
|
|
<Trans i18nKey="plan_upgrade_instructions">
|
|
|
|
You can
|
|
|
|
<a href="/api/upgrade" className="underline">
|
|
|
|
upgrade here
|
|
|
|
</a>
|
|
|
|
.
|
|
|
|
</Trans>
|
2021-09-13 09:48:55 +00:00
|
|
|
</p>
|
|
|
|
</div>
|
2022-02-09 00:05:13 +00:00
|
|
|
<div className="mt-5 gap-x-2 sm:mt-4 sm:flex sm:flex-row-reverse">
|
2021-10-12 19:43:22 +00:00
|
|
|
<DialogClose asChild>
|
2022-02-09 00:05:13 +00:00
|
|
|
<Button className="btn-wide table-cell text-center" onClick={() => setModalOpen(false)}>
|
2021-10-13 09:34:55 +00:00
|
|
|
{t("dismiss")}
|
2021-10-12 19:43:22 +00:00
|
|
|
</Button>
|
|
|
|
</DialogClose>
|
|
|
|
</div>
|
|
|
|
</DialogContent>
|
|
|
|
</Dialog>
|
2021-09-13 09:48:55 +00:00
|
|
|
</>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2021-10-15 11:32:09 +00:00
|
|
|
function SettingsView(props: ComponentProps<typeof Settings> & { localeProp: string }) {
|
|
|
|
const utils = trpc.useContext();
|
2021-10-13 09:34:55 +00:00
|
|
|
const { t } = useLocale();
|
2021-10-28 22:45:58 +00:00
|
|
|
const router = useRouter();
|
2021-10-15 11:32:09 +00:00
|
|
|
const mutation = trpc.useMutation("viewer.updateProfile", {
|
2021-12-18 15:06:05 +00:00
|
|
|
onSuccess: async () => {
|
2021-10-15 11:32:09 +00:00
|
|
|
showToast(t("your_user_profile_updated_successfully"), "success");
|
|
|
|
setHasErrors(false); // dismiss any open errors
|
2021-12-18 15:06:05 +00:00
|
|
|
await utils.invalidateQueries(["viewer.me"]);
|
2021-10-15 11:32:09 +00:00
|
|
|
},
|
|
|
|
onError: (err) => {
|
|
|
|
setHasErrors(true);
|
|
|
|
setErrorMessage(err.message);
|
|
|
|
document?.getElementsByTagName("main")[0]?.scrollTo({ top: 0, behavior: "smooth" });
|
|
|
|
},
|
|
|
|
async onSettled() {
|
|
|
|
await utils.invalidateQueries(["viewer.i18n"]);
|
|
|
|
},
|
|
|
|
});
|
|
|
|
|
2022-01-14 13:49:15 +00:00
|
|
|
const deleteAccount = async () => {
|
|
|
|
await fetch("/api/user/me", {
|
|
|
|
method: "DELETE",
|
|
|
|
headers: {
|
|
|
|
"Content-Type": "application/json",
|
|
|
|
},
|
|
|
|
}).catch((e) => {
|
|
|
|
console.error(`Error Removing user: ${props.user.id}, email: ${props.user.email} :`, e);
|
|
|
|
});
|
2022-01-19 16:03:51 +00:00
|
|
|
if (process.env.NEXT_PUBLIC_BASE_URL === "https://app.cal.com") {
|
2022-01-20 09:32:24 +00:00
|
|
|
signOut({ callbackUrl: "/auth/logout?survey=true" });
|
2022-01-19 16:03:51 +00:00
|
|
|
} else {
|
|
|
|
signOut({ callbackUrl: "/auth/logout" });
|
|
|
|
}
|
2022-01-14 13:49:15 +00:00
|
|
|
};
|
|
|
|
|
2021-10-28 22:45:58 +00:00
|
|
|
const localeOptions = useMemo(() => {
|
|
|
|
return (router.locales || []).map((locale) => ({
|
|
|
|
value: locale,
|
|
|
|
// FIXME
|
|
|
|
// @ts-ignore
|
|
|
|
label: new Intl.DisplayNames(props.localeProp, { type: "language" }).of(locale),
|
|
|
|
}));
|
|
|
|
}, [props.localeProp, router.locales]);
|
2021-09-23 08:49:17 +00:00
|
|
|
|
2021-10-13 09:34:55 +00:00
|
|
|
const themeOptions = [
|
|
|
|
{ value: "light", label: t("light") },
|
|
|
|
{ value: "dark", label: t("dark") },
|
|
|
|
];
|
2022-02-28 16:24:47 +00:00
|
|
|
|
|
|
|
const timeFormatOptions = [
|
|
|
|
{ value: 12, label: t("12_hour") },
|
|
|
|
{ value: 24, label: t("24_hour") },
|
|
|
|
];
|
2021-10-14 10:57:49 +00:00
|
|
|
const usernameRef = useRef<HTMLInputElement>(null!);
|
|
|
|
const nameRef = useRef<HTMLInputElement>(null!);
|
2022-01-12 21:54:48 +00:00
|
|
|
const emailRef = useRef<HTMLInputElement>(null!);
|
2021-10-14 10:57:49 +00:00
|
|
|
const descriptionRef = useRef<HTMLTextAreaElement>(null!);
|
|
|
|
const avatarRef = useRef<HTMLInputElement>(null!);
|
|
|
|
const hideBrandingRef = useRef<HTMLInputElement>(null!);
|
2021-12-09 23:51:30 +00:00
|
|
|
const [selectedTheme, setSelectedTheme] = useState<typeof themeOptions[number] | undefined>();
|
2022-02-28 16:24:47 +00:00
|
|
|
const [selectedTimeFormat, setSelectedTimeFormat] = useState({
|
|
|
|
value: props.user.timeFormat || 12,
|
|
|
|
label: timeFormatOptions.find((option) => option.value === props.user.timeFormat)?.label || 12,
|
|
|
|
});
|
2021-10-28 22:45:58 +00:00
|
|
|
const [selectedTimeZone, setSelectedTimeZone] = useState<ITimezone>(props.user.timeZone);
|
2021-12-09 23:51:30 +00:00
|
|
|
const [selectedWeekStartDay, setSelectedWeekStartDay] = useState({
|
2021-10-12 13:11:33 +00:00
|
|
|
value: props.user.weekStart,
|
2021-10-15 11:32:09 +00:00
|
|
|
label: nameOfDay(props.localeProp, props.user.weekStart === "Sunday" ? 0 : 1),
|
2021-10-12 13:11:33 +00:00
|
|
|
});
|
2021-10-15 11:32:09 +00:00
|
|
|
|
2021-12-09 23:51:30 +00:00
|
|
|
const [selectedLanguage, setSelectedLanguage] = useState({
|
|
|
|
value: props.localeProp || "",
|
|
|
|
label: localeOptions.find((option) => option.value === props.localeProp)?.label || "",
|
2021-09-23 08:49:17 +00:00
|
|
|
});
|
2021-10-12 13:11:33 +00:00
|
|
|
const [imageSrc, setImageSrc] = useState<string>(props.user.avatar || "");
|
2021-06-23 15:49:10 +00:00
|
|
|
const [hasErrors, setHasErrors] = useState(false);
|
|
|
|
const [errorMessage, setErrorMessage] = useState("");
|
2022-02-08 16:13:42 +00:00
|
|
|
const [brandColor, setBrandColor] = useState(props.user.brandColor);
|
2022-03-05 15:37:46 +00:00
|
|
|
const [darkBrandColor, setDarkBrandColor] = useState(props.user.darkBrandColor);
|
2021-04-20 12:56:50 +00:00
|
|
|
|
2021-07-11 19:35:56 +00:00
|
|
|
useEffect(() => {
|
2021-12-09 23:51:30 +00:00
|
|
|
if (!props.user.theme) return;
|
|
|
|
const userTheme = themeOptions.find((theme) => theme.value === props.user.theme);
|
|
|
|
if (!userTheme) return;
|
|
|
|
setSelectedTheme(userTheme);
|
2021-10-28 22:45:58 +00:00
|
|
|
// eslint-disable-next-line react-hooks/exhaustive-deps
|
2021-07-09 22:59:21 +00:00
|
|
|
}, []);
|
|
|
|
|
2021-10-20 15:42:40 +00:00
|
|
|
async function updateProfileHandler(event: FormEvent<HTMLFormElement>) {
|
2021-06-23 15:49:10 +00:00
|
|
|
event.preventDefault();
|
|
|
|
|
|
|
|
const enteredUsername = usernameRef.current.value.toLowerCase();
|
|
|
|
const enteredName = nameRef.current.value;
|
2022-01-12 21:54:48 +00:00
|
|
|
const enteredEmail = emailRef.current.value;
|
2021-06-23 15:49:10 +00:00
|
|
|
const enteredDescription = descriptionRef.current.value;
|
|
|
|
const enteredAvatar = avatarRef.current.value;
|
2022-02-08 16:13:42 +00:00
|
|
|
const enteredBrandColor = brandColor;
|
2022-03-05 15:37:46 +00:00
|
|
|
const enteredDarkBrandColor = darkBrandColor;
|
2021-10-28 22:45:58 +00:00
|
|
|
const enteredTimeZone = typeof selectedTimeZone === "string" ? selectedTimeZone : selectedTimeZone.value;
|
2021-07-09 22:59:21 +00:00
|
|
|
const enteredWeekStartDay = selectedWeekStartDay.value;
|
2021-06-29 16:08:55 +00:00
|
|
|
const enteredHideBranding = hideBrandingRef.current.checked;
|
2021-09-23 08:49:17 +00:00
|
|
|
const enteredLanguage = selectedLanguage.value;
|
2022-02-28 16:24:47 +00:00
|
|
|
const enteredTimeFormat = selectedTimeFormat.value;
|
2021-06-23 15:49:10 +00:00
|
|
|
|
|
|
|
// TODO: Add validation
|
|
|
|
|
2021-10-15 11:32:09 +00:00
|
|
|
mutation.mutate({
|
|
|
|
username: enteredUsername,
|
|
|
|
name: enteredName,
|
2022-01-12 21:54:48 +00:00
|
|
|
email: enteredEmail,
|
2021-10-15 11:32:09 +00:00
|
|
|
bio: enteredDescription,
|
|
|
|
avatar: enteredAvatar,
|
|
|
|
timeZone: enteredTimeZone,
|
|
|
|
weekStart: asStringOrUndefined(enteredWeekStartDay),
|
|
|
|
hideBranding: enteredHideBranding,
|
|
|
|
theme: asStringOrNull(selectedTheme?.value),
|
2021-11-16 08:51:46 +00:00
|
|
|
brandColor: enteredBrandColor,
|
2022-03-05 15:37:46 +00:00
|
|
|
darkBrandColor: enteredDarkBrandColor,
|
2021-10-15 11:32:09 +00:00
|
|
|
locale: enteredLanguage,
|
2022-02-28 16:24:47 +00:00
|
|
|
timeFormat: enteredTimeFormat,
|
2021-10-15 11:32:09 +00:00
|
|
|
});
|
2021-06-23 15:49:10 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return (
|
2021-10-15 11:32:09 +00:00
|
|
|
<form className="divide-y divide-gray-200 lg:col-span-9" onSubmit={updateProfileHandler}>
|
|
|
|
{hasErrors && <Alert severity="error" title={errorMessage} />}
|
|
|
|
<div className="py-6 lg:pb-8">
|
|
|
|
<div className="flex flex-col lg:flex-row">
|
|
|
|
<div className="flex-grow space-y-6">
|
2022-02-17 11:28:49 +00:00
|
|
|
<div className="block rtl:space-x-reverse sm:flex sm:space-x-2">
|
2022-02-09 00:05:13 +00:00
|
|
|
<div className="mb-6 w-full sm:w-1/2">
|
2021-12-09 23:51:30 +00:00
|
|
|
<TextField
|
|
|
|
name="username"
|
|
|
|
addOnLeading={
|
2022-02-09 00:05:13 +00:00
|
|
|
<span className="inline-flex items-center rounded-l-sm border border-r-0 border-gray-300 bg-gray-50 px-3 text-gray-500 sm:text-sm">
|
2021-12-20 16:26:35 +00:00
|
|
|
{process.env.NEXT_PUBLIC_APP_URL}/
|
2021-12-09 23:51:30 +00:00
|
|
|
</span>
|
|
|
|
}
|
|
|
|
ref={usernameRef}
|
|
|
|
defaultValue={props.user.username || undefined}
|
|
|
|
/>
|
2021-06-23 15:49:10 +00:00
|
|
|
</div>
|
2022-02-01 22:17:37 +00:00
|
|
|
<div className="w-full sm:w-1/2">
|
2021-10-15 11:32:09 +00:00
|
|
|
<label htmlFor="name" className="block text-sm font-medium text-gray-700">
|
|
|
|
{t("full_name")}
|
|
|
|
</label>
|
|
|
|
<input
|
|
|
|
ref={nameRef}
|
|
|
|
type="text"
|
|
|
|
name="name"
|
|
|
|
id="name"
|
|
|
|
autoComplete="given-name"
|
|
|
|
placeholder={t("your_name")}
|
|
|
|
required
|
2022-02-09 00:05:13 +00:00
|
|
|
className="mt-1 block w-full rounded-sm border border-gray-300 px-3 py-2 shadow-sm focus:border-neutral-800 focus:outline-none focus:ring-neutral-800 sm:text-sm"
|
2021-10-20 15:42:40 +00:00
|
|
|
defaultValue={props.user.name || undefined}
|
2021-10-15 11:32:09 +00:00
|
|
|
/>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
<div className="block sm:flex">
|
2022-02-09 00:05:13 +00:00
|
|
|
<div className="mb-6 w-full sm:w-1/2">
|
2021-10-15 11:32:09 +00:00
|
|
|
<label htmlFor="email" className="block text-sm font-medium text-gray-700">
|
|
|
|
{t("email")}
|
|
|
|
</label>
|
|
|
|
<input
|
2022-01-12 21:54:48 +00:00
|
|
|
ref={emailRef}
|
2022-01-29 19:22:02 +00:00
|
|
|
type="email"
|
2021-10-15 11:32:09 +00:00
|
|
|
name="email"
|
|
|
|
id="email"
|
|
|
|
placeholder={t("your_email")}
|
2022-02-09 00:05:13 +00:00
|
|
|
className="mt-1 block w-full rounded-sm border-gray-300 shadow-sm focus:border-neutral-800 focus:ring-neutral-800 sm:text-sm"
|
2021-10-15 11:32:09 +00:00
|
|
|
defaultValue={props.user.email}
|
|
|
|
/>
|
|
|
|
<p className="mt-2 text-sm text-gray-500" id="email-description">
|
2022-01-12 21:54:48 +00:00
|
|
|
{t("change_email_tip")}
|
2021-06-23 15:49:10 +00:00
|
|
|
</p>
|
2021-10-15 11:32:09 +00:00
|
|
|
</div>
|
|
|
|
</div>
|
2021-06-23 15:49:10 +00:00
|
|
|
|
2021-10-15 11:32:09 +00:00
|
|
|
<div>
|
|
|
|
<label htmlFor="about" className="block text-sm font-medium text-gray-700">
|
|
|
|
{t("about")}
|
|
|
|
</label>
|
|
|
|
<div className="mt-1">
|
|
|
|
<textarea
|
|
|
|
ref={descriptionRef}
|
|
|
|
id="about"
|
|
|
|
name="about"
|
|
|
|
placeholder={t("little_something_about")}
|
|
|
|
rows={3}
|
|
|
|
defaultValue={props.user.bio || undefined}
|
2022-02-09 00:05:13 +00:00
|
|
|
className="mt-1 block w-full rounded-sm border-gray-300 shadow-sm focus:border-neutral-800 focus:ring-neutral-800 sm:text-sm"></textarea>
|
2021-10-15 11:32:09 +00:00
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
<div>
|
2022-02-09 00:05:13 +00:00
|
|
|
<div className="mt-1 flex">
|
2021-10-15 11:32:09 +00:00
|
|
|
<Avatar
|
2021-10-20 15:42:40 +00:00
|
|
|
alt={props.user.name || ""}
|
2022-02-09 00:05:13 +00:00
|
|
|
className="relative h-10 w-10 rounded-full"
|
2021-10-15 11:32:09 +00:00
|
|
|
gravatarFallbackMd5={props.user.emailMd5}
|
|
|
|
imageSrc={imageSrc}
|
|
|
|
/>
|
|
|
|
<input
|
|
|
|
ref={avatarRef}
|
|
|
|
type="hidden"
|
|
|
|
name="avatar"
|
|
|
|
id="avatar"
|
|
|
|
placeholder="URL"
|
2022-02-09 00:05:13 +00:00
|
|
|
className="mt-1 block w-full rounded-sm border border-gray-300 px-3 py-2 shadow-sm focus:border-neutral-800 focus:outline-none focus:ring-neutral-800 sm:text-sm"
|
2021-10-15 11:32:09 +00:00
|
|
|
defaultValue={imageSrc}
|
|
|
|
/>
|
2021-12-09 23:51:30 +00:00
|
|
|
<div className="flex items-center px-5">
|
|
|
|
<ImageUploader
|
|
|
|
target="avatar"
|
|
|
|
id="avatar-upload"
|
|
|
|
buttonMsg={t("change_avatar")}
|
|
|
|
handleAvatarChange={(newAvatar) => {
|
|
|
|
avatarRef.current.value = newAvatar;
|
|
|
|
const nativeInputValueSetter = Object.getOwnPropertyDescriptor(
|
|
|
|
window.HTMLInputElement.prototype,
|
|
|
|
"value"
|
|
|
|
)?.set;
|
|
|
|
nativeInputValueSetter?.call(avatarRef.current, newAvatar);
|
|
|
|
const ev2 = new Event("input", { bubbles: true });
|
|
|
|
avatarRef.current.dispatchEvent(ev2);
|
|
|
|
updateProfileHandler(ev2 as unknown as FormEvent<HTMLFormElement>);
|
|
|
|
setImageSrc(newAvatar);
|
|
|
|
}}
|
|
|
|
imageSrc={imageSrc}
|
|
|
|
/>
|
|
|
|
</div>
|
2021-10-15 11:32:09 +00:00
|
|
|
</div>
|
|
|
|
<hr className="mt-6" />
|
|
|
|
</div>
|
|
|
|
<div>
|
|
|
|
<label htmlFor="language" className="block text-sm font-medium text-gray-700">
|
|
|
|
{t("language")}
|
|
|
|
</label>
|
|
|
|
<div className="mt-1">
|
|
|
|
<Select
|
|
|
|
id="languageSelect"
|
|
|
|
value={selectedLanguage || props.localeProp}
|
2021-12-09 23:51:30 +00:00
|
|
|
onChange={(v) => v && setSelectedLanguage(v)}
|
2021-10-15 11:32:09 +00:00
|
|
|
classNamePrefix="react-select"
|
2022-02-09 00:05:13 +00:00
|
|
|
className="react-select-container mt-1 block w-full rounded-sm border border-gray-300 capitalize shadow-sm focus:border-neutral-800 focus:ring-neutral-800 sm:text-sm"
|
2021-10-15 11:32:09 +00:00
|
|
|
options={localeOptions}
|
|
|
|
/>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
<div>
|
|
|
|
<label htmlFor="timeZone" className="block text-sm font-medium text-gray-700">
|
|
|
|
{t("timezone")}
|
|
|
|
</label>
|
|
|
|
<div className="mt-1">
|
|
|
|
<TimezoneSelect
|
|
|
|
id="timeZone"
|
|
|
|
value={selectedTimeZone}
|
2021-12-09 23:51:30 +00:00
|
|
|
onChange={(v) => v && setSelectedTimeZone(v)}
|
2021-10-15 11:32:09 +00:00
|
|
|
classNamePrefix="react-select"
|
2022-02-09 00:05:13 +00:00
|
|
|
className="react-select-container mt-1 block w-full rounded-sm border border-gray-300 shadow-sm focus:border-neutral-800 focus:ring-neutral-800 sm:text-sm"
|
2021-10-15 11:32:09 +00:00
|
|
|
/>
|
|
|
|
</div>
|
|
|
|
</div>
|
2022-02-28 16:24:47 +00:00
|
|
|
<div>
|
|
|
|
<label htmlFor="timeFormat" className="block text-sm font-medium text-gray-700">
|
|
|
|
{t("time_format")}
|
|
|
|
</label>
|
|
|
|
<div className="mt-1">
|
|
|
|
<Select
|
|
|
|
id="timeFormatSelect"
|
|
|
|
value={selectedTimeFormat || props.user.timeFormat}
|
|
|
|
onChange={(v) => v && setSelectedTimeFormat(v)}
|
|
|
|
classNamePrefix="react-select"
|
|
|
|
className="react-select-container mt-1 block w-full rounded-sm border border-gray-300 capitalize shadow-sm focus:border-neutral-800 focus:ring-neutral-800 sm:text-sm"
|
|
|
|
options={timeFormatOptions}
|
|
|
|
/>
|
|
|
|
</div>
|
|
|
|
</div>
|
2021-10-15 11:32:09 +00:00
|
|
|
<div>
|
|
|
|
<label htmlFor="weekStart" className="block text-sm font-medium text-gray-700">
|
|
|
|
{t("first_day_of_week")}
|
|
|
|
</label>
|
|
|
|
<div className="mt-1">
|
|
|
|
<Select
|
|
|
|
id="weekStart"
|
|
|
|
value={selectedWeekStartDay}
|
2021-12-09 23:51:30 +00:00
|
|
|
onChange={(v) => v && setSelectedWeekStartDay(v)}
|
2021-10-15 11:32:09 +00:00
|
|
|
classNamePrefix="react-select"
|
2022-02-09 00:05:13 +00:00
|
|
|
className="react-select-container mt-1 block w-full rounded-sm border border-gray-300 capitalize shadow-sm focus:border-neutral-800 focus:ring-neutral-800 sm:text-sm"
|
2021-10-15 11:32:09 +00:00
|
|
|
options={[
|
|
|
|
{ value: "Sunday", label: nameOfDay(props.localeProp, 0) },
|
|
|
|
{ value: "Monday", label: nameOfDay(props.localeProp, 1) },
|
|
|
|
]}
|
|
|
|
/>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
<div>
|
|
|
|
<label htmlFor="theme" className="block text-sm font-medium text-gray-700">
|
|
|
|
{t("single_theme")}
|
|
|
|
</label>
|
|
|
|
<div className="my-1">
|
|
|
|
<Select
|
|
|
|
id="theme"
|
|
|
|
isDisabled={!selectedTheme}
|
|
|
|
defaultValue={selectedTheme || themeOptions[0]}
|
|
|
|
value={selectedTheme || themeOptions[0]}
|
2021-12-09 23:51:30 +00:00
|
|
|
onChange={(v) => v && setSelectedTheme(v)}
|
2022-02-09 00:05:13 +00:00
|
|
|
className="| { value: string } mt-1 block w-full rounded-sm border-gray-300 shadow-sm focus:border-neutral-800 focus:ring-neutral-800 sm:text-sm"
|
2021-10-15 11:32:09 +00:00
|
|
|
options={themeOptions}
|
|
|
|
/>
|
|
|
|
</div>
|
2022-02-09 00:05:13 +00:00
|
|
|
<div className="relative mt-8 flex items-start">
|
|
|
|
<div className="flex h-5 items-center">
|
2021-10-15 11:32:09 +00:00
|
|
|
<input
|
|
|
|
id="theme-adjust-os"
|
|
|
|
name="theme-adjust-os"
|
|
|
|
type="checkbox"
|
2021-10-20 15:42:40 +00:00
|
|
|
onChange={(e) => setSelectedTheme(e.target.checked ? undefined : themeOptions[0])}
|
2021-10-15 11:32:09 +00:00
|
|
|
checked={!selectedTheme}
|
2022-02-09 00:05:13 +00:00
|
|
|
className="h-4 w-4 rounded-sm border-gray-300 text-neutral-900 focus:ring-neutral-800"
|
2021-06-23 15:49:10 +00:00
|
|
|
/>
|
|
|
|
</div>
|
2022-02-01 22:17:37 +00:00
|
|
|
<div className="text-sm ltr:ml-3 rtl:mr-3">
|
2021-10-15 11:32:09 +00:00
|
|
|
<label htmlFor="theme-adjust-os" className="font-medium text-gray-700">
|
|
|
|
{t("automatically_adjust_theme")}
|
2021-06-23 15:49:10 +00:00
|
|
|
</label>
|
|
|
|
</div>
|
2021-10-15 11:32:09 +00:00
|
|
|
</div>
|
2021-06-23 15:49:10 +00:00
|
|
|
</div>
|
2022-03-05 15:37:46 +00:00
|
|
|
<div className="block rtl:space-x-reverse sm:flex sm:space-x-2">
|
|
|
|
<div className="mb-6 w-full sm:w-1/2">
|
|
|
|
<label htmlFor="brandColor" className="block text-sm font-medium text-gray-700">
|
|
|
|
{t("light_brand_color")}
|
|
|
|
</label>
|
|
|
|
<ColorPicker defaultValue={props.user.brandColor} onChange={setBrandColor} />
|
|
|
|
</div>
|
|
|
|
<div className="mb-6 w-full sm:w-1/2">
|
|
|
|
<label htmlFor="darkBrandColor" className="block text-sm font-medium text-gray-700">
|
|
|
|
{t("dark_brand_color")}
|
|
|
|
</label>
|
|
|
|
<ColorPicker defaultValue={props.user.darkBrandColor} onChange={setDarkBrandColor} />
|
|
|
|
</div>
|
2021-11-16 08:51:46 +00:00
|
|
|
<hr className="mt-6" />
|
|
|
|
</div>
|
2021-10-15 11:32:09 +00:00
|
|
|
<div>
|
|
|
|
<div className="relative flex items-start">
|
2022-02-09 00:05:13 +00:00
|
|
|
<div className="flex h-5 items-center">
|
2021-10-15 11:32:09 +00:00
|
|
|
<HideBrandingInput user={props.user} hideBrandingRef={hideBrandingRef} />
|
|
|
|
</div>
|
2022-02-01 22:17:37 +00:00
|
|
|
<div className="text-sm ltr:ml-3 rtl:mr-3">
|
2021-10-15 11:32:09 +00:00
|
|
|
<label htmlFor="hide-branding" className="font-medium text-gray-700">
|
|
|
|
{t("disable_cal_branding")}{" "}
|
|
|
|
{props.user.plan !== "PRO" && <Badge variant="default">PRO</Badge>}
|
|
|
|
</label>
|
|
|
|
<p className="text-gray-500">{t("disable_cal_branding_description")}</p>
|
|
|
|
</div>
|
|
|
|
</div>
|
2021-06-23 15:49:10 +00:00
|
|
|
</div>
|
2022-02-09 00:05:13 +00:00
|
|
|
<h3 className="text-md mt-7 font-bold leading-6 text-red-700">{t("danger_zone")}</h3>
|
2022-01-14 13:49:15 +00:00
|
|
|
<div>
|
|
|
|
<div className="relative flex items-start">
|
|
|
|
<Dialog>
|
|
|
|
<DialogTrigger asChild>
|
|
|
|
<Button
|
|
|
|
type="button"
|
|
|
|
color="warn"
|
|
|
|
StartIcon={TrashIcon}
|
2022-02-09 00:05:13 +00:00
|
|
|
className="border-2 border-red-700 text-red-700"
|
2022-01-14 13:49:15 +00:00
|
|
|
data-testid="delete-account">
|
|
|
|
{t("delete_account")}
|
|
|
|
</Button>
|
|
|
|
</DialogTrigger>
|
|
|
|
<ConfirmationDialogContent
|
|
|
|
variety="danger"
|
|
|
|
title={t("delete_account")}
|
|
|
|
confirmBtn={
|
|
|
|
<Button color="warn" data-testid="delete-account-confirm">
|
|
|
|
{t("confirm_delete_account")}
|
|
|
|
</Button>
|
|
|
|
}
|
|
|
|
onConfirm={() => deleteAccount()}>
|
|
|
|
{t("delete_account_confirmation_message")}
|
|
|
|
</ConfirmationDialogContent>
|
|
|
|
</Dialog>
|
|
|
|
</div>
|
|
|
|
</div>
|
2021-06-23 15:49:10 +00:00
|
|
|
</div>
|
2021-10-15 11:32:09 +00:00
|
|
|
</div>
|
|
|
|
<hr className="mt-8" />
|
|
|
|
<div className="flex justify-end py-4">
|
|
|
|
<Button type="submit">{t("save")}</Button>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</form>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
export default function Settings(props: Props) {
|
|
|
|
const { t } = useLocale();
|
|
|
|
const query = trpc.useQuery(["viewer.i18n"]);
|
|
|
|
|
|
|
|
return (
|
|
|
|
<Shell heading={t("profile")} subtitle={t("edit_profile_info_description")}>
|
|
|
|
<SettingsShell>
|
|
|
|
<QueryCell
|
|
|
|
query={query}
|
|
|
|
success={({ data }) => <SettingsView {...props} localeProp={data.locale} />}
|
|
|
|
/>
|
2021-06-23 15:49:10 +00:00
|
|
|
</SettingsShell>
|
|
|
|
</Shell>
|
|
|
|
);
|
2021-04-07 15:03:02 +00:00
|
|
|
}
|
|
|
|
|
2021-09-13 09:48:55 +00:00
|
|
|
export const getServerSideProps = async (context: GetServerSidePropsContext) => {
|
2021-06-23 15:49:10 +00:00
|
|
|
const session = await getSession(context);
|
2021-09-23 08:49:17 +00:00
|
|
|
|
2021-09-13 09:48:55 +00:00
|
|
|
if (!session?.user?.id) {
|
2021-06-23 15:49:10 +00:00
|
|
|
return { redirect: { permanent: false, destination: "/auth/login" } };
|
|
|
|
}
|
2021-04-07 15:03:02 +00:00
|
|
|
|
2021-08-22 13:16:42 +00:00
|
|
|
const user = await prisma.user.findUnique({
|
|
|
|
where: {
|
2021-07-09 22:59:21 +00:00
|
|
|
id: session.user.id,
|
2021-07-11 19:35:56 +00:00
|
|
|
},
|
2021-08-22 13:16:42 +00:00
|
|
|
select: {
|
|
|
|
id: true,
|
|
|
|
username: true,
|
|
|
|
name: true,
|
|
|
|
email: true,
|
|
|
|
bio: true,
|
|
|
|
avatar: true,
|
|
|
|
timeZone: true,
|
|
|
|
weekStart: true,
|
|
|
|
hideBranding: true,
|
|
|
|
theme: true,
|
2021-09-13 09:48:55 +00:00
|
|
|
plan: true,
|
2021-11-16 08:51:46 +00:00
|
|
|
brandColor: true,
|
2022-03-05 15:37:46 +00:00
|
|
|
darkBrandColor: true,
|
2022-01-14 13:49:15 +00:00
|
|
|
metadata: true,
|
2022-02-28 16:24:47 +00:00
|
|
|
timeFormat: true,
|
2021-08-22 13:16:42 +00:00
|
|
|
},
|
|
|
|
});
|
2021-06-23 15:49:10 +00:00
|
|
|
|
2021-09-13 09:48:55 +00:00
|
|
|
if (!user) {
|
|
|
|
throw new Error("User seems logged in but cannot be found in the db");
|
|
|
|
}
|
2021-09-23 08:49:17 +00:00
|
|
|
|
2021-06-23 15:49:10 +00:00
|
|
|
return {
|
2021-08-22 13:16:42 +00:00
|
|
|
props: {
|
|
|
|
user: {
|
|
|
|
...user,
|
|
|
|
emailMd5: crypto.createHash("md5").update(user.email).digest("hex"),
|
|
|
|
},
|
|
|
|
},
|
2021-06-23 15:49:10 +00:00
|
|
|
};
|
|
|
|
};
|