diff --git a/src/features/workspaces/api/use-get-workspaces.ts b/src/features/workspaces/api/use-get-workspaces.ts new file mode 100644 index 0000000..3a8d5f8 --- /dev/null +++ b/src/features/workspaces/api/use-get-workspaces.ts @@ -0,0 +1,21 @@ +import { client } from "@/lib/rpc"; +import { useQuery } from "@tanstack/react-query"; + +export const useGetWorkspaces = () => { + const query = useQuery({ + queryKey: ["workspaces"], + queryFn: async () => { + const response = await client.api.workspaces.$get(); + + if (!response.ok) { + throw new Error("Failed to fetch workspaces"); + } + + const { data } = await response.json(); + + return data; + }, + }); + + return query; +};