feat(expo): add tablo members read-only hook
This commit is contained in:
parent
d6d7892684
commit
db0b077c0d
1 changed files with 31 additions and 0 deletions
31
xtablo-expo/hooks/members.ts
Normal file
31
xtablo-expo/hooks/members.ts
Normal file
|
|
@ -0,0 +1,31 @@
|
|||
import { useQuery } from "@tanstack/react-query";
|
||||
import { api } from "@/lib/api";
|
||||
import { useAuthStore } from "@/stores/auth";
|
||||
|
||||
export type TabloMember = {
|
||||
id: string;
|
||||
name: string;
|
||||
is_admin: boolean;
|
||||
email: string;
|
||||
avatar_url: string | null;
|
||||
};
|
||||
|
||||
export const useTabloMembers = (tabloId: string | undefined) => {
|
||||
const session = useAuthStore((state) => state.session);
|
||||
|
||||
return useQuery({
|
||||
queryKey: ["tablo-members", tabloId],
|
||||
queryFn: async () => {
|
||||
const { data } = await api.get<{ members: TabloMember[] }>(
|
||||
`/api/v1/tablos/members/${tabloId}`,
|
||||
{
|
||||
headers: {
|
||||
Authorization: `Bearer ${session?.access_token}`,
|
||||
},
|
||||
}
|
||||
);
|
||||
return data.members;
|
||||
},
|
||||
enabled: !!tabloId && !!session,
|
||||
});
|
||||
};
|
||||
Loading…
Reference in a new issue