mirror of
https://github.com/lukevella/rallly.git
synced 2025-06-05 20:21:50 +02:00
📈 Improvements to posthog analytics data (#1189)
This commit is contained in:
parent
278713d57f
commit
587e11de17
10 changed files with 93 additions and 80 deletions
|
@ -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 }) => {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue