Skip to content

Commit

Permalink
Merge pull request #616 from idurar/upgrade/react-router-to-v6
Browse files Browse the repository at this point in the history
⚡️ upgrade react reouter to v6
  • Loading branch information
salahlalami authored Oct 30, 2023
2 parents e5a0301 + a9f9423 commit 599b3a4
Show file tree
Hide file tree
Showing 35 changed files with 461 additions and 662 deletions.
403 changes: 82 additions & 321 deletions frontend/package-lock.json

Large diffs are not rendered by default.

8 changes: 4 additions & 4 deletions frontend/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
"dependencies": {
"@ant-design/icons": "^5.2.6",
"@ant-design/pro-layout": "^7.17.12",
"@vitejs/plugin-react": "^4.0.4",
"antd": "^5.10.2",
"axios": "0.27.2",
"cross-env": "7.0.3",
Expand All @@ -18,14 +19,14 @@
"react-dom": "^18.2.0",
"react-quill": "^2.0.0",
"react-redux": "7.2.8",
"react-router-dom": "5.2.0",
"react-router-dom": "^6.17.0",
"react-use": "^17.4.0",
"redux": "4.2.0",
"redux-logger": "3.0.6",
"redux-thunk": "2.4.1",
"reselect": "4.1.5",
"@vitejs/plugin-react": "^4.0.4",
"vite": "^4.4.8"
"vite": "^4.4.8",
"@rollup/plugin-dynamic-import-vars": "^2.1.0"
},
"scripts": {
"dev": "vite",
Expand All @@ -35,7 +36,6 @@
"dev:remote": "REACT_APP_DEV_REMOTE=remote npm run dev"
},
"devDependencies": {
"@rollup/plugin-dynamic-import-vars": "^2.1.0",
"@types/react": "^18.2.18",
"@types/react-dom": "^18.2.7",
"eslint": "^8.46.0",
Expand Down
6 changes: 3 additions & 3 deletions frontend/src/app/HeaderContent/index.jsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import React from 'react';
import { useDispatch, useSelector } from 'react-redux';
import { Link } from 'react-router-dom';
import { Avatar, Dropdown, Layout } from 'antd';
Expand All @@ -11,7 +10,7 @@ import { checkImage } from '@/request';

import { selectCurrentAdmin } from '@/redux/auth/selectors';
import { translateAction } from '@/redux/translate/actions';
import history from '@/utils/history';
import { useNavigate } from 'react-router-dom';

import { BASE_URL } from '@/config/serverApiConfig';

Expand All @@ -31,8 +30,9 @@ export default function HeaderContent() {
: null;

const ProfileDropdown = () => {
const navigate = useNavigate();
return (
<div className="profileDropdown" onClick={() => history.push('/profile')}>
<div className="profileDropdown" onClick={() => navigate('/profile')}>
<Avatar
size="large"
className="last"
Expand Down
5 changes: 3 additions & 2 deletions frontend/src/app/Navigation/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import { useAppContext } from '@/context/appContext';
import useLanguage from '@/lang/useLanguage';
import logoIcon from '@/style/images/logo-icon.svg';
import logoText from '@/style/images/logo-text.svg';
import history from '@/utils/history';
import { useNavigate } from 'react-router-dom';

import {
SettingOutlined,
Expand Down Expand Up @@ -46,6 +46,7 @@ function Sidebar({ collapsible }) {
const [currentPath, setCurrentPath] = useState(location.pathname);

const translate = useLanguage();
const navigate = useNavigate();

const items = [
{
Expand Down Expand Up @@ -158,7 +159,7 @@ function Sidebar({ collapsible }) {
}}
theme={'light'}
>
<div className="logo" onClick={() => history.push('/')} style={{ cursor: 'pointer' }}>
<div className="logo" onClick={() => navigate('/')} style={{ cursor: 'pointer' }}>
<img src={logoIcon} alt="Logo" style={{ height: '32px' }} />

{!showLogoApp && (
Expand Down
31 changes: 31 additions & 0 deletions frontend/src/components/IconMenu/index.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
import {
DesktopOutlined,
SettingOutlined,
CustomerServiceOutlined,
FileTextOutlined,
FileSyncOutlined,
DashboardOutlined,
TeamOutlined,
UserOutlined,
CreditCardOutlined,
BankOutlined,
} from '@ant-design/icons';

export const IconMenu = ({ name }) => {
const elements = {
DesktopOutlined: DesktopOutlined,
SettingOutlined: SettingOutlined,
CustomerServiceOutlined: CustomerServiceOutlined,
FileTextOutlined: FileTextOutlined,
FileSyncOutlined: FileSyncOutlined,
DashboardOutlined: DashboardOutlined,
TeamOutlined: TeamOutlined,
UserOutlined: UserOutlined,
CreditCardOutlined: CreditCardOutlined,
BankOutlined: BankOutlined,
Default: DesktopOutlined,
};

const IconTag = elements[name || 'Default'] || SettingOutlined;
return <IconTag />;
};
6 changes: 3 additions & 3 deletions frontend/src/components/NotFound/index.jsx
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import { Result, Button } from 'antd';
import useLanguage from '@/lang/useLanguage';
import { useHistory } from 'react-router-dom';
import { useNavigate } from 'react-router-dom';

export default function NotFound({ entity }) {
const translate = useLanguage();

const history = useHistory();
const navigate = useNavigate();

return (
<Result
Expand All @@ -16,7 +16,7 @@ export default function NotFound({ entity }) {
<Button
type="primary"
onClick={() => {
history.push(`/${entity?.toLowerCase()}`);
navigate(`/${entity?.toLowerCase()}`);
}}
>
{translate('Back')}
Expand Down
6 changes: 3 additions & 3 deletions frontend/src/components/SelectAsync/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import React, { useState, useEffect, useRef } from 'react';
import { request } from '@/request';
import useFetch from '@/hooks/useFetch';
import { Select } from 'antd';
import { useHistory } from 'react-router-dom';
import { useNavigate } from 'react-router-dom';
import { PlusCircleOutlined } from '@ant-design/icons';

export default function SelectAsync({
Expand All @@ -18,7 +18,7 @@ export default function SelectAsync({
const [selectOptions, setOptions] = useState([]);
const [currentValue, setCurrentValue] = useState(undefined);

const history = useHistory();
const navigate = useNavigate();

const asyncList = () => {
return request.list({ entity });
Expand All @@ -42,7 +42,7 @@ export default function SelectAsync({
const handleSelectChange = (newValue) => {
if (newValue === 'redirectURL') {
// Navigate to another page when "Add payment" is selected
history.push(urlToRedirect);
navigate(urlToRedirect);
} else {
// Handle other select options
if (onChange) {
Expand Down
14 changes: 6 additions & 8 deletions frontend/src/main.jsx
Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@
import React from 'react';

import App from './app';
import './style/app.css';
// import * as serviceWorker from './serviceWorker';

import { Router as RouterHistory } from 'react-router-dom';
import { BrowserRouter } from 'react-router-dom';
import { Provider } from 'react-redux';
import history from '@/utils/history';

import store from '@/redux/store';

import { AppContextProvider } from '@/context/appContext';
Expand All @@ -15,11 +13,11 @@ import { createRoot } from 'react-dom/client';
const container = document.getElementById('root');
const root = createRoot(container); // createRoot(container!) if you use TypeScript
root.render(
<RouterHistory history={history}>
<Provider store={store}>
<Provider store={store}>
<BrowserRouter>
<AppContextProvider>
<App />
</AppContextProvider>
</Provider>
</RouterHistory>
</BrowserRouter>
</Provider>
);
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import { EllipsisOutlined, EyeOutlined, EditOutlined, FilePdfOutlined } from '@a
import { useDispatch, useSelector } from 'react-redux';
import { erp } from '@/redux/erp/actions';
import useLanguage from '@/lang/useLanguage';
import { useHistory } from 'react-router-dom';
import { useNavigate } from 'react-router-dom';
import { DOWNLOAD_BASE_URL } from '@/config/serverApiConfig';
import useResponsiveTable from '@/hooks/useResponsiveTable';

Expand All @@ -34,16 +34,16 @@ export default function RecentTable({ ...props }) {
},
];

const history = useHistory();
const navigate = useNavigate();
const dispatch = useDispatch();

const handleRead = (record) => {
dispatch(erp.currentItem({ data: record }));
history.push(`/${entity}/read/${record._id}`);
navigate(`/${entity}/read/${record._id}`);
};
const handleEdit = (record) => {
dispatch(erp.currentAction({ actionType: 'update', data: record }));
history.push(`/${entity}/update/${record._id}`);
navigate(`/${entity}/update/${record._id}`);
};
const handleDownload = (record) => {
window.open(`${DOWNLOAD_BASE_URL}${entity}/${entity}-${record._id}.pdf`, '_blank');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import uniqueId from '@/utils/uinqueId';

import { selectCurrentItem } from '@/redux/erp/selectors';

import { useHistory } from 'react-router-dom';
import { useNavigate } from 'react-router-dom';
import useLanguage from '@/lang/useLanguage';

const { Title, Paragraph } = Typography;
Expand All @@ -22,7 +22,7 @@ export default function ReadItem({ config, selectedItem }) {
const { entity, ENTITY_NAME } = config;
const dispatch = useDispatch();
const { erpContextAction } = useErpContext();
const history = useHistory();
const navigate = useNavigate();

const { result: currentResult } = useSelector(selectCurrentItem);

Expand Down Expand Up @@ -61,7 +61,7 @@ export default function ReadItem({ config, selectedItem }) {
key={`${uniqueId()}`}
onClick={() => {
readPanel.close();
history.push(`/${entity.toLowerCase()}`);
navigate(`/${entity.toLowerCase()}`);
}}
icon={<CloseCircleOutlined />}
>
Expand All @@ -78,7 +78,7 @@ export default function ReadItem({ config, selectedItem }) {
})
);
updatePanel.open();
history.push(`/${entity.toLowerCase()}/update/${currentErp._id}`);
navigate(`/${entity.toLowerCase()}/update/${currentErp._id}`);
}}
type="primary"
icon={<EditOutlined />}
Expand Down
9 changes: 5 additions & 4 deletions frontend/src/modules/ErpPanelModule/CreateItem.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import uniqueId from '@/utils/uinqueId';
import Loading from '@/components/Loading';
import { CloseCircleOutlined, PlusOutlined } from '@ant-design/icons';

import history from '@/utils/history';
import { useNavigate } from 'react-router-dom';

function SaveForm({ form }) {
const translate = useLanguage();
Expand All @@ -35,6 +35,7 @@ function SaveForm({ form }) {
export default function CreateItem({ config, CreateForm }) {
const translate = useLanguage();
const dispatch = useDispatch();
const navigate = useNavigate();

useLayoutEffect(() => {
dispatch(settingsAction.list({ entity: 'setting' }));
Expand Down Expand Up @@ -76,7 +77,7 @@ export default function CreateItem({ config, CreateForm }) {
dispatch(erp.resetAction({ actionType: 'create' }));
setSubTotal(0);
setOfferSubTotal(0);
history.push(`/${entity.toLowerCase()}/read/${result._id}`);
navigate(`/${entity.toLowerCase()}/read/${result._id}`);
}
return () => {};
}, [isSuccess]);
Expand All @@ -101,7 +102,7 @@ export default function CreateItem({ config, CreateForm }) {
<>
<PageHeader
onBack={() => {
history.push(`/${entity.toLowerCase()}`);
navigate(`/${entity.toLowerCase()}`);
}}
title={CREATE_ENTITY}
ghost={false}
Expand All @@ -110,7 +111,7 @@ export default function CreateItem({ config, CreateForm }) {
extra={[
<Button
key={`${uniqueId()}`}
onClick={() => history.push(`/${entity.toLowerCase()}`)}
onClick={() => navigate(`/${entity.toLowerCase()}`)}
icon={<CloseCircleOutlined />}
>
{translate('Cancel')}
Expand Down
14 changes: 7 additions & 7 deletions frontend/src/modules/ErpPanelModule/DataTable.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,18 +17,18 @@ import { erp } from '@/redux/erp/actions';
import { selectListItems } from '@/redux/erp/selectors';
import { useErpContext } from '@/context/erp';
import uniqueId from '@/utils/uinqueId';
import { useHistory } from 'react-router-dom';
import { useNavigate } from 'react-router-dom';

import useResponsiveTable from '@/hooks/useResponsiveTable';

import { DOWNLOAD_BASE_URL } from '@/config/serverApiConfig';

function AddNewItem({ config, hasCreate = true }) {
const history = useHistory();
const navigate = useNavigate();
const { ADD_NEW_ENTITY, entity } = config;

const handleClick = () => {
history.push(`/${entity.toLowerCase()}/create`);
navigate(`/${entity.toLowerCase()}/create`);
};

if (hasCreate)
Expand Down Expand Up @@ -80,15 +80,15 @@ export default function DataTable({ config, extra = [] }) {
},
];

const history = useHistory();
const navigate = useNavigate();

const handleRead = (record) => {
dispatch(erp.currentItem({ data: record }));
history.push(`/${entity}/read/${record._id}`);
navigate(`/${entity}/read/${record._id}`);
};
const handleEdit = (record) => {
dispatch(erp.currentAction({ actionType: 'update', data: record }));
history.push(`/${entity}/update/${record._id}`);
navigate(`/${entity}/update/${record._id}`);
};
const handleDownload = (record) => {
window.open(`${DOWNLOAD_BASE_URL}${entity}/${entity}-${record._id}.pdf`, '_blank');
Expand All @@ -101,7 +101,7 @@ export default function DataTable({ config, extra = [] }) {

const handleRecordPayment = (record) => {
dispatch(erp.currentItem({ data: record }));
history.push(`/invoice/pay/${record._id}`);
navigate(`/invoice/pay/${record._id}`);
};

dataTableColumns = [
Expand Down
Loading

0 comments on commit 599b3a4

Please sign in to comment.