import { useEffect, Fragment } from "react"; import { observer } from "mobx-react-lite"; import { useRouter } from "next/router"; import { Controller, useForm } from "react-hook-form"; import { Check, ChevronDown } from "lucide-react"; import { Listbox, Transition } from "@headlessui/react"; // mobx store import { Button, Input } from "@plane/ui"; import { USER_ROLES } from "@/constants/workspace"; import { useMobxStore } from "@/lib/mobx/store-provider"; // constants // hooks import { UserService } from "@/services/user.service"; import useToast from "hooks/use-toast"; // services // 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-custom-background-80" : "" } ${selected ? "text-custom-text-100" : "text-custom-text-200"}` } > {({ selected }) => (
{role.label}
{selected && }
)}
))}
)} /> {errors.role && {errors.role.message}}
); });