2022-09-06 22:58:16 +00:00
|
|
|
import { ArrowRightIcon } from "@heroicons/react/outline";
|
2023-03-21 10:43:07 +00:00
|
|
|
import { zodResolver } from "@hookform/resolvers/zod";
|
2023-02-10 09:53:03 +00:00
|
|
|
import { useEffect, useState } from "react";
|
2022-12-07 20:15:15 +00:00
|
|
|
import { useForm } from "react-hook-form";
|
2023-03-21 10:43:07 +00:00
|
|
|
import { z } from "zod";
|
2022-09-06 22:58:16 +00:00
|
|
|
|
|
|
|
import dayjs from "@calcom/dayjs";
|
2023-03-21 10:43:07 +00:00
|
|
|
import { FULL_NAME_LENGTH_MAX_LIMIT } from "@calcom/lib/constants";
|
2022-09-06 22:58:16 +00:00
|
|
|
import { useLocale } from "@calcom/lib/hooks/useLocale";
|
2023-02-10 09:53:03 +00:00
|
|
|
import { telemetryEventTypes, useTelemetry } from "@calcom/lib/telemetry";
|
2022-09-06 22:58:16 +00:00
|
|
|
import { trpc } from "@calcom/trpc/react";
|
2022-11-23 02:55:25 +00:00
|
|
|
import { Button, TimezoneSelect } from "@calcom/ui";
|
2022-09-06 22:58:16 +00:00
|
|
|
|
2022-12-07 20:15:15 +00:00
|
|
|
import { UsernameAvailabilityField } from "@components/ui/UsernameAvailability";
|
2022-09-06 22:58:16 +00:00
|
|
|
|
2022-12-03 19:20:18 +00:00
|
|
|
import type { IOnboardingPageProps } from "../../../pages/getting-started/[[...step]]";
|
|
|
|
|
2022-09-06 22:58:16 +00:00
|
|
|
interface IUserSettingsProps {
|
2022-12-03 19:20:18 +00:00
|
|
|
user: IOnboardingPageProps["user"];
|
2022-09-06 22:58:16 +00:00
|
|
|
nextStep: () => void;
|
|
|
|
}
|
|
|
|
|
|
|
|
const UserSettings = (props: IUserSettingsProps) => {
|
|
|
|
const { user, nextStep } = props;
|
|
|
|
const { t } = useLocale();
|
2023-01-12 16:17:57 +00:00
|
|
|
const [selectedTimeZone, setSelectedTimeZone] = useState(dayjs.tz.guess());
|
2023-02-10 09:53:03 +00:00
|
|
|
const telemetry = useTelemetry();
|
2023-03-21 10:43:07 +00:00
|
|
|
const userSettingsSchema = z.object({
|
|
|
|
name: z
|
|
|
|
.string()
|
|
|
|
.min(1)
|
|
|
|
.max(FULL_NAME_LENGTH_MAX_LIMIT, {
|
|
|
|
message: t("max_limit_allowed_hint", { limit: FULL_NAME_LENGTH_MAX_LIMIT }),
|
|
|
|
}),
|
|
|
|
});
|
2022-11-08 16:36:14 +00:00
|
|
|
const {
|
|
|
|
register,
|
|
|
|
handleSubmit,
|
|
|
|
formState: { errors },
|
2023-03-21 10:43:07 +00:00
|
|
|
} = useForm<z.infer<typeof userSettingsSchema>>({
|
2022-09-06 22:58:16 +00:00
|
|
|
defaultValues: {
|
2022-11-08 16:36:14 +00:00
|
|
|
name: user?.name || "",
|
2022-09-06 22:58:16 +00:00
|
|
|
},
|
|
|
|
reValidateMode: "onChange",
|
2023-03-21 10:43:07 +00:00
|
|
|
resolver: zodResolver(userSettingsSchema),
|
2022-09-06 22:58:16 +00:00
|
|
|
});
|
2023-02-10 09:53:03 +00:00
|
|
|
|
|
|
|
useEffect(() => {
|
|
|
|
telemetry.event(telemetryEventTypes.onboardingStarted);
|
|
|
|
}, [telemetry]);
|
|
|
|
|
2022-09-06 22:58:16 +00:00
|
|
|
const utils = trpc.useContext();
|
|
|
|
const onSuccess = async () => {
|
2022-11-10 23:40:01 +00:00
|
|
|
await utils.viewer.me.invalidate();
|
2022-09-06 22:58:16 +00:00
|
|
|
nextStep();
|
|
|
|
};
|
2022-11-10 23:40:01 +00:00
|
|
|
const mutation = trpc.viewer.updateProfile.useMutation({
|
2022-09-06 22:58:16 +00:00
|
|
|
onSuccess: onSuccess,
|
|
|
|
});
|
2022-12-07 19:55:47 +00:00
|
|
|
|
2022-09-06 22:58:16 +00:00
|
|
|
const onSubmit = handleSubmit((data) => {
|
|
|
|
mutation.mutate({
|
|
|
|
name: data.name,
|
|
|
|
timeZone: selectedTimeZone,
|
|
|
|
});
|
|
|
|
});
|
2022-11-08 16:36:14 +00:00
|
|
|
|
2022-09-06 22:58:16 +00:00
|
|
|
return (
|
|
|
|
<form onSubmit={onSubmit}>
|
2022-09-07 01:34:33 +00:00
|
|
|
<div className="space-y-6">
|
2022-09-06 22:58:16 +00:00
|
|
|
{/* Username textfield */}
|
2022-12-07 20:15:15 +00:00
|
|
|
<UsernameAvailabilityField user={user} />
|
2022-09-06 22:58:16 +00:00
|
|
|
|
|
|
|
{/* Full name textfield */}
|
|
|
|
<div className="w-full">
|
|
|
|
<label htmlFor="name" className="mb-2 block text-sm font-medium text-gray-700">
|
|
|
|
{t("full_name")}
|
|
|
|
</label>
|
|
|
|
<input
|
2023-03-21 10:43:07 +00:00
|
|
|
{...register("name", {
|
|
|
|
required: true,
|
|
|
|
})}
|
2022-09-06 22:58:16 +00:00
|
|
|
id="name"
|
|
|
|
name="name"
|
|
|
|
type="text"
|
|
|
|
autoComplete="off"
|
|
|
|
autoCorrect="off"
|
|
|
|
className="w-full rounded-md border border-gray-300 text-sm"
|
|
|
|
/>
|
|
|
|
{errors.name && (
|
2022-10-01 21:01:41 +00:00
|
|
|
<p data-testid="required" className="py-2 text-xs text-red-500">
|
2023-03-21 10:43:07 +00:00
|
|
|
{errors.name.message}
|
2022-09-06 22:58:16 +00:00
|
|
|
</p>
|
|
|
|
)}
|
|
|
|
</div>
|
|
|
|
{/* Timezone select field */}
|
|
|
|
<div className="w-full">
|
|
|
|
<label htmlFor="timeZone" className="block text-sm font-medium text-gray-700">
|
|
|
|
{t("timezone")}
|
|
|
|
</label>
|
|
|
|
|
|
|
|
<TimezoneSelect
|
|
|
|
id="timeZone"
|
|
|
|
value={selectedTimeZone}
|
|
|
|
onChange={({ value }) => setSelectedTimeZone(value)}
|
|
|
|
className="mt-2 w-full rounded-md text-sm"
|
|
|
|
/>
|
|
|
|
|
2022-09-07 01:34:33 +00:00
|
|
|
<p className="mt-3 flex flex-row font-sans text-xs leading-tight text-gray-500 dark:text-white">
|
|
|
|
{t("current_time")} {dayjs().tz(selectedTimeZone).format("LT").toString().toLowerCase()}
|
2022-09-06 22:58:16 +00:00
|
|
|
</p>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
<Button
|
|
|
|
type="submit"
|
|
|
|
className="mt-8 flex w-full flex-row justify-center"
|
|
|
|
disabled={mutation.isLoading}>
|
|
|
|
{t("next_step_text")}
|
|
|
|
<ArrowRightIcon className="ml-2 h-4 w-4 self-center" aria-hidden="true" />
|
|
|
|
</Button>
|
|
|
|
</form>
|
|
|
|
);
|
|
|
|
};
|
|
|
|
|
|
|
|
export { UserSettings };
|