Skip to content

Commit dae8aa6

Browse files
author
Ahtesham Quraish
committed
fix: Bug: Date picker controls cause MFE error on Safari #2323
1 parent 8326257 commit dae8aa6

File tree

6 files changed

+77
-47
lines changed

6 files changed

+77
-47
lines changed

package-lock.json

Lines changed: 69 additions & 35 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@
8080
"moment-shortformat": "^2.1.0",
8181
"prop-types": "^15.8.1",
8282
"react": "^18.3.1",
83-
"react-datepicker": "^4.13.0",
83+
"react-datepicker": "^7.6.0",
8484
"react-dom": "^18.3.1",
8585
"react-error-boundary": "^4.0.13",
8686
"react-helmet": "^6.1.0",

src/course-updates/hooks.jsx

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ import { useEffect, useState } from 'react';
44
import { useToggle } from '@openedx/paragon';
55

66
import { COMMA_SEPARATED_DATE_FORMAT } from '../constants';
7-
import { convertToDateFromString } from '../utils';
87
import { getCourseHandouts, getCourseUpdates } from './data/selectors';
98
import { REQUEST_TYPES } from './constants';
109
import {
@@ -56,7 +55,7 @@ const useCourseUpdates = ({ courseId }) => {
5655
};
5756

5857
const handleUpdatesSubmit = (data) => {
59-
const dateWithoutTimezone = convertToDateFromString(data.date);
58+
const dateWithoutTimezone = data.date;
6059
const dataToSend = {
6160
...data,
6261
date: moment(dateWithoutTimezone).format(COMMA_SEPARATED_DATE_FORMAT),

src/course-updates/update-form/UpdateForm.jsx

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,6 @@ import { Calendar as CalendarIcon, Error as ErrorIcon } from '@openedx/paragon/i
1313
import { Formik } from 'formik';
1414

1515
import {
16-
convertToStringFromDate,
17-
convertToDateFromString,
1816
isValidDate,
1917
} from '../../utils';
2018
import { DATE_FORMAT, DEFAULT_EMPTY_WYSIWYG_VALUE } from '../../constants';
@@ -73,7 +71,7 @@ const UpdateForm = ({
7371
<DatePicker
7472
name="date"
7573
data-testid="course-updates-datepicker"
76-
selected={isValidDate(values.date) ? convertToDateFromString(values.date) : ''}
74+
selected={isValidDate(values.date) ? values.date : ''}
7775
dateFormat={DATE_FORMAT}
7876
className={classNames('datepicker-custom-control', {
7977
'datepicker-custom-control_isInvalid': !isValid,
@@ -85,7 +83,7 @@ const UpdateForm = ({
8583
if (!isValidDate(value)) {
8684
return;
8785
}
88-
setFieldValue('date', convertToStringFromDate(value));
86+
setFieldValue('date', value);
8987
}}
9088
/>
9189
</div>

src/generic/datepicker-control/DatepickerControl.jsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import { Form, Icon } from '@openedx/paragon';
66
import { Calendar } from '@openedx/paragon/icons';
77
import { useIntl } from '@edx/frontend-platform/i18n';
88

9-
import { convertToDateFromString, convertToStringFromDate, isValidDate } from '../../utils';
9+
import { isValidDate } from '../../utils';
1010
import { DATE_FORMAT, TIME_FORMAT } from '../../constants';
1111
import messages from './messages';
1212

@@ -27,7 +27,7 @@ const DatepickerControl = ({
2727
onChange,
2828
}) => {
2929
const intl = useIntl();
30-
const formattedDate = convertToDateFromString(value);
30+
const formattedDate = value;
3131
const inputFormat = {
3232
[DATEPICKER_TYPES.date]: DATE_FORMAT,
3333
[DATEPICKER_TYPES.time]: TIME_FORMAT,
@@ -69,7 +69,7 @@ const DatepickerControl = ({
6969
showPopperArrow={false}
7070
onChange={(date) => {
7171
if (isValidDate(date)) {
72-
onChange(convertToStringFromDate(date));
72+
onChange(date);
7373
}
7474
}}
7575
/>

src/generic/datepicker-control/DatepickerControl.test.jsx

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ import React from 'react';
22
import { render, fireEvent } from '@testing-library/react';
33
import { IntlProvider } from '@edx/frontend-platform/i18n';
44

5-
import { convertToStringFromDate } from '../../utils';
65
import { DatepickerControl, DATEPICKER_TYPES } from '.';
76
import messages from './messages';
87
import { DATE_FORMAT } from '../../constants';
@@ -45,7 +44,7 @@ describe('<DatepickerControl />', () => {
4544
const input = getByPlaceholderText(DATE_FORMAT.toLocaleUpperCase());
4645
fireEvent.change(input, { target: { value: '06/16/2023' } });
4746
expect(onChangeMock).toHaveBeenCalledWith(
48-
convertToStringFromDate('06/16/2023'),
47+
new Date('2023-06-16T00:00:00.000Z'),
4948
);
5049
});
5150
});

0 commit comments

Comments
 (0)