2023-09-01 11:12:30 +00:00
|
|
|
import { useEffect, Fragment } from "react";
|
|
|
|
import { useRouter } from "next/router";
|
|
|
|
import { observer } from "mobx-react-lite";
|
2023-10-20 12:21:01 +00:00
|
|
|
import { Controller, useForm } from "react-hook-form";
|
2023-09-01 11:12:30 +00:00
|
|
|
import { Listbox, Transition } from "@headlessui/react";
|
2023-10-20 12:21:01 +00:00
|
|
|
import { Check, ChevronDown } from "lucide-react";
|
|
|
|
// mobx store
|
|
|
|
import { useMobxStore } from "lib/mobx/store-provider";
|
2023-09-01 11:12:30 +00:00
|
|
|
// constants
|
|
|
|
import { USER_ROLES } from "constants/workspace";
|
|
|
|
// hooks
|
|
|
|
import useToast from "hooks/use-toast";
|
|
|
|
// services
|
2023-12-06 11:12:57 +00:00
|
|
|
import { UserService } from "services/user.service";
|
2023-09-01 11:12:30 +00:00
|
|
|
// ui
|
2023-12-05 10:37:25 +00:00
|
|
|
import { Button, Input } from "@plane/ui";
|
2023-09-01 11:12:30 +00:00
|
|
|
|
|
|
|
const defaultValues = {
|
|
|
|
first_name: "",
|
|
|
|
last_name: "",
|
|
|
|
role: "",
|
|
|
|
};
|
|
|
|
|
|
|
|
type Props = {
|
|
|
|
user?: any;
|
|
|
|
};
|
|
|
|
|
|
|
|
export const OnBoardingForm: React.FC<Props> = 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();
|
|
|
|
|
2023-10-20 12:21:01 +00:00
|
|
|
await userService.updateMe(payload).then((response) => {
|
|
|
|
userStore.setCurrentUser(response);
|
|
|
|
router.push(next_path?.toString() || "/");
|
|
|
|
setToastAlert({
|
|
|
|
type: "success",
|
|
|
|
title: "Success!",
|
|
|
|
message: "Details updated successfully.",
|
|
|
|
});
|
|
|
|
});
|
2023-09-01 11:12:30 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
useEffect(() => {
|
|
|
|
if (user) {
|
|
|
|
reset({
|
|
|
|
first_name: user.first_name,
|
|
|
|
last_name: user.last_name,
|
|
|
|
role: user.role,
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}, [user, reset]);
|
|
|
|
|
|
|
|
return (
|
|
|
|
<form
|
2023-12-10 10:18:10 +00:00
|
|
|
className="h-full w-full space-y-7 overflow-y-auto sm:flex sm:flex-col sm:items-start sm:justify-center sm:space-y-10"
|
2023-09-01 11:12:30 +00:00
|
|
|
onSubmit={handleSubmit(onSubmit)}
|
|
|
|
>
|
|
|
|
<div className="relative sm:text-lg">
|
2023-12-10 10:18:10 +00:00
|
|
|
<div className="absolute -left-3 -top-1 text-gray-800">{'"'}</div>
|
2023-09-01 11:12:30 +00:00
|
|
|
<h5>Hey there 👋🏻</h5>
|
2023-12-10 10:18:10 +00:00
|
|
|
<h5 className="mb-6 mt-5">Let{"'"}s get you onboard!</h5>
|
|
|
|
<h4 className="text-xl font-semibold sm:text-2xl">Set up your Plane profile.</h4>
|
2023-09-01 11:12:30 +00:00
|
|
|
</div>
|
|
|
|
|
|
|
|
<div className="space-y-7 sm:w-3/4 md:w-2/5">
|
|
|
|
<div className="space-y-1 text-sm">
|
|
|
|
<label htmlFor="firstName">First Name</label>
|
|
|
|
<Input
|
|
|
|
id="firstName"
|
|
|
|
autoComplete="off"
|
2023-12-06 11:12:57 +00:00
|
|
|
className="w-full"
|
2023-09-01 11:12:30 +00:00
|
|
|
placeholder="Enter your first name..."
|
|
|
|
{...register("first_name", {
|
|
|
|
required: "First name is required",
|
|
|
|
})}
|
|
|
|
/>
|
|
|
|
{errors.first_name && <div className="text-sm text-red-500">{errors.first_name.message}</div>}
|
|
|
|
</div>
|
|
|
|
<div className="space-y-1 text-sm">
|
|
|
|
<label htmlFor="lastName">Last Name</label>
|
|
|
|
<Input
|
|
|
|
id="lastName"
|
|
|
|
autoComplete="off"
|
2023-12-06 11:12:57 +00:00
|
|
|
className="w-full"
|
2023-09-01 11:12:30 +00:00
|
|
|
placeholder="Enter your last name..."
|
|
|
|
{...register("last_name", {
|
|
|
|
required: "Last name is required",
|
|
|
|
})}
|
|
|
|
/>
|
|
|
|
{errors.last_name && <div className="text-sm text-red-500">{errors.last_name.message}</div>}
|
|
|
|
</div>
|
|
|
|
<div className="space-y-1 text-sm">
|
|
|
|
<span>What{"'"}s your role?</span>
|
|
|
|
<div className="w-full">
|
|
|
|
<Controller
|
|
|
|
name="role"
|
|
|
|
control={control}
|
|
|
|
rules={{ required: "This field is required" }}
|
|
|
|
render={({ field: { value, onChange } }) => (
|
|
|
|
<Listbox as="div" value={value} onChange={onChange} className="relative flex-shrink-0 text-left">
|
|
|
|
<Listbox.Button
|
|
|
|
type="button"
|
2024-01-29 08:17:56 +00:00
|
|
|
className={`flex w-full items-center justify-between gap-1 rounded-md border border-neutral-border-medium px-3 py-2 text-sm shadow-sm duration-300 focus:outline-none`}
|
2023-09-01 11:12:30 +00:00
|
|
|
>
|
2024-02-08 12:53:13 +00:00
|
|
|
<span className={value ? "" : "text-neutral-text-subtle"}>{value || "Select your role..."}</span>
|
2023-10-20 12:21:01 +00:00
|
|
|
<ChevronDown className="h-3 w-3" aria-hidden="true" strokeWidth={2} />
|
2023-09-01 11:12:30 +00:00
|
|
|
</Listbox.Button>
|
|
|
|
|
|
|
|
<Transition
|
|
|
|
as={Fragment}
|
|
|
|
enter="transition ease-out duration-100"
|
|
|
|
enterFrom="transform opacity-0 scale-95"
|
|
|
|
enterTo="transform opacity-100 scale-100"
|
|
|
|
leave="transition ease-in duration-75"
|
|
|
|
leaveFrom="transform opacity-100 scale-100"
|
|
|
|
leaveTo="transform opacity-0 scale-95"
|
|
|
|
>
|
|
|
|
<Listbox.Options
|
2024-01-30 06:46:21 +00:00
|
|
|
className={`absolute left-0 z-10 mt-1 max-h-36 w-full origin-top-left overflow-y-auto rounded-md border border-neutral-border-medium bg-neutral-component-surface-medium text-xs shadow-lg focus:outline-none`}
|
2023-09-01 11:12:30 +00:00
|
|
|
>
|
|
|
|
<div className="space-y-1 p-2">
|
|
|
|
{USER_ROLES.map((role) => (
|
|
|
|
<Listbox.Option
|
|
|
|
key={role.value}
|
|
|
|
value={role.value}
|
|
|
|
className={({ active, selected }) =>
|
|
|
|
`cursor-pointer select-none truncate rounded px-1 py-1.5 ${
|
2024-01-30 06:46:21 +00:00
|
|
|
active || selected ? "bg-neutral-component-surface-dark" : ""
|
2024-02-08 12:53:13 +00:00
|
|
|
} ${selected ? "text-neutral-text-strong" : "text-neutral-text-medium"}`
|
2023-09-01 11:12:30 +00:00
|
|
|
}
|
|
|
|
>
|
|
|
|
{({ selected }) => (
|
|
|
|
<div className="flex items-center justify-between gap-2">
|
|
|
|
<div className="flex items-center gap-2">
|
|
|
|
<span>{role.label}</span>
|
|
|
|
</div>
|
2023-10-20 12:21:01 +00:00
|
|
|
{selected && <Check className="h-3 w-3 flex-shrink-0" strokeWidth={2} />}
|
2023-09-01 11:12:30 +00:00
|
|
|
</div>
|
|
|
|
)}
|
|
|
|
</Listbox.Option>
|
|
|
|
))}
|
|
|
|
</div>
|
|
|
|
</Listbox.Options>
|
|
|
|
</Transition>
|
|
|
|
</Listbox>
|
|
|
|
)}
|
|
|
|
/>
|
|
|
|
{errors.role && <span className="text-sm text-red-500">{errors.role.message}</span>}
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
|
2023-12-06 11:12:57 +00:00
|
|
|
<Button variant="primary" type="submit" size="xl" disabled={!isValid} loading={isSubmitting}>
|
2023-09-01 11:12:30 +00:00
|
|
|
{isSubmitting ? "Updating..." : "Continue"}
|
2023-12-05 10:37:25 +00:00
|
|
|
</Button>
|
2023-09-01 11:12:30 +00:00
|
|
|
</form>
|
|
|
|
);
|
|
|
|
});
|