refactor(web): FieldInput form type unknown (drop any); wire localized_text required; a11y/comment nits
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -10,8 +10,7 @@ import { Label } from "@/components/ui/label";
|
|||||||
type FieldDefinitionView = components["schemas"]["FieldDefinitionView"];
|
type FieldDefinitionView = components["schemas"]["FieldDefinitionView"];
|
||||||
type LabelView = components["schemas"]["LabelView"];
|
type LabelView = components["schemas"]["LabelView"];
|
||||||
|
|
||||||
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
type FieldForm = UseFormReturn<{ fields: Record<string, unknown> }>;
|
||||||
type AnyForm = UseFormReturn<{ fields: Record<string, any> }>;
|
|
||||||
|
|
||||||
function labelIn(labels: LabelView[], lang: string): string {
|
function labelIn(labels: LabelView[], lang: string): string {
|
||||||
return (
|
return (
|
||||||
@@ -62,7 +61,7 @@ export function FieldInput({
|
|||||||
form,
|
form,
|
||||||
}: {
|
}: {
|
||||||
definition: FieldDefinitionView;
|
definition: FieldDefinitionView;
|
||||||
form: AnyForm;
|
form: FieldForm;
|
||||||
}) {
|
}) {
|
||||||
const { t, i18n } = useTranslation();
|
const { t, i18n } = useTranslation();
|
||||||
const lang = i18n.language.startsWith("sv") ? "sv" : "en";
|
const lang = i18n.language.startsWith("sv") ? "sv" : "en";
|
||||||
@@ -101,6 +100,7 @@ export function FieldInput({
|
|||||||
);
|
);
|
||||||
|
|
||||||
case "boolean":
|
case "boolean":
|
||||||
|
// A checkbox always has a boolean value, so `required` is a no-op here.
|
||||||
return (
|
return (
|
||||||
<div className="flex items-center gap-2">
|
<div className="flex items-center gap-2">
|
||||||
<Controller
|
<Controller
|
||||||
@@ -122,7 +122,7 @@ export function FieldInput({
|
|||||||
case "localized_text":
|
case "localized_text":
|
||||||
return (
|
return (
|
||||||
<div className="space-y-1">
|
<div className="space-y-1">
|
||||||
<Label>{label}</Label>
|
<div className="text-sm font-medium">{label}</div>
|
||||||
|
|
||||||
<Label
|
<Label
|
||||||
htmlFor={`${definition.key}-en`}
|
htmlFor={`${definition.key}-en`}
|
||||||
@@ -133,7 +133,7 @@ export function FieldInput({
|
|||||||
|
|
||||||
<Input
|
<Input
|
||||||
id={`${definition.key}-en`}
|
id={`${definition.key}-en`}
|
||||||
{...form.register(`fields.${definition.key}.en` as `fields.${string}`)}
|
{...form.register(`fields.${definition.key}.en` as `fields.${string}`, { required: definition.required })}
|
||||||
/>
|
/>
|
||||||
|
|
||||||
<Label
|
<Label
|
||||||
@@ -195,7 +195,7 @@ function TermField({
|
|||||||
placeholder,
|
placeholder,
|
||||||
}: {
|
}: {
|
||||||
definition: FieldDefinitionView;
|
definition: FieldDefinitionView;
|
||||||
form: AnyForm;
|
form: FieldForm;
|
||||||
label: string;
|
label: string;
|
||||||
lang: string;
|
lang: string;
|
||||||
placeholder: string;
|
placeholder: string;
|
||||||
@@ -233,7 +233,7 @@ function AuthorityField({
|
|||||||
placeholder,
|
placeholder,
|
||||||
}: {
|
}: {
|
||||||
definition: FieldDefinitionView;
|
definition: FieldDefinitionView;
|
||||||
form: AnyForm;
|
form: FieldForm;
|
||||||
label: string;
|
label: string;
|
||||||
lang: string;
|
lang: string;
|
||||||
placeholder: string;
|
placeholder: string;
|
||||||
|
|||||||
Reference in New Issue
Block a user