feat: added user role on onboarding event (#684)

* feat: added tracker for views

* feat: added user role on onboarding event
This commit is contained in:
Dakshesh Jain 2023-04-03 23:57:19 +05:30 committed by GitHub
parent a1f0f43992
commit 67952bc225
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 22 additions and 9 deletions

View File

@ -22,9 +22,10 @@ const defaultValues: Partial<IUser> = {
type Props = { type Props = {
user?: IUser; user?: IUser;
setStep: React.Dispatch<React.SetStateAction<number>>; setStep: React.Dispatch<React.SetStateAction<number>>;
setUserRole: React.Dispatch<React.SetStateAction<string | null>>;
}; };
export const UserDetails: React.FC<Props> = ({ user, setStep }) => { export const UserDetails: React.FC<Props> = ({ user, setStep, setUserRole }) => {
const { setToastAlert } = useToast(); const { setToastAlert } = useToast();
const { const {
@ -53,13 +54,15 @@ export const UserDetails: React.FC<Props> = ({ user, setStep }) => {
}; };
useEffect(() => { useEffect(() => {
if (user) if (user) {
reset({ reset({
first_name: user.first_name, first_name: user.first_name,
last_name: user.last_name, last_name: user.last_name,
role: user.role, role: user.role,
}); });
}, [user, reset]); setUserRole(user.role);
}
}, [user, reset, setUserRole]);
return ( return (
<form className="flex w-full items-center justify-center" onSubmit={handleSubmit(onSubmit)}> <form className="flex w-full items-center justify-center" onSubmit={handleSubmit(onSubmit)}>
@ -101,7 +104,10 @@ export const UserDetails: React.FC<Props> = ({ user, setStep }) => {
render={({ field: { value, onChange } }) => ( render={({ field: { value, onChange } }) => (
<CustomSelect <CustomSelect
value={value} value={value}
onChange={onChange} onChange={(value: any) => {
onChange(value);
setUserRole(value ?? null);
}}
label={value ? value.toString() : "Select your role"} label={value ? value.toString() : "Select your role"}
input input
width="w-full" width="w-full"

View File

@ -24,6 +24,7 @@ import type { NextPage, GetServerSidePropsContext } from "next";
const Onboarding: NextPage = () => { const Onboarding: NextPage = () => {
const [step, setStep] = useState(1); const [step, setStep] = useState(1);
const [userRole, setUserRole] = useState<string | null>(null);
const [workspace, setWorkspace] = useState(); const [workspace, setWorkspace] = useState();
@ -40,7 +41,7 @@ const Onboarding: NextPage = () => {
<Image src={Logo} height="50" alt="Plane Logo" /> <Image src={Logo} height="50" alt="Plane Logo" />
</div> </div>
{step === 1 ? ( {step === 1 ? (
<UserDetails user={user} setStep={setStep} /> <UserDetails user={user} setStep={setStep} setUserRole={setUserRole} />
) : step === 2 ? ( ) : step === 2 ? (
<Workspace setStep={setStep} setWorkspace={setWorkspace} /> <Workspace setStep={setStep} setWorkspace={setWorkspace} />
) : ( ) : (
@ -69,7 +70,7 @@ const Onboarding: NextPage = () => {
onClick={() => { onClick={() => {
if (step === 8) { if (step === 8) {
userService userService
.updateUserOnBoard() .updateUserOnBoard({ userRole })
.then(() => { .then(() => {
router.push("/"); router.push("/");
}) })

View File

@ -47,10 +47,16 @@ class UserService extends APIService {
}); });
} }
async updateUserOnBoard(): Promise<any> { async updateUserOnBoard({ userRole }: any): Promise<any> {
return this.patch("/api/users/me/onboard/", { is_onboarded: true }) return this.patch("/api/users/me/onboard/", {
is_onboarded: true,
})
.then((response) => { .then((response) => {
if (trackEvent) trackEventServices.trackUserOnboardingCompleteEvent(response.data); if (trackEvent)
trackEventServices.trackUserOnboardingCompleteEvent({
...response.data,
user_role: userRole ?? "None",
});
return response?.data; return response?.data;
}) })
.catch((error) => { .catch((error) => {