[HOLD for payment 2021-12-06] VBA - Able to proceed with future incorporation date for VBA flow.
If you haven’t already, check out our contributing guidelines for onboarding and email [email protected] to request to join our Slack channel!
Action Performed:
- Launch the app
- Log in with expensifail account
- Enable Staging server
- Click on deeplink https://staging.new.expensify.com/bank-account/contract
- Log in with Chase credentials
- In Company Information Page put future date. For example 01.01.2022
Expected Result:
Error should displayed below for invalid incorporated date.
Actual Result:
Able to proceed for future incorporated date
Workaround:
Unknown
Platform:
Where is this issue occurring?
- Web
- iOS
- Android
- Desktop App
- Mobile Web
Version Number: 1.1.7-0 Reproducible in staging?: Yes Reproducible in production?: Yes Logs: https://stackoverflow.com/c/expensify/questions/4856 Notes/Photos/Videos:
https://user-images.githubusercontent.com/43996225/136493502-a776ec2f-aa21-4834-a329-d03bd78290cf.mp4

Expensify/Expensify Issue URL: Issue reported by: Applause Slack conversation:
Triggered auto assignment to @tylerkaraszewski (Engineering), see https://stackoverflow.com/c/expensify/questions/4319 for more details.
Proposed Solution (If considered as external)
Here is Problem: For incorporationDate validation we are using isValidDate() function from src/libs/ValidationUtils.js. This function is checking that given date is between pastDate(current -1000 years) and futureDate(current + 1000 years) as shown code below:
https://github.com/Expensify/App/blob/79eafd4e2f5bd85547c189737e6655a3f49935d0/src/libs/ValidationUtils.js#L48-L57
https://github.com/Expensify/App/blob/79eafd4e2f5bd85547c189737e6655a3f49935d0/src/pages/ReimbursementAccount/CompanyStep.js#L131-L133
Solution 1: We can prepare new function within src/libs/ValidationUtils.js that can be used to validate incorporation date etc. i.e. It will validate given date between pastDate(current -1000 years) and currentDate as shown below.
function isValidIncorporationDate(date) {
if (!date) {
return false;
}
const pastDate = moment().subtract(1000, 'years');
const currentDate = moment();
const testDate = moment(date);
return testDate.isValid() && testDate.isBetween(pastDate, currentDate);
}
Within CompanyStep.js we have to validate date input using isValidIncorporationDate() as under
if (!isValidIncorporationDate(this.state.incorporationDate)) {
errors.incorporationDate = true;
}
Note: we can also keep generic name like isValidPastDate() etc. so it can be used for multiple purpose where date should be less then current date.
Solution 2: We can change code within isValidDate() function, so it allows date between pastDate(current -1000 years) and currentDate. (similar to solution1) But I will not suggest to change code for isValidDate() because isValidDate() can be used as general date validation where we need to allow date between past and future. So better to keep isValidDate() code as it and add new function to validate incorporation date etc.
Solution 3: We can disable future date within DatePicker for respective platform (Web, iOS and Android). At present not tested this, so can not say exactly how we can disable future date in calendar for each platform. But somhow we disable future date in calendar then also date input field is editable so user can input any date value (e.g. dd/mm/yyyy) via text input. So we also need to validate date during form submit. So for clean and simple code better to implement Solution1 that will validate date during form submit and fulfil the purpose.
Issue reproducible during KI retests.
@tylerkaraszewski Whoops! This issue is 2 days overdue. Let's get this updated quick!
I'm gonna unassign myself and add the external label.
Triggered auto assignment to @SofiedeVreese (External), see https://stackoverflow.com/c/expensify/questions/8582 for more details.
Posted on Upwork: https://www.upwork.com/jobs/~0107e38bdc744afef4
Triggered auto assignment to @puneetlath (Exported), see https://stackoverflow.com/c/expensify/questions/7972 for more details.
@puneetlath please check out @PrashantMangukiya 's proposal here.
Proposal
In DatePicker add a new prop maximumDate
For iOS & Android Native files we can use maximumDate prop to restrict.
For Web/Desktop:
We have a max attribute for input type date to restrict the maximum range.
Also similarly we can customize it for minimumDate also if needed additionally.
We can take advantage of these props to avoid unnecessary min & max date range validation.
Screens
Heh, interesting scenario. I like both solutions. I agree with @PrashantMangukiya that we should validate even if we disable the picker, since the user doesn't have to use the picker. And I like @Santhosh-Sellavel's suggestions on how to disable the picker.
@SofiedeVreese I think the fairest/most straightforward thing to do here is to split this into two issues and hire them both. So let's:
- Use this issue for the validation. @PrashantMangukiya let's go with solution 1 that you mentioned and create a generic function like
isValidPastDatefor validating that the date entered isn't a future date. - Let's create a new issue for disabling future dates in the date picker and assign that to @Santhosh-Sellavel. @SofiedeVreese you can also assign me as the CME on that one.
Thanks y'all!
Sounds good @puneetlath !
@PrashantMangukiya please see Puneet's comment above. I'm going to split the issue. Can you tackle your solution by creating a generic function like isValidPastDate for validating that the date entered isn't a future date.
@Santhosh-Sellavel I'll be spinning up a new issue shortly for disabling future dates and I'll assign you to that separate issue.
@SofiedeVreese I will update with isValidPastDate() and post final proposed solution here soon. thanks.
Updated Solution:
Here is Problem: For incorporationDate validation we are using isValidDate() function from src/libs/ValidationUtils.js. This function is checking that given date is between pastDate(current -1000 years) and futureDate(current + 1000 years) as shown code below:
https://github.com/Expensify/App/blob/79eafd4e2f5bd85547c189737e6655a3f49935d0/src/libs/ValidationUtils.js#L42-L57
https://github.com/Expensify/App/blob/74b77a81d2c3fddee43b2c8b04802fed9251d96f/src/pages/ReimbursementAccount/CompanyStep.js#L156-L158
Solution:
Create new function named isValidPastDate() within src/libs/ValidationUtils.js, It will be used to validate that given date is not future date as shown below.
/**
* 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');
return testDate.isValid() && testDate.isBetween(pastDate, currentDate);
}
Within src/pages/ReimbursementAccount/CompanyStep.js we have to validate incorporation date (line 156) using isValidPastDate() function (instead of isValidDate) as shown below:
if (!isValidPastDate(this.state.incorporationDate)) {
errors.incorporationDate = true;
}
Please confirm this updated solution so I can proceed to submit PR.
cc @puneetlath @SofiedeVreese
Issue reproducible during KI retests.
@PrashantMangukiya the proposal sounds good. Let's do it!
@PrashantMangukiya I've hired you in Upwork 👍
@SofiedeVreese Accepted proposal. Thank you. I will submit PR soon.
FYI @PrashantMangukiya I've lifted the n6 hold!
Issue reproducible during KI retests.