ui: close modal after brain creation (#720)

This commit is contained in:
Mamadou DICKO 2023-07-20 18:21:36 +02:00 committed by GitHub
parent d27504f735
commit 8125d0858c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -13,6 +13,7 @@ export const AddBrainModal = (): JSX.Element => {
const [isPending, setIsPending] = useState(false);
const { publish } = useToast();
const { createBrain } = useBrainContext();
const [isShareModalOpen, setIsShareModalOpen] = useState(false);
const handleSubmit = async (e: FormEvent) => {
e.preventDefault();
@ -23,6 +24,11 @@ export const AddBrainModal = (): JSX.Element => {
setIsPending(true);
await createBrain(newBrainName);
setNewBrainName("");
setIsShareModalOpen(false);
publish({
variant: "success",
text: "Brain created successfully",
});
} catch (err) {
if (axios.isAxiosError(err) && err.response?.status === 429) {
publish({
@ -56,6 +62,9 @@ export const AddBrainModal = (): JSX.Element => {
}
title="Add Brain"
desc="Add a new brain"
isOpen={isShareModalOpen}
setOpen={setIsShareModalOpen}
CloseTrigger={<div />}
>
<form
onSubmit={(e) => void handleSubmit(e)}