Rallly is an open-source scheduling and collaboration tool designed to make organizing events and meetings easier.
TypeScript i18nextnext-authnextjspostgresqlprismareact-emailt3-stacktailwindcsstrpcturborepotypescriptzod
📈 Update posthog user profile
Luke Vellaedf8e938087e
diff --git a/apps/web/src/components/user-provider.tsx b/apps/web/src/components/user-provider.tsxindex 86903fe0d..a9f24c75a 100644--- a/apps/web/src/components/user-provider.tsx+++ b/apps/web/src/components/user-provider.tsx@@ -2,7 +2,6 @@import { Session } from "next-auth";import { useSession } from "next-auth/react";import React from "react";-import { z } from "zod";import { useTranslation } from "@/app/i18n/client";import { Spinner } from "@/components/spinner";@@ -13,20 +12,21 @@ import { trpc } from "@/utils/trpc/client";import { useRequiredContext } from "./use-required-context";-const userSchema = z.object({- id: z.string(),- name: z.string(),- email: z.string().email().nullable(),- isGuest: z.boolean(),- tier: z.enum(["guest", "hobby", "pro"]),- timeZone: z.string().nullish(),- timeFormat: z.enum(["hours12", "hours24"]).nullish(),- weekStart: z.number().min(0).max(6).nullish(),- image: z.string().nullish(),-});+type UserData = {+ id: string;+ name: string;+ email?: string | null;+ isGuest: boolean;+ tier: "guest" | "hobby" | "pro";+ timeZone?: string | null;+ timeFormat?: "hours12" | "hours24" | null;+ weekStart?: number | null;+ image?: string | null;+ locale?: string | null;+};export const UserContext = React.createContext<{- user: z.infer<typeof userSchema>;+ user: UserData;refresh: (data?: Record<string, unknown>) => Promise<Session | null>;ownsObject: (obj: { userId?: string | null }) => boolean;} | null>(null);@@ -58,7 +58,7 @@ export const UserProvider = (props: { children?: React.ReactNode }) => {const user = session.data?.user;const subscription = useSubscription();const updatePreferences = trpc.user.updatePreferences.useMutation();- const { t } = useTranslation();+ const { t, i18n } = useTranslation();if (!user) {return (@@ -82,6 +82,7 @@ export const UserProvider = (props: { children?: React.ReactNode }) => {tier,timeZone: user.timeZone ?? null,image: user.image ?? null,+ locale: user.locale ?? i18n.language,},refresh: session.update,ownsObject: ({ userId }) => {diff --git a/apps/web/src/contexts/posthog.tsx b/apps/web/src/contexts/posthog.tsxindex 8838a92b7..602b7dee2 100644--- a/apps/web/src/contexts/posthog.tsx+++ b/apps/web/src/contexts/posthog.tsx@@ -5,7 +5,6 @@ import { PostHogProvider as Provider, usePostHog } from "posthog-js/react";import React from "react";import { useMount } from "react-use";-import { useTranslation } from "@/app/i18n/client";import { useUser } from "@/components/user-provider";import { env } from "@/env";@@ -49,22 +48,17 @@ function usePostHogPageView() {export function PostHogProvider(props: PostHogProviderProps) {const { user } = useUser();- const { i18n } = useTranslation();usePostHogPageView();useMount(() => {- if (user.email) {- posthog.identify(user.id, {- email: user.email,- name: user.name,- tier: user.tier,- timeZone: user.timeZone,- locale: i18n.language,- });- } else {- posthog.alias(user.id);- }+ posthog.identify(user.id, {+ email: user.email,+ name: user.name,+ tier: user.tier,+ timeZone: user.timeZone,+ locale: user.locale,+ });});return <Provider client={posthog}>{props.children}</Provider>;