File size: 729 Bytes
9b906ea | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 | import { useQuery } from "@tanstack/react-query";
import { batchGetCloudSandboxes } from "#/api/cloud/sandbox-service.api";
import { useActiveBackend } from "#/contexts/active-backend-context";
export const useCloudSandbox = (sandboxId: string | null | undefined) => {
const active = useActiveBackend();
const isCloud = active.backend.kind === "cloud";
return useQuery({
queryKey: ["cloud", "sandbox", active.backend.id, active.orgId, sandboxId],
queryFn: async () => {
if (!sandboxId) return null;
const [sandbox] = await batchGetCloudSandboxes([sandboxId]);
return sandbox ?? null;
},
enabled: isCloud && !!sandboxId,
staleTime: 1000 * 60 * 5,
gcTime: 1000 * 60 * 15,
});
};
|