mirror of
https://github.com/QuivrHQ/quivr.git
synced 2024-12-15 17:43:03 +03:00
3d3e6b7306
# Description Please include a summary of the changes and the related issue. Please also include relevant motivation and context. ## Checklist before requesting a review Please delete options that are not relevant. - [ ] My code follows the style guidelines of this project - [ ] I have performed a self-review of my code - [ ] I have commented hard-to-understand areas - [ ] I have ideally added tests that prove my fix is effective or that my feature works - [ ] New and existing unit tests pass locally with my changes - [ ] Any dependent changes have been merged ## Screenshots (if appropriate):
76 lines
2.8 KiB
TypeScript
76 lines
2.8 KiB
TypeScript
import { useEffect } from "react";
|
|
import { FormProvider, useForm } from "react-hook-form";
|
|
import { useTranslation } from "react-i18next";
|
|
|
|
import { useFromConnectionsContext } from "@/app/chat/[chatId]/components/ActionsBar/components/KnowledgeToFeed/components/FromConnections/FromConnectionsProvider/hooks/useFromConnectionContext";
|
|
import { Modal } from "@/lib/components/ui/Modal/Modal";
|
|
import { addBrainDefaultValues } from "@/lib/config/defaultBrainConfig";
|
|
import { useKnowledgeToFeedContext } from "@/lib/context/KnowledgeToFeedProvider/hooks/useKnowledgeToFeedContext";
|
|
import { useUserData } from "@/lib/hooks/useUserData";
|
|
|
|
import styles from "./AddBrainModal.module.scss";
|
|
import { useBrainCreationContext } from "./brainCreation-provider";
|
|
import { BrainMainInfosStep } from "./components/BrainMainInfosStep/BrainMainInfosStep";
|
|
import { BrainRecapStep } from "./components/BrainRecapStep/BrainRecapStep";
|
|
import { FeedBrainStep } from "./components/FeedBrainStep/FeedBrainStep";
|
|
import { Stepper } from "./components/Stepper/Stepper";
|
|
import { useBrainCreationSteps } from "./hooks/useBrainCreationSteps";
|
|
import { CreateBrainProps } from "./types/types";
|
|
|
|
export const AddBrainModal = (): JSX.Element => {
|
|
const { t } = useTranslation(["translation", "brain", "config"]);
|
|
const { userIdentityData } = useUserData();
|
|
const { currentStep, steps } = useBrainCreationSteps();
|
|
const {
|
|
isBrainCreationModalOpened,
|
|
setIsBrainCreationModalOpened,
|
|
setCurrentSelectedBrain,
|
|
} = useBrainCreationContext();
|
|
const { setCurrentSyncId, setOpenedConnections } =
|
|
useFromConnectionsContext();
|
|
const { removeAllKnowledgeToFeed } = useKnowledgeToFeedContext();
|
|
|
|
const defaultValues: CreateBrainProps = {
|
|
...addBrainDefaultValues,
|
|
setDefault: true,
|
|
brainCreationStep: "FIRST_STEP",
|
|
};
|
|
|
|
const methods = useForm<CreateBrainProps>({
|
|
defaultValues,
|
|
});
|
|
|
|
useEffect(() => {
|
|
setCurrentSelectedBrain(undefined);
|
|
setCurrentSyncId(undefined);
|
|
setOpenedConnections([]);
|
|
methods.reset(defaultValues);
|
|
removeAllKnowledgeToFeed();
|
|
}, [isBrainCreationModalOpened]);
|
|
|
|
return (
|
|
<FormProvider {...methods}>
|
|
<Modal
|
|
title={t("newBrainTitle", { ns: "brain" })}
|
|
desc={t("newBrainSubtitle", { ns: "brain" })}
|
|
isOpen={isBrainCreationModalOpened}
|
|
setOpen={setIsBrainCreationModalOpened}
|
|
unclosable={!userIdentityData?.onboarded}
|
|
size="big"
|
|
CloseTrigger={<div />}
|
|
>
|
|
<div className={styles.add_brain_modal_container}>
|
|
<div className={styles.stepper_container}>
|
|
<Stepper currentStep={currentStep} steps={steps} />
|
|
</div>
|
|
<div className={styles.content_wrapper}>
|
|
<BrainMainInfosStep />
|
|
<FeedBrainStep />
|
|
<BrainRecapStep />
|
|
</div>
|
|
</div>
|
|
</Modal>
|
|
</FormProvider>
|
|
);
|
|
};
|