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

Implement target date modal improvements #835

Merged
merged 3 commits into from
Nov 20, 2023
Merged
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
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);
};
Loading