diff --git a/frontend/app/config/components/BackendConfig.tsx b/frontend/app/config/components/BackendConfig.tsx new file mode 100644 index 000000000..0b46d0872 --- /dev/null +++ b/frontend/app/config/components/BackendConfig.tsx @@ -0,0 +1,54 @@ +"use client"; + +import { BrainConfig } from "@/lib/context/BrainConfigProvider/types"; +import { UseFormRegister } from "react-hook-form"; +import Field from "../../components/ui/Field"; + +interface BackendConfigProps { + register: UseFormRegister; +} + +export const BackendConfig = ({ + register, +}: BackendConfigProps): JSX.Element => { + return ( + <> +
+

+ Backend config +

+
+ + + + + + ); +}; diff --git a/frontend/app/config/components/ConfigForm.tsx b/frontend/app/config/components/ConfigForm.tsx new file mode 100644 index 000000000..46d327d76 --- /dev/null +++ b/frontend/app/config/components/ConfigForm.tsx @@ -0,0 +1,61 @@ +"use client"; + +import { useRouter } from "next/navigation"; +import Button from "../../components/ui/Button"; +import { useConfig } from "../hooks/useConfig"; +import { BackendConfig } from "./BackendConfig"; +import { ModelConfig } from "./ModelConfig"; +import { UserAccountSection } from "./UserAccountSection"; + +export const ConfigForm = (): JSX.Element => { + const { + handleSubmit, + isDirty, + maxTokens, + openAiKey, + saveConfig, + register, + temperature, + model, + resetBrainConfig, + } = useConfig(); + + const router = useRouter(); + + const handleDoneClick = () => { + if (isDirty) { + saveConfig(); + } + router.back(); + }; + + return ( +
+ + +
+ + +
+ + + ); +}; diff --git a/frontend/app/config/components/ConfigTitle.tsx b/frontend/app/config/components/ConfigTitle.tsx new file mode 100644 index 000000000..d42fb08bf --- /dev/null +++ b/frontend/app/config/components/ConfigTitle.tsx @@ -0,0 +1,10 @@ +export const ConfigTitle = (): JSX.Element => { + return ( +
+

Configuration

+

+ Here, you can choose your model, set your credentials... +

+
+ ); +}; diff --git a/frontend/app/config/components/ModelConfig.tsx b/frontend/app/config/components/ModelConfig.tsx new file mode 100644 index 000000000..5151b3f37 --- /dev/null +++ b/frontend/app/config/components/ModelConfig.tsx @@ -0,0 +1,96 @@ +"use client"; + +import { + BrainConfig, + Model, + anthropicModels, + models, + paidModels, +} from "@/lib/context/BrainConfigProvider/types"; +import { UseFormRegister } from "react-hook-form"; +import Field from "../../components/ui/Field"; + +interface ModelConfigProps { + register: UseFormRegister; + model: Model; + openAiKey: string | undefined; + temperature: number; + maxTokens: number; +} + +export const ModelConfig = ({ + register, + model, + openAiKey, + temperature, + maxTokens, +}: ModelConfigProps): JSX.Element => { + return ( + <> +
+

+ Model config +

+
+ +
+ + +
+ {(anthropicModels as readonly string[]).includes(model) && ( + + )} +
+ + +
+
+ + +
+ + ); +}; diff --git a/frontend/app/config/components/UserAccountSection.tsx b/frontend/app/config/components/UserAccountSection.tsx new file mode 100644 index 000000000..084f76641 --- /dev/null +++ b/frontend/app/config/components/UserAccountSection.tsx @@ -0,0 +1,34 @@ +"use client"; + +import { useSupabase } from "@/app/supabase-provider"; +import Link from "next/link"; +import Button from "../../components/ui/Button"; + +export const UserAccountSection = (): JSX.Element => { + const { session } = useSupabase(); + + if (session === null) { + return <>; + } + + return ( + <> +
+

+ Your Account +

+
+
+ + Signed In as: {session.user.email} + + + + + {/* TODO: add functionality to change password */} +
+ + ); +}; diff --git a/frontend/app/config/components/index.tsx b/frontend/app/config/components/index.tsx new file mode 100644 index 000000000..4b0b8b8bf --- /dev/null +++ b/frontend/app/config/components/index.tsx @@ -0,0 +1,2 @@ +export * from "./ConfigForm"; +export * from "./ConfigTitle"; diff --git a/frontend/app/config/page.tsx b/frontend/app/config/page.tsx index 229862513..3a2933ee6 100644 --- a/frontend/app/config/page.tsx +++ b/frontend/app/config/page.tsx @@ -1,30 +1,12 @@ "use client"; import { redirect } from "next/navigation"; -import { - anthropicModels, - models, - paidModels, -} from "@/lib/context/BrainConfigProvider/types"; -import Link from "next/link"; -import Button from "../components/ui/Button"; -import Field from "../components/ui/Field"; import { useSupabase } from "../supabase-provider"; -import { useConfig } from "./hooks/useConfig"; +import { ConfigForm, ConfigTitle } from "./components"; -export default function ExplorePage() { +// TODO: Use states instead of NEXTJS router to open and close modal +export default function ConfigPage() { const { session } = useSupabase(); - const { - handleSubmit, - isDirty, - maxTokens, - openAiKey, - saveConfig, - register, - temperature, - model, - resetBrainConfig, - } = useConfig(); if (session === null) { redirect("/login"); @@ -33,150 +15,8 @@ export default function ExplorePage() { return (
-
-

Configuration

-

- Here, you can choose your model, set your credentials... -

-
-
-
-

- Model config -

-
- -
- - -
- {(anthropicModels as readonly string[]).includes(model) && ( - - )} -
- - -
-
- - -
-
-

- Backend config -

-
- - - - -
- - -
-
-

- Your Account -

-
-
- - Signed In as: {session.user.email} - - - - - {/* TODO: add functionality to change password */} -
- + +
);