├── .gitignore
├── README.md
├── package-lock.json
├── package.json
├── public
├── favicon.ico
└── index.html
└── src
├── App.js
├── App.scss
├── assets
└── images
│ ├── error.png
│ ├── slider-img-1.png
│ ├── slider-img-2.png
│ ├── slider-img-3.png
│ └── spinner.svg
├── components
├── Category
│ ├── Category.js
│ └── Category.scss
├── Error
│ ├── Error.js
│ └── Error.scss
├── Footer
│ ├── Footer.js
│ └── Footer.scss
├── Loader
│ ├── Loader.js
│ └── Loader.scss
├── Navbar
│ ├── Navbar.js
│ └── Navbar.scss
├── ProductList
│ ├── ProductList.js
│ └── ProductList.scss
├── SingleCategory
│ ├── SingleCategory.js
│ └── SingleCategory.scss
├── SingleProduct
│ ├── SingleProduct.js
│ └── SingleProduct.scss
└── Slider
│ ├── Slider.js
│ └── Slider.scss
├── index.js
├── pages
├── CartPage
│ ├── CartPage.js
│ └── CartPage.scss
├── CategoryPage
│ ├── CategoryPage.js
│ └── CategoryPage.scss
├── HomePage
│ ├── HomePage.js
│ └── HomePage.scss
└── index.js
├── store
├── cartSlice.js
├── categorySlice.js
├── modalSlice.js
├── productSlice.js
├── sidebarSlice.js
└── store.js
└── utils
├── apiURL.js
├── helpers.js
├── images.js
└── status.js
/.gitignore:
--------------------------------------------------------------------------------
1 | # See https://help.github.com/articles/ignoring-files/ for more about ignoring files.
2 |
3 | # dependencies
4 | /node_modules
5 | /.pnp
6 | .pnp.js
7 |
8 | # testing
9 | /coverage
10 |
11 | # production
12 | /build
13 |
14 | # misc
15 | .DS_Store
16 | .env.local
17 | .env.development.local
18 | .env.test.local
19 | .env.production.local
20 |
21 | npm-debug.log*
22 | yarn-debug.log*
23 | yarn-error.log*
24 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # Getting Started with Create React App
2 |
3 | This project was bootstrapped with [Create React App](https://github.com/facebook/create-react-app).
4 |
5 | ## Available Scripts
6 |
7 | In the project directory, you can run:
8 |
9 | ### `npm start`
10 |
11 | Runs the app in the development mode.\
12 | Open [http://localhost:3000](http://localhost:3000) to view it in your browser.
13 |
14 | The page will reload when you make changes.\
15 | You may also see any lint errors in the console.
16 |
17 | ### `npm test`
18 |
19 | Launches the test runner in the interactive watch mode.\
20 | See the section about [running tests](https://facebook.github.io/create-react-app/docs/running-tests) for more information.
21 |
22 | ### `npm run build`
23 |
24 | Builds the app for production to the `build` folder.\
25 | It correctly bundles React in production mode and optimizes the build for the best performance.
26 |
27 | The build is minified and the filenames include the hashes.\
28 | Your app is ready to be deployed!
29 |
30 | See the section about [deployment](https://facebook.github.io/create-react-app/docs/deployment) for more information.
31 |
32 | ### `npm run eject`
33 |
34 | **Note: this is a one-way operation. Once you `eject`, you can't go back!**
35 |
36 | If you aren't satisfied with the build tool and configuration choices, you can `eject` at any time. This command will remove the single build dependency from your project.
37 |
38 | Instead, it will copy all the configuration files and the transitive dependencies (webpack, Babel, ESLint, etc) right into your project so you have full control over them. All of the commands except `eject` will still work, but they will point to the copied scripts so you can tweak them. At this point you're on your own.
39 |
40 | You don't have to ever use `eject`. The curated feature set is suitable for small and middle deployments, and you shouldn't feel obligated to use this feature. However we understand that this tool wouldn't be useful if you couldn't customize it when you are ready for it.
41 |
42 | ## Learn More
43 |
44 | You can learn more in the [Create React App documentation](https://facebook.github.io/create-react-app/docs/getting-started).
45 |
46 | To learn React, check out the [React documentation](https://reactjs.org/).
47 |
48 | ### Code Splitting
49 |
50 | This section has moved here: [https://facebook.github.io/create-react-app/docs/code-splitting](https://facebook.github.io/create-react-app/docs/code-splitting)
51 |
52 | ### Analyzing the Bundle Size
53 |
54 | This section has moved here: [https://facebook.github.io/create-react-app/docs/analyzing-the-bundle-size](https://facebook.github.io/create-react-app/docs/analyzing-the-bundle-size)
55 |
56 | ### Making a Progressive Web App
57 |
58 | This section has moved here: [https://facebook.github.io/create-react-app/docs/making-a-progressive-web-app](https://facebook.github.io/create-react-app/docs/making-a-progressive-web-app)
59 |
60 | ### Advanced Configuration
61 |
62 | This section has moved here: [https://facebook.github.io/create-react-app/docs/advanced-configuration](https://facebook.github.io/create-react-app/docs/advanced-configuration)
63 |
64 | ### Deployment
65 |
66 | This section has moved here: [https://facebook.github.io/create-react-app/docs/deployment](https://facebook.github.io/create-react-app/docs/deployment)
67 |
68 | ### `npm run build` fails to minify
69 |
70 | This section has moved here: [https://facebook.github.io/create-react-app/docs/troubleshooting#npm-run-build-fails-to-minify](https://facebook.github.io/create-react-app/docs/troubleshooting#npm-run-build-fails-to-minify)
71 |
--------------------------------------------------------------------------------
/package.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "my-app",
3 | "version": "0.1.0",
4 | "private": true,
5 | "dependencies": {
6 | "@reduxjs/toolkit": "^1.8.5",
7 | "@testing-library/jest-dom": "^5.16.5",
8 | "@testing-library/react": "^13.4.0",
9 | "@testing-library/user-event": "^13.5.0",
10 | "react": "^18.2.0",
11 | "react-dom": "^18.2.0",
12 | "react-redux": "^8.0.4",
13 | "react-router-dom": "^6.4.0",
14 | "react-scripts": "5.0.1",
15 | "react-slick": "^0.29.0",
16 | "redux": "^4.2.0",
17 | "sass": "^1.54.9",
18 | "slick-carousel": "^1.8.1",
19 | "web-vitals": "^2.1.4"
20 | },
21 | "scripts": {
22 | "start": "react-scripts start",
23 | "build": "react-scripts build",
24 | "test": "react-scripts test",
25 | "eject": "react-scripts eject"
26 | },
27 | "eslintConfig": {
28 | "extends": [
29 | "react-app",
30 | "react-app/jest"
31 | ]
32 | },
33 | "browserslist": {
34 | "production": [
35 | ">0.2%",
36 | "not dead",
37 | "not op_mini all"
38 | ],
39 | "development": [
40 | "last 1 chrome version",
41 | "last 1 firefox version",
42 | "last 1 safari version"
43 | ]
44 | }
45 | }
46 |
--------------------------------------------------------------------------------
/public/favicon.ico:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/prabinmagar/shopping-hub-react-js-ecom-site-with-redux-toolkit/fb25ff545ff129171f01d3a60f4e8a3fa13d1d98/public/favicon.ico
--------------------------------------------------------------------------------
/public/index.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
12 |
13 | CheapDeals.
14 |
15 |
16 |
17 |
18 |
28 |
29 |
30 |
--------------------------------------------------------------------------------
/src/App.js:
--------------------------------------------------------------------------------
1 | import './App.scss';
2 | import {BrowserRouter, Routes, Route} from 'react-router-dom';
3 | // pages
4 | import {Home, Category, Cart} from "./pages/index";
5 | // components
6 | import Navbar from './components/Navbar/Navbar';
7 | import Footer from "./components/Footer/Footer";
8 | import {Provider} from 'react-redux';
9 | import store from "./store/store";
10 |
11 | function App() {
12 | return (
13 |
14 |
15 |
16 |
17 |
18 | } />
19 | } />
20 | } />
21 |
22 |
23 |
24 |
25 |
26 | );
27 | }
28 |
29 | export default App;
30 |
--------------------------------------------------------------------------------
/src/App.scss:
--------------------------------------------------------------------------------
1 | @import url('https://fonts.googleapis.com/css2?family=Poppins:ital,wght@0,100;0,200;0,300;0,400;0,500;0,600;0,700;0,800;0,900;1,100;1,200;1,300;1,400;1,500;1,600;1,700;1,800;1,900&display=swap');
2 |
3 | // variables
4 | $clr-black: #000;
5 | $clr-white: #fff;
6 | $clr-regal-blue: #103755;
7 | $clr-gold: #eeb808;
8 | $clr-light-blue: #707b8e;
9 | $clr-pine-green: #63766b;
10 | $clr-ghost-white: #f8f8fa;
11 | $clr-dark: #212529;
12 | $clr-red: #CE4F4B;
13 | $fnt-base: 'Poppins', sans-serif;
14 | $transition: all 300ms linear;
15 |
16 | // global styles & resets
17 | *,
18 | *::after,
19 | *::before{
20 | margin: 0;
21 | padding: 0;
22 | box-sizing: border-box;
23 | scroll-behavior: smooth;
24 | }
25 | html{
26 | font-size: 10px;
27 | }
28 | body{
29 | font-size: 1.6rem;
30 | line-height: 1.6;
31 | font-family: $fnt-base;
32 | color: $clr-black;
33 | }
34 | ul{
35 | list-style-type: none;
36 | }
37 | a{
38 | text-decoration: none;
39 | color: unset;
40 | }
41 | h1, h2, h3, h4, h5, h6{
42 | letter-spacing: var(--spacing);
43 | text-transform: capitalize;
44 | }
45 | img{
46 | width: 100%;
47 | display: block;
48 | }
49 | .img-cover{
50 | width: 100%;
51 | height: 100%;
52 | object-fit: cover;
53 | }
54 | button{
55 | cursor: pointer;
56 | outline: 0;
57 | border: none;
58 | background-color: transparent;
59 | font-family: inherit;
60 | font-size: 1.8rem;
61 | }
62 | input, textarea, select{
63 | outline: 0;
64 | border: none;
65 | resize: none;
66 | font-family: inherit;
67 | font-size: 1.6rem;
68 | }
69 |
70 | /* custom utility classes */
71 | .container{
72 | max-width: 1320px;
73 | margin: 0 auto;
74 | padding: 0 2rem;
75 | }
76 |
77 | /* flexbox and grid */
78 | .flex{
79 | display: flex;
80 | align-items: center;
81 |
82 | &-column{ flex-direction: column;}
83 | &-center{ justify-content: center;}
84 | &-between{ justify-content: space-between;}
85 | &-start{ justify-content: flex-start;}
86 | &-end{ justify-content: flex-end;}
87 | }
88 |
89 | .grid{ display: grid; }
90 |
91 | /* height and width */
92 | .h-100{height: 100%;}
93 | .w-100{width: 100%;}
94 |
95 | /* text align and transformation */
96 | .text{
97 | &-center{text-align: center;}
98 | &-start{text-align: left;}
99 | &-end{text-align: right;}
100 | &-justify{text-align: justify;}
101 | &-uppercase{text-transform: uppercase;}
102 | &-capitalize{text-transform: capitalize;}
103 | &-regal-blue{color: $clr-regal-blue;}
104 | &-gold{color: $clr-gold;}
105 | &-light-blue{color: $clr-light-blue;}
106 | &-pine-green{color: $clr-pine-green;}
107 | &-white{color: $clr-white;}
108 | &-black{color: $clr-black;}
109 | &-ghost-white{color: $clr-ghost-white;}
110 | &-red{color: $clr-red;}
111 | }
112 |
113 | .bg{
114 | &-regal-blue{background-color: $clr-regal-blue;}
115 | &-gold{background-color: $clr-gold;}
116 | &-light-blue{background-color: $clr-light-blue;}
117 | &-pine-green{background-color: $clr-pine-green;}
118 | &-white{background-color: $clr-white;}
119 | &-black{background-color: $clr-black;}
120 | &-ghost-white{background-color: $clr-ghost-white;}
121 | &-dark{background-color: $clr-dark;}
122 | }
123 |
124 | /* font weights */
125 | .fw{
126 | &-1{font-weight: 100;}
127 | &-2{font-weight: 200;}
128 | &-3{font-weight: 300;}
129 | &-4{font-weight: 400;}
130 | &-5{font-weight: 500;}
131 | &-6{font-weight: 600;}
132 | &-7{font-weight: 700;}
133 | &-8{font-weight: 800;}
134 | &-9{font-weight: 900;}
135 | }
136 |
137 | /* common font sizes */
138 | .fs{
139 | &-13{font-size: 13px;}
140 | &-14{font-size: 14px;}
141 | &-15{font-size: 15px;}
142 | &-16{font-size: 16px;}
143 | &-17{font-size: 17px;}
144 | &-18{font-size: 18px;}
145 | &-19{font-size: 19px;}
146 | &-20{font-size: 20px;}
147 | &-21{font-size: 21px;}
148 | &-22{font-size: 22px;}
149 | &-23{font-size: 23px;}
150 | &-24{font-size: 24px;}
151 | &-25{font-size: 25px;}
152 | &-26{font-size: 26px;}
153 | }
154 |
155 | /* letter spacing */
156 | .ls-1{letter-spacing: 1px;}
157 | .ls-2{letter-spacing: 2px;}
158 |
159 | /* margin and padding */
160 | .mx-auto{
161 | margin-right: auto;
162 | margin-left: auto;
163 | }
164 | .py-5{
165 | padding-top: 50px;
166 | padding-bottom: 50px;
167 | }
168 |
169 | /* animation and transition stopper */
170 | .resize-animation-stopper *{
171 | animation: none!important;
172 | transition: none!important;
173 | }
174 |
175 | // section
176 | .section-title{
177 | padding: 16px 0;
178 | & *{
179 | font-size: 26px;
180 | }
181 | }
182 |
183 | // breadcrumb
184 | .breadcrumb{
185 | padding: 12px 0;
186 | color: $clr-light-blue;
187 | &-separator{
188 | margin: 0 8px;
189 | }
190 | }
191 |
192 | // butons
193 | %btn-shared{
194 | padding: 8px 14px;
195 | display: inline-block;
196 | border-radius: 6px;
197 | transition: $transition;
198 |
199 | .btn-icon{
200 | margin-right: 8px;
201 | }
202 | }
203 | .btn-primary{
204 | @extend %btn-shared;
205 | background-color: $clr-regal-blue;
206 | color: $clr-white;
207 |
208 | &:hover{
209 | background-color: darken($clr-regal-blue, 6%);
210 | }
211 | }
212 |
213 | .btn-secondary{
214 | @extend %btn-shared;
215 | background-color: $clr-gold;
216 | color: $clr-white;
217 |
218 | &:hover{
219 | background-color: darken($clr-gold, 6%);
220 | }
221 | }
222 |
223 | .btn-danger{
224 | @extend %btn-shared;
225 | color: $clr-white;
226 | background-color: $clr-red;
227 | padding: 3px 14px;
228 | border-radius: 4px;
229 |
230 | &:hover{
231 | background-color: darken($clr-red, 6%);
232 | }
233 | }
234 |
235 | .btn-square{
236 | width: 28px;
237 | height: 28px;
238 | border: 1px solid rgba(0, 0, 0, 0.2);
239 | display: flex;
240 | align-items: center;
241 | justify-content: center;
242 | border-radius: 2px;
243 |
244 | &-icon{
245 | font-size: 14px;
246 | color: $clr-regal-blue;
247 | transition: $transition;
248 |
249 | &:hover{
250 | color: $clr-gold;
251 | }
252 | }
253 | }
--------------------------------------------------------------------------------
/src/assets/images/error.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/prabinmagar/shopping-hub-react-js-ecom-site-with-redux-toolkit/fb25ff545ff129171f01d3a60f4e8a3fa13d1d98/src/assets/images/error.png
--------------------------------------------------------------------------------
/src/assets/images/slider-img-1.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/prabinmagar/shopping-hub-react-js-ecom-site-with-redux-toolkit/fb25ff545ff129171f01d3a60f4e8a3fa13d1d98/src/assets/images/slider-img-1.png
--------------------------------------------------------------------------------
/src/assets/images/slider-img-2.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/prabinmagar/shopping-hub-react-js-ecom-site-with-redux-toolkit/fb25ff545ff129171f01d3a60f4e8a3fa13d1d98/src/assets/images/slider-img-2.png
--------------------------------------------------------------------------------
/src/assets/images/slider-img-3.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/prabinmagar/shopping-hub-react-js-ecom-site-with-redux-toolkit/fb25ff545ff129171f01d3a60f4e8a3fa13d1d98/src/assets/images/slider-img-3.png
--------------------------------------------------------------------------------
/src/assets/images/spinner.svg:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
--------------------------------------------------------------------------------
/src/components/Category/Category.js:
--------------------------------------------------------------------------------
1 | import React from 'react';
2 | import { STATUS } from "../../utils/status";
3 | import "./Category.scss";
4 | import {Link} from "react-router-dom";
5 | import Error from '../Error/Error';
6 | import Loader from '../Loader/Loader';
7 |
8 | const Category = ({categories, status}) => {
9 | if(status === STATUS.ERROR) return ( );
10 | if(status === STATUS.LOADING) return ( );
11 |
12 | return (
13 |
14 |
15 |
16 |
17 |
Category
18 |
19 |
20 | {
21 | categories.slice(0, 5).map(category => (
22 |
23 |
24 |
25 |
26 |
27 |
28 |
{category.name}
29 |
30 |
31 |
32 | ))
33 | }
34 |
35 |
36 |
37 |
38 |
39 | )
40 | }
41 |
42 | export default Category
--------------------------------------------------------------------------------
/src/components/Category/Category.scss:
--------------------------------------------------------------------------------
1 | @import "../../App.scss";
2 |
3 | .category-items{
4 | row-gap: 20px;
5 | .category-item{
6 | &-img{
7 | border-radius: 10px;
8 | overflow: hidden;
9 | }
10 | &-name{
11 | padding: 12px 0;
12 | }
13 | }
14 |
15 | @media screen and (min-width: 576px){
16 | grid-template-columns: repeat(2, 1fr);
17 | column-gap: 20px;
18 | }
19 |
20 | @media screen and (min-width: 992px){
21 | grid-template-columns: repeat(3, 1fr);
22 | }
23 |
24 | @media screen and (min-width: 1200px){
25 | grid-template-columns: repeat(4, 1fr);
26 | }
27 |
28 | @media screen and (min-width: 1400px){
29 | grid-template-columns: repeat(5, 1fr);
30 | }
31 | }
--------------------------------------------------------------------------------
/src/components/Error/Error.js:
--------------------------------------------------------------------------------
1 | import React from 'react';
2 | import "./Error.scss";
3 | import {error} from "../../utils/images";
4 |
5 | const Error = () => {
6 | return (
7 |
8 |
9 |
10 |
11 |
12 | )
13 | }
14 |
15 | export default Error
--------------------------------------------------------------------------------
/src/components/Error/Error.scss:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/prabinmagar/shopping-hub-react-js-ecom-site-with-redux-toolkit/fb25ff545ff129171f01d3a60f4e8a3fa13d1d98/src/components/Error/Error.scss
--------------------------------------------------------------------------------
/src/components/Footer/Footer.js:
--------------------------------------------------------------------------------
1 | import React from 'react';
2 | import "./Footer.scss";
3 |
4 | const Footer = () => {
5 | return (
6 |
7 |
8 |
9 |
18 |
19 |
27 |
28 |
29 |
About Shopping Hub
30 |
35 |
36 |
37 |
38 |
Contact
39 |
40 |
41 |
42 | +678 004 5754
43 |
44 |
45 |
46 | info@shophub.com
47 |
48 |
49 |
50 |
51 |
52 |
53 | )
54 | }
55 |
56 | export default Footer
--------------------------------------------------------------------------------
/src/components/Footer/Footer.scss:
--------------------------------------------------------------------------------
1 | @import "../../App.scss";
2 | .footer{
3 | .footer-content{
4 | row-gap: 20px;
5 | .footer-item{
6 | ul{
7 | li{
8 | margin: 0.7rem 0;
9 | opacity: 0.8;
10 | transition: $transition;
11 | &:hover{
12 | opacity: 1;
13 | }
14 | }
15 | }
16 |
17 | &:nth-child(4){
18 | ul{
19 | li{
20 | span{
21 | &:first-child{
22 | margin-right: 8px;
23 | }
24 | }
25 | }
26 | }
27 | }
28 | }
29 |
30 | @media screen and (min-width: 768px){
31 | grid-template-columns: repeat(2, 1fr);
32 | .footer-item{
33 | text-align: left;
34 | }
35 | }
36 |
37 | @media screen and (min-width: 992px){
38 | grid-template-columns: repeat(4, 1fr);
39 | .footer-item{
40 | text-align: left;
41 | }
42 | }
43 | }
44 | }
--------------------------------------------------------------------------------
/src/components/Loader/Loader.js:
--------------------------------------------------------------------------------
1 | import React from 'react';
2 | import { spinner } from '../../utils/images';
3 | import "./Loader.scss";
4 |
5 | const Loader = () => {
6 | return (
7 |
8 |
9 |
10 |
11 |
12 | )
13 | }
14 |
15 | export default Loader
--------------------------------------------------------------------------------
/src/components/Loader/Loader.scss:
--------------------------------------------------------------------------------
1 | .loader{
2 | img{
3 | width: 60px;
4 | }
5 | }
--------------------------------------------------------------------------------
/src/components/Navbar/Navbar.js:
--------------------------------------------------------------------------------
1 | import React, { useState, useEffect} from 'react';
2 | import "./Navbar.scss";
3 | import { Link } from 'react-router-dom';
4 | import { useSelector, useDispatch } from 'react-redux';
5 | import { fetchCategories } from '../../store/categorySlice';
6 | import { getCartTotal } from '../../store/cartSlice';
7 |
8 | const Navbar = () => {
9 | const dispatch = useDispatch();
10 | const {data: categories} = useSelector((state) => state.category);
11 | const {totalItems} = useSelector((state => state.cart));
12 |
13 | const [isSidebarOpen, setIsSidebarOpen] = useState(false);
14 |
15 | useEffect(() => {
16 | dispatch(fetchCategories());
17 | dispatch(getCartTotal());
18 | // eslint-disable-next-line react-hooks/exhaustive-deps
19 | }, []);
20 |
21 | return (
22 |
23 |
24 |
25 |
26 |
27 |
Shopping Hub.
28 |
29 |
30 |
36 |
37 |
38 |
39 |
40 |
41 |
42 |
Cart
43 | {totalItems}
44 |
45 |
46 |
47 |
48 |
49 |
50 |
51 |
52 |
53 | setIsSidebarOpen(false)}>
54 |
55 |
56 | {
57 | categories.map(category => (
58 | setIsSidebarOpen(false)}>{category.name}
59 | ))
60 | }
61 |
62 |
63 |
setIsSidebarOpen(true)}>
64 |
65 |
66 |
67 |
68 |
69 |
70 | )
71 | }
72 |
73 | export default Navbar;
--------------------------------------------------------------------------------
/src/components/Navbar/Navbar.scss:
--------------------------------------------------------------------------------
1 | @import "../../App.scss";
2 |
3 | .navbar{
4 | padding: 16px 0 0 0;
5 | border-bottom: 1px solid rgba(0, 0, 0, 0.05);
6 | &-brand{
7 | font-size: 30px;
8 | font-weight: 700;
9 |
10 | @media screen and (max-width: 992px){
11 | font-size: 24px;
12 | }
13 |
14 | @media screen and (max-width: 576px){
15 | font-size: 20px;
16 | }
17 | }
18 | &-search{
19 | align-items: stretch;
20 | input{
21 | width: 100%;
22 | border: 0.5px solid rgba(0, 0, 0, 0.05);
23 | color: $clr-light-blue;
24 | height: 44px;
25 | padding: 4px 16px;
26 | border-radius: 3px 0 0 3px;
27 | }
28 | .navbar-search-btn{
29 | width: 60px;
30 | height: 44px;
31 | background-color: $clr-gold;
32 | color: $clr-white;
33 | transition: $transition;
34 |
35 | &:hover{
36 | background-color: $clr-regal-blue;
37 | }
38 | }
39 | }
40 |
41 | &-btns{
42 | .add-to-cart-btn{
43 | margin-right: 28px;
44 | color: $clr-pine-green;
45 | .btn-ico{
46 | margin-right: 10px;
47 | }
48 | .btn-txt{
49 | position: relative;
50 | .cart-count-value{
51 | position: absolute;
52 | top: -10px;
53 | display: inline-flex;
54 | justify-content: center;
55 | align-items: center;
56 | background-color: $clr-gold;
57 | width: 20px;
58 | height: 20px;
59 | border-radius: 50%;
60 | font-size: 14px;
61 | color: $clr-black;
62 | opacity: 0.8;
63 | font-weight: 500;
64 | }
65 | }
66 | }
67 | }
68 | .navbar-bottom{
69 | padding: 10px 0;
70 | margin-top: 14px;
71 |
72 | > .container{
73 | justify-content: flex-end;
74 | }
75 |
76 | .nav-links{
77 | li{
78 | margin: 0 10px;
79 | }
80 | .nav-link{
81 | font-size: 14.5px;
82 | transition: $transition;
83 |
84 | &:hover{
85 | opacity: 0.8;
86 | }
87 | }
88 | }
89 | .navbar-show-btn{
90 | transition: $transition;
91 | display: none;
92 |
93 | &:hover{
94 | color: $clr-white;
95 | }
96 | }
97 | .navbar-hide-btn{
98 | display: none;
99 | }
100 | }
101 |
102 | @media screen and (max-width: 1200px){
103 | .nav-links{
104 | .nav-link{
105 | font-size: 13px!important;
106 | }
107 | }
108 | }
109 |
110 | @media screen and (max-width: 992px){
111 | .nav-links{
112 | position: fixed;
113 | top: 0;
114 | right: 0;
115 | height: 100%;
116 | width: 280px;
117 | background-color: $clr-white;
118 | box-shadow: rgba(0, 0, 0, 0.24) 0px 3px 8px;
119 | flex-direction: column;
120 | align-items: flex-start;
121 | padding-top: 60px;
122 | padding-left: 16px;
123 | transform: translateX(100%);
124 | transition: $transition;
125 | z-index: 999;
126 | li{
127 | margin-bottom: 10px!important;
128 | border-bottom: 0.5px solid rgba(0, 0, 0, 0.05);
129 |
130 | .nav-link{
131 | color: $clr-regal-blue;
132 | font-size: 14px!important;
133 | }
134 | }
135 | }
136 | .show-nav-links{
137 | transform: translateX(0);
138 | }
139 | .navbar-show-btn{
140 | display: block!important;
141 | }
142 | .navbar-hide-btn{
143 | position: absolute;
144 | top: 20px;
145 | right: 20px;
146 | font-size: 16px;
147 | width: 24px;
148 | height: 24px;
149 | background-color: $clr-black;
150 | border-radius: 50%;
151 | display: flex!important;
152 | align-items: center;
153 | justify-content: center;
154 | }
155 | }
156 |
157 | @media screen and (max-width: 768px){
158 | .navbar-top{
159 | .navbar-search{
160 | display: none;
161 | }
162 | }
163 | }
164 | }
--------------------------------------------------------------------------------
/src/components/ProductList/ProductList.js:
--------------------------------------------------------------------------------
1 | import React from 'react';
2 | import { STATUS } from '../../utils/status';
3 | import "./ProductList.scss";
4 | import { setModalData, setIsModalVisible } from '../../store/modalSlice';
5 | import SingleProduct from '../SingleProduct/SingleProduct';
6 | import { useSelector, useDispatch } from 'react-redux';
7 | import { formatPrice } from '../../utils/helpers';
8 | import Loader from '../Loader/Loader';
9 | import Error from '../Error/Error';
10 |
11 | const ProductList = ({products, status}) => {
12 | const dispatch = useDispatch();
13 | const {isModalVisible} = useSelector((state) => state.modal);
14 |
15 | const viewModalHandler = (data) => {
16 | dispatch(setModalData(data));
17 | dispatch(setIsModalVisible(true));
18 | }
19 |
20 | if(status === STATUS.ERROR) return ( );
21 | if(status === STATUS.LOADING) return ( );
22 |
23 | return (
24 |
25 | { isModalVisible && }
26 |
27 |
28 |
29 |
30 |
Our Products
31 |
32 |
33 | {
34 | products.slice(0, 20).map(product => (
35 |
viewModalHandler(product)}>
36 |
37 |
38 |
{product.category.name}
39 |
40 |
41 |
{product.title}
42 |
{formatPrice(product.price)}
43 |
44 |
45 | ))
46 | }
47 |
48 |
49 |
50 |
51 | )
52 | }
53 |
54 | export default ProductList
--------------------------------------------------------------------------------
/src/components/ProductList/ProductList.scss:
--------------------------------------------------------------------------------
1 | @import "../../App.scss";
2 |
3 | .product-items{
4 | row-gap: 20px;
5 | .product-item{
6 | cursor: pointer;
7 | box-shadow: rgba(99, 99, 99, 0.05) 0px 2px 8px 0px;
8 | padding: 18px;
9 | border-radius: 4px;
10 | transition: $transition;
11 |
12 | &-body{
13 | padding: 12px 0;
14 | }
15 |
16 | &-img{
17 | position: relative;
18 |
19 | .product-item-cat{
20 | position: absolute;
21 | top: 8px;
22 | right: 8px;
23 | border-radius: 8px;
24 | padding-right: 8px;
25 | padding-left: 8px;
26 | box-shadow: rgba(0, 0, 0, 0.35) 0px 5px 15px;
27 | }
28 | }
29 |
30 | &-title{
31 | padding: 8px 0;
32 | opacity: 0.8;
33 | display: block;
34 | }
35 | &:hover{
36 | box-shadow: rgba(99, 99, 99, 0.2) 0px 2px 8px 0px;
37 | }
38 | }
39 |
40 | @media screen and (min-width: 576px){
41 | grid-template-columns: repeat(2, 1fr);
42 | column-gap: 20px;
43 | }
44 |
45 | @media screen and (min-width: 768px){
46 | grid-template-columns: repeat(3, 1fr);
47 | column-gap: 20px;
48 | }
49 |
50 | @media screen and (min-width: 992px){
51 | grid-template-columns: repeat(4, 1fr);
52 | column-gap: 20px;
53 | }
54 |
55 | @media screen and (min-width: 1200px){
56 | grid-template-columns: repeat(5, 1fr);
57 | column-gap: 20px;
58 | }
59 | }
--------------------------------------------------------------------------------
/src/components/SingleCategory/SingleCategory.js:
--------------------------------------------------------------------------------
1 | import React from 'react';
2 | import { useSelector, useDispatch } from 'react-redux';
3 | import { setIsModalVisible, setModalData } from '../../store/modalSlice';
4 | import { formatPrice } from '../../utils/helpers';
5 | import SingleProduct from '../SingleProduct/SingleProduct';
6 | import Error from '../Error/Error';
7 | import Loader from '../Loader/Loader';
8 | import {STATUS} from "../../utils/status";
9 |
10 | const SingleCategory = ({products, status}) => {
11 | const dispatch = useDispatch();
12 | const {isModalVisible} = useSelector((state) => state.modal);
13 |
14 | const viewModalHandler = (data) => {
15 | dispatch(setModalData(data));
16 | dispatch(setIsModalVisible(true));
17 | }
18 |
19 | if(status === STATUS.ERROR) return ( );
20 | if(status === STATUS.LOADING) return ( );
21 |
22 | return (
23 |
24 | { isModalVisible && }
25 |
26 |
27 |
28 |
29 |
{products[0].category.name}
30 |
31 |
32 | {
33 | products.map(product => (
34 |
viewModalHandler(product)}>
35 |
36 |
37 |
{product.category.name}
38 |
39 |
40 |
{product.title}
41 |
{formatPrice(product.price)}
42 |
43 |
44 | ))
45 | }
46 |
47 |
48 |
49 |
50 | )
51 | }
52 |
53 | export default SingleCategory;
54 |
--------------------------------------------------------------------------------
/src/components/SingleCategory/SingleCategory.scss:
--------------------------------------------------------------------------------
1 | @import "../../App.scss";
2 |
3 | .product-items{
4 | row-gap: 20px;
5 | .product-item{
6 | box-shadow: rgba(99, 99, 99, 0.05) 0px 2px 8px 0px;
7 | padding: 18px;
8 | border-radius: 4px;
9 | &-body{
10 | padding: 12px 0;
11 | }
12 |
13 | &-img{
14 | position: relative;
15 |
16 | .product-item-cat{
17 | position: absolute;
18 | top: 8px;
19 | right: 8px;
20 | border-radius: 8px;
21 | padding-right: 8px;
22 | padding-left: 8px;
23 | box-shadow: rgba(0, 0, 0, 0.35) 0px 5px 15px;
24 | }
25 | }
26 |
27 | &-title{
28 | padding: 8px 0;
29 | opacity: 0.8;
30 | display: block;
31 | }
32 | }
33 |
34 | @media screen and (min-width: 576px){
35 | grid-template-columns: repeat(2, 1fr);
36 | column-gap: 20px;
37 | }
38 |
39 | @media screen and (min-width: 768px){
40 | grid-template-columns: repeat(3, 1fr);
41 | column-gap: 20px;
42 | }
43 |
44 | @media screen and (min-width: 992px){
45 | grid-template-columns: repeat(4, 1fr);
46 | column-gap: 20px;
47 | }
48 |
49 | @media screen and (min-width: 1200px){
50 | grid-template-columns: repeat(5, 1fr);
51 | column-gap: 20px;
52 | }
53 | }
--------------------------------------------------------------------------------
/src/components/SingleProduct/SingleProduct.js:
--------------------------------------------------------------------------------
1 | import React, {useState} from 'react';
2 | import "./SingleProduct.scss";
3 | import { useSelector, useDispatch } from 'react-redux';
4 | import { setIsModalVisible } from '../../store/modalSlice';
5 | import { addToCart } from '../../store/cartSlice';
6 | import { useNavigate } from 'react-router-dom';
7 | import { formatPrice } from '../../utils/helpers';
8 |
9 | const SingleProduct = () => {
10 | const dispatch = useDispatch();
11 | const navigate = useNavigate();
12 | const [qty, setQty] = useState(1);
13 |
14 | const { data: product } = useSelector(state => state.modal);
15 |
16 | const increaseQty = () => {
17 | setQty((prevQty) => {
18 | let newQty = prevQty + 1;
19 | return newQty;
20 | })
21 | }
22 |
23 | const decreaseQty = () => {
24 | setQty((prevQty) => {
25 | let newQty = prevQty - 1;
26 | if(newQty < 1){
27 | newQty = 1;
28 | }
29 | return newQty;
30 | })
31 | }
32 |
33 | const addToCartHandler = (product) => {
34 | let totalPrice = qty * product.price;
35 | const tempProduct = {
36 | ...product,
37 | quantity: qty,
38 | totalPrice
39 | }
40 | dispatch(addToCart(tempProduct));
41 | dispatch(setIsModalVisible(false));
42 | navigate('/cart');
43 | };
44 |
45 | const modalOverlayHandler = (e) => {
46 | if(e.target.classList.contains('overlay-bg')){
47 | dispatch(setIsModalVisible(false));
48 | }
49 | }
50 |
51 | return (
52 |
53 |
54 |
dispatch(setIsModalVisible(false))}>
55 |
56 |
57 |
58 | {/* details left */}
59 |
60 |
61 |
62 |
63 |
64 | {/* detials right */}
65 |
66 |
67 |
{product.title}
68 |
{product.description}
69 |
Price: {formatPrice(product.price)}
70 |
71 |
Qty:
72 |
73 | decreaseQty()}>
74 |
75 |
76 | {qty}
77 | increaseQty()}>
78 |
79 |
80 |
81 |
82 |
addToCartHandler(product)}>
83 |
84 |
85 |
86 | Add To Cart
87 |
88 |
89 |
90 |
91 |
92 |
93 | )
94 | }
95 |
96 | export default SingleProduct
--------------------------------------------------------------------------------
/src/components/SingleProduct/SingleProduct.scss:
--------------------------------------------------------------------------------
1 | @import "../../App.scss";
2 | .overlay-bg{
3 | position: fixed;
4 | top: 0;
5 | left: 0;
6 | width: 100%;
7 | height: 100%;
8 | background-color: rgba(0, 0, 0, 0.3);
9 | z-index: 99;
10 | }
11 | .product-details-modal{
12 | position: fixed;
13 | top: 50%;
14 | left: 50%;
15 | transform: translate(-50%, -50%);
16 | z-index: 100;
17 | box-shadow: rgba(149, 157, 165, 0.2) 0px 8px 24px;
18 | border-radius: 4px;
19 | padding: 36px 24px;
20 | width: 90%;
21 | max-width: 920px;
22 |
23 | .modal-close-btn{
24 | position: absolute;
25 | right: -12px;
26 | top: -12px;
27 | width: 24px;
28 | height: 24px;
29 | background-color: $clr-dark;
30 | color: $clr-white;
31 | transition: $transition;
32 | border-radius: 50%;
33 | &:hover{
34 | color: $clr-gold;
35 | }
36 | }
37 |
38 | .details-content{
39 | overflow-y: scroll;
40 | row-gap: 32px;
41 | height: 70vh;
42 | .details-right{
43 | .details-img{
44 | max-width: 500px;
45 | }
46 | }
47 | .details-left{
48 | .description{
49 | margin: 6px 0 12px 0;
50 | }
51 | .price{
52 | opacity: 0.7;
53 | border-bottom: 1px dashed $clr-light-blue;
54 | padding-bottom: 6px;
55 | }
56 | .qty{
57 | margin-top: 20px;
58 |
59 | &-text{
60 | margin-right: 10px;
61 | }
62 |
63 | &-change{
64 | .qty-inc, .qty-dec{
65 | border: 2px solid $clr-ghost-white;
66 | width: 32px;
67 | height: 32px;
68 |
69 | &:hover{
70 | color: darken($clr-light-blue, 10%);
71 | }
72 | }
73 |
74 | .qty-value{
75 | width: 40px;
76 | }
77 | }
78 | }
79 | .add-to-cart-btn{
80 | margin-top: 22px;
81 | }
82 | }
83 |
84 | @media screen and (min-width: 800px){
85 | grid-template-columns: repeat(2, 1fr);
86 | column-gap: 40px;
87 | height: auto;
88 | }
89 | }
90 |
91 |
92 | }
--------------------------------------------------------------------------------
/src/components/Slider/Slider.js:
--------------------------------------------------------------------------------
1 | import React from 'react';
2 | import "./Slider.scss";
3 | import "slick-carousel/slick/slick.css";
4 | import "slick-carousel/slick/slick-theme.css";
5 | import {sliderImages} from '../../utils/images';
6 |
7 | const Slider = () => {
8 | return (
9 |
10 |
11 |
12 |
13 |
14 | )
15 | }
16 |
17 | export default Slider
--------------------------------------------------------------------------------
/src/components/Slider/Slider.scss:
--------------------------------------------------------------------------------
1 | @import "../../App.scss";
2 | .hero-slider{
3 | &-item{
4 | height: 280px;
5 | img{
6 | height: 100%;
7 | width: 100%;
8 | object-fit: cover;
9 | }
10 | }
11 | }
--------------------------------------------------------------------------------
/src/index.js:
--------------------------------------------------------------------------------
1 | import React from 'react';
2 | import ReactDOM from 'react-dom/client';
3 | import App from './App';
4 |
5 | const root = ReactDOM.createRoot(document.getElementById('root'));
6 | root.render(
7 |
8 | );
9 |
10 |
--------------------------------------------------------------------------------
/src/pages/CartPage/CartPage.js:
--------------------------------------------------------------------------------
1 | import React, {useEffect} from 'react';
2 | import "./CartPage.scss";
3 | import { useSelector, useDispatch } from 'react-redux';
4 | import {Link} from "react-router-dom";
5 | import { removeFromCart, toggleCartQty, getCartTotal, clearCart } from '../../store/cartSlice';
6 | import {formatPrice} from "../../utils/helpers";
7 |
8 | const CartPage = () => {
9 | const dispatch = useDispatch();
10 | const {data: cartProducts, totalItems, totalAmount, deliveryCharge} = useSelector(state => state.cart);
11 |
12 | useEffect(() => {
13 | dispatch(getCartTotal());
14 | // eslint-disable-next-line react-hooks/exhaustive-deps
15 | }, [useSelector(state => state.cart)]);
16 |
17 | const emptyCartMsg = No items found! ;
18 |
19 | return (
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
29 |
30 |
31 |
32 | Cart
33 |
34 |
35 |
36 |
37 |
38 |
39 |
My Cart
40 |
41 | {
42 | cartProducts.length === 0 ? emptyCartMsg : (
43 |
44 |
45 |
46 | {
47 | cartProducts.map(cartProduct => (
48 |
49 |
50 |
51 |
dispatch(removeFromCart(cartProduct.id))}>
52 |
53 |
54 |
55 |
56 |
57 |
{cartProduct.title}
58 |
59 |
Qty:
60 |
61 | dispatch(toggleCartQty({id: cartProduct.id, type: "DEC"}))}>
62 |
63 |
64 | {cartProduct.quantity}
65 | dispatch(toggleCartQty({id: cartProduct.id, type: "INC"}))}>
66 |
67 |
68 |
69 |
70 |
71 |
Price : {formatPrice(cartProduct.price)}.00
72 |
73 | Sub Total:
74 | {formatPrice(cartProduct.totalPrice)}
75 |
76 |
77 |
78 |
79 | ))
80 | }
81 |
82 |
dispatch(clearCart())}>
83 | Clear Cart
84 |
85 |
86 |
87 |
88 |
89 |
Order Summary
90 |
91 |
92 |
93 | Selected {totalItems} items(s) Price
94 | {formatPrice(totalAmount)}
95 |
96 |
97 | Discount
98 |
99 | -
100 | {formatPrice(0)}
101 |
102 |
103 |
104 | Delivery Cost
105 |
106 | + {formatPrice(deliveryCharge)}
107 |
108 |
109 |
110 |
111 | Grand Total:
112 | {formatPrice(totalAmount + deliveryCharge)}
113 |
114 |
115 | Proceed to Checkout
116 |
117 |
118 |
119 |
120 | )
121 | }
122 |
123 |
124 |
125 | )
126 | }
127 |
128 | export default CartPage
--------------------------------------------------------------------------------
/src/pages/CartPage/CartPage.scss:
--------------------------------------------------------------------------------
1 | @import "../../App.scss";
2 | .cart-page{
3 | min-height: 50vh;
4 | }
5 | .qty{
6 | margin: 12px 0 6px 0;
7 |
8 | &-text{
9 | margin-right: 10px;
10 | }
11 |
12 | &-change{
13 | .qty-inc, .qty-dec{
14 | border: 1px solid rgba(0, 0, 0, 0.1);
15 | width: 32px;
16 | height: 32px;
17 | transition: $transition;
18 |
19 | &:hover{
20 | border: 1px solid rgba(0, 0, 0, 0.3);
21 | }
22 | }
23 |
24 | .qty-value{
25 | width: 40px;
26 | }
27 | }
28 | }
29 |
30 | .cart-content{
31 | row-gap: 40px;
32 | @media screen and (min-width: 992px){
33 | grid-template-columns: 2fr 1fr;
34 | column-gap: 36px;
35 | align-items: flex-start;
36 | }
37 |
38 | @media screen and (min-width: 1200px){
39 | column-gap: 60px;
40 | }
41 |
42 | .cart-left{
43 | .cart-items{
44 | row-gap: 20px;
45 | margin: 24px 0;
46 |
47 | .cart-item{
48 | padding-bottom: 20px;
49 | border-bottom: 1px solid rgba(0, 0, 0, 0.1);
50 | row-gap: 20px;
51 |
52 | .rmv-from-cart-btn{
53 | margin-top: 12px;
54 | }
55 |
56 | @media screen and (min-width: 576px){
57 | grid-template-columns: 30% auto;
58 | column-gap: 14px;
59 | }
60 |
61 | @media screen and (min-width: 678px){
62 | grid-template-columns: 150px auto;
63 | column-gap: 20px;
64 | }
65 |
66 | @media screen and (min-width: 992px){
67 | column-gap: 32px;
68 | }
69 |
70 | &-img{
71 | padding-bottom: 12px;
72 | }
73 |
74 | &-info{
75 | .sub-total{
76 | padding: 6px 0;
77 | }
78 | }
79 | }
80 | }
81 | }
82 |
83 | .cart-right{
84 | margin: 24px 0;
85 | .cart-summary{
86 | display: flex;
87 | flex-direction: column;
88 | min-height: 420px;
89 |
90 | > &{
91 | padding: 16px;
92 | }
93 | &-title{
94 | border-bottom: 1px solid rgba(0, 0, 0, 0.1);
95 | padding-bottom: 12px;
96 | }
97 |
98 | &-info{
99 | padding-top: 16px;
100 | padding-bottom: 16px;
101 | li{
102 | margin: 6px 0;
103 | }
104 | }
105 |
106 | &-total{
107 | margin-top: auto;
108 | margin-bottom: 16px;
109 | padding-top: 12px;
110 | border-top: 1px solid rgba(0, 0, 0, 0.1);
111 | }
112 |
113 | &-btn{
114 | .btn-secondary{
115 | width: 100%;
116 | }
117 | }
118 | }
119 | }
120 | }
--------------------------------------------------------------------------------
/src/pages/CategoryPage/CategoryPage.js:
--------------------------------------------------------------------------------
1 | import React, {useEffect} from 'react';
2 | import ProductList from '../../components/ProductList/ProductList';
3 | import { useSelector, useDispatch } from 'react-redux';
4 | import { fetchProductsByCategory } from '../../store/categorySlice';
5 | import { useParams, Link } from 'react-router-dom';
6 | import "./CategoryPage.scss";
7 |
8 | const CategoryPage = () => {
9 | const dispatch = useDispatch();
10 | const {id} = useParams();
11 | const {catProductSingle: products, catProductSingleStatus: status} = useSelector((state) => state.category);
12 |
13 | useEffect(() => {
14 | dispatch(fetchProductsByCategory(id, 'single'));
15 | // eslint-disable-next-line react-hooks/exhaustive-deps
16 | }, [id]);
17 |
18 | return (
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
29 |
30 |
31 |
32 | Category
33 |
34 |
35 |
36 |
37 |
38 | { products[0] && products[0].category.name}
39 |
40 |
41 |
42 |
43 |
44 |
45 | )
46 | }
47 |
48 | export default CategoryPage
--------------------------------------------------------------------------------
/src/pages/CategoryPage/CategoryPage.scss:
--------------------------------------------------------------------------------
1 | @import "../../App.scss";
2 | .category-page{
3 | min-height: 60vh;
4 | }
--------------------------------------------------------------------------------
/src/pages/HomePage/HomePage.js:
--------------------------------------------------------------------------------
1 | import React, {useEffect} from 'react';
2 | import Slider from '../../components/Slider/Slider';
3 | import Category from '../../components/Category/Category';
4 | import ProductList from '../../components/ProductList/ProductList';
5 | import SingleCategory from '../../components/SingleCategory/SingleCategory';
6 | import { useSelector, useDispatch } from 'react-redux';
7 | import { fetchProducts } from '../../store/productSlice';
8 | import { fetchCategories, fetchProductsByCategory } from '../../store/categorySlice';
9 | import "./HomePage.scss";
10 |
11 | const HomePage = () => {
12 | const dispatch = useDispatch();
13 | const {data: categories, status: categoryStatus} = useSelector((state) => state.category);
14 | const {data: products, status: productStatus} = useSelector((state) => state.product);
15 | const {catProductAll: productsByCategory, catProductAllStatus} = useSelector((state) => state.category);
16 | useEffect(() => {
17 | dispatch(fetchProducts());
18 | dispatch(fetchCategories());
19 | dispatch(fetchProductsByCategory(1, 'all'));
20 | dispatch(fetchProductsByCategory(2, 'all'));
21 | // eslint-disable-next-line react-hooks/exhaustive-deps
22 | }, []);
23 |
24 | return (
25 |
26 |
27 |
28 |
29 |
30 | { productsByCategory[0] && }
31 |
32 |
33 | { productsByCategory[1] && }
34 |
35 |
36 | )
37 | }
38 |
39 | export default HomePage;
--------------------------------------------------------------------------------
/src/pages/HomePage/HomePage.scss:
--------------------------------------------------------------------------------
1 | .home-page{
2 | min-height: 60vh;
3 | }
--------------------------------------------------------------------------------
/src/pages/index.js:
--------------------------------------------------------------------------------
1 | import Home from "./HomePage/HomePage";
2 | import Category from "./CategoryPage/CategoryPage";
3 | import Cart from "./CartPage/CartPage";
4 |
5 | export {Home, Category, Cart};
--------------------------------------------------------------------------------
/src/store/cartSlice.js:
--------------------------------------------------------------------------------
1 | import { createSlice } from "@reduxjs/toolkit";
2 |
3 | const fetchFromLocalStorage = () => {
4 | let cart = localStorage.getItem('cart');
5 | if(cart){
6 | return JSON.parse(localStorage.getItem('cart'))
7 | } else {
8 | return [];
9 | }
10 | }
11 |
12 | const storeInLocalStorage = (data) => {
13 | localStorage.setItem('cart', JSON.stringify(data))
14 | }
15 |
16 | const cartSlice = createSlice({
17 | name: 'cart',
18 | initialState: {
19 | data: fetchFromLocalStorage(),
20 | totalItems: 0,
21 | totalAmount: 0,
22 | deliveryCharge: 1000
23 | },
24 | reducers: {
25 | addToCart(state, action){
26 | const tempItem = state.data.find(item => item.id === action.payload.id);
27 | if(tempItem){
28 | const tempCart = state.data.map(item => {
29 | if(item.id === action.payload.id){
30 | let newQty = item.quantity + action.payload.quantity;
31 | let newTotalPrice = newQty * item.price;
32 | return { ...item, quantity: newQty, totalPrice: newTotalPrice };
33 | } else {
34 | return item;
35 | }
36 | });
37 | state.data = tempCart;
38 | storeInLocalStorage(state.data);
39 | } else {
40 | state.data.push(action.payload);
41 | storeInLocalStorage(state.data);
42 | }
43 | },
44 | removeFromCart(state, action){
45 | const tempCart = state.data.filter(item => item.id !== action.payload);
46 | state.data = tempCart;
47 | storeInLocalStorage(state.data);
48 | },
49 | clearCart(state){
50 | state.data = [];
51 | storeInLocalStorage(state.data);
52 | },
53 | toggleCartQty(state, action){
54 | const tempCart = state.data.map(item => {
55 | if(item.id === action.payload.id){
56 | let tempQty = item.quantity;
57 | let tempTotalPrice = item.totalPrice;
58 | if(action.payload.type === "INC"){
59 | tempQty++;
60 | tempTotalPrice = tempQty * item.price;
61 | }
62 | if(action.payload.type === "DEC"){
63 | tempQty--;
64 | if(tempQty < 1) tempQty = 1;
65 | tempTotalPrice = tempQty * item.price;
66 | }
67 | return {...item, quantity: tempQty, totalPrice: tempTotalPrice};
68 | } else {
69 | return item;
70 | }
71 | });
72 | state.data = tempCart;
73 | storeInLocalStorage(state.data);
74 | },
75 | getCartTotal(state){
76 | state.totalAmount = state.data.reduce((cartTotal, cartItem) => {
77 | return cartTotal += cartItem.totalPrice;
78 | }, 0);
79 | state.totalItems = state.data.length;
80 | }
81 | }
82 | });
83 |
84 | export const {addToCart, removeFromCart, toggleCartQty, getCartTotal, clearCart} = cartSlice.actions;
85 | export default cartSlice.reducer;
--------------------------------------------------------------------------------
/src/store/categorySlice.js:
--------------------------------------------------------------------------------
1 | import { createSlice } from "@reduxjs/toolkit";
2 | import { BASE_URL } from "../utils/apiURL";
3 | import { STATUS } from "../utils/status";
4 |
5 | const categorySlice = createSlice({
6 | name: 'category',
7 | initialState: {
8 | data: [],
9 | status: STATUS.IDLE,
10 | catProductAll : [],
11 | catProductAllStatus: STATUS.IDLE,
12 | catProductSingle : [],
13 | catProductSingleStatus: STATUS.IDLE
14 | },
15 |
16 | reducers: {
17 | setCategories(state, action){
18 | state.data = action.payload;
19 | },
20 | setStatus(state, action){
21 | state.status = action.payload;
22 | },
23 | setCategoriesProductAll(state, action){
24 | state.catProductAll.push(action.payload);
25 | },
26 | setCategoriesStatusAll(state, action){
27 | state.catProductAllStatus = action.payload;
28 | },
29 | setCategoriesProductSingle(state, action){
30 | state.catProductSingle = action.payload;
31 | },
32 | setCategoriesStatusSingle(state, action){
33 | state.catProductSingleStatus = action.payload;
34 | }
35 | }
36 | });
37 |
38 | export const { setCategories, setStatus, setCategoriesProductAll, setCategoriesStatusAll, setCategoriesProductSingle, setCategoriesStatusSingle } = categorySlice.actions;
39 | export default categorySlice.reducer;
40 |
41 | export const fetchCategories = () => {
42 | return async function fetchCategoryThunk(dispatch){
43 | dispatch(setStatus(STATUS.LOADING));
44 | try{
45 | const response = await fetch(`${BASE_URL}categories`);
46 | const data = await response.json();
47 | dispatch(setCategories(data.slice(0, 5)));
48 | dispatch(setStatus(STATUS.IDLE));
49 | } catch(error){
50 | dispatch(setStatus(STATUS.ERROR));
51 | }
52 | }
53 | }
54 |
55 | export const fetchProductsByCategory = (categoryID, dataType) => {
56 | return async function fetchCategoryProductThunk(dispatch){
57 | if(dataType === 'all') dispatch(setCategoriesStatusAll(STATUS.LOADING));
58 | if(dataType === 'single') dispatch(setCategoriesStatusSingle(STATUS.LOADING));
59 |
60 | try{
61 | const response = await fetch(`${BASE_URL}categories/${categoryID}/products`);
62 | const data = await response.json();
63 | if(dataType === 'all'){
64 | dispatch(setCategoriesProductAll(data.slice(0, 10)));
65 | dispatch(setCategoriesStatusAll(STATUS.IDLE));
66 | }
67 | if(dataType === 'single'){
68 | dispatch(setCategoriesProductSingle(data.slice(0, 20)));
69 | dispatch(setCategoriesStatusSingle(STATUS.IDLE));
70 | }
71 | } catch(error){
72 | dispatch(setCategoriesStatusAll(STATUS.ERROR));
73 | }
74 | }
75 | }
--------------------------------------------------------------------------------
/src/store/modalSlice.js:
--------------------------------------------------------------------------------
1 | import { createSlice } from "@reduxjs/toolkit";
2 |
3 | const modalSlice = createSlice({
4 | name: "modal",
5 | initialState: {
6 | data: [],
7 | isModalVisible: false
8 | },
9 | reducers: {
10 | setModalData(state, action){
11 | state.data = action.payload;
12 | },
13 | setIsModalVisible(state, action){
14 | state.isModalVisible = action.payload;
15 | }
16 | }
17 | });
18 |
19 | export const { setModalData, setIsModalVisible} = modalSlice.actions;
20 | export default modalSlice.reducer;
21 |
22 |
--------------------------------------------------------------------------------
/src/store/productSlice.js:
--------------------------------------------------------------------------------
1 | import { createSlice } from "@reduxjs/toolkit";
2 | import { BASE_URL } from "../utils/apiURL";
3 | import { STATUS } from "../utils/status";
4 |
5 | const productSlice = createSlice({
6 | name: "product",
7 | initialState: {
8 | data: [],
9 | status: STATUS.IDLE,
10 | },
11 |
12 | reducers: {
13 | setProducts(state, action){
14 | state.data = action.payload;
15 | },
16 | setStatus(state, action){
17 | state.status = action.payload;
18 | },
19 | },
20 | });
21 |
22 | export const {setProducts, setStatus} = productSlice.actions;
23 | export default productSlice.reducer;
24 |
25 | export const fetchProducts = () => {
26 | return async function fetchProductThunk(dispatch){
27 | dispatch(setStatus(STATUS.LOADING));
28 | try{
29 | const response = await fetch(`${BASE_URL}products`);
30 | const data = await response.json();
31 | dispatch(setProducts(data));
32 | dispatch(setStatus(STATUS.IDLE));
33 | } catch(error){
34 | dispatch(setStatus(STATUS.ERROR));
35 | }
36 | }
37 | }
38 |
--------------------------------------------------------------------------------
/src/store/sidebarSlice.js:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/prabinmagar/shopping-hub-react-js-ecom-site-with-redux-toolkit/fb25ff545ff129171f01d3a60f4e8a3fa13d1d98/src/store/sidebarSlice.js
--------------------------------------------------------------------------------
/src/store/store.js:
--------------------------------------------------------------------------------
1 | import { configureStore } from "@reduxjs/toolkit";
2 | import productReducer from "./productSlice";
3 | import categoryReducer from "./categorySlice";
4 | import modalReducer from "./modalSlice";
5 | import cartReducer from "./cartSlice";
6 |
7 | const store = configureStore({
8 | reducer: {
9 | product: productReducer,
10 | category: categoryReducer,
11 | modal: modalReducer,
12 | cart: cartReducer
13 | }
14 | });
15 |
16 | export default store;
--------------------------------------------------------------------------------
/src/utils/apiURL.js:
--------------------------------------------------------------------------------
1 | export const BASE_URL = `https://api.escuelajs.co/api/v1/`;
--------------------------------------------------------------------------------
/src/utils/helpers.js:
--------------------------------------------------------------------------------
1 | export const formatPrice = (price) => {
2 | return new Intl.NumberFormat('en-US', {
3 | style: 'currency',
4 | currency: "USD"
5 | }).format(price / 100);
6 | }
--------------------------------------------------------------------------------
/src/utils/images.js:
--------------------------------------------------------------------------------
1 | import slider_img_1 from "../assets/images/slider-img-1.png";
2 | import slider_img_2 from "../assets/images/slider-img-2.png";
3 | import slider_img_3 from "../assets/images/slider-img-3.png";
4 | import spinner from "../assets/images/spinner.svg";
5 | import error from "../assets/images/error.png";
6 |
7 | const sliderImages = [slider_img_1, slider_img_2, slider_img_3];
8 | export {sliderImages, spinner, error};
--------------------------------------------------------------------------------
/src/utils/status.js:
--------------------------------------------------------------------------------
1 | export const STATUS = Object.freeze({
2 | IDLE: 'idle',
3 | ERROR: 'error',
4 | LOADING: 'loading',
5 | })
--------------------------------------------------------------------------------