Skip to content

Commit

Permalink
Implement target date modal improvements (#835)
Browse files Browse the repository at this point in the history
* Implement target date modal improvements

* Add esc support to target date modal
  • Loading branch information
alflennik authored Nov 20, 2023
1 parent 662303d commit a5f0e80
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 11 deletions.
8 changes: 4 additions & 4 deletions client/components/DataManagement/DataManagementRow/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import {
} from '../queries';
import { LoadingStatus, useTriggerLoad } from '../../common/LoadingStatus';
import {
checkTimeBetweenDates,
checkDaysBetweenDates,
convertDateToString,
convertStringFormatToAnotherFormat
} from '../../../utils/formatter';
Expand Down Expand Up @@ -843,18 +843,18 @@ const DataManagementRow = ({
let timeToTargetDate = 0;
if (currentDate > recommendedPhaseTargetDate) {
// Indicates that this is in the past
timeToTargetDate = checkTimeBetweenDates(
timeToTargetDate = checkDaysBetweenDates(
currentDate,
recommendedPhaseTargetDate
);
timeToTargetDate = -timeToTargetDate;
} else
timeToTargetDate = checkTimeBetweenDates(
timeToTargetDate = checkDaysBetweenDates(
recommendedPhaseTargetDate,
currentDate
);

const daysBetweenDates = checkTimeBetweenDates(
const daysBetweenDates = checkDaysBetweenDates(
currentDate,
latestVersion.candidatePhaseReachedAt
);
Expand Down
14 changes: 11 additions & 3 deletions client/components/common/BasicModal/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -29,13 +29,18 @@ const BasicModal = ({
handleAction = null,
handleHide = null,
staticBackdrop = false,
useOnHide = false
useOnHide = false,
initialFocusRef = null
}) => {
const headerRef = useRef();

useEffect(() => {
if (!show) return;
headerRef.current.focus();
if (initialFocusRef?.current) {
initialFocusRef.current.focus();
} else {
headerRef.current.focus();
}
}, [show]);

const id = useMemo(() => {
Expand Down Expand Up @@ -111,7 +116,10 @@ BasicModal.propTypes = {
handleAction: PropTypes.func,
handleHide: PropTypes.func,
staticBackdrop: PropTypes.bool,
useOnHide: PropTypes.bool
useOnHide: PropTypes.bool,
initialFocusRef: PropTypes.shape({
current: PropTypes.any
})
};

export default BasicModal;
8 changes: 7 additions & 1 deletion client/components/common/UpdateTargetDateModal/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -92,8 +92,11 @@ const UpdateTargetDateModal = ({
content={
<ModalInnerSectionContainer>
<Form.Group className="form-group">
<Form.Label>Target Date</Form.Label>
<Form.Label htmlFor="target-date-input">
Target Date
</Form.Label>
<Form.Control
id="target-date-input"
ref={dateTextRef}
type="text"
placeholder="DD-MM-YYYY"
Expand All @@ -118,6 +121,9 @@ const UpdateTargetDateModal = ({
actionLabel={'Save'}
handleAction={onSubmit}
handleClose={handleClose}
useOnHide={true}
handleHide={handleClose}
initialFocusRef={dateTextRef}
/>
);
};
Expand Down
6 changes: 3 additions & 3 deletions client/utils/formatter.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,9 @@ export const isValidDate = (date, format = 'DD-MM-YYYY') => {
return moment(date, format).isValid();
};

export const checkTimeBetweenDates = (date, otherDate, unit = 'days') => {
export const checkDaysBetweenDates = (date, otherDate) => {
const _date = moment(date);
const _otherDate = moment(otherDate);

return _date.diff(_otherDate, unit);
const hours = _date.diff(_otherDate, 'hours');
return Math.ceil(hours / 24);
};

0 comments on commit a5f0e80

Please sign in to comment.