Skip to content

Commit f442311

Browse files
Fix DateFns conflict with hook-form
1 parent 7d06097 commit f442311

File tree

3 files changed

+4
-22
lines changed

3 files changed

+4
-22
lines changed

package-lock.json

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

package.json

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,6 @@
1414
"npm": "^10.9.2"
1515
},
1616
"dependencies": {
17-
"@date-fns/tz": "^1.2.0",
18-
"@date-fns/utc": "^2.1.0",
1917
"@emotion/react": "^11.14.0",
2018
"@emotion/styled": "^11.14.0",
2119
"@gridsuite/commons-ui": "file:../commons-ui/gridsuite-commons-ui-0.95.0.tgz",

src/pages/announcements/add-announcement-form.tsx

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,6 @@ import { type SubmitHandler, useForm } from 'react-hook-form';
1616
import { yupResolver } from '@hookform/resolvers/yup';
1717
import { FormContainer, SelectElement, TextareaAutosizeElement } from 'react-hook-form-mui';
1818
import { DateTimePickerElement, type DateTimePickerElementProps } from 'react-hook-form-mui/date-pickers';
19-
import { TZDate } from '@date-fns/tz';
20-
import { endOfMinute, startOfMinute } from 'date-fns';
2119
import { UserAdminSrv } from '../../services';
2220
import { getErrorMessage, handleAnnouncementCreationErrors } from '../../utils/error';
2321

@@ -50,7 +48,7 @@ const formSchema = yup
5048
type FormSchema = InferType<typeof formSchema>;
5149

5250
const datetimePickerTransform: NonNullable<DateTimePickerElementProps<FormSchema>['transform']> = {
53-
input: (value) => (value ? new TZDate(value) : null),
51+
input: (value) => (value ? new Date(value) : null),
5452
output: (value) => value?.toISOString() ?? '',
5553
};
5654
const pickerView = ['year', 'month', 'day', 'hours', 'minutes'] as const satisfies readonly DateOrTimeView[];
@@ -76,8 +74,8 @@ export default function AddAnnouncementForm({ onAnnouncementCreated }: Readonly<
7674
UserAdminSrv.addAnnouncement({
7775
//id: crypto.randomUUID(),
7876
message: params.message,
79-
startDate: startOfMinute(new TZDate(params.startDate)).toISOString(),
80-
endDate: endOfMinute(new TZDate(params.endDate)).toISOString(),
77+
startDate: params.startDate,
78+
endDate: params.endDate,
8179
severity: params.severity,
8280
})
8381
.then(() => onAnnouncementCreated?.())
@@ -125,7 +123,7 @@ export default function AddAnnouncementForm({ onAnnouncementCreated }: Readonly<
125123
views={pickerView}
126124
timeSteps={{ hours: 1, minutes: 1, seconds: 0 }}
127125
disablePast
128-
minDateTime={startDateValue ? new TZDate(startDateValue) : undefined}
126+
minDateTime={startDateValue ? new Date(startDateValue) : undefined}
129127
/>
130128
</Grid>
131129
<Grid item xs={2}>

0 commit comments

Comments
 (0)