Skip to content

Commit

Permalink
feat(newBrain): update data validation logic and add * on required fi…
Browse files Browse the repository at this point in the history
…elds (#1065)

* feat(createBrain): add * on required fields

* fix: update brain data validation logic
  • Loading branch information
mamadoudicko authored Aug 30, 2023
1 parent f84b1b3 commit 182099c
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ export const SettingsTab = ({ brainId }: SettingsTabProps): JSX.Element => {
placeholder={t("brainNamePlaceholder", { ns: "brain" })}
autoComplete="off"
className="flex-1"
required
{...register("name")}
/>
</div>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -209,9 +209,9 @@ export const useSettingsTab = ({ brainId }: UseSettingsTabProps) => {
if (!hasChanges && checkDirty) {
return;
}
const { name: isNameDirty } = dirtyFields;
const { name, openAiKey: openai_api_key } = getValues();
if (isNameDirty !== undefined && isNameDirty && name.trim() === "") {

if (name.trim() === "") {
publish({
variant: "danger",
text: t("nameRequired", { ns: "config" }),
Expand All @@ -222,6 +222,7 @@ export const useSettingsTab = ({ brainId }: UseSettingsTabProps) => {

if (
openai_api_key !== undefined &&
openai_api_key !== "" &&
!(await validateOpenAIKey(
openai_api_key,
{
Expand Down
1 change: 1 addition & 0 deletions frontend/lib/components/AddBrainModal/AddBrainModal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ export const AddBrainModal = (): JSX.Element => {
placeholder={t("brainNamePlaceholder", { ns: "brain" })}
autoComplete="off"
className="flex-1"
required
{...register("name")}
/>

Expand Down
6 changes: 5 additions & 1 deletion frontend/lib/components/ui/Field.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,16 @@ interface FieldProps
}

const Field = forwardRef(
({ label, className, name, ...props }: FieldProps, forwardedRef) => {
(
{ label, className, name, required = false, ...props }: FieldProps,
forwardedRef
) => {
return (
<fieldset className={cn("flex flex-col w-full", className)} name={name}>
{label && (
<label htmlFor={name} className="text-sm">
{label}
{required && <span>*</span>}
</label>
)}
<input
Expand Down

0 comments on commit 182099c

Please sign in to comment.