jan/web/app/_hooks/useDeleteBot.ts
NamH 6e2210cb22
feat: adding create bot functionality (#368)
* feat: adding create bot functionality

Signed-off-by: James <james@jan.ai>

* update the temperature progress bar

Signed-off-by: James <james@jan.ai>

* chore: remove tgz

Signed-off-by: James <james@jan.ai>

* update core dependency

Signed-off-by: James <james@jan.ai>

* fix e2e test

Signed-off-by: James <james@jan.ai>

---------

Signed-off-by: James <james@jan.ai>
Co-authored-by: James <james@jan.ai>
2023-10-23 15:57:56 +07:00

26 lines
891 B
TypeScript

import { useSetAtom } from "jotai";
import { executeSerial } from "../../../electron/core/plugin-manager/execution/extension-manager";
import { activeBotAtom } from "@/_helpers/atoms/Bot.atom";
import { rightSideBarExpandStateAtom } from "@/_helpers/atoms/LeftSideBarExpand.atom";
import { DataService } from "@janhq/core";
export default function useDeleteBot() {
const setActiveBot = useSetAtom(activeBotAtom);
const setRightPanelVisibility = useSetAtom(rightSideBarExpandStateAtom);
const deleteBot = async (botId: string): Promise<"success" | "failed"> => {
try {
await executeSerial(DataService.DeleteBot, botId);
setRightPanelVisibility(false);
setActiveBot(undefined);
return "success";
} catch (err) {
alert(`Failed to delete bot ${botId}: ${err}`);
console.error(err);
return "failed";
}
};
return { deleteBot };
}