import { ArrowRightIcon } from "@heroicons/react/outline"; import { useState } from "react"; import { Controller, useForm } from "react-hook-form"; import dayjs from "@calcom/dayjs"; import { useLocale } from "@calcom/lib/hooks/useLocale"; import { User } from "@calcom/prisma/client"; import { trpc } from "@calcom/trpc/react"; import { Button, TimezoneSelect } from "@calcom/ui"; import { UsernameAvailability } from "@components/ui/UsernameAvailability"; interface IUserSettingsProps { user: User; nextStep: () => void; } const UserSettings = (props: IUserSettingsProps) => { const { user, nextStep } = props; const { t } = useLocale(); const [selectedTimeZone, setSelectedTimeZone] = useState(user.timeZone ?? dayjs.tz.guess()); const { register, handleSubmit, formState: { errors }, control, } = useForm({ defaultValues: { name: user?.name || "", username: user?.username || "", }, reValidateMode: "onChange", }); const defaultOptions = { required: true, maxLength: 255 }; const utils = trpc.useContext(); const onSuccess = async () => { await utils.viewer.me.invalidate(); nextStep(); }; const mutation = trpc.viewer.updateProfile.useMutation({ onSuccess: onSuccess, }); const { data: stripeCustomer } = trpc.viewer.stripeCustomer.useQuery(); const paymentRequired = stripeCustomer?.isPremium ? !stripeCustomer?.paidForPremium : false; const onSubmit = handleSubmit((data) => { if (paymentRequired) { return; } mutation.mutate({ name: data.name, timeZone: selectedTimeZone, }); }); const [currentUsername, setCurrentUsername] = useState(user.username || ""); return (
{/* Username textfield */} ( )} /> {/* Full name textfield */}
{errors.name && (

{t("required")}

)}
{/* Timezone select field */}
setSelectedTimeZone(value)} className="mt-2 w-full rounded-md text-sm" />

{t("current_time")} {dayjs().tz(selectedTimeZone).format("LT").toString().toLowerCase()}

); }; export { UserSettings };