From 58b2960899483e326766204d1008fd2e905a6994 Mon Sep 17 00:00:00 2001 From: Thomas L Fagermyr Date: Mon, 14 Oct 2024 14:11:40 +0200 Subject: [PATCH] feat: Added validation for area model --- .../AreaCoordinates/hooks/AreaCoordinates.hooks.ts | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/components/AreaCoordinates/hooks/AreaCoordinates.hooks.ts b/src/components/AreaCoordinates/hooks/AreaCoordinates.hooks.ts index 71039b4..7fcece8 100644 --- a/src/components/AreaCoordinates/hooks/AreaCoordinates.hooks.ts +++ b/src/components/AreaCoordinates/hooks/AreaCoordinates.hooks.ts @@ -22,6 +22,12 @@ export const validateCoordinates = async ( errors.area = 'You must select a model area'; } + if (area && area.coordinates[0].x > area.coordinates[1].x) { + errors.x0 = 'X start cannot be greater than X end.'; + } + if (area && area.coordinates[0].y > area.coordinates[1].y) { + errors.y0 = 'Y start cannot be greater than Y end.'; + } if (area && area.coordinates[0].x === area.coordinates[1].x) { errors.x0 = "X start/end coordinates can't be equal."; }