chore: user properties update

This commit is contained in:
LAKHAN BAHETI 2024-02-21 14:12:18 +05:30
parent 8cd651f1a5
commit 64fe785722
3 changed files with 9 additions and 15 deletions

View File

@ -33,10 +33,7 @@ export interface IAppProvider {
export const AppProvider: FC<IAppProvider> = observer((props) => { export const AppProvider: FC<IAppProvider> = observer((props) => {
const { children } = props; const { children } = props;
// store hooks // store hooks
const { const { currentUser } = useUser();
currentUser,
membership: { currentWorkspaceRole },
} = useUser();
const { currentWorkspace, workspaces } = useWorkspace(); const { currentWorkspace, workspaces } = useWorkspace();
const { const {
config: { envConfig }, config: { envConfig },
@ -50,8 +47,7 @@ export const AppProvider: FC<IAppProvider> = observer((props) => {
<CrispWrapper user={currentUser}> <CrispWrapper user={currentUser}>
<PostHogProvider <PostHogProvider
user={currentUser} user={currentUser}
currentWorkspaceId= {currentWorkspace?.id} currentWorkspaceId={currentWorkspace?.id}
workspaceRole={currentWorkspaceRole}
workspaces={workspaces} workspaces={workspaces}
posthogAPIKey={envConfig?.posthog_api_key || null} posthogAPIKey={envConfig?.posthog_api_key || null}
posthogHost={envConfig?.posthog_host || null} posthogHost={envConfig?.posthog_host || null}

View File

@ -3,24 +3,21 @@ import { useRouter } from "next/router";
import posthog from "posthog-js"; import posthog from "posthog-js";
import { PostHogProvider as PHProvider } from "posthog-js/react"; import { PostHogProvider as PHProvider } from "posthog-js/react";
// mobx store provider // mobx store provider
import { IUser } from "@plane/types"; import { IUser, IWorkspace } from "@plane/types";
// helpers
import { getUserRole } from "helpers/user.helper";
// constants // constants
import { GROUP_WORKSPACE } from "constants/event-tracker"; import { GROUP_WORKSPACE } from "constants/event-tracker";
export interface IPosthogWrapper { export interface IPosthogWrapper {
children: ReactNode; children: ReactNode;
user: IUser | null; user: IUser | null;
workspaces: Record<string, IWorkspace>;
currentWorkspaceId: string | undefined; currentWorkspaceId: string | undefined;
workspaceRole: number | undefined;
projectRole: number | undefined;
posthogAPIKey: string | null; posthogAPIKey: string | null;
posthogHost: string | null; posthogHost: string | null;
} }
const PostHogProvider: FC<IPosthogWrapper> = (props) => { const PostHogProvider: FC<IPosthogWrapper> = (props) => {
const { children, user, workspaceRole, currentWorkspaceId, projectRole, posthogAPIKey, posthogHost } = props; const { children, user, workspaces, currentWorkspaceId, posthogAPIKey, posthogHost } = props;
// states // states
const [lastWorkspaceId, setLastWorkspaceId] = useState(currentWorkspaceId); const [lastWorkspaceId, setLastWorkspaceId] = useState(currentWorkspaceId);
// router // router
@ -35,11 +32,10 @@ const PostHogProvider: FC<IPosthogWrapper> = (props) => {
last_name: user.last_name, last_name: user.last_name,
email: user.email, email: user.email,
use_case: user.use_case, use_case: user.use_case,
workspace_role: workspaceRole ? getUserRole(workspaceRole) : undefined, workspaces: Object.keys(workspaces),
project_role: projectRole ? getUserRole(projectRole) : undefined,
}); });
} }
}, [user, workspaceRole, projectRole]); }, [user, workspaces]);
useEffect(() => { useEffect(() => {
if (posthogAPIKey && posthogHost) { if (posthogAPIKey && posthogHost) {

View File

@ -62,12 +62,14 @@ export class EventTrackerStore implements IEventTrackerStore {
* @description: Returns the necessary property for the event tracking * @description: Returns the necessary property for the event tracking
*/ */
get getRequiredProperties() { get getRequiredProperties() {
const currentWorkspaceRole = this.rootStore.user.membership.currentWorkspaceRole;
const currentWorkspaceDetails = this.rootStore.workspaceRoot.currentWorkspace; const currentWorkspaceDetails = this.rootStore.workspaceRoot.currentWorkspace;
const currentProjectDetails = this.rootStore.projectRoot.project.currentProjectDetails; const currentProjectDetails = this.rootStore.projectRoot.project.currentProjectDetails;
return { return {
workspace_id: currentWorkspaceDetails?.id, workspace_id: currentWorkspaceDetails?.id,
project_id: currentProjectDetails?.id, project_id: currentProjectDetails?.id,
user_project_role: getUserRole(currentProjectDetails?.member_role as number), user_project_role: getUserRole(currentProjectDetails?.member_role as number),
user_workspace_role: getUserRole(currentWorkspaceRole as number),
}; };
} }