From 67952bc225e09efb486ab1c6db603bca1f313387 Mon Sep 17 00:00:00 2001 From: Dakshesh Jain <65905942+dakshesh14@users.noreply.github.com> Date: Mon, 3 Apr 2023 23:57:19 +0530 Subject: [PATCH] feat: added user role on onboarding event (#684) * feat: added tracker for views * feat: added user role on onboarding event --- apps/app/components/onboarding/user-details.tsx | 14 ++++++++++---- apps/app/pages/onboarding.tsx | 5 +++-- apps/app/services/user.service.ts | 12 +++++++++--- 3 files changed, 22 insertions(+), 9 deletions(-) diff --git a/apps/app/components/onboarding/user-details.tsx b/apps/app/components/onboarding/user-details.tsx index febfc0a39..ab7af9ab3 100644 --- a/apps/app/components/onboarding/user-details.tsx +++ b/apps/app/components/onboarding/user-details.tsx @@ -22,9 +22,10 @@ const defaultValues: Partial = { type Props = { user?: IUser; setStep: React.Dispatch>; + setUserRole: React.Dispatch>; }; -export const UserDetails: React.FC = ({ user, setStep }) => { +export const UserDetails: React.FC = ({ user, setStep, setUserRole }) => { const { setToastAlert } = useToast(); const { @@ -53,13 +54,15 @@ export const UserDetails: React.FC = ({ user, setStep }) => { }; useEffect(() => { - if (user) + if (user) { reset({ first_name: user.first_name, last_name: user.last_name, role: user.role, }); - }, [user, reset]); + setUserRole(user.role); + } + }, [user, reset, setUserRole]); return (
@@ -101,7 +104,10 @@ export const UserDetails: React.FC = ({ user, setStep }) => { render={({ field: { value, onChange } }) => ( { + onChange(value); + setUserRole(value ?? null); + }} label={value ? value.toString() : "Select your role"} input width="w-full" diff --git a/apps/app/pages/onboarding.tsx b/apps/app/pages/onboarding.tsx index b2a7e987f..0c1c95326 100644 --- a/apps/app/pages/onboarding.tsx +++ b/apps/app/pages/onboarding.tsx @@ -24,6 +24,7 @@ import type { NextPage, GetServerSidePropsContext } from "next"; const Onboarding: NextPage = () => { const [step, setStep] = useState(1); + const [userRole, setUserRole] = useState(null); const [workspace, setWorkspace] = useState(); @@ -40,7 +41,7 @@ const Onboarding: NextPage = () => { Plane Logo {step === 1 ? ( - + ) : step === 2 ? ( ) : ( @@ -69,7 +70,7 @@ const Onboarding: NextPage = () => { onClick={() => { if (step === 8) { userService - .updateUserOnBoard() + .updateUserOnBoard({ userRole }) .then(() => { router.push("/"); }) diff --git a/apps/app/services/user.service.ts b/apps/app/services/user.service.ts index 95f42554d..cab79ab3a 100644 --- a/apps/app/services/user.service.ts +++ b/apps/app/services/user.service.ts @@ -47,10 +47,16 @@ class UserService extends APIService { }); } - async updateUserOnBoard(): Promise { - return this.patch("/api/users/me/onboard/", { is_onboarded: true }) + async updateUserOnBoard({ userRole }: any): Promise { + return this.patch("/api/users/me/onboard/", { + is_onboarded: true, + }) .then((response) => { - if (trackEvent) trackEventServices.trackUserOnboardingCompleteEvent(response.data); + if (trackEvent) + trackEventServices.trackUserOnboardingCompleteEvent({ + ...response.data, + user_role: userRole ?? "None", + }); return response?.data; }) .catch((error) => {