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
124f70528b
commit
a32c05a679
10 changed files with 721 additions and 0 deletions
30
src/hooks/use-agent-instance.ts
Normal file
30
src/hooks/use-agent-instance.ts
Normal file
|
|
@ -0,0 +1,30 @@
|
|||
"use client";
|
||||
|
||||
import { useQuery } from "@tanstack/react-query";
|
||||
import { supabase } from "@/integrations/supabase/client";
|
||||
import { useAuth } from "@/hooks/use-auth";
|
||||
|
||||
export interface AgentInstance {
|
||||
id: string;
|
||||
user_id: string;
|
||||
status: string;
|
||||
telegram_bot_username: string | null;
|
||||
created_at: string;
|
||||
}
|
||||
|
||||
export function useAgentInstance() {
|
||||
const { user } = useAuth();
|
||||
return useQuery({
|
||||
queryKey: ["agent-instance", user?.id],
|
||||
enabled: !!user,
|
||||
queryFn: async (): Promise<AgentInstance | null> => {
|
||||
const { data, error } = await supabase
|
||||
.from("agent_instances")
|
||||
.select("id, user_id, status, telegram_bot_username, created_at")
|
||||
.eq("user_id", user!.id)
|
||||
.maybeSingle();
|
||||
if (error) throw error;
|
||||
return data;
|
||||
},
|
||||
});
|
||||
}
|
||||
46
src/hooks/use-skills.ts
Normal file
46
src/hooks/use-skills.ts
Normal file
|
|
@ -0,0 +1,46 @@
|
|||
"use client";
|
||||
|
||||
import { useQuery } from "@tanstack/react-query";
|
||||
import { supabase } from "@/integrations/supabase/client";
|
||||
import { useAuth } from "@/hooks/use-auth";
|
||||
import type { Database } from "@/integrations/supabase/types";
|
||||
|
||||
export type Skill = Database["public"]["Tables"]["skills"]["Row"];
|
||||
export type SkillStatus = "draft" | "testing" | "active" | "disabled" | "archived";
|
||||
|
||||
export function useSkills(includeArchived = false) {
|
||||
const { user } = useAuth();
|
||||
return useQuery({
|
||||
queryKey: ["skills", user?.id, includeArchived],
|
||||
enabled: !!user,
|
||||
queryFn: async (): Promise<Skill[]> => {
|
||||
let q = supabase
|
||||
.from("skills")
|
||||
.select("*")
|
||||
.eq("user_id", user!.id)
|
||||
.order("updated_at", { ascending: false });
|
||||
if (!includeArchived) {
|
||||
q = q.neq("status", "archived");
|
||||
}
|
||||
const { data, error } = await q;
|
||||
if (error) throw error;
|
||||
return (data ?? []) as Skill[];
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
export function useSkill(skillId: string | undefined) {
|
||||
return useQuery({
|
||||
queryKey: ["skill", skillId],
|
||||
enabled: !!skillId,
|
||||
queryFn: async (): Promise<Skill | null> => {
|
||||
const { data, error } = await supabase
|
||||
.from("skills")
|
||||
.select("*")
|
||||
.eq("id", skillId!)
|
||||
.maybeSingle();
|
||||
if (error) throw error;
|
||||
return data as Skill | null;
|
||||
},
|
||||
});
|
||||
}
|
||||
29
src/hooks/use-user-skill-limits.ts
Normal file
29
src/hooks/use-user-skill-limits.ts
Normal file
|
|
@ -0,0 +1,29 @@
|
|||
"use client";
|
||||
|
||||
import { useQuery } from "@tanstack/react-query";
|
||||
import { supabase } from "@/integrations/supabase/client";
|
||||
import { useAuth } from "@/hooks/use-auth";
|
||||
|
||||
export interface UserSkillLimits {
|
||||
user_id: string;
|
||||
plan_slug: string | null;
|
||||
max_skills: number | null;
|
||||
current_skills_count: number;
|
||||
}
|
||||
|
||||
export function useUserSkillLimits() {
|
||||
const { user } = useAuth();
|
||||
return useQuery({
|
||||
queryKey: ["user-limits", user?.id],
|
||||
enabled: !!user,
|
||||
queryFn: async (): Promise<UserSkillLimits | null> => {
|
||||
const { data, error } = await supabase
|
||||
.from("user_skill_limits")
|
||||
.select("*")
|
||||
.eq("user_id", user!.id)
|
||||
.maybeSingle();
|
||||
if (error) throw error;
|
||||
return data as UserSkillLimits | null;
|
||||
},
|
||||
});
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue