mirror of
https://github.com/QuivrHQ/quivr.git
synced 2024-08-17 02:10:31 +03:00
feat(sdk): add setAsDefaultBrain
This commit is contained in:
parent
5d308d4ab1
commit
8366f3a3f6
@ -189,4 +189,16 @@ describe("useBrainApi", () => {
|
||||
{ rights: "Viewer", email }
|
||||
);
|
||||
});
|
||||
|
||||
it("should call setAsDefaultBrain with correct brainId", async () => {
|
||||
const {
|
||||
result: {
|
||||
current: { setAsDefaultBrain },
|
||||
},
|
||||
} = renderHook(() => useBrainApi());
|
||||
const brainId = "123";
|
||||
await setAsDefaultBrain(brainId);
|
||||
expect(axiosPutMock).toHaveBeenCalledTimes(1);
|
||||
expect(axiosPutMock).toHaveBeenCalledWith(`/brains/${brainId}/default`);
|
||||
});
|
||||
});
|
||||
|
@ -126,3 +126,10 @@ export const updateBrainAccess = async (
|
||||
email: userEmail,
|
||||
});
|
||||
};
|
||||
|
||||
export const setAsDefaultBrain = async (
|
||||
brainId: string,
|
||||
axiosInstance: AxiosInstance
|
||||
): Promise<void> => {
|
||||
await axiosInstance.put(`/brains/${brainId}/default`);
|
||||
};
|
||||
|
@ -10,6 +10,7 @@ import {
|
||||
getBrains,
|
||||
getBrainUsers,
|
||||
getDefaultBrain,
|
||||
setAsDefaultBrain,
|
||||
Subscription,
|
||||
updateBrainAccess,
|
||||
} from "./brain";
|
||||
@ -39,5 +40,7 @@ export const useBrainApi = () => {
|
||||
userEmail: string,
|
||||
subscription: SubscriptionUpdatableProperties
|
||||
) => updateBrainAccess(brainId, userEmail, subscription, axiosInstance),
|
||||
setAsDefaultBrain: async (brainId: string) =>
|
||||
setAsDefaultBrain(brainId, axiosInstance),
|
||||
};
|
||||
};
|
||||
|
@ -3,6 +3,7 @@ import axios from "axios";
|
||||
import { FormEvent, useState } from "react";
|
||||
import { useForm } from "react-hook-form";
|
||||
|
||||
import { useBrainApi } from "@/lib/api/brain/useBrainApi";
|
||||
import { useBrainConfig } from "@/lib/context/BrainConfigProvider";
|
||||
import { useBrainContext } from "@/lib/context/BrainProvider/hooks/useBrainContext";
|
||||
import { useToast } from "@/lib/hooks";
|
||||
@ -12,6 +13,7 @@ export const useAddBrainModal = () => {
|
||||
const [isPending, setIsPending] = useState(false);
|
||||
const { publish } = useToast();
|
||||
const { createBrain } = useBrainContext();
|
||||
const { setAsDefaultBrain } = useBrainApi();
|
||||
const [isShareModalOpen, setIsShareModalOpen] = useState(false);
|
||||
const { config } = useBrainConfig();
|
||||
const defaultValues = {
|
||||
@ -50,7 +52,7 @@ export const useAddBrainModal = () => {
|
||||
|
||||
try {
|
||||
setIsPending(true);
|
||||
await createBrain({
|
||||
const createdBrainId = await createBrain({
|
||||
name,
|
||||
description,
|
||||
max_tokens: maxTokens,
|
||||
@ -60,7 +62,15 @@ export const useAddBrainModal = () => {
|
||||
});
|
||||
|
||||
if (setDefault) {
|
||||
//
|
||||
if (createdBrainId === undefined) {
|
||||
publish({
|
||||
variant: "danger",
|
||||
text: "Error occurred while creating a brain",
|
||||
});
|
||||
|
||||
return;
|
||||
}
|
||||
await setAsDefaultBrain(createdBrainId);
|
||||
}
|
||||
|
||||
setIsShareModalOpen(false);
|
||||
|
Loading…
Reference in New Issue
Block a user