refactor: update dependencies and improve Capitalize utility

- Updated dependencies in package.json to latest versions for better performance and security.
- Refactored Capitalize utility function into a new component for improved reusability and clarity.
- Replaced all instances of the old Capitalize function with the new component in Card and Cart components.
- Removed the old Utils.js file as it is no longer needed.
This commit is contained in:
Dan Dobos
2025-10-16 17:27:32 +02:00
parent 51ec86e12e
commit 9ff5baf5fb
7 changed files with 6744 additions and 17687 deletions
+6716 -17666
View File
File diff suppressed because it is too large Load Diff
+9 -10
View File
@@ -4,18 +4,17 @@
"version": "0.1.0", "version": "0.1.0",
"private": true, "private": true,
"dependencies": { "dependencies": {
"@reduxjs/toolkit": "^1.9.1", "@reduxjs/toolkit": "^2.9.0",
"@testing-library/jest-dom": "^5.16.5", "@testing-library/jest-dom": "^6.9.1",
"@testing-library/react": "^13.4.0", "@testing-library/react": "^16.3.0",
"@testing-library/user-event": "^13.5.0", "@testing-library/user-event": "^14.6.1",
"react": "^18.2.0", "react": "^18.2.0",
"react-dom": "^18.2.0", "react-dom": "^18.2.0",
"react-redux": "^8.0.5", "react-redux": "^9.2.0",
"react-router-dom": "^6.4.4", "react-router-dom": "^7.9.4",
"react-scripts": "^5.0.1", "react-scripts": "^5.0.1",
"react-toastify": "^9.1.1", "react-toastify": "^11.0.5",
"sass": "^1.56.1", "sass": "^1.93.2"
"web-vitals": "^2.1.4"
}, },
"scripts": { "scripts": {
"start": "react-scripts start", "start": "react-scripts start",
@@ -44,6 +43,6 @@
] ]
}, },
"devDependencies": { "devDependencies": {
"gh-pages": "^4.0.0" "gh-pages": "^6.3.0"
} }
} }
+11
View File
@@ -0,0 +1,11 @@
const Capitalize = ({ children, text })=> {
// ensure we always work with a string
const value = (children ?? "").toString();
if (!value) return null;
const capitalized = value.replace(/\b\w/g, (c) => c.toUpperCase());
return <>{capitalized}</>;
}
export default Capitalize
+6 -6
View File
@@ -2,7 +2,7 @@ import { useEffect } from 'react';
import { useSelector, useDispatch } from 'react-redux'; import { useSelector, useDispatch } from 'react-redux';
import { addToCart, getTotals } from '../features/cartSlice'; import { addToCart, getTotals } from '../features/cartSlice';
import { Capitalize } from '../features/Utils'; import Capitalize from './Capitalize';
const Card = ({ product }) => { const Card = ({ product }) => {
const dispatch = useDispatch(); const dispatch = useDispatch();
@@ -18,15 +18,15 @@ const Card = ({ product }) => {
return ( return (
<> <>
<h3 className='title'>{Capitalize(product.title)}</h3> <h3 className='title'>{Capitalize(product?.title ?? "")}</h3>
<div className='image-container'> <div className='image-container'>
<img src={product.images[0]} alt={Capitalize(product.title)} /> <img src={product.images[0]} alt={Capitalize(product?.title ?? "")} />
</div> </div>
<div className='category'> <div className='category'>
<span>{Capitalize(product.category)}</span> <span>{Capitalize(product?.category ?? "")}</span>
<span>{Capitalize(product.brand)}</span> <span>{Capitalize(product?.brand ?? "")}</span>
</div> </div>
<p className='description'>{Capitalize(product.description)}</p> <p className='description'>{Capitalize(product?.description ?? "")}</p>
<div> <div>
<p className='discount'> <p className='discount'>
<span>Discount: </span> <span>Discount: </span>
+1 -1
View File
@@ -8,7 +8,7 @@ import {
getTotals, getTotals,
} from '../features/cartSlice'; } from '../features/cartSlice';
import { Capitalize } from '../features/Utils'; import Capitalize from './Capitalize';
import BackHomeButton from './BackHomeButton'; import BackHomeButton from './BackHomeButton';
const Cart = () => { const Cart = () => {
-3
View File
@@ -1,3 +0,0 @@
export const Capitalize = (text) => {
return text.replace(/[_-]/g, " ").replace(/(^\w|\s\w)(\S*)/g, (_,m1,m2) => m1.toUpperCase()+m2.toLowerCase())
};
+1 -1
View File
@@ -1,6 +1,6 @@
import { createSlice } from '@reduxjs/toolkit'; import { createSlice } from '@reduxjs/toolkit';
import { toast } from 'react-toastify'; import { toast } from 'react-toastify';
import { Capitalize } from './Utils'; import Capitalize from '../components/Capitalize';
import GoToCartButton from '../components/GoToCartButton'; import GoToCartButton from '../components/GoToCartButton';
const initialState = { const initialState = {