Skip to content

Commit 4e27f32

Browse files
committed
Migrate to react-router v6
1 parent 87523cf commit 4e27f32

File tree

20 files changed

+203
-346
lines changed

20 files changed

+203
-346
lines changed

package-lock.json

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

package.json

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -31,17 +31,14 @@
3131
"@mui/material": "^5.8.7",
3232
"@mui/styles": "^5.8.7",
3333
"@reduxjs/toolkit": "^1.2.5",
34-
"@types/lodash": "^4.14.158",
3534
"@types/react-redux": "^7.1.7",
36-
"@types/react-router-dom": "^5.1.5",
3735
"@types/yup": "^0.29.14",
3836
"axios": "^0.19.2",
3937
"formik": "^2.2.9",
40-
"lodash": "^4.17.19",
4138
"react": "^17.0.0",
4239
"react-dom": "^17.0.0",
4340
"react-redux": "^7.2.0",
44-
"react-router-dom": "^5.2.0",
41+
"react-router-dom": "^6.3.0",
4542
"serverless": "^2.29.0",
4643
"serverless-finch": "^2.6.0",
4744
"yup": "^0.32.11"

src/components/AddProductToCart/AddProductToCart.tsx

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
import React from "react";
21
import Typography from "@mui/material/Typography";
32
import { Product } from "~/models/Product";
43
import CartIcon from "@mui/icons-material/ShoppingCart";

src/components/App/App.tsx

Lines changed: 14 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
1-
import React from "react";
21
import PageProducts from "~/components/pages/PageProducts/PageProducts";
32
import MainLayout from "~/components/MainLayout/MainLayout";
4-
import { BrowserRouter as Router, Switch, Route } from "react-router-dom";
3+
import { Routes, Route } from "react-router-dom";
54
import PageProductForm from "~/components/pages/PageProductForm/PageProductForm";
65
import PageCart from "~/components/pages/PageCart/PageCart";
76
import PageOrders from "~/components/pages/PageOrders/PageOrders";
@@ -10,35 +9,20 @@ import PageProductImport from "~/components/pages/admin/PageProductImport/PagePr
109

1110
function App() {
1211
return (
13-
<Router>
14-
<Switch>
15-
<Route path="/">
16-
<MainLayout>
17-
<Route exact path="/">
18-
<PageProducts />
19-
</Route>
20-
<Route
21-
exact
22-
path={["/admin/product-form/:id", "/admin/product-form"]}
23-
>
24-
<PageProductForm />
25-
</Route>
26-
<Route exact path="/cart">
27-
<PageCart />
28-
</Route>
29-
<Route exact path="/admin/orders">
30-
<PageOrders />
31-
</Route>
32-
<Route exact path="/admin/order/:id">
33-
<PageOrder />
34-
</Route>
35-
<Route exact path="/admin/products">
36-
<PageProductImport />
37-
</Route>
38-
</MainLayout>
12+
<MainLayout>
13+
<Routes>
14+
<Route path="/" element={<PageProducts />} />
15+
<Route path="cart" element={<PageCart />} />
16+
<Route path="admin">
17+
<Route path="orders" element={<PageOrders />} />
18+
<Route path="order/:id" element={<PageOrder />} />
19+
<Route path="products" element={<PageProductImport />} />
20+
<Route path="product-form" element={<PageProductForm />}>
21+
<Route path=":id" element={<PageProductForm />} />
22+
</Route>
3923
</Route>
40-
</Switch>
41-
</Router>
24+
</Routes>
25+
</MainLayout>
4226
);
4327
}
4428

src/components/CartItems/CartItems.tsx

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
import React from "react";
21
import Typography from "@mui/material/Typography";
32
import List from "@mui/material/List";
43
import ListItem from "@mui/material/ListItem";

src/components/MainLayout/MainLayout.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ const MainLayout: React.FC = ({ children }) => {
2424
<Header />
2525
<main>
2626
<Container sx={{ pb: 8 }} maxWidth="md">
27-
{children!}
27+
{children}
2828
</Container>
2929
</main>
3030
<Box

src/components/MainLayout/components/Cart.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import Badge from "@mui/material/Badge";
22
import CartIcon from "@mui/icons-material/ShoppingCart";
33
import IconButton from "@mui/material/IconButton";
4-
import React, { useEffect } from "react";
4+
import React from "react";
55
import axios from "axios";
66
import { useDispatch, useSelector } from "react-redux";
77
import { selectCartItems, updateFromApi } from "~/store/cartSlice";
@@ -10,7 +10,7 @@ import API_PATHS from "~/constants/apiPaths";
1010

1111
export default function Cart() {
1212
const dispatch = useDispatch();
13-
useEffect(() => {
13+
React.useEffect(() => {
1414
axios
1515
.get(`${API_PATHS.cart}/profile/cart`, {
1616
headers: {

src/components/pages/PageCart/PageCart.tsx

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -9,14 +9,7 @@ import ReviewOrder from "~/components/pages/PageCart/components/ReviewOrder";
99
import { useDispatch, useSelector } from "react-redux";
1010
import { selectCartItems, clearCart } from "~/store/cartSlice";
1111
import PaperLayout from "~/components/PaperLayout/PaperLayout";
12-
import {
13-
Formik,
14-
Form,
15-
FormikProps,
16-
FormikValues,
17-
FastField,
18-
Field,
19-
} from "formik";
12+
import { Formik, Form, FormikProps, FormikValues, Field } from "formik";
2013
import Grid from "@mui/material/Grid";
2114
import axios from "axios";
2215
import API_PATHS from "~/constants/apiPaths";
Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
import React from "react";
21
import Typography from "@mui/material/Typography";
32
import CartItems from "~/components/CartItems/CartItems";
43
import { useSelector } from "react-redux";
@@ -8,11 +7,11 @@ export default function ReviewCart() {
87
const cartItems = useSelector(selectCartItems);
98

109
return (
11-
<React.Fragment>
10+
<>
1211
<Typography variant="h6" gutterBottom>
1312
Order summary
1413
</Typography>
1514
<CartItems items={cartItems} isEditable />
16-
</React.Fragment>
15+
</>
1716
);
1817
}

src/components/pages/PageCart/components/ReviewOrder.tsx

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
import React from "react";
21
import Typography from "@mui/material/Typography";
32
import Grid from "@mui/material/Grid";
43
import CartItems from "~/components/CartItems/CartItems";
@@ -12,7 +11,7 @@ type ReviewOrderProps = {
1211

1312
export default function ReviewOrder({ address, items }: ReviewOrderProps) {
1413
return (
15-
<React.Fragment>
14+
<>
1615
<Typography variant="h6" gutterBottom>
1716
Order summary
1817
</Typography>
@@ -34,6 +33,6 @@ export default function ReviewOrder({ address, items }: ReviewOrderProps) {
3433
<Typography gutterBottom>{address.comment}</Typography>
3534
</Grid>
3635
</Grid>
37-
</React.Fragment>
36+
</>
3837
);
3938
}

0 commit comments

Comments
 (0)