Skip to content

Commit

Permalink
✨ Add Ant lang ConfigProvider
Browse files Browse the repository at this point in the history
  • Loading branch information
Salah Eddine Lalami committed Oct 27, 2023
1 parent 94ba528 commit de1fe83
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 11 deletions.
42 changes: 32 additions & 10 deletions frontend/src/app/index.jsx
Original file line number Diff line number Diff line change
@@ -1,14 +1,18 @@

import { useState, useEffect } from 'react';
import Router from '@/router';
import enUS from 'antd/es/locale/en_US';
import zhCN from 'antd/es/locale/zh_CN';
import frFR from 'antd/es/locale/fr_FR';

import useNetwork from '@/hooks/useNetwork';

import { Layout, notification } from 'antd';
import { Layout, ConfigProvider } from 'antd';

import Navigation from '@/app/Navigation';

import { useSelector, useDispatch } from 'react-redux';
import { selectAuth } from '@/redux/auth/selectors';
import { selectLangCode } from '@/redux/lang/selectors';

import HeaderContent from '@/app/HeaderContent';
// import { useNetworkState } from "react-use";
Expand All @@ -26,23 +30,41 @@ function App() {
// description: "Cannot connect to the server, Check your internet network",
// });
// }
const dispatch = useDispatch();

const { isLoggedIn } = useSelector(selectAuth);
const langCode = useSelector(selectLangCode);

const [locale, setLocal] = useState(enUS);

useEffect(() => {
if (langCode === 'fr_FR') {
setLocal(frFR);
} else {
setLocal(enUS);
}

const { isLoggedIn } = useSelector(selectAuth);
return () => {
return false;
};
}, [langCode]);

if (!isLoggedIn) return <Router />;
if (!isLoggedIn)
return (
<ConfigProvider direction="ltr" locale={locale}>
<Router />
</ConfigProvider>
);
else {
return (
<Layout style={{ minHeight: '100vh' }}>
<Navigation />
<ConfigProvider direction="ltr" locale={locale}>
<Layout style={{ minHeight: '100vh' }}>
<HeaderContent />
<Router isLoggedIn={true} />
<Navigation />
<Layout style={{ minHeight: '100vh' }}>
<HeaderContent />
<Router isLoggedIn={true} />
</Layout>
</Layout>
</Layout>
</ConfigProvider>
);
}
}
Expand Down
1 change: 1 addition & 0 deletions frontend/src/redux/lang/actions.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ export const langAction = {
dispatch({
type: actionTypes.REQUEST_SUCCESS,
payload: data,
langCode: 'fr_FR',
});
window.localStorage.setItem('lang', JSON.stringify(data));
} else {
Expand Down
2 changes: 1 addition & 1 deletion frontend/src/redux/lang/reducer.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ const INITIAL_LANG_STATE = {

const INITIAL_STATE = {
result: INITIAL_LANG_STATE,
langCode: 'en_us',
langCode: 'en_US',
isLoading: false,
isSuccess: false,
};
Expand Down

0 comments on commit de1fe83

Please sign in to comment.