2021-10-12 19:43:22 +00:00
|
|
|
import { InformationCircleIcon } from "@heroicons/react/outline";
|
2021-09-22 19:52:38 +00:00
|
|
|
import crypto from "crypto";
|
2021-09-13 09:48:55 +00:00
|
|
|
import { GetServerSidePropsContext } from "next";
|
2021-10-28 22:45:58 +00:00
|
|
|
import { useRouter } from "next/router";
|
|
|
|
import { ComponentProps, FormEvent, RefObject, useEffect, useRef, useState, useMemo } from "react";
|
2021-10-15 11:32:09 +00:00
|
|
|
import Select, { OptionTypeBase } 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";
|
|
|
|
|
2021-10-15 11:32:09 +00:00
|
|
|
import { Dialog, DialogClose, DialogContent } 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";
|
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";
|
2021-09-22 19:52:38 +00:00
|
|
|
import { UsernameInput } from "@components/ui/UsernameInput";
|
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={
|
|
|
|
"focus:ring-neutral-500 h-4 w-4 text-neutral-900 border-gray-300 rounded-sm disabled:opacity-50"
|
|
|
|
}
|
|
|
|
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>
|
2021-10-15 11:32:09 +00:00
|
|
|
<div className="flex items-center justify-center w-12 h-12 mx-auto mb-4 bg-yellow-100 rounded-full">
|
|
|
|
<InformationCircleIcon className="w-6 h-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">
|
2021-10-15 11:32:09 +00:00
|
|
|
<h3 className="text-lg font-bold leading-6 text-gray-900 font-cal" 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>
|
|
|
|
{" "}
|
2021-10-13 09:34:55 +00:00
|
|
|
{t("to_upgrade_go_to")}{" "}
|
2021-09-15 20:35:55 +00:00
|
|
|
<a href="https://cal.com/upgrade" className="underline">
|
|
|
|
cal.com/upgrade
|
2021-09-13 09:48:55 +00:00
|
|
|
</a>
|
|
|
|
.
|
|
|
|
</p>
|
|
|
|
</div>
|
2021-10-12 19:43:22 +00:00
|
|
|
<div className="mt-5 sm:mt-4 sm:flex sm:flex-row-reverse gap-x-2">
|
|
|
|
<DialogClose asChild>
|
2021-11-29 06:37:31 +00:00
|
|
|
<Button className="table-cell text-center btn-wide" 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", {
|
|
|
|
onSuccess: () => {
|
|
|
|
showToast(t("your_user_profile_updated_successfully"), "success");
|
|
|
|
setHasErrors(false); // dismiss any open errors
|
|
|
|
},
|
|
|
|
onError: (err) => {
|
|
|
|
setHasErrors(true);
|
|
|
|
setErrorMessage(err.message);
|
|
|
|
document?.getElementsByTagName("main")[0]?.scrollTo({ top: 0, behavior: "smooth" });
|
|
|
|
},
|
|
|
|
async onSettled() {
|
|
|
|
await utils.invalidateQueries(["viewer.i18n"]);
|
|
|
|
},
|
|
|
|
});
|
|
|
|
|
2021-10-28 22:45:58 +00:00
|
|
|
const localeOptions = useMemo(() => {
|
|
|
|
return (router.locales || []).map((locale) => ({
|
|
|
|
value: locale,
|
|
|
|
// FIXME
|
|
|
|
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
|
|
// @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") },
|
|
|
|
];
|
2021-10-28 22:45:58 +00:00
|
|
|
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
2021-10-14 10:57:49 +00:00
|
|
|
const usernameRef = useRef<HTMLInputElement>(null!);
|
2021-10-28 22:45:58 +00:00
|
|
|
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
2021-10-14 10:57:49 +00:00
|
|
|
const nameRef = useRef<HTMLInputElement>(null!);
|
2021-10-28 22:45:58 +00:00
|
|
|
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
2021-10-14 10:57:49 +00:00
|
|
|
const descriptionRef = useRef<HTMLTextAreaElement>(null!);
|
2021-10-28 22:45:58 +00:00
|
|
|
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
2021-10-14 10:57:49 +00:00
|
|
|
const avatarRef = useRef<HTMLInputElement>(null!);
|
2021-10-28 22:45:58 +00:00
|
|
|
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
2021-11-16 08:51:46 +00:00
|
|
|
const brandColorRef = useRef<HTMLInputElement>(null!);
|
|
|
|
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
2021-10-14 10:57:49 +00:00
|
|
|
const hideBrandingRef = useRef<HTMLInputElement>(null!);
|
2021-10-15 11:32:09 +00:00
|
|
|
const [selectedTheme, setSelectedTheme] = useState<OptionTypeBase>();
|
2021-10-28 22:45:58 +00:00
|
|
|
const [selectedTimeZone, setSelectedTimeZone] = useState<ITimezone>(props.user.timeZone);
|
2021-10-15 11:32:09 +00:00
|
|
|
const [selectedWeekStartDay, setSelectedWeekStartDay] = useState<OptionTypeBase>({
|
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
|
|
|
|
|
|
|
const [selectedLanguage, setSelectedLanguage] = useState<OptionTypeBase>({
|
2021-10-12 13:11:33 +00:00
|
|
|
value: props.localeProp,
|
2021-10-15 11:32:09 +00:00
|
|
|
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("");
|
2021-04-20 12:56:50 +00:00
|
|
|
|
2021-07-11 19:35:56 +00:00
|
|
|
useEffect(() => {
|
|
|
|
setSelectedTheme(
|
2021-10-14 10:57:49 +00:00
|
|
|
props.user.theme ? themeOptions.find((theme) => theme.value === props.user.theme) : undefined
|
2021-07-11 19:35:56 +00:00
|
|
|
);
|
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;
|
|
|
|
const enteredDescription = descriptionRef.current.value;
|
|
|
|
const enteredAvatar = avatarRef.current.value;
|
2021-11-16 08:51:46 +00:00
|
|
|
const enteredBrandColor = brandColorRef.current.value;
|
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;
|
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,
|
|
|
|
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,
|
2021-10-15 11:32:09 +00:00
|
|
|
locale: enteredLanguage,
|
|
|
|
});
|
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">
|
|
|
|
<div className="block sm:flex">
|
|
|
|
<div className="w-full mb-6 sm:w-1/2 sm:mr-2">
|
2021-10-20 15:42:40 +00:00
|
|
|
<UsernameInput ref={usernameRef} defaultValue={props.user.username || undefined} />
|
2021-06-23 15:49:10 +00:00
|
|
|
</div>
|
2021-10-15 11:32:09 +00:00
|
|
|
<div className="w-full sm:w-1/2 sm:ml-2">
|
|
|
|
<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
|
|
|
|
className="block w-full px-3 py-2 mt-1 border border-gray-300 rounded-sm shadow-sm focus:outline-none focus:ring-neutral-500 focus:border-neutral-500 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>
|
2021-06-23 15:49:10 +00:00
|
|
|
|
2021-10-15 11:32:09 +00:00
|
|
|
<div className="block sm:flex">
|
|
|
|
<div className="w-full mb-6 sm:w-1/2 sm:mr-2">
|
|
|
|
<label htmlFor="email" className="block text-sm font-medium text-gray-700">
|
|
|
|
{t("email")}
|
|
|
|
</label>
|
|
|
|
<input
|
|
|
|
type="text"
|
|
|
|
name="email"
|
|
|
|
id="email"
|
|
|
|
placeholder={t("your_email")}
|
|
|
|
disabled
|
|
|
|
className="block w-full px-3 py-2 mt-1 text-gray-500 border border-gray-300 rounded-l-sm bg-gray-50 sm:text-sm"
|
|
|
|
defaultValue={props.user.email}
|
|
|
|
/>
|
|
|
|
<p className="mt-2 text-sm text-gray-500" id="email-description">
|
|
|
|
{t("change_email_contact")}{" "}
|
|
|
|
<a className="text-blue-500" href="mailto:help@cal.com">
|
|
|
|
help@cal.com
|
|
|
|
</a>
|
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}
|
|
|
|
className="block w-full mt-1 border-gray-300 rounded-sm shadow-sm focus:ring-neutral-500 focus:border-neutral-500 sm:text-sm"></textarea>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
<div>
|
|
|
|
<div className="flex mt-1">
|
|
|
|
<Avatar
|
2021-10-20 15:42:40 +00:00
|
|
|
alt={props.user.name || ""}
|
2021-10-15 11:32:09 +00:00
|
|
|
className="relative w-10 h-10 rounded-full"
|
|
|
|
gravatarFallbackMd5={props.user.emailMd5}
|
|
|
|
imageSrc={imageSrc}
|
|
|
|
/>
|
|
|
|
<input
|
|
|
|
ref={avatarRef}
|
|
|
|
type="hidden"
|
|
|
|
name="avatar"
|
|
|
|
id="avatar"
|
|
|
|
placeholder="URL"
|
|
|
|
className="block w-full px-3 py-2 mt-1 border border-gray-300 rounded-sm shadow-sm focus:outline-none focus:ring-neutral-500 focus:border-neutral-500 sm:text-sm"
|
|
|
|
defaultValue={imageSrc}
|
|
|
|
/>
|
|
|
|
<ImageUploader
|
|
|
|
target="avatar"
|
|
|
|
id="avatar-upload"
|
|
|
|
buttonMsg={t("change_avatar")}
|
|
|
|
handleAvatarChange={(newAvatar) => {
|
|
|
|
avatarRef.current.value = newAvatar;
|
|
|
|
const nativeInputValueSetter = Object.getOwnPropertyDescriptor(
|
|
|
|
window.HTMLInputElement.prototype,
|
|
|
|
"value"
|
2021-10-20 15:42:40 +00:00
|
|
|
)?.set;
|
|
|
|
nativeInputValueSetter?.call(avatarRef.current, newAvatar);
|
2021-10-15 11:32:09 +00:00
|
|
|
const ev2 = new Event("input", { bubbles: true });
|
|
|
|
avatarRef.current.dispatchEvent(ev2);
|
2021-10-20 15:42:40 +00:00
|
|
|
updateProfileHandler(ev2 as unknown as FormEvent<HTMLFormElement>);
|
2021-10-15 11:32:09 +00:00
|
|
|
setImageSrc(newAvatar);
|
|
|
|
}}
|
|
|
|
imageSrc={imageSrc}
|
|
|
|
/>
|
|
|
|
</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}
|
|
|
|
onChange={setSelectedLanguage}
|
|
|
|
classNamePrefix="react-select"
|
|
|
|
className="block w-full mt-1 capitalize border border-gray-300 rounded-sm shadow-sm react-select-container focus:ring-neutral-500 focus:border-neutral-500 sm:text-sm"
|
|
|
|
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}
|
|
|
|
onChange={setSelectedTimeZone}
|
|
|
|
classNamePrefix="react-select"
|
|
|
|
className="block w-full mt-1 border border-gray-300 rounded-sm shadow-sm react-select-container focus:ring-neutral-500 focus:border-neutral-500 sm:text-sm"
|
|
|
|
/>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
<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}
|
|
|
|
onChange={setSelectedWeekStartDay}
|
|
|
|
classNamePrefix="react-select"
|
|
|
|
className="block w-full mt-1 capitalize border border-gray-300 rounded-sm shadow-sm react-select-container focus:ring-neutral-500 focus:border-neutral-500 sm:text-sm"
|
|
|
|
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]}
|
|
|
|
onChange={setSelectedTheme}
|
|
|
|
className="shadow-sm | { value: string } focus:ring-neutral-500 focus:border-neutral-500 mt-1 block w-full sm:text-sm border-gray-300 rounded-sm"
|
|
|
|
options={themeOptions}
|
|
|
|
/>
|
|
|
|
</div>
|
|
|
|
<div className="relative flex items-start mt-8">
|
|
|
|
<div className="flex items-center h-5">
|
|
|
|
<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}
|
|
|
|
className="w-4 h-4 border-gray-300 rounded-sm focus:ring-neutral-500 text-neutral-900"
|
2021-06-23 15:49:10 +00:00
|
|
|
/>
|
|
|
|
</div>
|
2021-10-15 11:32:09 +00:00
|
|
|
<div className="ml-3 text-sm">
|
|
|
|
<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>
|
2021-11-16 08:51:46 +00:00
|
|
|
<div>
|
|
|
|
<label htmlFor="brandColor" className="block text-sm font-medium text-gray-700">
|
|
|
|
{t("brand_color")}
|
|
|
|
</label>
|
|
|
|
<div className="flex mt-1">
|
|
|
|
<input
|
|
|
|
ref={brandColorRef}
|
|
|
|
type="text"
|
|
|
|
name="brandColor"
|
|
|
|
id="brandColor"
|
|
|
|
placeholder="#hex-code"
|
|
|
|
className="block w-full px-3 py-2 mt-1 border border-gray-300 rounded-sm shadow-sm focus:outline-none focus:ring-neutral-500 focus:border-neutral-500 sm:text-sm"
|
|
|
|
defaultValue={props.user.brandColor}
|
|
|
|
/>
|
|
|
|
</div>
|
|
|
|
<hr className="mt-6" />
|
|
|
|
</div>
|
2021-10-15 11:32:09 +00:00
|
|
|
<div>
|
|
|
|
<div className="relative flex items-start">
|
|
|
|
<div className="flex items-center h-5">
|
|
|
|
<HideBrandingInput user={props.user} hideBrandingRef={hideBrandingRef} />
|
|
|
|
</div>
|
|
|
|
<div className="ml-3 text-sm">
|
|
|
|
<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>
|
|
|
|
</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,
|
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
|
|
|
};
|
|
|
|
};
|