mirror of
https://github.com/domfelipe/mika-agent-assist.git
synced 2026-08-07 16:16:50 +00:00
Changes
Co-authored-by: domfelipe <53182096+domfelipe@users.noreply.github.com>
This commit is contained in:
parent
0eb8689a27
commit
fa8bee0e36
7 changed files with 271 additions and 0 deletions
68
src/hooks/use-profile.ts
Normal file
68
src/hooks/use-profile.ts
Normal file
|
|
@ -0,0 +1,68 @@
|
|||
"use client";
|
||||
|
||||
import { useQuery } from "@tanstack/react-query";
|
||||
import { supabase } from "@/integrations/supabase/client";
|
||||
import { useAuth } from "./use-auth";
|
||||
|
||||
export interface Profile {
|
||||
id: string;
|
||||
full_name: string;
|
||||
company_name: string | null;
|
||||
cpf_cnpj: string | null;
|
||||
phone: string | null;
|
||||
avatar_url: string | null;
|
||||
stripe_customer_id: string | null;
|
||||
onboarding_completed: boolean;
|
||||
}
|
||||
|
||||
export function useProfile() {
|
||||
const { user } = useAuth();
|
||||
|
||||
return useQuery({
|
||||
queryKey: ["profile", user?.id],
|
||||
enabled: !!user,
|
||||
queryFn: async (): Promise<Profile | null> => {
|
||||
if (!user) return null;
|
||||
const { data, error } = await supabase
|
||||
.from("profiles")
|
||||
.select("*")
|
||||
.eq("id", user.id)
|
||||
.maybeSingle();
|
||||
if (error) throw error;
|
||||
return data as Profile | null;
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
export interface SubscriptionRow {
|
||||
id: string;
|
||||
user_id: string;
|
||||
plan_id: string | null;
|
||||
stripe_subscription_id: string | null;
|
||||
status: "active" | "trialing" | "past_due" | "canceled" | "incomplete" | "incomplete_expired" | "unpaid";
|
||||
billing_cycle: "monthly" | "yearly";
|
||||
current_period_start: string | null;
|
||||
current_period_end: string | null;
|
||||
cancel_at_period_end: boolean;
|
||||
}
|
||||
|
||||
export function useSubscription() {
|
||||
const { user } = useAuth();
|
||||
|
||||
return useQuery({
|
||||
queryKey: ["subscription", user?.id],
|
||||
enabled: !!user,
|
||||
queryFn: async (): Promise<SubscriptionRow | null> => {
|
||||
if (!user) return null;
|
||||
const { data, error } = await supabase
|
||||
.from("subscriptions")
|
||||
.select("*")
|
||||
.eq("user_id", user.id)
|
||||
.order("created_at", { ascending: false })
|
||||
.limit(1)
|
||||
.maybeSingle();
|
||||
if (error) throw error;
|
||||
return data as SubscriptionRow | null;
|
||||
},
|
||||
});
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue