mirror of
https://github.com/hexastack/hexabot
synced 2025-06-26 18:27:28 +00:00
fix(frontend): instable blocks type
This commit is contained in:
parent
ac9c10c576
commit
4bcaf6c786
@ -17,6 +17,7 @@ import { IBlockAttributes } from "@/types/block.types";
|
|||||||
import { useBlock } from "./BlockFormProvider";
|
import { useBlock } from "./BlockFormProvider";
|
||||||
import { FormSectionTitle } from "./FormSectionTitle";
|
import { FormSectionTitle } from "./FormSectionTitle";
|
||||||
import ReplacementTokens from "./inputs/ReplacementTokens";
|
import ReplacementTokens from "./inputs/ReplacementTokens";
|
||||||
|
import { getInputControls } from "./utils/inputControls";
|
||||||
|
|
||||||
const TextMessageForm = () => {
|
const TextMessageForm = () => {
|
||||||
const block = useBlock();
|
const block = useBlock();
|
||||||
@ -26,15 +27,6 @@ const TextMessageForm = () => {
|
|||||||
register,
|
register,
|
||||||
formState: { errors },
|
formState: { errors },
|
||||||
} = useFormContext<IBlockAttributes>();
|
} = useFormContext<IBlockAttributes>();
|
||||||
const getInputProps = (index: number) => {
|
|
||||||
return {
|
|
||||||
...register(`message.${index}`, {
|
|
||||||
required: t("message.message_is_required"),
|
|
||||||
}),
|
|
||||||
error: !!errors?.message?.[index],
|
|
||||||
helperText: errors?.message?.[index]?.message,
|
|
||||||
};
|
|
||||||
};
|
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<ContentItem>
|
<ContentItem>
|
||||||
@ -50,7 +42,12 @@ const TextMessageForm = () => {
|
|||||||
<MultipleInput
|
<MultipleInput
|
||||||
label=""
|
label=""
|
||||||
{...rest}
|
{...rest}
|
||||||
getInputProps={getInputProps}
|
getInputProps={getInputControls(
|
||||||
|
"message",
|
||||||
|
errors,
|
||||||
|
register,
|
||||||
|
t("message.text_message_is_invalid"),
|
||||||
|
)}
|
||||||
value={value as string[]}
|
value={value as string[]}
|
||||||
multiline={true}
|
multiline={true}
|
||||||
minRows={3}
|
minRows={3}
|
||||||
|
@ -18,6 +18,7 @@ import { SXStyleOptions } from "@/utils/SXStyleOptions";
|
|||||||
import { createValueWithId, ValueWithId } from "@/utils/valueWithId";
|
import { createValueWithId, ValueWithId } from "@/utils/valueWithId";
|
||||||
|
|
||||||
import PatternInput from "./PatternInput";
|
import PatternInput from "./PatternInput";
|
||||||
|
import { getInputControls } from "../../utils/inputControls";
|
||||||
|
|
||||||
type PatternsInputProps = {
|
type PatternsInputProps = {
|
||||||
value: Pattern[];
|
value: Pattern[];
|
||||||
@ -42,15 +43,6 @@ const PatternsInput: FC<PatternsInputProps> = ({ value, onChange }) => {
|
|||||||
register,
|
register,
|
||||||
formState: { errors },
|
formState: { errors },
|
||||||
} = useFormContext<any>();
|
} = useFormContext<any>();
|
||||||
const getInputProps = (index: number) => {
|
|
||||||
return {
|
|
||||||
...register(`message.${index}`, {
|
|
||||||
required: t("message.text_is_required"),
|
|
||||||
}),
|
|
||||||
error: !!errors?.message?.[index],
|
|
||||||
helperText: errors?.message?.[index]?.message,
|
|
||||||
};
|
|
||||||
};
|
|
||||||
const addInput = () => {
|
const addInput = () => {
|
||||||
setPatterns([...patterns, createValueWithId<Pattern>("")]);
|
setPatterns([...patterns, createValueWithId<Pattern>("")]);
|
||||||
};
|
};
|
||||||
@ -87,7 +79,12 @@ const PatternsInput: FC<PatternsInputProps> = ({ value, onChange }) => {
|
|||||||
idx={idx}
|
idx={idx}
|
||||||
value={value}
|
value={value}
|
||||||
onChange={updateInput(idx)}
|
onChange={updateInput(idx)}
|
||||||
getInputProps={getInputProps}
|
getInputProps={getInputControls(
|
||||||
|
"label",
|
||||||
|
errors,
|
||||||
|
register,
|
||||||
|
t("message.text_is_required"),
|
||||||
|
)}
|
||||||
/>
|
/>
|
||||||
</Fragment>
|
</Fragment>
|
||||||
))
|
))
|
||||||
|
@ -0,0 +1,34 @@
|
|||||||
|
/*
|
||||||
|
* Copyright © 2024 Hexastack. All rights reserved.
|
||||||
|
*
|
||||||
|
* Licensed under the GNU Affero General Public License v3.0 (AGPLv3) with the following additional terms:
|
||||||
|
* 1. The name "Hexabot" is a trademark of Hexastack. You may not use this name in derivative works without express written permission.
|
||||||
|
* 2. All derivative works must include clear attribution to the original creator and software, Hexastack and Hexabot, in a prominent location (e.g., in the software's "About" section, documentation, and README file).
|
||||||
|
*/
|
||||||
|
|
||||||
|
import {
|
||||||
|
Path,
|
||||||
|
FieldErrors,
|
||||||
|
FieldValues,
|
||||||
|
UseFormRegister,
|
||||||
|
} from "react-hook-form";
|
||||||
|
|
||||||
|
export const getInputControls =
|
||||||
|
<T extends FieldValues = FieldValues>(
|
||||||
|
field: string,
|
||||||
|
errors: FieldErrors<T>,
|
||||||
|
register: UseFormRegister<T>,
|
||||||
|
requiredMessage?: string,
|
||||||
|
) =>
|
||||||
|
(index: number) => ({
|
||||||
|
...register(
|
||||||
|
`${field}.${index}` as Path<T>,
|
||||||
|
requiredMessage
|
||||||
|
? {
|
||||||
|
required: requiredMessage,
|
||||||
|
}
|
||||||
|
: {},
|
||||||
|
),
|
||||||
|
error: !!errors?.[field]?.[index],
|
||||||
|
helperText: errors?.[field]?.[index]?.message,
|
||||||
|
});
|
Loading…
Reference in New Issue
Block a user