From ddd375d4cee6d663276b7cc18f9c46bf8fa3c020 Mon Sep 17 00:00:00 2001 From: Bilal Catic Date: Fri, 6 Sep 2019 07:25:03 +0200 Subject: [PATCH] disable sending fees for current or month in future --- .../GenerateFeesInORDButton/index.js | 24 +++++++++++++++++-- 1 file changed, 22 insertions(+), 2 deletions(-) diff --git a/client/src/components/GenerateFeesInORDButton/index.js b/client/src/components/GenerateFeesInORDButton/index.js index 43e6d0f..ab645c6 100644 --- a/client/src/components/GenerateFeesInORDButton/index.js +++ b/client/src/components/GenerateFeesInORDButton/index.js @@ -1,8 +1,10 @@ import React, { Component } from 'react'; import { connect } from 'react-redux'; import { Button, Modal } from 'semantic-ui-react'; +import moment from 'moment'; import { addFeesToOrd } from '../../store/actions'; +import { defaultDateFormat } from '../../constants/constants'; class GenerateFeesInORDButton extends Component { state = { open: false }; @@ -21,7 +23,25 @@ class GenerateFeesInORDButton extends Component { render() { const { open, size } = this.state; - const { singleMember, disabled } = this.props; + const { singleMember, disabled, dateRange } = this.props; + + let submitIsDisabled = disabled; + + if (dateRange && dateRange.startDate) { + const startDateMoment = moment(dateRange.startDate, defaultDateFormat); + const currentMoment = moment(); + + const startMomentMonth = startDateMoment.month(); + const startMomentYear = startDateMoment.year(); + const currentMonth = currentMoment.month(); + const currentYear = currentMoment.year(); + + const monthSelectorIsInPast = (startMomentYear < currentYear) || + (startMomentYear === currentYear && startMomentMonth < currentMonth); + + submitIsDisabled = disabled || !monthSelectorIsInPast; + } + const modalContent = singleMember ? 'This will remove all existing fees in ORD for selected member in selected date range and generate new fees based on shown incident tables. Do you want to continue ?': @@ -29,7 +49,7 @@ class GenerateFeesInORDButton extends Component { return (
- + Add fees to the ORD