This commit is contained in:
Mythie
2025-01-02 15:33:37 +11:00
committed by David Nguyen
parent 9183f668d3
commit f7a98180d7
413 changed files with 29538 additions and 1606 deletions

View File

@ -0,0 +1,29 @@
import { createContext, useContext } from 'react';
import React from 'react';
import type { Session, User } from '@prisma/client';
interface AuthProviderProps {
children: React.ReactNode;
session: Session;
user: User;
}
const AuthContext = createContext<{
user: User; // Todo: Exclude password
session: Session;
} | null>(null);
export const useAuth = () => {
const context = useContext(AuthContext);
if (!context) {
throw new Error('useAuth must be used within a AuthProvider');
}
return context;
};
export const AuthProvider = ({ children, session, user }: AuthProviderProps) => {
return <AuthContext.Provider value={{ session, user }}>{children}</AuthContext.Provider>;
};

View File

@ -0,0 +1,10 @@
'use client';
import * as React from 'react';
import { ThemeProvider as NextThemesProvider } from 'next-themes';
import type { ThemeProviderProps } from 'next-themes/dist/types';
export function ThemeProvider({ children, ...props }: ThemeProviderProps) {
return <NextThemesProvider {...props}>{children}</NextThemesProvider>;
}

View File

@ -0,0 +1,13 @@
'use client';
import React from 'react';
import NextPlausibleProvider from 'next-plausible';
export type PlausibleProviderProps = {
children: React.ReactNode;
};
export const PlausibleProvider = ({ children }: PlausibleProviderProps) => {
return <NextPlausibleProvider domain="documenso.com">{children}</NextPlausibleProvider>;
};

View File

@ -0,0 +1,51 @@
import { useEffect } from 'react';
import { getSession } from 'next-auth/react';
import posthog from 'posthog-js';
import { useLocation, useSearchParams } from 'react-router';
import { extractPostHogConfig } from '@documenso/lib/constants/feature-flags';
export function PostHogPageview() {
const postHogConfig = extractPostHogConfig();
const { pathname } = useLocation();
const [searchParams] = useSearchParams();
if (typeof window !== 'undefined' && postHogConfig) {
posthog.init(postHogConfig.key, {
api_host: postHogConfig.host,
disable_session_recording: true,
loaded: () => {
getSession()
.then((session) => {
if (session) {
posthog.identify(session.user.email ?? session.user.id.toString());
} else {
posthog.reset();
}
})
.catch(() => {
// Do nothing.
});
},
custom_campaign_params: ['src'],
});
}
useEffect(() => {
if (!postHogConfig || !pathname) {
return;
}
let url = window.origin + pathname;
if (searchParams && searchParams.toString()) {
url = url + `?${searchParams.toString()}`;
}
posthog.capture('$pageview', {
$current_url: url,
});
}, [pathname, searchParams, postHogConfig]);
return null;
}

View File

@ -0,0 +1,29 @@
import { createContext, useContext } from 'react';
import React from 'react';
import type { TGetTeamByIdResponse } from '@documenso/lib/server-only/team/get-team';
interface TeamProviderProps {
children: React.ReactNode;
team: TGetTeamByIdResponse;
}
const TeamContext = createContext<TGetTeamByIdResponse | null>(null);
export const useCurrentTeam = () => {
const context = useContext(TeamContext);
if (!context) {
throw new Error('useCurrentTeam must be used within a TeamProvider');
}
return context;
};
export const useOptionalCurrentTeam = () => {
return useContext(TeamContext);
};
export const TeamProvider = ({ children, team }: TeamProviderProps) => {
return <TeamContext.Provider value={team}>{children}</TeamContext.Provider>;
};