🐛 [release-0.2] Fix state management and validation of date pickers in migration wave modal #1110
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Currently, the date pickers in the create/edit migration wave modal misbehave when the user attempts to enter a date string manually.
The problem seemed to mostly stem from the fact that these dates were stored in form state as
Date
objects, which made it impossible to reference the user's entered string in validation if it was formatted incorrectly. This PR changes the form state to use strings instead of Dates, updates the validation accordingly, and transforms the strings into the correct format on submit.Note also that the interdependent validation has been changed: before, there was a validation error on the start date if it was after the end date AND a validation error on the end date if it was before the start date. Since these validations have been moved to use
.when
and.test
(because.min
withyup.ref
is unreliable when the value could be in an invalid format), yup gives an error if there is a circular dependency in validation. To address this, only the end date field is validated to enforce the requirement that it is after the start date, and if the start date is changed, validation is re-triggered on the end date.