-
Notifications
You must be signed in to change notification settings - Fork 23
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
48bf0eb
commit 2a5cd1e
Showing
17 changed files
with
193 additions
and
249 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
79 changes: 0 additions & 79 deletions
79
src/core_modules/capture-core-utils/validators/form/age.validator.js
This file was deleted.
Oops, something went wrong.
38 changes: 0 additions & 38 deletions
38
src/core_modules/capture-core-utils/validators/form/date.validator.js
This file was deleted.
Oops, something went wrong.
65 changes: 0 additions & 65 deletions
65
src/core_modules/capture-core-utils/validators/form/dateTime.validator.js
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
6 changes: 3 additions & 3 deletions
6
.../EnrollmentWithFirstStageDataEntry/fieldValidators/eventDate.validatorContainersGetter.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
30 changes: 10 additions & 20 deletions
30
...onents/DataEntries/Enrollment/fieldValidators/enrollmentDate.validatorContainersGetter.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,40 +1,30 @@ | ||
// @flow | ||
import { hasValue } from 'capture-core-utils/validators/form'; | ||
import i18n from '@dhis2/d2-i18n'; | ||
import moment from 'moment'; | ||
import { parseDate } from '../../../../utils/converters/date'; | ||
|
||
const isValidEnrollmentDate = (value: string, isFutureDateAllowed: boolean) => { | ||
const dateContainer = parseDate(value); | ||
if (!dateContainer.isValid) { | ||
return false; | ||
} | ||
import { hasValue } from 'capture-core-utils/validators/form'; | ||
import { isValidDate, isValidNonFutureDate } from '../../../../utils/validators/form'; | ||
|
||
if (isFutureDateAllowed) { | ||
const isValidEnrollmentDate = (value: string, internalComponentError?: ?{error: ?string, errorCode: ?string}) => { | ||
if (!value) { | ||
return true; | ||
} | ||
|
||
const momentDate = dateContainer.momentDate; | ||
const momentToday = moment(); | ||
// $FlowFixMe -> if parseDate returns isValid true, there should always be a momentDate | ||
const isNotFutureDate = momentDate.isSameOrBefore(momentToday); | ||
return { | ||
valid: isNotFutureDate, | ||
message: i18n.t('A future date is not allowed'), | ||
}; | ||
return isValidDate(value, internalComponentError); | ||
}; | ||
|
||
export const getEnrollmentDateValidatorContainer = (isFutureEnrollmentDateAllowed: boolean) => { | ||
export const getEnrollmentDateValidatorContainer = () => { | ||
const validatorContainers = [ | ||
{ | ||
validator: hasValue, | ||
message: | ||
i18n.t('A value is required'), | ||
}, | ||
{ | ||
validator: (value: string) => isValidEnrollmentDate(value, isFutureEnrollmentDateAllowed), | ||
validator: isValidEnrollmentDate, | ||
message: i18n.t('Please provide a valid date'), | ||
}, | ||
{ validator: isValidNonFutureDate, | ||
message: i18n.t('A date in the future is not allowed'), | ||
}, | ||
]; | ||
return validatorContainers; | ||
}; |
35 changes: 17 additions & 18 deletions
35
...omponents/DataEntries/Enrollment/fieldValidators/incidentDate.validatorContainerGetter.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.