📈 Improvements to posthog analytics data (#1189)

This commit is contained in:
Luke Vella 2024-07-03 12:09:58 +01:00 committed by GitHub
parent 278713d57f
commit 587e11de17
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
10 changed files with 93 additions and 80 deletions

View file

@ -5,6 +5,8 @@ import React from "react";
import { z } from "zod";
import { useTranslation } from "@/app/i18n/client";
import { Spinner } from "@/components/spinner";
import { useSubscription } from "@/contexts/plan";
import { PostHogProvider } from "@/contexts/posthog";
import { PreferencesProvider } from "@/contexts/preferences";
@ -15,6 +17,7 @@ const userSchema = z.object({
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(),
@ -50,15 +53,22 @@ export const IfGuest = (props: { children?: React.ReactNode }) => {
export const UserProvider = (props: { children?: React.ReactNode }) => {
const session = useSession();
const user = session.data?.user;
const subscription = useSubscription();
const { t } = useTranslation();
if (!user) {
return null;
return (
<div className="flex h-screen items-center justify-center">
<Spinner />
</div>
);
}
const isGuest = !user.email;
const tier = isGuest ? "guest" : subscription?.active ? "pro" : "hobby";
return (
<UserContext.Provider
value={{
@ -66,7 +76,8 @@ export const UserProvider = (props: { children?: React.ReactNode }) => {
id: user.id as string,
name: user.name ?? t("guest"),
email: user.email || null,
isGuest: user.email === null,
isGuest: !user.email,
tier,
},
refresh: session.update,
ownsObject: ({ userId }) => {