Skip to content

Commit 38512e2

Browse files
Fix date library and timezone management
1 parent 99134f3 commit 38512e2

File tree

6 files changed

+159
-67
lines changed

6 files changed

+159
-67
lines changed

package-lock.json

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

package.json

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,20 +14,22 @@
1414
"npm": "^10.9.2"
1515
},
1616
"dependencies": {
17+
"@date-fns/tz": "^1.2.0",
18+
"@date-fns/utc": "^2.1.0",
1719
"@emotion/react": "^11.14.0",
1820
"@emotion/styled": "^11.14.0",
1921
"@gridsuite/commons-ui": "file:../commons-ui/gridsuite-commons-ui-0.95.0.tgz",
2022
"@hookform/resolvers": "^4.0.0",
2123
"@mui/icons-material": "^5.16.14",
2224
"@mui/lab": "5.0.0-alpha.175",
2325
"@mui/material": "^5.16.14",
24-
"@mui/x-date-pickers": "^7.28.3",
26+
"@mui/x-date-pickers": "^8.1.0",
2527
"@mui/x-tree-view": "^7.28.1",
2628
"@reduxjs/toolkit": "^2.5.1",
2729
"ag-grid-community": "^33.1.0",
2830
"ag-grid-react": "^33.1.0",
2931
"core-js": "^3.40.0",
30-
"dayjs": "^1.11.13",
32+
"date-fns": "^4.1.0",
3133
"notistack": "^3.0.2",
3234
"oidc-client": "^1.11.5",
3335
"react": "^18.3.1",

src/components/App/app-wrapper.tsx

Lines changed: 33 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,14 @@
66
*/
77

88
import App from './app';
9-
import { FunctionComponent, useMemo } from 'react';
9+
import { FunctionComponent, PropsWithChildren, useMemo } from 'react';
1010
import { CssBaseline, responsiveFontSizes, ThemeOptions } from '@mui/material';
1111
import { createTheme, StyledEngineProvider, Theme, ThemeProvider } from '@mui/material/styles';
1212
import { enUS as MuiCoreEnUS, frFR as MuiCoreFrFR } from '@mui/material/locale';
13+
import { LocalizationProvider } from '@mui/x-date-pickers';
14+
import { AdapterDateFns } from '@mui/x-date-pickers/AdapterDateFns';
15+
import { enUS as MuiDatePickersEnUS, frFR as MuiDatePickersFrFR } from '@mui/x-date-pickers/locales';
16+
import { enUS as dateFnsEnUS, fr as dateFnsFr } from 'date-fns/locale';
1317
import {
1418
cardErrorBoundaryEn,
1519
cardErrorBoundaryFr,
@@ -26,7 +30,7 @@ import {
2630
topBarFr,
2731
NotificationsProvider,
2832
} from '@gridsuite/commons-ui';
29-
import { IntlConfig, IntlProvider } from 'react-intl';
33+
import { type IntlConfig, IntlProvider } from 'react-intl';
3034
import { Provider, useSelector } from 'react-redux';
3135
import messages_en from '../../translations/en.json';
3236
import messages_fr from '../../translations/fr.json';
@@ -103,7 +107,8 @@ const getMuiTheme = (theme: GsTheme, locale: GsLangUser): Theme => {
103107
return responsiveFontSizes(
104108
createTheme(
105109
theme === LIGHT_THEME ? lightTheme : darkTheme,
106-
locale === LANG_FRENCH ? MuiCoreFrFR : MuiCoreEnUS // MUI core translations
110+
locale === LANG_FRENCH ? MuiCoreFrFR : MuiCoreEnUS, // MUI core translations
111+
locale === LANG_FRENCH ? MuiDatePickersFrFR : MuiDatePickersEnUS // MUI x-date-pickers translations
107112
)
108113
);
109114
};
@@ -125,10 +130,21 @@ const messages: Record<GsLangUser, IntlConfig['messages']> = {
125130

126131
const basename = new URL(document.baseURI ?? '').pathname;
127132

133+
function intlToDateFnsLocale(lng: GsLangUser) {
134+
switch (lng) {
135+
case LANG_FRENCH:
136+
return dateFnsFr;
137+
case LANG_ENGLISH:
138+
return dateFnsEnUS;
139+
default:
140+
return undefined;
141+
}
142+
}
143+
128144
/**
129145
* Layer injecting Theme, Internationalization (i18n) and other tools (snackbar, error boundary, ...)
130146
*/
131-
const AppWrapperRouterLayout: typeof App = (props, context) => {
147+
const AppWrapperRouterLayout: typeof App = (props: Readonly<PropsWithChildren<{}>>) => {
132148
const computedLanguage = useSelector((state: AppState) => state.computedLanguage);
133149
const theme = useSelector((state: AppState) => state[PARAM_THEME]);
134150
const themeCompiled = useMemo(() => getMuiTheme(theme, computedLanguage), [computedLanguage, theme]);
@@ -137,14 +153,19 @@ const AppWrapperRouterLayout: typeof App = (props, context) => {
137153
<IntlProvider locale={computedLanguage} defaultLocale={LANG_ENGLISH} messages={messages[computedLanguage]}>
138154
<StyledEngineProvider injectFirst>
139155
<ThemeProvider theme={themeCompiled}>
140-
<SnackbarProvider hideIconVariant={false}>
141-
<CssBaseline />
142-
<CardErrorBoundary>
143-
<NotificationsProvider urls={urlMapper}>
144-
<App {...props}>{props.children}</App>
145-
</NotificationsProvider>
146-
</CardErrorBoundary>
147-
</SnackbarProvider>
156+
<LocalizationProvider
157+
dateAdapter={AdapterDateFns}
158+
adapterLocale={intlToDateFnsLocale(computedLanguage)}
159+
>
160+
<SnackbarProvider hideIconVariant={false}>
161+
<CssBaseline />
162+
<CardErrorBoundary>
163+
<NotificationsProvider urls={urlMapper}>
164+
<App {...props}>{props.children}</App>
165+
</NotificationsProvider>
166+
</CardErrorBoundary>
167+
</SnackbarProvider>
168+
</LocalizationProvider>
148169
</ThemeProvider>
149170
</StyledEngineProvider>
150171
</IntlProvider>

src/components/App/app.tsx

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
66
*/
77

8-
import { FunctionComponent, PropsWithChildren, useCallback, useEffect } from 'react';
8+
import { type PropsWithChildren, useCallback, useEffect } from 'react';
99
import { useDispatch, useSelector } from 'react-redux';
1010
import { Grid } from '@mui/material';
1111
import {
@@ -24,7 +24,7 @@ import AppTopBar from './app-top-bar';
2424
import { useDebugRender } from '../../utils/hooks';
2525
import { AppDispatch } from '../../redux/store';
2626

27-
const App: FunctionComponent<PropsWithChildren<{}>> = (props, context) => {
27+
export default function App({ children }: Readonly<PropsWithChildren<{}>>) {
2828
useDebugRender('app');
2929
const { snackError } = useSnackMessage();
3030
const dispatch = useDispatch<AppDispatch>();
@@ -102,9 +102,8 @@ const App: FunctionComponent<PropsWithChildren<{}>> = (props, context) => {
102102
<AnnouncementNotification user={user} />
103103
</Grid>
104104
<Grid item container xs component="main">
105-
<CardErrorBoundary>{/*Router outlet ->*/ props.children}</CardErrorBoundary>
105+
<CardErrorBoundary>{/*Router outlet ->*/ children}</CardErrorBoundary>
106106
</Grid>
107107
</Grid>
108108
);
109-
};
110-
export default App;
109+
}

src/module-mui.d.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,9 @@
88
import { CSSObject } from '@mui/styled-engine';
99
import { Theme as MuiTheme, ThemeOptions as MuiThemeOptions } from '@mui/material/styles/createTheme';
1010

11+
// https://mui.com/x/react-date-pickers/quickstart/#theme-augmentation
12+
import type {} from '@mui/x-date-pickers/themeAugmentation';
13+
1114
declare module '@mui/material/styles/createTheme' {
1215
export * from '@mui/material/styles/createTheme';
1316

0 commit comments

Comments
 (0)