Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 19 additions & 16 deletions components/form/IntlFields.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Input, Select } from 'ooni-components'
import { Input, Textarea, Select } from 'ooni-components'
import { Controller, useFieldArray, useFormContext } from 'react-hook-form'
import { FaRegTrashCan } from 'react-icons/fa6'
import { useIntl } from 'react-intl'
Expand All @@ -12,7 +12,7 @@ const langOptions = supportedLanguages.map((lang) => ({
),
}))

const IntlFields = ({ name }: FieldsPropTypes) => {
const IntlFields = ({ name, inputType = 'text' }: FieldsPropTypes & { inputType?: 'text' | 'textarea' }) => {
const intl = useIntl()
const { control } = useFormContext()
const { fields, append, remove } = useFieldArray({
Expand Down Expand Up @@ -63,20 +63,23 @@ const IntlFields = ({ name }: FieldsPropTypes) => {
<div className="flex flex-row mt-2 md:mt-0 items-end">
<div className="w-full">
<Controller
render={({ field, fieldState }) => (
<Input
label={intl.formatMessage({
id: 'TestListForm.Intl.Translation',
})}
{...field}
error={
!!fieldState?.error?.message &&
intl.formatMessage({ id: fieldState?.error?.message })
}
/>
)}
name={`${name}[${index}].value`}
control={control}
render={({ field, fieldState }) => {
const Component = inputType === 'textarea' ? Textarea : Input
return (
<Component
label={intl.formatMessage({
id: 'TestListForm.Intl.Translation',
})}
{...field}
error={
!!fieldState?.error?.message &&
intl.formatMessage({ id: fieldState?.error?.message })
}
/>
)
}}
name={`${name}[${index}].value`}
control={control}
/>
</div>
<button
Expand Down
2 changes: 1 addition & 1 deletion components/form/TestListForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -284,7 +284,7 @@ const TestListForm = ({
name="description"
control={control}
/>
<IntlFields name="description_intl" />
<IntlFields name="description_intl" inputType="textarea" />
</StyledInputWrapper>
{isClient && (
<StyledInputWrapper>
Expand Down