Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Updated logic to Not allow future date as incorporation date #5939

Merged
merged 6 commits into from
Nov 16, 2021
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/languages/en.js
Original file line number Diff line number Diff line change
Expand Up @@ -431,6 +431,7 @@ export default {
addressStreet: 'Please enter a valid street address that is not a PO Box',
addressState: 'Please select a valid state',
incorporationDate: 'Please enter a valid date',
incorporationDateFuture: 'Incorporation date cannot be in the future',
incorporationState: 'Please enter a valid state',
industryCode: 'Please enter a valid industry classification code. Must be 6 digits.',
restrictedBusiness: 'Please confirm company is not on the list of restricted businesses',
Expand Down
1 change: 1 addition & 0 deletions src/languages/es.js
Original file line number Diff line number Diff line change
Expand Up @@ -431,6 +431,7 @@ export default {
addressStreet: 'Ingresa una calle de dirección válida que no sea un apartado postal',
addressState: 'Por favor, selecciona un estado',
incorporationDate: 'Ingresa una fecha válida',
incorporationDateFuture: 'La fecha de incorporación no puede ser futura',
incorporationState: 'Ingresa un estado válido',
industryCode: 'Ingresa un código de clasificación de industria válido',
restrictedBusiness: 'Confirma que la empresa no está en la lista de negocios restringidos',
Expand Down
18 changes: 18 additions & 0 deletions src/libs/ValidationUtils.js
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,23 @@ function isValidDate(date) {
return testDate.isValid() && testDate.isBetween(pastDate, futureDate);
}

/**
* Validate that date entered isn't a future date.
*
* @param {String|Date} date
* @returns {Boolean} true if valid
*/
function isValidPastDate(date) {
if (!date) {
return false;
}

const pastDate = moment().subtract(1000, 'years');
const currentDate = moment();
const testDate = moment(date).startOf('day');
puneetlath marked this conversation as resolved.
Show resolved Hide resolved
return testDate.isValid() && testDate.isBetween(pastDate, currentDate);
}

/**
* Used to validate a value that is "required".
*
Expand Down Expand Up @@ -216,6 +233,7 @@ export {
meetsAgeRequirements,
isValidAddress,
isValidDate,
isValidPastDate,
isValidSecurityCode,
isValidExpirationDate,
isValidDebitCard,
Expand Down
54 changes: 34 additions & 20 deletions src/pages/ReimbursementAccount/CompanyStep.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ import TextLink from '../../components/TextLink';
import StatePicker from '../../components/StatePicker';
import withLocalize, {withLocalizePropTypes} from '../../components/withLocalize';
import {
isValidDate, isRequiredFulfilled, isValidURL, isValidPhoneWithSpecialChars,
isValidDate, isValidPastDate, isRequiredFulfilled, isValidURL, isValidPhoneWithSpecialChars,
} from '../../libs/ValidationUtils';
import compose from '../../libs/compose';
import ONYXKEYS from '../../ONYXKEYS';
Expand Down Expand Up @@ -94,13 +94,15 @@ class CompanyStep extends React.Component {
website: 'bankAccount.error.website',
companyTaxID: 'bankAccount.error.taxID',
incorporationDate: 'bankAccount.error.incorporationDate',
incorporationDateFuture: 'bankAccount.error.incorporationDateFuture',
incorporationType: 'bankAccount.error.companyType',
hasNoConnectionToCannabis: 'bankAccount.error.restrictedBusiness',
};

this.getErrorText = inputKey => ReimbursementAccountUtils.getErrorText(this.props, this.errorTranslationKeys, inputKey);
this.clearError = inputKey => ReimbursementAccountUtils.clearError(this.props, inputKey);
this.getErrors = () => ReimbursementAccountUtils.getErrors(this.props);
this.clearDateErrorsAndSetValue = this.clearDateErrorsAndSetValue.bind(this);
}

getFormattedAddressValue() {
Expand Down Expand Up @@ -139,6 +141,16 @@ class CompanyStep extends React.Component {
this.clearError(inputKey);
}

/**
* Clear errors associated with incorporation date.
*
* @param {String} value
*/
clearDateErrorsAndSetValue(value) {
this.clearErrorAndSetValue('incorporationDate', value);
this.clearError('incorporationDateFuture');
PrashantMangukiya marked this conversation as resolved.
Show resolved Hide resolved
}

/**
* @returns {Boolean}
*/
Expand All @@ -157,6 +169,10 @@ class CompanyStep extends React.Component {
errors.incorporationDate = true;
}

if (!isValidPastDate(this.state.incorporationDate)) {
errors.incorporationDateFuture = true;
}

if (!isValidPhoneWithSpecialChars(this.state.companyPhone)) {
errors.companyPhone = true;
}
Expand Down Expand Up @@ -250,25 +266,23 @@ class CompanyStep extends React.Component {
hasError={this.getErrors().incorporationType}
/>
</View>
<View style={[styles.flexRow, styles.mt4]}>
<View style={[styles.flex1, styles.mr2]}>
<DatePicker
label={this.props.translate('companyStep.incorporationDate')}
onChange={value => this.clearErrorAndSetValue('incorporationDate', value)}
value={this.state.incorporationDate}
placeholder={this.props.translate('companyStep.incorporationDatePlaceholder')}
errorText={this.getErrorText('incorporationDate')}
translateX={-14}
/>
</View>
<View style={[styles.flex1]}>
<StatePicker
label={this.props.translate('companyStep.incorporationState')}
onChange={value => this.clearErrorAndSetValue('incorporationState', value)}
value={this.state.incorporationState}
hasError={this.getErrors().incorporationState}
/>
</View>
<View style={styles.mt4}>
<DatePicker
label={this.props.translate('companyStep.incorporationDate')}
onChange={this.clearDateErrorsAndSetValue}
value={this.state.incorporationDate}
placeholder={this.props.translate('companyStep.incorporationDatePlaceholder')}
errorText={this.getErrorText('incorporationDate') || this.getErrorText('incorporationDateFuture')}
translateX={-14}
/>
</View>
<View style={styles.mt4}>
<StatePicker
label={this.props.translate('companyStep.incorporationState')}
onChange={value => this.clearErrorAndSetValue('incorporationState', value)}
value={this.state.incorporationState}
hasError={this.getErrors().incorporationState}
/>
</View>
<CheckboxWithLabel
isChecked={this.state.hasNoConnectionToCannabis}
Expand Down