import { useEffect, Fragment } from "react"; import { useRouter } from "next/router"; // react-hook-form import { Controller, useForm } from "react-hook-form"; // mobx import { observer } from "mobx-react-lite"; import { useMobxStore } from "lib/mobx/store-provider"; // headless ui import { Listbox, Transition } from "@headlessui/react"; // icons import { ChevronDownIcon, CheckIcon } from "@heroicons/react/20/solid"; // constants import { USER_ROLES } from "constants/workspace"; // hooks import useToast from "hooks/use-toast"; // services import UserService from "services/user.service"; // ui import { Input, PrimaryButton } from "components/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.", }); }) .catch((err) => {}); }; 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}}
{isSubmitting ? "Updating..." : "Continue"}
); });