import { useEffect, Fragment } from "react"; import { useRouter } from "next/router"; import { observer } from "mobx-react-lite"; import { Controller, useForm } from "react-hook-form"; import { Listbox, Transition } from "@headlessui/react"; import { Check, ChevronDown } from "lucide-react"; // mobx store import { useMobxStore } from "lib/mobx/store-provider"; // constants import { USER_ROLES } from "constants/workspace"; // hooks import useToast from "hooks/use-toast"; // services import { UserService } from "services/user.service"; // ui import { Button, Input } from "@plane/ui"; const defaultValues = { first_name: "", last_name: "", role: "", }; type Props = { user?: any; }; export const OnBoardingForm: React.FC = observer(({ user }) => { const { setToastAlert } = useToast(); const router = useRouter(); const { next_path } = router.query; const { user: userStore } = useMobxStore(); const { register, handleSubmit, control, reset, formState: { errors, isSubmitting, isValid }, } = useForm({ defaultValues, }); const onSubmit = async (formData: any) => { const payload = { ...formData, onboarding_step: { ...user.onboarding_step, profile_complete: true, }, }; const userService = new UserService(); await userService.updateMe(payload).then((response) => { userStore.setCurrentUser(response); router.push(next_path?.toString() || "/"); setToastAlert({ type: "success", title: "Success!", message: "Details updated successfully.", }); }); }; useEffect(() => { if (user) { reset({ first_name: user.first_name, last_name: user.last_name, role: user.role, }); } }, [user, reset]); return (
{'"'}
Hey there 👋🏻
Let{"'"}s get you onboard!

Set up your Plane profile.

{errors.first_name &&
{errors.first_name.message}
}
{errors.last_name &&
{errors.last_name.message}
}
What{"'"}s your role?
( {value || "Select your role..."}
{USER_ROLES.map((role) => ( `cursor-pointer select-none truncate rounded px-1 py-1.5 ${ active || selected ? "bg-neutral-component-surface-dark" : "" } ${selected ? "text-neutral-text-strong" : "text-neutral-text-medium"}` } > {({ selected }) => (
{role.label}
{selected && }
)}
))}
)} /> {errors.role && {errors.role.message}}
); });