Skip to content

Commit 6260f76

Browse files
committed
Migrate to mui v5
1 parent 951ebf9 commit 6260f76

File tree

28 files changed

+1156
-798
lines changed

28 files changed

+1156
-798
lines changed

package-lock.json

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

package.json

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,9 @@
77
"start": "vite",
88
"build": "tsc && vite build",
99
"preview": "vite preview",
10+
"test": "vitest",
11+
"test:ui": "vitest --ui",
12+
"test:coverage": "vitest run --coverage",
1013
"client:deploy": "sls client deploy --no-config-change --no-policy-change --no-cors-change",
1114
"client:deploy:nc": "npm run client:deploy -- --no-confirm",
1215
"client:build:deploy": "npm run build && npm run client:deploy",
@@ -17,30 +20,29 @@
1720
"cloudfront:build:deploy": "npm run client:build:deploy && npm run cloudfront:invalidateCache",
1821
"cloudfront:build:deploy:nc": "npm run client:build:deploy:nc && npm run cloudfront:invalidateCache",
1922
"cloudfront:update:build:deploy": "npm run cloudfront:setup && npm run cloudfront:build:deploy",
20-
"cloudfront:update:build:deploy:nc": "npm run cloudfront:setup && npm run cloudfront:build:deploy:nc",
21-
"test": "vitest",
22-
"test:ui": "vitest --ui",
23-
"test:coverage": "vitest run --coverage"
23+
"cloudfront:update:build:deploy:nc": "npm run cloudfront:setup && npm run cloudfront:build:deploy:nc"
2424
},
2525
"dependencies": {
26-
"@material-ui/core": "^4.11.0",
27-
"@material-ui/icons": "^4.9.1",
26+
"@emotion/react": "^11.9.3",
27+
"@emotion/styled": "^11.9.3",
28+
"@mui/icons-material": "^5.8.4",
29+
"@mui/material": "^5.8.7",
30+
"@mui/styles": "^5.8.7",
2831
"@reduxjs/toolkit": "^1.2.5",
2932
"@types/lodash": "^4.14.158",
3033
"@types/react-redux": "^7.1.7",
3134
"@types/react-router-dom": "^5.1.5",
32-
"@types/yup": "^0.29.3",
35+
"@types/yup": "^0.29.14",
3336
"axios": "^0.19.2",
34-
"formik": "^2.1.5",
35-
"formik-material-ui": "^2.0.1",
37+
"formik": "^2.2.9",
3638
"lodash": "^4.17.19",
3739
"react": "^17.0.0",
3840
"react-dom": "^17.0.0",
3941
"react-redux": "^7.2.0",
4042
"react-router-dom": "^5.2.0",
4143
"serverless": "^2.29.0",
4244
"serverless-finch": "^2.6.0",
43-
"yup": "^0.29.1"
45+
"yup": "^0.32.11"
4446
},
4547
"devDependencies": {
4648
"@testing-library/jest-dom": "^5.16.4",
Lines changed: 21 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
import React from "react";
2-
import Typography from "@material-ui/core/Typography";
2+
import Typography from "@mui/material/Typography";
33
import { Product } from "~/models/Product";
4-
import CartIcon from "@material-ui/icons/ShoppingCart";
5-
import Add from "@material-ui/icons/Add";
6-
import Remove from "@material-ui/icons/Remove";
7-
import IconButton from "@material-ui/core/IconButton";
4+
import CartIcon from "@mui/icons-material/ShoppingCart";
5+
import Add from "@mui/icons-material/Add";
6+
import Remove from "@mui/icons-material/Remove";
7+
import IconButton from "@mui/material/IconButton";
88
import { useDispatch, useSelector } from "react-redux";
99
import { addToCart, selectCartItems, removeFromCart } from "~/store/cartSlice";
1010

@@ -17,23 +17,21 @@ export default function AddProductToCart({ product }: AddProductToCartProps) {
1717
const cartItems = useSelector(selectCartItems);
1818
const cartItem = cartItems.find((i) => i.product.id === product.id);
1919

20-
return (
21-
<>
22-
{cartItem ? (
23-
<>
24-
<IconButton onClick={() => dispatch(removeFromCart(product))}>
25-
<Remove color={"secondary"} />
26-
</IconButton>
27-
<Typography align="center">{cartItem.count}</Typography>
28-
<IconButton onClick={() => dispatch(addToCart(product))}>
29-
<Add color={"secondary"} />
30-
</IconButton>
31-
</>
32-
) : (
33-
<IconButton onClick={() => dispatch(addToCart(product))}>
34-
<CartIcon color={"secondary"} />
20+
return <>
21+
{cartItem ? (
22+
<>
23+
<IconButton onClick={() => dispatch(removeFromCart(product))} size="large">
24+
<Remove color={"secondary"} />
3525
</IconButton>
36-
)}
37-
</>
38-
);
26+
<Typography align="center">{cartItem.count}</Typography>
27+
<IconButton onClick={() => dispatch(addToCart(product))} size="large">
28+
<Add color={"secondary"} />
29+
</IconButton>
30+
</>
31+
) : (
32+
<IconButton onClick={() => dispatch(addToCart(product))} size="large">
33+
<CartIcon color={"secondary"} />
34+
</IconButton>
35+
)}
36+
</>;
3937
}

src/components/App/App.css

Lines changed: 0 additions & 38 deletions
This file was deleted.

src/components/App/App.tsx

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import React from "react";
2-
import "~/components/App/App.css";
32
import PageProducts from "~/components/pages/PageProducts/PageProducts";
43
import MainLayout from "~/components/MainLayout/MainLayout";
54
import { BrowserRouter as Router, Switch, Route } from "react-router-dom";

src/components/CartItems/CartItems.tsx

Lines changed: 11 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,33 +1,18 @@
11
import React from "react";
2-
import Typography from "@material-ui/core/Typography";
3-
import List from "@material-ui/core/List";
4-
import ListItem from "@material-ui/core/ListItem";
5-
import ListItemText from "@material-ui/core/ListItemText";
6-
import { makeStyles } from "@material-ui/core/styles";
2+
import Typography from "@mui/material/Typography";
3+
import List from "@mui/material/List";
4+
import ListItem from "@mui/material/ListItem";
5+
import ListItemText from "@mui/material/ListItemText";
76
import { CartItem } from "~/models/CartItem";
87
import { formatAsPrice } from "~/utils/utils";
98
import AddProductToCart from "~/components/AddProductToCart/AddProductToCart";
109

11-
const useStyles = makeStyles((theme) => ({
12-
listItem: {
13-
padding: theme.spacing(1, 0),
14-
},
15-
total: {
16-
fontWeight: 700,
17-
},
18-
title: {
19-
marginTop: theme.spacing(2),
20-
},
21-
}));
22-
2310
type CartItemsProps = {
2411
items: CartItem[];
2512
isEditable: boolean;
2613
};
2714

2815
export default function CartItems({ items, isEditable }: CartItemsProps) {
29-
const classes = useStyles();
30-
3116
const totalPrice: number = items.reduce(
3217
(total, item) => item.count * item.product.price + total,
3318
0
@@ -37,7 +22,10 @@ export default function CartItems({ items, isEditable }: CartItemsProps) {
3722
<>
3823
<List disablePadding>
3924
{items.map((cartItem: CartItem) => (
40-
<ListItem className={classes.listItem} key={cartItem.product.id}>
25+
<ListItem
26+
sx={{ padding: (theme) => theme.spacing(1, 0) }}
27+
key={cartItem.product.id}
28+
>
4129
{isEditable && <AddProductToCart product={cartItem.product} />}
4230
<ListItemText
4331
primary={cartItem.product.title}
@@ -49,13 +37,13 @@ export default function CartItems({ items, isEditable }: CartItemsProps) {
4937
</Typography>
5038
</ListItem>
5139
))}
52-
<ListItem className={classes.listItem}>
40+
<ListItem sx={{ padding: (theme) => theme.spacing(1, 0) }}>
5341
<ListItemText primary="Shipping" />
5442
<Typography variant="body2">Free</Typography>
5543
</ListItem>
56-
<ListItem className={classes.listItem}>
44+
<ListItem sx={{ padding: (theme) => theme.spacing(1, 0) }}>
5745
<ListItemText primary="Total" />
58-
<Typography variant="subtitle1" className={classes.total}>
46+
<Typography variant="subtitle1" sx={{ fontWeight: "bold" }}>
5947
{formatAsPrice(totalPrice)}
6048
</Typography>
6149
</ListItem>

src/components/Counter/Counter.module.css

Lines changed: 0 additions & 74 deletions
This file was deleted.

src/components/Counter/Counter.tsx

Lines changed: 0 additions & 60 deletions
This file was deleted.

src/components/Form/TextField.tsx

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
import MuiTextField, {
2+
TextFieldProps as MuiTextFieldProps,
3+
} from "@mui/material/TextField";
4+
import { FieldProps, getIn } from "formik";
5+
6+
export interface TextFieldProps
7+
extends FieldProps,
8+
Omit<MuiTextFieldProps, "name" | "value" | "error"> {}
9+
10+
export function fieldToTextField({
11+
disabled,
12+
field: { onBlur: fieldOnBlur, ...field },
13+
form: { isSubmitting, touched, errors },
14+
onBlur,
15+
helperText,
16+
...props
17+
}: TextFieldProps): MuiTextFieldProps {
18+
const fieldError = getIn(errors, field.name);
19+
const showError = getIn(touched, field.name) && !!fieldError;
20+
21+
return {
22+
error: showError,
23+
helperText: showError ? fieldError : helperText,
24+
disabled: disabled ?? isSubmitting,
25+
onBlur:
26+
onBlur ??
27+
function (e) {
28+
fieldOnBlur(e ?? field.name);
29+
},
30+
...field,
31+
...props,
32+
};
33+
}
34+
35+
const TextField = ({ children, ...props }: TextFieldProps) => {
36+
return <MuiTextField {...fieldToTextField(props)}>{children}</MuiTextField>;
37+
};
38+
39+
export default TextField;

0 commit comments

Comments
 (0)