import { ArrowRightIcon } from "@heroicons/react/outline"; import { useRef, useState } from "react"; import { 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 TimezoneSelect from "@calcom/ui/form/TimezoneSelect"; import { Button } from "@calcom/ui/v2"; import { UsernameAvailability } from "@components/ui/UsernameAvailability"; interface IUserSettingsProps { user: User; nextStep: () => void; } type FormData = { name: string; }; const UserSettings = (props: IUserSettingsProps) => { const { user, nextStep } = props; const { t } = useLocale(); const [selectedTimeZone, setSelectedTimeZone] = useState(user.timeZone ?? dayjs.tz.guess()); const { register, handleSubmit, formState } = useForm({ defaultValues: { name: user?.name || undefined, }, reValidateMode: "onChange", }); const { errors } = formState; const defaultOptions = { required: true, maxLength: 255 }; const utils = trpc.useContext(); const onSuccess = async () => { await utils.invalidateQueries(["viewer.me"]); nextStep(); }; const mutation = trpc.useMutation("viewer.updateProfile", { onSuccess: onSuccess, }); const { data: stripeCustomer } = trpc.useQuery(["viewer.stripeCustomer"]); 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 || undefined); const [inputUsernameValue, setInputUsernameValue] = useState(currentUsername); const usernameRef = useRef(null!); 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 };