Last active
January 19, 2021 04:17
-
-
Save appsparkler/b99ca3010976d17870c86178e4493de4 to your computer and use it in GitHub Desktop.
Conditionally setting a value
This file contains hidden or 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
const getIsDisabled = ({fromDate, toDate, selectedKey) => { | |
let isDisabled = true; // set the initial value to true | |
if(selectedKey === 'valueA') { | |
isDisabled = false; | |
} else if(selectedKey === 'valueB') { | |
if(fromDate) { | |
const isfromDateValid = moment(fromDate).isValid(); | |
const isfromDateGreaterThanOrEqualToToday = moment().diff(fromDate) <= 0; | |
if(isfromDateValid && isfromDateGreaterThanOrEqualToToday) { | |
isDisabled = false | |
} | |
} | |
if(toDate) { | |
const isToDateValid = moment(toDate).isValid(); | |
const isToDateGreaterThanOrEqualToFromDate = moment(fromDate) | |
.diff(toDate) <= 0; | |
if(isToDateValid && isToDateGreaterThanOrEqualToFromDate) { | |
isDisabled = false | |
} | |
} | |
} | |
return isDisabled; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment