diff --git a/frontend/src/components/SurveyModal/CheckboxList.tsx b/frontend/src/components/SurveyModal/CheckboxList.tsx index c0bd9b8..fac837e 100644 --- a/frontend/src/components/SurveyModal/CheckboxList.tsx +++ b/frontend/src/components/SurveyModal/CheckboxList.tsx @@ -8,15 +8,32 @@ export type CheckboxListProps = { label: string description?: string maxValues?: number + hasError?: boolean } -export function CheckboxList({ field, data, watch, label, description, maxValues = data.length }: CheckboxListProps) { +export function CheckboxList({ + field, + data, + watch, + label, + description, + maxValues = data.length, + hasError, +}: CheckboxListProps) { const selectedOptions: string[] = watch(field.name, []) || [] const getDisabled = (value: string) => !selectedOptions.includes(value) && selectedOptions.length >= maxValues return ( -
+
!selectedOptions.includes(value) && selectedOptions.length >= maxValues return ( -
+
{description} diff --git a/frontend/src/components/SurveyModal/index.tsx b/frontend/src/components/SurveyModal/index.tsx index 4e82479..645bcb3 100644 --- a/frontend/src/components/SurveyModal/index.tsx +++ b/frontend/src/components/SurveyModal/index.tsx @@ -41,12 +41,19 @@ type SchemaToComponentsProps = { renderFilter?: Record } function SchemaToComponents({ schema, formHook, renderFilter = {} }: SchemaToComponentsProps) { - const { control, setValue, watch, register } = formHook // passed from parent cause it needed for filter + const { + control, + setValue, + watch, + register, + formState: { errors }, + } = formHook // passed from parent cause it needed for filter return schema .filter((item) => renderFilter?.[item.id] ?? true) .map((item) => { switch (item.type) { case "select": { + const hasError = !!errors[item.id] return ( @@ -70,6 +81,7 @@ function SchemaToComponents({ schema, formHook, renderFilter = {} }: SchemaToCom ) } case "checkboxOther": { + const hasError = !!errors[item.id] return ( )} /> ) } case "textarea": { + const hasError = !!errors[item.id] return ( {item.id === "a7b52f44-cc92-4df5-bf26-f45a66fe5cb0" && ( @@ -119,7 +133,9 @@ function SchemaToComponents({ schema, formHook, renderFilter = {} }: SchemaToCom description={item?.description} styles={{ wrapper: { - "--input-bd-focus": "var(--mantine-color-secondary-0)", + "--input-bd-focus": hasError ? "tomato" : "var(--mantine-color-secondary-0)", + "--input-invalid": "tomato", + border: hasError ? "2px solid tomato" : undefined, }, }} /> @@ -130,30 +146,38 @@ function SchemaToComponents({ schema, formHook, renderFilter = {} }: SchemaToCom return (
- {(item.list ?? []).map((listItem: string, index: number) => ( - ( - + )} + /> + ) + })}
) @@ -178,48 +202,62 @@ function SchemaToComponents({ schema, formHook, renderFilter = {} }: SchemaToCom {item?.description} - {(item.list ?? []).map((listItem: string, index: number) => ( - ( - - { + const fieldName = `${item.id}-${index}` + const hasError = !!errors[fieldName] + return ( + ( + - {listItem} - - ({ - value: x, - label: String(x), - }))} - label={null} - styles={{ - root: { - "--slider-color": "var(--mantine-color-secondary-0)", - }, - }} - /> - - )} - /> - ))} + + {listItem} + + ({ + value: x, + label: String(x), + }))} + label={null} + styles={{ + root: { + "--slider-color": hasError + ? "tomato" + : "var(--mantine-color-secondary-0)", + }, + }} + /> + + )} + /> + ) + })}
) } case "checkboxList": { + const hasError = !!errors[item.id] return ( )} />