-
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.
fix: remove current context from function
- Loading branch information
1 parent
4871302
commit 48bf0eb
Showing
9 changed files
with
18 additions
and
24 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
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
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
2 changes: 1 addition & 1 deletion
2
src/core_modules/capture-core/utils/validators/form/ageValidator.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,6 +1,6 @@ | ||
// @flow | ||
import { isValidAge as isValidAgeCore } from 'capture-core-utils/validators/form'; | ||
|
||
export function isValidAge(value: Object, currentContext?: Object, internalComponentError?: Object) { | ||
export function isValidAge(value: Object, internalComponentError?: Object) { | ||
return isValidAgeCore(value, internalComponentError); | ||
} |
2 changes: 1 addition & 1 deletion
2
src/core_modules/capture-core/utils/validators/form/dateTimeValidator.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,6 +1,6 @@ | ||
// @flow | ||
import { isValidDateTime as isValidDateTimeCore } from 'capture-core-utils/validators/form'; | ||
|
||
export function isValidDateTime(value: Object, currentContext?: Object, internalComponentError?: Object) { | ||
export function isValidDateTime(value: Object, internalComponentError?: Object) { | ||
return isValidDateTimeCore(value, internalComponentError); | ||
} |
2 changes: 1 addition & 1 deletion
2
src/core_modules/capture-core/utils/validators/form/dateValidator.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,6 +1,6 @@ | ||
// @flow | ||
import { isValidDate as isValidDateCore } from 'capture-core-utils/validators/form'; | ||
|
||
export function isValidDate(value: string, currentContext?: Object, internalComponentError?: Object) { | ||
export function isValidDate(value: string, internalComponentError?: Object) { | ||
return isValidDateCore(value, internalComponentError); | ||
} |
20 changes: 7 additions & 13 deletions
20
src/core_modules/capture-core/utils/validators/form/isValidNonFutureDate.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,22 +1,16 @@ | ||
// @flow | ||
import i18n from '@dhis2/d2-i18n'; | ||
import moment from 'moment'; | ||
import { parseDate } from '../../converters/date'; | ||
|
||
const CUSTOM_VALIDATION_MESSAGES = { | ||
INVALID_DATE_MORE_THAN_MAX: i18n.t('A date in the future is not allowed'), | ||
}; | ||
|
||
export const isValidNonFutureDate = (value: string) => { | ||
const { isValid, momentDate } = parseDate(value); | ||
|
||
if (!isValid) { | ||
return isValid; | ||
export const isValidNonFutureDate = (value: string, internalComponentError) => { | ||
if (internalComponentError && internalComponentError?.errorCode === 'INVALID_DATE_MORE_THAN_MAX') { | ||
return { | ||
valid: !internalComponentError.error, | ||
errorMessage: CUSTOM_VALIDATION_MESSAGES.INVALID_DATE_MORE_THAN_MAX, | ||
}; | ||
} | ||
|
||
return { | ||
// $FlowFixMe -> if parseDate returns isValid true, there should always be a momentDate | ||
valid: momentDate.isSameOrBefore(moment()), | ||
errorMessage: CUSTOM_VALIDATION_MESSAGES.INVALID_DATE_MORE_THAN_MAX, | ||
}; | ||
return true; | ||
}; |