import { useEffect } from "react"; import { mutate } from "swr"; // react-hook-form import { Controller, useForm } from "react-hook-form"; // hooks import useToast from "hooks/use-toast"; // services import userService from "services/user.service"; // ui import { CustomSelect, Input, PrimaryButton } from "components/ui"; // types import { ICurrentUserResponse, IUser } from "types"; // fetch-keys import { CURRENT_USER } from "constants/fetch-keys"; // constants import { USER_ROLES } from "constants/workspace"; const defaultValues: Partial = { first_name: "", last_name: "", role: "", }; type Props = { user?: IUser; }; export const UserDetails: React.FC = ({ user }) => { const { setToastAlert } = useToast(); const { register, handleSubmit, control, reset, formState: { errors, isSubmitting, isValid }, } = useForm({ defaultValues, }); const onSubmit = async (formData: IUser) => { if (!user) return; const payload: Partial = { ...formData, onboarding_step: { ...user.onboarding_step, profile_complete: true, }, }; await userService .updateUser(payload) .then(() => { mutate( CURRENT_USER, (prevData) => { if (!prevData) return prevData; return { ...prevData, ...payload, }; }, false ); setToastAlert({ type: "success", title: "Success!", message: "Details updated successfully.", }); }) .catch((err) => { mutate(CURRENT_USER); }); }; 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.

What{"'"}s your role?
( onChange(val)} label={ value ? ( value.toString() ) : ( Select your role... ) } input width="w-full" verticalPosition="top" > {USER_ROLES.map((item) => ( {item.label} ))} )} /> {errors.role && {errors.role.message}}
{isSubmitting ? "Updating..." : "Continue"}
); };