From d22492835c5226340030aa80360a0a6f3e62f62a Mon Sep 17 00:00:00 2001 From: Maja Komel Date: Mon, 27 Feb 2023 12:30:38 +0100 Subject: [PATCH] Adjust MAT confirmation modal logic --- components/aggregation/mat/Form.js | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/components/aggregation/mat/Form.js b/components/aggregation/mat/Form.js index 32a10e357..12fc83843 100644 --- a/components/aggregation/mat/Form.js +++ b/components/aggregation/mat/Form.js @@ -17,8 +17,8 @@ import DateRangePicker from '../../DateRangePicker' import { ConfirmationModal } from './ConfirmationModal' import { TestNameOptions } from '../../TestNameOptions' -const THRESHOLD_IN_MONTHS = 12 -const MAX_RANGE_DAYS = 31 +const DAY_GRAIN_THRESHOLD_IN_MONTHS = 12 +const WEEK_GRAIN_THRESHOLD_IN_MONTHS = 36 export const StyledLabel = styled(Label).attrs({ my: 2, @@ -175,10 +175,15 @@ export const Form = ({ onSubmit, testNames, query }) => { const maybeWarnBeforeSubmit = useCallback((e) => { e.preventDefault() - const [since, until] = getValues(['since', 'until']) - const isDurationMoreThanThresold = (dayjs(until).diff(dayjs(since), 'month')) > THRESHOLD_IN_MONTHS + const [since, until, timeGrain] = getValues(['since', 'until', 'time_grain']) + const shouldShowConfirmationModal = () => { + if (timeGrain === 'month') return false + const diff = (dayjs(until).diff(dayjs(since), 'month')) + if (timeGrain === 'week') return diff > WEEK_GRAIN_THRESHOLD_IN_MONTHS + return diff > DAY_GRAIN_THRESHOLD_IN_MONTHS + } - if (isDurationMoreThanThresold) { + if (shouldShowConfirmationModal()) { setShowConfirmation(true) } else { // Otherwise just continue with submission without interruption @@ -296,7 +301,6 @@ export const Form = ({ onSubmit, testNames, query }) => { { showDatePicker && setShowDatePicker(false)}