mirror of
https://github.com/hexastack/hexabot
synced 2025-06-26 18:27:28 +00:00
fix(frontend): apply feedback
This commit is contained in:
parent
74beb9426c
commit
da5200eb1b
@ -131,9 +131,14 @@ export const ContentTypeForm: FC<ComponentFormProps<IContentType>> = ({
|
||||
gap={2}
|
||||
>
|
||||
<FieldInput
|
||||
{...{ index, remove, control, setValue }}
|
||||
uuid={f.uuid}
|
||||
index={index}
|
||||
remove={remove}
|
||||
control={control}
|
||||
setValue={setValue}
|
||||
disabled={READ_ONLY_FIELDS.includes(f.label as any)}
|
||||
contentTypeField={contentType?.fields?.find(
|
||||
({ uuid }) => uuid === f.uuid,
|
||||
)}
|
||||
/>
|
||||
</ContentItem>
|
||||
))}
|
||||
|
@ -18,13 +18,17 @@ import {
|
||||
import { IconButton } from "@/app-components/buttons/IconButton";
|
||||
import { Input } from "@/app-components/inputs/Input";
|
||||
import { useTranslate } from "@/hooks/useTranslate";
|
||||
import { ContentFieldType, IContentType } from "@/types/content-type.types";
|
||||
import {
|
||||
ContentField,
|
||||
ContentFieldType,
|
||||
IContentType,
|
||||
} from "@/types/content-type.types";
|
||||
import { slugify } from "@/utils/string";
|
||||
|
||||
export const FieldInput = ({
|
||||
setValue,
|
||||
index,
|
||||
uuid,
|
||||
contentTypeField,
|
||||
...props
|
||||
}: {
|
||||
index: number;
|
||||
@ -32,7 +36,7 @@ export const FieldInput = ({
|
||||
remove: UseFieldArrayRemove;
|
||||
control: Control<IContentType>;
|
||||
setValue: UseFormSetValue<IContentType>;
|
||||
uuid?: string;
|
||||
contentTypeField?: ContentField;
|
||||
}) => {
|
||||
const { t } = useTranslate();
|
||||
|
||||
@ -61,14 +65,8 @@ export const FieldInput = ({
|
||||
helperText={fieldState.error?.message}
|
||||
onChange={(e) => {
|
||||
const currentValue = e.target.value;
|
||||
const { label, name } =
|
||||
props.control._defaultValues.fields?.find(
|
||||
(field) => field?.uuid === uuid,
|
||||
) || {};
|
||||
|
||||
if (label && name !== slugify(label)) {
|
||||
name && setValue(`fields.${index}.name`, name);
|
||||
} else {
|
||||
if (!contentTypeField?.label || !contentTypeField?.name) {
|
||||
setValue(
|
||||
`fields.${index}.name`,
|
||||
currentValue ? slugify(currentValue) : "",
|
||||
|
Loading…
Reference in New Issue
Block a user