Skip to content

Commit

Permalink
Adjust MAT confirmation modal logic
Browse files Browse the repository at this point in the history
  • Loading branch information
majakomel committed Feb 27, 2023
1 parent 63d7a14 commit d224928
Showing 1 changed file with 10 additions and 6 deletions.
16 changes: 10 additions & 6 deletions components/aggregation/mat/Form.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -296,7 +301,6 @@ export const Form = ({ onSubmit, testNames, query }) => {
</Flex>
{ showDatePicker &&
<DateRangePicker
max={MAX_RANGE_DAYS}
handleRangeSelect={handleRangeSelect}
initialRange={{from: getValues('since'), to: getValues('until')}}
close={() => setShowDatePicker(false)}
Expand Down

1 comment on commit d224928

@vercel
Copy link

@vercel vercel bot commented on d224928 Feb 27, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Successfully deployed to the following URLs:

explorer – ./

explorer-ooni1.vercel.app
explorer-git-master-ooni1.vercel.app
explorer-one.vercel.app

Please sign in to comment.