From 171b95d40e877066c994f1ded6e4d970acc24b79 Mon Sep 17 00:00:00 2001 From: Maciej Bodek Date: Wed, 8 Jan 2025 11:49:58 +0100 Subject: [PATCH] Enhance validation --- .../src/scenes/Editor/Metrics/date-time-picker.tsx | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/packages/web-console/src/scenes/Editor/Metrics/date-time-picker.tsx b/packages/web-console/src/scenes/Editor/Metrics/date-time-picker.tsx index 4431ec153..1aad2f7eb 100644 --- a/packages/web-console/src/scenes/Editor/Metrics/date-time-picker.tsx +++ b/packages/web-console/src/scenes/Editor/Metrics/date-time-picker.tsx @@ -187,7 +187,8 @@ export const DateTimePicker = ({ "string.empty": "Please enter a date or duration", "string.invalidDate": "Date format or duration is invalid", "string.toIsBeforeFrom": "To date must be after From date", - "string.dateInFuture": "Date cannot be in the future", + "string.dateInFuture": "Please set a date in the past or use `now`", + "string.fromIsAfterTo": "From date must be before To date", } const schema = Joi.object({ @@ -199,7 +200,9 @@ export const DateTimePicker = ({ return helpers.error("string.invalidDate") } else if ( new Date(dateValue).getTime() >= - new Date(helpers.state.ancestors[0].dateTo).getTime() + new Date( + durationTokenToDate(helpers.state.ancestors[0].dateTo), + ).getTime() ) { return helpers.error("string.fromIsAfterTo") } else if (new Date(dateValue).getTime() > new Date().getTime()) { @@ -216,7 +219,9 @@ export const DateTimePicker = ({ return helpers.error("string.invalidDate") } else if ( new Date(dateValue).getTime() <= - new Date(helpers.state.ancestors[0].dateFrom).getTime() + new Date( + durationTokenToDate(helpers.state.ancestors[0].dateFrom), + ).getTime() ) { return helpers.error("string.toIsBeforeFrom") } else if (new Date(dateValue).getTime() > new Date().getTime()) {