From 37935c59ca64a195e19c528bf4475a863680c99b Mon Sep 17 00:00:00 2001 From: Mamadou DICKO <63923024+mamadoudicko@users.noreply.github.com> Date: Wed, 20 Sep 2023 09:35:09 +0200 Subject: [PATCH] feat: add public brain creation (#1218) * feat: add brain status input * feat: update translations * feat: add confirmation modal for brain status changing to public --- frontend/lib/api/brain/types.ts | 3 +- .../AddBrainModal/AddBrainModal.tsx | 297 ++++++++++-------- .../PublicAccessConfirmationModal.tsx | 42 +++ .../AddBrainModal/hooks/useAddBrainModal.ts | 46 ++- .../lib/components/AddBrainModal/styles.css | 3 + frontend/lib/components/ui/Modal.tsx | 7 +- frontend/lib/components/ui/Radio.tsx | 48 +++ frontend/lib/config/defaultBrainConfig.ts | 1 + frontend/lib/types/brainConfig.ts | 5 + frontend/package.json | 1 + frontend/public/locales/en/brain.json | 9 +- frontend/public/locales/es/brain.json | 9 +- frontend/public/locales/fr/brain.json | 9 +- frontend/public/locales/pt-br/brain.json | 9 +- frontend/public/locales/ru/brain.json | 9 +- frontend/public/locales/zh-cn/brain.json | 9 +- frontend/yarn.lock | 110 ++++--- 17 files changed, 424 insertions(+), 193 deletions(-) create mode 100644 frontend/lib/components/AddBrainModal/components/PublicAccessConfirmationModal.tsx create mode 100644 frontend/lib/components/AddBrainModal/styles.css create mode 100644 frontend/lib/components/ui/Radio.tsx diff --git a/frontend/lib/api/brain/types.ts b/frontend/lib/api/brain/types.ts index 32b846911..ddd8437ba 100644 --- a/frontend/lib/api/brain/types.ts +++ b/frontend/lib/api/brain/types.ts @@ -1,4 +1,5 @@ import { BrainRoleType } from "@/lib/components/BrainUsers/types"; +import { BrainStatus } from "@/lib/types/brainConfig"; export type SubscriptionUpdatableProperties = { role: BrainRoleType | null; @@ -7,7 +8,7 @@ export type SubscriptionUpdatableProperties = { export type CreateBrainInput = { name: string; description?: string; - status?: string; + status?: BrainStatus; model?: string; temperature?: number; max_tokens?: number; diff --git a/frontend/lib/components/AddBrainModal/AddBrainModal.tsx b/frontend/lib/components/AddBrainModal/AddBrainModal.tsx index 6742eb657..2d2c33256 100644 --- a/frontend/lib/components/AddBrainModal/AddBrainModal.tsx +++ b/frontend/lib/components/AddBrainModal/AddBrainModal.tsx @@ -1,5 +1,6 @@ +/* eslint-disable max-lines */ /* eslint-disable @typescript-eslint/no-unsafe-assignment */ -/* eslint-disable */ + import { useTranslation } from "react-i18next"; import { MdAdd } from "react-icons/md"; @@ -9,9 +10,11 @@ import Field from "@/lib/components/ui/Field"; import { Modal } from "@/lib/components/ui/Modal"; import { defineMaxTokens } from "@/lib/helpers/defineMaxTokens"; -import { Divider } from "../ui/Divider"; -import { TextArea } from "../ui/TextArea"; +import { PublicAccessConfirmationModal } from "./components/PublicAccessConfirmationModal"; import { useAddBrainModal } from "./hooks/useAddBrainModal"; +import { Divider } from "../ui/Divider"; +import { Radio } from "../ui/Radio"; +import { TextArea } from "../ui/TextArea"; export const AddBrainModal = (): JSX.Element => { const { t } = useTranslation(["translation", "brain", "config"]); @@ -20,150 +23,170 @@ export const AddBrainModal = (): JSX.Element => { isShareModalOpen, setIsShareModalOpen, register, - openAiKey, temperature, maxTokens, model, isPending, pickPublicPrompt, accessibleModels, + brainStatusOptions, + status, + isPublicAccessConfirmationModalOpened, + onCancelPublicAccess, + onConfirmPublicAccess, } = useAddBrainModal(); return ( - void 0} - variant={"tertiary"} - className="border-0" - data-testid="add-brain-button" - > - {t("newBrain", { ns: "brain" })} - - - } - title={t("newBrainTitle", { ns: "brain" })} - desc={t("newBrainSubtitle", { ns: "brain" })} - isOpen={isShareModalOpen} - setOpen={setIsShareModalOpen} - CloseTrigger={
} - > -
{ - e.preventDefault(); - void handleSubmit(); - }} - className="my-10 flex flex-col items-center gap-2" - > - - -