Skip to content

Commit ac1e9e1

Browse files
chore(deps): update code to work with react-datepicker v8
1 parent 45f0dbf commit ac1e9e1

File tree

4 files changed

+14
-12
lines changed

4 files changed

+14
-12
lines changed

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import {
77
Icon,
88
} from '@openedx/paragon';
99
import classNames from 'classnames';
10-
import DatePicker from 'react-datepicker/dist';
10+
import DatePicker from 'react-datepicker';
1111
import { useIntl } from '@edx/frontend-platform/i18n';
1212
import { Calendar as CalendarIcon, Error as ErrorIcon } from '@openedx/paragon/icons';
1313
import { Formik } from 'formik';
@@ -73,7 +73,7 @@ const UpdateForm = ({
7373
<DatePicker
7474
name="date"
7575
data-testid="course-updates-datepicker"
76-
selected={isValidDate(values.date) ? convertToDateFromString(values.date) : ''}
76+
selected={isValidDate(values.date) ? convertToDateFromString(values.date) : undefined}
7777
dateFormat={DATE_FORMAT}
7878
className={classNames('datepicker-custom-control', {
7979
'datepicker-custom-control_isInvalid': !isValid,

src/generic/datepicker-control/DatepickerControl.jsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import React from 'react';
2-
import DatePicker from 'react-datepicker/dist';
2+
import DatePicker from 'react-datepicker';
33
import PropTypes from 'prop-types';
44
import classNames from 'classnames';
55
import { Form, Icon } from '@openedx/paragon';

src/utils.test.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -124,10 +124,10 @@ describe('FilesAndUploads utils', () => {
124124
expect(date.toISOString()).toBe('2023-10-01T12:00:00.000Z');
125125
});
126126

127-
it('returns an empty string for invalid date strings', () => {
127+
it('returns undefined for invalid date strings', () => {
128128
const dateStr = '';
129129
const date = convertToDateFromString(dateStr);
130-
expect(date).toBe('');
130+
expect(date).toBeUndefined();
131131
});
132132
});
133133

src/utils.tsx

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -265,28 +265,30 @@ export function setupYupExtensions() {
265265
});
266266
}
267267

268-
export const convertToDateFromString = (dateStr: string) => {
268+
export const convertToDateFromString = (dateStr: string): Date | undefined => {
269269
/**
270270
* Convert UTC to local time for react-datepicker
271-
* Note: react-datepicker has a bug where it only interacts with local time
271+
* Note: react-datepicker v4 had a bug where it only interacts with local time
272+
* but this bug may no longer be affecting v8+ ?
272273
* @param {string} dateStr - YYYY-MM-DDTHH:MM:SSZ
273-
* @return {Date} date in local time
274+
* @return date in local time
274275
*/
275276
if (!dateStr) {
276-
return '';
277+
return undefined;
277278
}
278279

279280
const stripTimeZone = (stringValue: string) => stringValue.substring(0, 19);
280281

281282
return moment(stripTimeZone(String(dateStr))).toDate();
282283
};
283284

284-
export const convertToStringFromDate = (date: moment.MomentInput) => {
285+
export const convertToStringFromDate = (date: moment.MomentInput): string => {
285286
/**
286287
* Convert local time to UTC from react-datepicker
287-
* Note: react-datepicker has a bug where it only interacts with local time
288+
* Note: react-datepicker v4 had a bug where it only interacts with local time
289+
* but this bug may no longer be affecting v8+ ?
288290
* @param {Date} date - date in local time
289-
* @return {string} YYYY-MM-DDTHH:MM:SSZ
291+
* @return YYYY-MM-DDTHH:MM:SSZ
290292
*/
291293
if (!date) {
292294
return '';

0 commit comments

Comments
 (0)