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