JSFiddle - React, Tailwind, and code Playground
by thewolff
JavaScript
const isValidDate = (arg) => true
updateMeetingTitleAndDateState = () => {
const labelMapping = {
0 : '',
1 : 'Please enter a title and a meeting date',
2 : 'Please enter a date in the format YYYY-MM-DD (e.g. 2019-09-22). It can\'t be in the past',
3 : 'Please enter a title',
4 : 'The date you entered is invalid. Please enter a date in the format YYYY-MM-DD. It can\'t be in the past'
};
const meetingTitle = "title"
const meetingDate = '4'
const hasTitle = meetingTitle.length != 0; // Did user input anything for a title
const hasDate = meetingDate.length != 0; // Did user input anything for a date
const dateIsValid = hasDate && isValidDate(meetingDate); // Is the user inputted date actually valid
let tempState = 0;
// Note: tempState 4 comes first so that in the case that the user has
// not entered a title but has entered an invalid date, the
// error message is displayed instead of the no title message
if (!dateIsValid && hasDate) { // If user inputted a date but its wrong
tempState = 4;
} else if (!hasTitle && !hasDate) { // User did not input date OR title
tempState = 1;
} else if (!hasDate) { // User inputted title but not date
tempState = 2;
} else if (!hasTitle) { // User inputted date but not title
tempState = 3;
}
if(!hasDate) {
tempState = 2
if(!hasTitle) {
tempState = 1
}
}
console.log('my temptstate', tempState)
}
updateMeetingTitleAndDateState()