Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Appointment Start date is missing when tried to view the past appointment fixed #143

Open
wants to merge 1 commit into
base: vGHC
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 2 additions & 12 deletions ui/react-components/components/DatePicker/DateInput.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ import {isValidUSDate} from '../../utils/DateUtil'
import PropTypes from "prop-types";
import moment from "moment";
import {isNil} from 'lodash'

const DateInput = (props) =>{
const validateDate= ({dateValue, minDate, maxDate}) =>{
const isDateFormatValid = isValidUSDate(dateValue) || dateValue==='';
Expand All @@ -26,14 +25,12 @@ const DateInput = (props) =>{
}
return isDateFormatValid;
};

const inputRef = useRef(null);
const {value, onBlur, minDate, maxDate, isDisabled, handleTab} = props;
const [componentValue, setComponentValue] = useState(validateDate({dateValue: value, minDate,maxDate})? value:'');
useEffect(() => {
setComponentValue(validateDate({dateValue: value, minDate,maxDate})?value:'');
}, [value, minDate]);

const handleBlur=(e) =>{
const inputValue = e.target.value;
const isValidDate = validateDate({dateValue: inputValue, minDate, maxDate});
Expand All @@ -47,15 +44,13 @@ const DateInput = (props) =>{
inputRef.current.focus();
}
};

const handleClear = (e) =>{
if(!isDisabled) {
setComponentValue('');
onBlur('');
inputRef.current.focus();
}
};

const handleKeyDown= (e) => {
if (e.key === 'Enter') {
inputRef.current.blur();
Expand All @@ -67,16 +62,13 @@ const DateInput = (props) =>{
else if(e.key === 'Tab')
handleTab && handleTab();
};

const inputClearStyles= [dateInputClear];
isDisabled && inputClearStyles.push(disable);

const inputFieldStyles= [dateInputBox];
isDisabled && inputFieldStyles.push(disable);

return(
<div className={classNames(dateTextHolder)}>
<input placeholder="mm/dd/yyyy" onChange={(e) => setComponentValue(e.target.value)}
<input placeholder={isDisabled ? value : "mm/dd/yyyy"} onChange={(e) => setComponentValue(e.target.value)}
className={classNames(inputFieldStyles)}
onKeyDown={handleKeyDown}
ref={inputRef}
Expand All @@ -86,7 +78,6 @@ const DateInput = (props) =>{
</div>
)
}

DateInput.propTypes = {
onBlur: PropTypes.func.isRequired,
value: PropTypes.string,
Expand All @@ -95,5 +86,4 @@ DateInput.propTypes = {
isDisabled: PropTypes.bool,
handleTab: PropTypes.func
};

export default DateInput;
export default DateInput;
13 changes: 3 additions & 10 deletions ui/react-components/components/DatePicker/DatePicker.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,25 +11,20 @@ import classNames from 'classnames';
import moment from 'moment';
import DateInput from './DateInput.jsx';
import DatePickerCustomHeader from './DatePickerCustomHeader.jsx';

const dateToMomentDate = (date) => date === '' || date === null || date === undefined ? date
: moment(date, 'MM/DD/YYYY');
const AppointmentDatePicker = (props) => {
const {minDate, value, onChange, isDisabled, handleDateSelection} = props;
let calendarStyles = [appointmentDatePicker];
isDisabled && calendarStyles.push(disable);
const selectedDate = value ? value.toDate() : value;

let containerStyles = [];
isDisabled && containerStyles.push(disable);

const handleBlurOfDateInput = (date) => {
const valueEntered = dateToMomentDate(date);
onChange(valueEntered);
};

const dateInputValue = isDisabled ? '' : (value && value !== '' ? value.format('MM/DD/YYYY') : value);

const dateInputValue = value && value !== "" ? value.format("MM/DD/YYYY") : value;
return (
<div data-testid="datePicker" className={classNames(containerStyles)}>
<DateInput value={dateInputValue}
Expand All @@ -39,7 +34,7 @@ const AppointmentDatePicker = (props) => {
handleTab={handleDateSelection}
/>
<div disabled={isDisabled} data-testid="datePicker-Calendar"><DatePicker
selected={isDisabled ? '' : selectedDate}
selected={selectedDate}
onSelect={() => handleDateSelection && handleDateSelection()}
onChange={(date) => onChange(dateToMomentDate(date))}
inline
Expand All @@ -58,13 +53,11 @@ const AppointmentDatePicker = (props) => {
</div>
);
};

AppointmentDatePicker.propTypes = {
onChange: PropTypes.func,
value: PropTypes.instanceOf(moment),
minDate: PropTypes.instanceOf(moment),
isDisabled: PropTypes.bool,
handleDateSelection: PropTypes.func
};

export default AppointmentDatePicker;
export default AppointmentDatePicker;