mirror of
https://github.com/StanGirard/quivr.git
synced 2024-12-29 22:32:40 +03:00
1643b54b7b
* feat: update translations * feat: add <DeleteOrUnsubscribeConfirmationModal /> * test(DeleteOrUnsubscribeConfirmationModal): update tests * feat: redirect to /brains-management on invalid brain id * refactor: move delete_brain_user to delete_brain_users * feat: add /POST '/brains/{brain_id}/subscribe' * feat: handle public brain unsubscription
39 lines
922 B
TypeScript
39 lines
922 B
TypeScript
import { useQuery } from "@tanstack/react-query";
|
|
import { UUID } from "crypto";
|
|
import { useRouter } from "next/navigation";
|
|
|
|
import { getBrainDataKey } from "@/lib/api/brain/config";
|
|
import { useBrainApi } from "@/lib/api/brain/useBrainApi";
|
|
|
|
type UseBrainFetcherProps = {
|
|
brainId?: UUID;
|
|
};
|
|
|
|
// eslint-disable-next-line @typescript-eslint/explicit-module-boundary-types
|
|
export const useBrainFetcher = ({ brainId }: UseBrainFetcherProps) => {
|
|
const { getBrain } = useBrainApi();
|
|
const router = useRouter();
|
|
|
|
const fetchBrain = async () => {
|
|
try {
|
|
if (brainId === undefined) {
|
|
return undefined;
|
|
}
|
|
|
|
return await getBrain(brainId);
|
|
} catch (error) {
|
|
router.push("/brains-management");
|
|
}
|
|
};
|
|
|
|
const { data: brain } = useQuery({
|
|
queryKey: [getBrainDataKey(brainId!)],
|
|
queryFn: fetchBrain,
|
|
enabled: brainId !== undefined,
|
|
});
|
|
|
|
return {
|
|
brain,
|
|
};
|
|
};
|