Co-authored-by: domfelipe <53182096+domfelipe@users.noreply.github.com>
This commit is contained in:
gpt-engineer-app[bot] 2026-04-17 17:47:57 +00:00
parent 2a9c5a8d09
commit 6bdca7b7b2
2 changed files with 13 additions and 3 deletions

View file

@ -3,6 +3,7 @@
import { useQuery } from "@tanstack/react-query"; import { useQuery } from "@tanstack/react-query";
import { supabase } from "@/integrations/supabase/client"; import { supabase } from "@/integrations/supabase/client";
import { useAuth } from "./use-auth"; import { useAuth } from "./use-auth";
import { getPaddleEnv } from "@/lib/paddle";
export interface Profile { export interface Profile {
id: string; id: string;
@ -12,6 +13,7 @@ export interface Profile {
phone: string | null; phone: string | null;
avatar_url: string | null; avatar_url: string | null;
stripe_customer_id: string | null; stripe_customer_id: string | null;
paddle_customer_id: string | null;
onboarding_completed: boolean; onboarding_completed: boolean;
} }
@ -38,8 +40,12 @@ export interface SubscriptionRow {
id: string; id: string;
user_id: string; user_id: string;
plan_id: string | null; plan_id: string | null;
stripe_subscription_id: string | null; paddle_subscription_id: string | null;
status: "active" | "trialing" | "past_due" | "canceled" | "incomplete" | "incomplete_expired" | "unpaid"; paddle_customer_id: string | null;
product_id: string | null;
price_id: string | null;
environment: "sandbox" | "live";
status: "active" | "trialing" | "past_due" | "canceled" | "incomplete" | "incomplete_expired" | "unpaid" | "paused";
billing_cycle: "monthly" | "yearly"; billing_cycle: "monthly" | "yearly";
current_period_start: string | null; current_period_start: string | null;
current_period_end: string | null; current_period_end: string | null;
@ -48,9 +54,10 @@ export interface SubscriptionRow {
export function useSubscription() { export function useSubscription() {
const { user } = useAuth(); const { user } = useAuth();
const env = getPaddleEnv();
return useQuery({ return useQuery({
queryKey: ["subscription", user?.id], queryKey: ["subscription", user?.id, env],
enabled: !!user, enabled: !!user,
queryFn: async (): Promise<SubscriptionRow | null> => { queryFn: async (): Promise<SubscriptionRow | null> => {
if (!user) return null; if (!user) return null;
@ -58,6 +65,7 @@ export function useSubscription() {
.from("subscriptions") .from("subscriptions")
.select("*") .select("*")
.eq("user_id", user.id) .eq("user_id", user.id)
.eq("environment", env)
.order("created_at", { ascending: false }) .order("created_at", { ascending: false })
.limit(1) .limit(1)
.maybeSingle(); .maybeSingle();

View file

@ -3,6 +3,7 @@ import type { QueryClient } from "@tanstack/react-query";
import { QueryClientProvider } from "@tanstack/react-query"; import { QueryClientProvider } from "@tanstack/react-query";
import { Toaster } from "@/components/ui/sonner"; import { Toaster } from "@/components/ui/sonner";
import { ThemeProvider } from "@/components/theme-provider"; import { ThemeProvider } from "@/components/theme-provider";
import { PaymentTestModeBanner } from "@/components/mika/PaymentTestModeBanner";
import appCss from "../styles.css?url"; import appCss from "../styles.css?url";
@ -98,6 +99,7 @@ function RootComponent() {
return ( return (
<QueryClientProvider client={queryClient}> <QueryClientProvider client={queryClient}>
<ThemeProvider> <ThemeProvider>
<PaymentTestModeBanner />
<Outlet /> <Outlet />
<Toaster richColors position="top-right" /> <Toaster richColors position="top-right" />
</ThemeProvider> </ThemeProvider>