add stripe (#121)
* add some stripe stuff * more stripe stuff * more stripe things * more stripr stuff * more stripe stuff * more stripe stuff * add more stuff * add more stripe stuff * more stuff * fix types
This commit is contained in:
@@ -6,6 +6,7 @@ import { AddSesSettings } from "~/components/settings/AddSesSettings";
|
||||
import CreateTeam from "~/components/team/CreateTeam";
|
||||
import { env } from "~/env";
|
||||
import { api } from "~/trpc/react";
|
||||
import { TeamProvider } from "./team-context";
|
||||
|
||||
export const DashboardProvider = ({
|
||||
children,
|
||||
@@ -37,5 +38,5 @@ export const DashboardProvider = ({
|
||||
return <CreateTeam />;
|
||||
}
|
||||
|
||||
return <>{children}</>;
|
||||
return <TeamProvider>{children}</TeamProvider>;
|
||||
};
|
||||
|
43
apps/web/src/providers/team-context.tsx
Normal file
43
apps/web/src/providers/team-context.tsx
Normal file
@@ -0,0 +1,43 @@
|
||||
"use client";
|
||||
|
||||
import { createContext, useContext, useState, useEffect } from "react";
|
||||
import { api } from "~/trpc/react";
|
||||
|
||||
// Define the Team type based on the Prisma schema
|
||||
type Team = {
|
||||
id: number;
|
||||
name: string;
|
||||
createdAt: Date;
|
||||
updatedAt: Date;
|
||||
plan: "FREE" | "BASIC";
|
||||
stripeCustomerId?: string | null;
|
||||
billingEmail?: string | null;
|
||||
};
|
||||
|
||||
interface TeamContextType {
|
||||
currentTeam: Team | null;
|
||||
teams: Team[];
|
||||
isLoading: boolean;
|
||||
}
|
||||
|
||||
const TeamContext = createContext<TeamContextType | undefined>(undefined);
|
||||
|
||||
export function TeamProvider({ children }: { children: React.ReactNode }) {
|
||||
const { data: teams, status } = api.team.getTeams.useQuery();
|
||||
|
||||
const value = {
|
||||
currentTeam: teams?.[0] ?? null,
|
||||
teams: teams || [],
|
||||
isLoading: status === "pending",
|
||||
};
|
||||
|
||||
return <TeamContext.Provider value={value}>{children}</TeamContext.Provider>;
|
||||
}
|
||||
|
||||
export function useTeam() {
|
||||
const context = useContext(TeamContext);
|
||||
if (context === undefined) {
|
||||
throw new Error("useTeam must be used within a TeamProvider");
|
||||
}
|
||||
return context;
|
||||
}
|
Reference in New Issue
Block a user