From 0935091ae0f9923159bcd94692eccc2622465137 Mon Sep 17 00:00:00 2001 From: mheggelund Date: Fri, 1 Dec 2023 10:10:38 +0100 Subject: [PATCH] refactor: Uppdated error styling on input validation. --- .../AreaCoordinates.styled.tsx | 20 +------ .../AreaCoordinates/AreaCoordinates.tsx | 55 ++++++++----------- .../ModelMetadata/ModelMetadata.styled.ts | 13 ----- .../AddModel/ModelMetadata/ModelMetadata.tsx | 18 +++--- 4 files changed, 33 insertions(+), 73 deletions(-) diff --git a/src/components/AreaCoordinates/AreaCoordinates.styled.tsx b/src/components/AreaCoordinates/AreaCoordinates.styled.tsx index 7d750731..942ee607 100644 --- a/src/components/AreaCoordinates/AreaCoordinates.styled.tsx +++ b/src/components/AreaCoordinates/AreaCoordinates.styled.tsx @@ -19,25 +19,7 @@ export const CoordinateGroup = styled.div` display: flex; flex-direction: column; - > .autocomplete-error { - color: red; - } - - > .autocomplete-error { - > div { - > div { - border: solid 2px red; - } - } - } - - > .input-error { - > div { - > input { - border: solid 2px red; - } - } - + > .error { color: red; } `; diff --git a/src/components/AreaCoordinates/AreaCoordinates.tsx b/src/components/AreaCoordinates/AreaCoordinates.tsx index 6903a7aa..8b408804 100644 --- a/src/components/AreaCoordinates/AreaCoordinates.tsx +++ b/src/components/AreaCoordinates/AreaCoordinates.tsx @@ -18,18 +18,7 @@ import { AnalogueModelsService } from '../../api/generated/services/AnalogueMode import optionTypes from '../../features/Compute/ComputeVariogram/CaseCard/CaseCard'; import * as Styled from './AreaCoordinates.styled'; -// const areaSchema = z.object({ -// id: z.number(), -// name: z.string().min(1, { message: 'Ares is required' }), -// }); - const schema = z.object({ - // area: z.array( - // z.object({ - // id: z.number(), - // name: z.string().min(1, { message: 'Ares is required' }), - // }), - // ), area: z.string().min(1, { message: 'Ares is required' }), topX: z @@ -50,9 +39,6 @@ const schema = z.object({ .max(12, { message: 'Coordinate is too long, max 12 characters' }), }); -// type innput = z.input; -// type output = z.infer; - export const AreaCoordinates = ({ modelId }: { modelId: string }) => { const [showSaveAlert, setSaveAlert] = useState(false); const { data, isLoading } = useQuery({ @@ -70,7 +56,6 @@ export const AreaCoordinates = ({ modelId }: { modelId: string }) => { { id: 12, name: 'Distal' }, ]; - // const selectedArea: optionTypes[] = [{ id: 10, name: 'Proximal' }]; const areaCoordinats = { area: '', topX: '', @@ -111,47 +96,53 @@ export const AreaCoordinates = ({ modelId }: { modelId: string }) => { Area to define Array(value), - // } - } + variant={errors.area ? 'error' : undefined} + {...register('area')} label={'Select area'} options={modelAreas} optionLabel={(option) => option.name} onOptionsChange={handleSelectChange} > -
+
{errors.area && errors.area?.message}
Top Left Corner -
+
-
+
Bottom Right Corner -
+
-
+
diff --git a/src/features/AddModel/ModelMetadata/ModelMetadata.styled.ts b/src/features/AddModel/ModelMetadata/ModelMetadata.styled.ts index 003f51f1..0ead148b 100644 --- a/src/features/AddModel/ModelMetadata/ModelMetadata.styled.ts +++ b/src/features/AddModel/ModelMetadata/ModelMetadata.styled.ts @@ -38,23 +38,10 @@ export const InputfieldRequired = styled.div` > label { color: red; } - - > .model-required { - > div { - border: solid 2px red; - } - } `; export const Required = styled.div` > label { color: red; } - > .model-required { - > div { - > div { - border: solid 2px red; - } - } - } `; diff --git a/src/features/AddModel/ModelMetadata/ModelMetadata.tsx b/src/features/AddModel/ModelMetadata/ModelMetadata.tsx index 3f2f7a8b..f85242d9 100644 --- a/src/features/AddModel/ModelMetadata/ModelMetadata.tsx +++ b/src/features/AddModel/ModelMetadata/ModelMetadata.tsx @@ -79,7 +79,7 @@ export const ModelMetadata = ({ option.name} @@ -154,8 +154,8 @@ export const ModelMetadata = ({ , type: string, @@ -203,7 +203,7 @@ const MetadataSelect = ({ return ( d.metadataType === type)} optionLabel={(option) => option.value}