2024-02-21 02:11:03 +03:00
|
|
|
import { useEffect } from "react";
|
2023-11-14 12:56:22 +03:00
|
|
|
import { FormProvider, useForm } from "react-hook-form";
|
2024-02-15 03:37:33 +03:00
|
|
|
import { useTranslation } from "react-i18next";
|
2023-09-20 10:35:09 +03:00
|
|
|
|
2024-02-15 03:37:33 +03:00
|
|
|
import { Modal } from "@/lib/components/ui/Modal/Modal";
|
2023-11-15 14:42:19 +03:00
|
|
|
import { addBrainDefaultValues } from "@/lib/config/defaultBrainConfig";
|
2024-04-09 19:06:33 +03:00
|
|
|
import { useUserData } from "@/lib/hooks/useUserData";
|
2023-07-25 13:08:08 +03:00
|
|
|
|
2024-02-15 03:37:33 +03:00
|
|
|
import styles from "./AddBrainModal.module.scss";
|
|
|
|
import { useBrainCreationContext } from "./brainCreation-provider";
|
|
|
|
import { BrainMainInfosStep } from "./components/BrainMainInfosStep/BrainMainInfosStep";
|
|
|
|
import { BrainTypeSelectionStep } from "./components/BrainTypeSelectionStep/BrainTypeSelectionStep";
|
2024-02-21 02:11:03 +03:00
|
|
|
import { CreateBrainStep } from "./components/CreateBrainStep/CreateBrainStep";
|
2024-02-15 03:37:33 +03:00
|
|
|
import { Stepper } from "./components/Stepper/Stepper";
|
|
|
|
import { CreateBrainProps } from "./types/types";
|
2023-07-25 13:08:08 +03:00
|
|
|
|
2024-02-07 03:05:07 +03:00
|
|
|
export const AddBrainModal = (): JSX.Element => {
|
2024-02-15 03:37:33 +03:00
|
|
|
const { t } = useTranslation(["translation", "brain", "config"]);
|
2024-04-09 19:06:33 +03:00
|
|
|
const { userIdentityData } = useUserData();
|
2024-02-15 03:37:33 +03:00
|
|
|
|
2024-02-21 02:11:03 +03:00
|
|
|
const {
|
|
|
|
isBrainCreationModalOpened,
|
|
|
|
setIsBrainCreationModalOpened,
|
2024-03-06 22:17:46 +03:00
|
|
|
setCurrentSelectedBrain,
|
2024-02-21 02:11:03 +03:00
|
|
|
} = useBrainCreationContext();
|
2024-02-15 03:37:33 +03:00
|
|
|
|
2023-11-15 14:42:19 +03:00
|
|
|
const defaultValues: CreateBrainProps = {
|
|
|
|
...addBrainDefaultValues,
|
|
|
|
setDefault: true,
|
2023-12-05 13:52:56 +03:00
|
|
|
brainCreationStep: "BRAIN_TYPE",
|
2023-11-15 14:42:19 +03:00
|
|
|
};
|
|
|
|
|
|
|
|
const methods = useForm<CreateBrainProps>({
|
|
|
|
defaultValues,
|
2023-11-14 12:56:22 +03:00
|
|
|
});
|
2023-07-25 13:08:08 +03:00
|
|
|
|
2024-02-21 02:11:03 +03:00
|
|
|
useEffect(() => {
|
2024-03-06 22:17:46 +03:00
|
|
|
setCurrentSelectedBrain(undefined);
|
2024-02-21 02:11:03 +03:00
|
|
|
}, [isBrainCreationModalOpened]);
|
|
|
|
|
2023-07-25 13:08:08 +03:00
|
|
|
return (
|
2023-11-14 12:56:22 +03:00
|
|
|
<FormProvider {...methods}>
|
2024-02-15 03:37:33 +03:00
|
|
|
<Modal
|
|
|
|
title={t("newBrainTitle", { ns: "brain" })}
|
|
|
|
desc={t("newBrainSubtitle", { ns: "brain" })}
|
|
|
|
isOpen={isBrainCreationModalOpened}
|
|
|
|
setOpen={setIsBrainCreationModalOpened}
|
2024-04-09 19:06:33 +03:00
|
|
|
unclosable={!userIdentityData?.onboarded}
|
2024-03-29 00:22:16 +03:00
|
|
|
size="big"
|
2024-02-15 03:37:33 +03:00
|
|
|
CloseTrigger={<div />}
|
|
|
|
>
|
|
|
|
<div className={styles.add_brain_modal_container}>
|
|
|
|
<div className={styles.stepper_container}>
|
|
|
|
<Stepper />
|
|
|
|
</div>
|
|
|
|
<div className={styles.content_wrapper}>
|
|
|
|
<BrainTypeSelectionStep />
|
|
|
|
<BrainMainInfosStep />
|
2024-02-21 02:11:03 +03:00
|
|
|
<CreateBrainStep />
|
2024-02-15 03:37:33 +03:00
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</Modal>
|
2023-11-14 12:56:22 +03:00
|
|
|
</FormProvider>
|
2023-07-25 13:08:08 +03:00
|
|
|
);
|
|
|
|
};
|