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:
KM Koushik
2025-03-23 07:06:56 +11:00
committed by GitHub
parent 6cfe41cd86
commit 403ad8b93e
34 changed files with 1352 additions and 238 deletions

View File

@@ -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>;
};

View 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;
}