├── src
├── App.scss
├── components
│ ├── SingleProduct
│ │ ├── RelatedProducts
│ │ │ ├── RelatedProducts.scss
│ │ │ └── RelatedProducts.jsx
│ │ ├── SingleProduct.jsx
│ │ └── SingleProduct.scss
│ ├── Home
│ │ ├── Home.scss
│ │ ├── Category
│ │ │ ├── Category.scss
│ │ │ └── Category.jsx
│ │ ├── Banner
│ │ │ ├── Banner.jsx
│ │ │ └── Banner.scss
│ │ └── Home.jsx
│ ├── Category
│ │ ├── Category.scss
│ │ └── Category.jsx
│ ├── Products
│ │ ├── Products.jsx
│ │ ├── Product
│ │ │ ├── Product.jsx
│ │ │ └── Product.scss
│ │ └── Products.scss
│ ├── Footer
│ │ ├── Newsletter
│ │ │ ├── Newsletter.jsx
│ │ │ └── Newsletter.scss
│ │ ├── Footer.scss
│ │ └── Footer.jsx
│ ├── header
│ │ ├── Header.jsx
│ │ └── Header.scss
│ ├── Cart
│ │ ├── CartItem
│ │ │ ├── CartItem.scss
│ │ │ └── CartItem.jsx
│ │ ├── Cart.jsx
│ │ └── Cart.scss
│ └── Header
│ │ └── Search
│ │ ├── Search.jsx
│ │ └── Search.scss
├── assets
│ ├── payments.png
│ ├── banner-img.png
│ └── newsletter-bg.jpeg
├── index.js
├── index.scss
├── hooks
│ └── useFetch.js
├── css-config
│ └── mixins.scss
├── utils
│ ├── api.js
│ └── context.js
└── App.js
├── public
├── favicon.ico
└── index.html
├── .gitignore
├── .env
├── package.json
└── README.md
/src/App.scss:
--------------------------------------------------------------------------------
1 |
2 |
--------------------------------------------------------------------------------
/src/components/SingleProduct/RelatedProducts/RelatedProducts.scss:
--------------------------------------------------------------------------------
1 |
--------------------------------------------------------------------------------
/public/favicon.ico:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/ShariqAnsari88/strapi-simple-one-client/HEAD/public/favicon.ico
--------------------------------------------------------------------------------
/src/assets/payments.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/ShariqAnsari88/strapi-simple-one-client/HEAD/src/assets/payments.png
--------------------------------------------------------------------------------
/src/assets/banner-img.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/ShariqAnsari88/strapi-simple-one-client/HEAD/src/assets/banner-img.png
--------------------------------------------------------------------------------
/src/assets/newsletter-bg.jpeg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/ShariqAnsari88/strapi-simple-one-client/HEAD/src/assets/newsletter-bg.jpeg
--------------------------------------------------------------------------------
/src/index.js:
--------------------------------------------------------------------------------
1 | import React from "react";
2 | import ReactDOM from "react-dom/client";
3 | import "./index.scss";
4 | import App from "./App";
5 |
6 | const root = ReactDOM.createRoot(document.getElementById("root"));
7 | root.render( );
8 |
--------------------------------------------------------------------------------
/src/components/Home/Home.scss:
--------------------------------------------------------------------------------
1 | @import "../../css-config/mixins.scss";
2 | .main-content {
3 | .layout {
4 | max-width: calc(100% - 20px);
5 | margin: 0 auto;
6 | @include md {
7 | max-width: 1200px;
8 | }
9 | }
10 | }
11 |
--------------------------------------------------------------------------------
/src/index.scss:
--------------------------------------------------------------------------------
1 | @import url("https://fonts.googleapis.com/css2?family=Cabin:wght@400;500;600;700&display=swap");
2 | * {
3 | margin: 0;
4 | padding: 0;
5 | box-sizing: border-box;
6 | font-family: "Cabin", sans-serif;
7 | }
8 | body {
9 | -webkit-font-smoothing: antialiased;
10 | -moz-osx-font-smoothing: grayscale;
11 | font-size: 16px;
12 | line-height: 22px;
13 | font-weight: 500;
14 | }
15 |
--------------------------------------------------------------------------------
/.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 |
25 | package-lock.json
26 |
--------------------------------------------------------------------------------
/src/hooks/useFetch.js:
--------------------------------------------------------------------------------
1 | import { useEffect, useState } from "react";
2 | import { fetchDataFromApi } from "../utils/api";
3 | const useFetch = (endpoint) => {
4 | const [data, setData] = useState();
5 |
6 | useEffect(() => {
7 | makeApiCall();
8 | }, [endpoint]);
9 |
10 | const makeApiCall = async () => {
11 | const res = await fetchDataFromApi(endpoint);
12 | setData(res);
13 | };
14 |
15 | return { data };
16 | };
17 | export default useFetch;
18 |
--------------------------------------------------------------------------------
/public/index.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
12 | JSDEV | STORE
13 |
14 |
15 |
16 |
17 |
18 |
--------------------------------------------------------------------------------
/src/css-config/mixins.scss:
--------------------------------------------------------------------------------
1 | @mixin sm {
2 | @media only screen and (min-width: 640px) {
3 | @content;
4 | }
5 | }
6 |
7 | @mixin md {
8 | @media only screen and (min-width: 768px) {
9 | @content;
10 | }
11 | }
12 |
13 | @mixin lg {
14 | @media only screen and (min-width: 1024px) {
15 | @content;
16 | }
17 | }
18 |
19 | @mixin xl {
20 | @media only screen and (min-width: 1280px) {
21 | @content;
22 | }
23 | }
24 |
25 | @mixin xxl {
26 | @media only screen and (min-width: 1536px) {
27 | @content;
28 | }
29 | }
30 |
--------------------------------------------------------------------------------
/src/components/Category/Category.scss:
--------------------------------------------------------------------------------
1 | @import "../../css-config/mixins.scss";
2 | .category-main-content {
3 | margin: 30px 0;
4 | @include md {
5 | margin: 75px 0;
6 | }
7 | .layout {
8 | max-width: calc(100% - 20px);
9 | margin: 0 auto;
10 | @include md {
11 | max-width: 1200px;
12 | }
13 | }
14 | .category-title {
15 | font-size: 24px;
16 | @include md {
17 | font-size: 34px;
18 | }
19 | }
20 | .products-container {
21 | margin: 20px 0;
22 | @include md {
23 | margin: 50px 0;
24 | }
25 | }
26 | }
27 |
--------------------------------------------------------------------------------
/src/components/SingleProduct/RelatedProducts/RelatedProducts.jsx:
--------------------------------------------------------------------------------
1 | import React from "react";
2 | import useFetch from "../../../hooks/useFetch";
3 | import Products from "../../Products/Products";
4 |
5 | const RelatedProducts = ({ categoryId, productId }) => {
6 | const { data } = useFetch(
7 | `/api/products?populate=*&filters[id][$ne]=${productId}&filters[categories][id]=${categoryId}&pagination[start]=0&pagination[limit]=4`
8 | );
9 |
10 | return (
11 |
14 | );
15 | };
16 |
17 | export default RelatedProducts;
18 |
--------------------------------------------------------------------------------
/src/components/Products/Products.jsx:
--------------------------------------------------------------------------------
1 | import "./Products.scss";
2 | import Product from "./Product/Product";
3 |
4 | const Products = ({ products, innerPage, headingText }) => {
5 | return (
6 |
7 | {!innerPage &&
{headingText}
}
8 |
9 | {products?.data?.map((item) => (
10 |
15 | ))}
16 |
17 |
18 | );
19 | };
20 |
21 | export default Products;
22 |
--------------------------------------------------------------------------------
/src/utils/api.js:
--------------------------------------------------------------------------------
1 | import axios from "axios";
2 |
3 | const params = {
4 | headers: {
5 | Authorization: "bearer " + process.env.REACT_APP_STRIPE_DEV_APP_KEY,
6 | },
7 | };
8 |
9 | export const fetchDataFromApi = async (url) => {
10 | try {
11 | const { data } = await axios.get(
12 | process.env.REACT_APP_STRIPE_APP_DEV_URL + url,
13 | params
14 | );
15 | return data;
16 | } catch (err) {
17 | console.log(err);
18 | return err;
19 | }
20 | };
21 |
22 | export const makePaymentRequest = axios.create({
23 | baseURL: process.env.REACT_APP_STRIPE_APP_DEV_URL,
24 | headers: {
25 | Authorization: "bearer " + process.env.REACT_APP_STRIPE_DEV_APP_KEY,
26 | },
27 | });
28 |
--------------------------------------------------------------------------------
/.env:
--------------------------------------------------------------------------------
1 | REACT_APP_STRIPE_DEV_APP_KEY=8ac76b5f08e1cd814b14ef20b1e803ceaa169511eaca96acc091ee756efa6c870fb7575dd255dd38b17c6b68074712d5e0b0a28fa36fe498192fb612411d585aeee726f2a137467bbc80157b233293aeecef5ca7c318e83da3d9fe7398ce68e30755990b0b40777364f88d2f5906812c74b988bec429fc742007dab46d2d7f8a
2 |
3 | REACT_APP_STRIPE_PROD_APP_KEY=027bb7c34b9a60c3c79ab8eada87aaed2f1e85de301b4c48167d1905b46d0f3197dfb7bbea315049dd451a24ae489843083825c2eb4f5ab328a9c82bdab3b8725ebaa182c1fdebfc1363b3243820395e17417e50536e6105bb152bc1fcb80e8e411adba6f6bd92f80c864207ab0cb6f6d2915659a69a5c8433ec3ba90898b43f
4 |
5 | REACT_APP_STRIPE_APP_DEV_URL=http://localhost:1337
6 | REACT_APP_STRIPE_APP_PROD_URL=https://strapi-simple-one-production.up.railway.app
7 |
8 | REACT_APP_STRIPE_PUBLISHABLE_KEY=pk_test_51MDp33SD8BxA31DW0RfZehhQP0BqgUiYliXnGZkE4jA4bUjtzwirmGhz7ngpp7RZLM3EHdpjX0UUKWNllRlPROC800l7vtgVb1
--------------------------------------------------------------------------------
/src/components/Home/Category/Category.scss:
--------------------------------------------------------------------------------
1 | @import "../../../css-config/mixins.scss";
2 | .shop-by-category {
3 | margin: 25px 0;
4 | @include md {
5 | margin: 50px 0;
6 | }
7 | .categories {
8 | display: flex;
9 | flex-flow: wrap;
10 | gap: 10px;
11 | .category {
12 | background-color: black;
13 | width: calc(50% - 5px);
14 | cursor: pointer;
15 | overflow: hidden;
16 | @include md {
17 | width: calc(25% - 10px);
18 | }
19 | img {
20 | width: 100%;
21 | display: block;
22 | transition: all ease 0.3s;
23 | }
24 | &:hover {
25 | img {
26 | transform: scale(1.2);
27 | }
28 | }
29 | }
30 | }
31 | }
32 |
--------------------------------------------------------------------------------
/src/components/Category/Category.jsx:
--------------------------------------------------------------------------------
1 | import { useParams } from "react-router-dom";
2 | import useFetch from "../../hooks/useFetch";
3 | import Products from "../Products/Products";
4 | import "./Category.scss";
5 | const Category = () => {
6 | const { id } = useParams();
7 | const { data } = useFetch(
8 | `/api/products?populate=*&[filters][categories][id]=${id}`
9 | );
10 | return (
11 |
12 |
13 |
14 | {
15 | data?.data?.[0]?.attributes?.categories?.data?.[0]
16 | ?.attributes?.title
17 | }
18 |
19 |
20 |
21 |
22 | );
23 | };
24 |
25 | export default Category;
26 |
--------------------------------------------------------------------------------
/src/components/Products/Product/Product.jsx:
--------------------------------------------------------------------------------
1 | import React from "react";
2 | import { useNavigate } from "react-router-dom";
3 | import "./Product.scss";
4 |
5 | const Product = ({ data, id }) => {
6 | const navigate = useNavigate();
7 | return (
8 | navigate("/product/" + id)}
11 | >
12 |
13 |
19 |
20 |
21 | {data.title}
22 | ₹{data.price}
23 |
24 |
25 | );
26 | };
27 |
28 | export default Product;
29 |
--------------------------------------------------------------------------------
/src/components/Products/Products.scss:
--------------------------------------------------------------------------------
1 | @import "../../css-config/mixins.scss";
2 | .products-container {
3 | margin: 50px 0;
4 | @include md {
5 | margin: 75px 0;
6 | }
7 | .sec-heading {
8 | margin-bottom: 20px;
9 | font-size: 18px;
10 | font-weight: 500;
11 | text-transform: uppercase;
12 | @include md {
13 | margin-bottom: 35px;
14 | font-size: 24px;
15 | }
16 | &:after {
17 | content: "";
18 | display: block;
19 | margin-top: 5px;
20 | width: 50px;
21 | height: 3px;
22 | background-color: #8e2de2;
23 | @include md {
24 | margin-top: 10px;
25 | }
26 | }
27 | }
28 | .products {
29 | display: flex;
30 | flex-flow: wrap;
31 | gap: 10px;
32 | @include md {
33 | gap: 20px;
34 | }
35 | }
36 | }
37 |
--------------------------------------------------------------------------------
/src/components/Home/Category/Category.jsx:
--------------------------------------------------------------------------------
1 | import { useNavigate } from "react-router-dom";
2 | import "./Category.scss";
3 |
4 | const Category = ({ categories }) => {
5 | const navigate = useNavigate();
6 | return (
7 |
8 |
9 | {categories?.data?.map((item) => (
10 |
navigate(`/category/${item.id}`)}
14 | >
15 |
21 |
22 | ))}
23 |
24 |
25 | );
26 | };
27 |
28 | export default Category;
29 |
--------------------------------------------------------------------------------
/src/components/Home/Banner/Banner.jsx:
--------------------------------------------------------------------------------
1 | import React from "react";
2 |
3 | import "./Banner.scss";
4 | import BannerImg from "../../../assets/banner-img.png";
5 |
6 | const Banner = () => {
7 | return (
8 |
9 |
10 |
11 |
SALES
12 |
13 | Convallis interdum purus adipiscing dis parturient
14 | posuere ac a quam a eleifend montes parturient posuere
15 | curae tempor
16 |
17 |
18 |
Read More
19 |
Shop Now
20 |
21 |
22 |
23 |
24 |
25 | );
26 | };
27 |
28 | export default Banner;
29 |
--------------------------------------------------------------------------------
/src/App.js:
--------------------------------------------------------------------------------
1 | import { BrowserRouter, Routes, Route } from "react-router-dom";
2 | import "./App.scss";
3 |
4 | import Header from "./components/Header/Header";
5 | import Footer from "./components/Footer/Footer";
6 | import Home from "./components/Home/Home";
7 | import Category from "./components/Category/Category";
8 | import SingleProduct from "./components/SingleProduct/SingleProduct";
9 | import Newsletter from "./components/Footer/Newsletter/Newsletter";
10 | import AppContext from "./utils/context";
11 |
12 | function App() {
13 | return (
14 |
15 |
16 |
17 |
18 | } />
19 | } />
20 | } />
21 |
22 |
23 |
24 |
25 |
26 | );
27 | }
28 |
29 | export default App;
30 |
--------------------------------------------------------------------------------
/package.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "client",
3 | "version": "0.1.0",
4 | "private": true,
5 | "dependencies": {
6 | "@emotion/react": "^11.10.5",
7 | "@emotion/styled": "^11.10.5",
8 | "@mui/material": "^5.10.17",
9 | "@stripe/react-stripe-js": "^1.16.1",
10 | "@stripe/stripe-js": "^1.46.0",
11 | "@testing-library/jest-dom": "^5.16.5",
12 | "@testing-library/react": "^13.4.0",
13 | "@testing-library/user-event": "^13.5.0",
14 | "axios": "^1.2.1",
15 | "react": "^18.2.0",
16 | "react-dom": "^18.2.0",
17 | "react-icons": "^4.7.1",
18 | "react-router-dom": "^6.4.5",
19 | "react-scripts": "5.0.1",
20 | "sass": "^1.56.2",
21 | "web-vitals": "^2.1.4"
22 | },
23 | "scripts": {
24 | "start": "react-scripts start",
25 | "build": "react-scripts build",
26 | "test": "react-scripts test",
27 | "eject": "react-scripts eject"
28 | },
29 | "eslintConfig": {
30 | "extends": [
31 | "react-app",
32 | "react-app/jest"
33 | ]
34 | },
35 | "browserslist": {
36 | "production": [
37 | ">0.2%",
38 | "not dead",
39 | "not op_mini all"
40 | ],
41 | "development": [
42 | "last 1 chrome version",
43 | "last 1 firefox version",
44 | "last 1 safari version"
45 | ]
46 | }
47 | }
48 |
--------------------------------------------------------------------------------
/src/components/Products/Product/Product.scss:
--------------------------------------------------------------------------------
1 | @import "../../../css-config/mixins.scss";
2 | .product-card {
3 | cursor: pointer;
4 | width: calc(50% - 5px);
5 | margin-bottom: 20px;
6 | @include md {
7 | width: calc(25% - 15px);
8 | }
9 | .thumbnail {
10 | width: 100%;
11 | height: 180px;
12 | background-color: rgba(0, 0, 0, 0.05);
13 | margin-bottom: 10px;
14 | padding: 25px;
15 | display: flex;
16 | align-items: center;
17 | @include md {
18 | height: 350px;
19 | }
20 | img {
21 | transition: all ease 0.3s;
22 | display: block;
23 | width: 100%;
24 | }
25 | }
26 | .prod-details {
27 | .name {
28 | font-size: 14px;
29 | display: block;
30 | text-overflow: ellipsis;
31 | white-space: nowrap;
32 | overflow: hidden;
33 | @include md {
34 | font-size: 16px;
35 | margin-bottom: 10px;
36 | }
37 | }
38 | .price {
39 | font-size: 18px;
40 | @include md {
41 | font-size: 24px;
42 | }
43 | }
44 | }
45 | &:hover {
46 | .thumbnail {
47 | img {
48 | transform: scale(1.2);
49 | }
50 | }
51 | }
52 | }
53 |
--------------------------------------------------------------------------------
/src/components/Home/Home.jsx:
--------------------------------------------------------------------------------
1 | import React, { useEffect, useContext } from "react";
2 | import "./Home.scss";
3 | import Banner from "./Banner/Banner";
4 | import Category from "./Category/Category";
5 | import Products from "../Products/Products";
6 | import { fetchDataFromApi } from "../../utils/api";
7 | import { Context } from "../../utils/context";
8 |
9 | const Home = () => {
10 | const { products, setProducts, categories, setCategories } =
11 | useContext(Context);
12 | useEffect(() => {
13 | getProducts();
14 | getCategories();
15 | }, []);
16 |
17 | const getProducts = () => {
18 | fetchDataFromApi("/api/products?populate=*").then((res) => {
19 | setProducts(res);
20 | });
21 | };
22 | const getCategories = () => {
23 | fetchDataFromApi("/api/categories?populate=*").then((res) => {
24 | setCategories(res);
25 | });
26 | };
27 |
28 | return (
29 |
41 | );
42 | };
43 |
44 | export default Home;
45 |
--------------------------------------------------------------------------------
/src/components/Footer/Newsletter/Newsletter.jsx:
--------------------------------------------------------------------------------
1 | import React from "react";
2 | import {
3 | FaFacebookF,
4 | FaTwitter,
5 | FaInstagram,
6 | FaLinkedinIn,
7 | } from "react-icons/fa";
8 | import "./Newsletter.scss";
9 | const Newsletter = () => {
10 | return (
11 |
12 |
13 |
Newsletter
14 |
15 | Sign up for latest updates and offers
16 |
17 |
18 |
19 | Subscribe
20 |
21 |
22 | Will be used in accordance with our Privacy Policy
23 |
24 |
25 |
26 |
27 |
28 |
29 |
30 |
31 |
32 |
33 |
34 |
35 |
36 |
37 |
38 |
39 |
40 | );
41 | };
42 |
43 | export default Newsletter;
44 |
--------------------------------------------------------------------------------
/src/components/Footer/Footer.scss:
--------------------------------------------------------------------------------
1 | @import "../../css-config/mixins.scss";
2 | .footer {
3 | width: 100%;
4 | .footer-content {
5 | padding: 50px 20px;
6 | max-width: 1200px;
7 | margin: 0 auto;
8 | display: flex;
9 | flex-flow: wrap;
10 | gap: 20px;
11 | @include md {
12 | justify-content: space-between;
13 | padding: 50px 0;
14 | }
15 | .col {
16 | max-width: 300px;
17 | &:nth-child(3) {
18 | width: 150px;
19 | @include md {
20 | width: auto;
21 | }
22 | }
23 | .title {
24 | margin-bottom: 20px;
25 | font-size: 20px;
26 | }
27 | .text {
28 | color: rgba(0, 0, 0, 0.5);
29 | font-size: 14px;
30 | }
31 | .c-item {
32 | display: flex;
33 | margin-bottom: 10px;
34 | svg {
35 | flex-shrink: 0;
36 | font-size: 14px;
37 | margin-right: 10px;
38 | margin-top: 4px;
39 | color: rgba(0, 0, 0, 0.5);
40 | }
41 | }
42 | span {
43 | &.text {
44 | display: block;
45 | margin-bottom: 10px;
46 | cursor: pointer;
47 | }
48 | }
49 | }
50 | }
51 | .bottom-bar {
52 | border-top: 1px solid rgba(0, 0, 0, 0.1);
53 | .bottom-bar-content {
54 | padding: 20px;
55 | display: flex;
56 | align-items: center;
57 | flex-direction: column;
58 | text-align: center;
59 | gap: 10px;
60 | @include md {
61 | padding: 0;
62 | height: 60px;
63 | max-width: 1200px;
64 | margin: 0 auto;
65 | flex-direction: row;
66 | justify-content: space-between;
67 | text-align: left;
68 | }
69 | .text {
70 | font-size: 12px;
71 | color: rgba(0, 0, 0, 0.5);
72 | }
73 | }
74 | }
75 | }
76 |
--------------------------------------------------------------------------------
/src/components/header/Header.jsx:
--------------------------------------------------------------------------------
1 | import { useEffect, useState, useContext } from "react";
2 | import { useNavigate } from "react-router-dom";
3 | import { TbSearch } from "react-icons/tb";
4 | import { CgShoppingCart } from "react-icons/cg";
5 | import { AiOutlineHeart } from "react-icons/ai";
6 | import "./Header.scss";
7 | import Search from "./Search/Search";
8 | import { Context } from "../../utils/context";
9 | import Cart from "../Cart/Cart";
10 |
11 | const Header = () => {
12 | const [scrolled, setScrolled] = useState(false);
13 | const [searchModal, setSearchModal] = useState(false);
14 | const navigate = useNavigate();
15 | const handleScroll = () => {
16 | const offset = window.scrollY;
17 | if (offset > 200) {
18 | setScrolled(true);
19 | } else {
20 | setScrolled(false);
21 | }
22 | };
23 |
24 | useEffect(() => {
25 | window.addEventListener("scroll", handleScroll);
26 | }, []);
27 |
28 | const { cartCount, showCart, setShowCart } = useContext(Context);
29 |
30 | return (
31 | <>
32 |
57 | {searchModal && }
58 | {showCart && }
59 | >
60 | );
61 | };
62 |
63 | export default Header;
64 |
--------------------------------------------------------------------------------
/src/components/Cart/CartItem/CartItem.scss:
--------------------------------------------------------------------------------
1 | .cart-products {
2 | flex-grow: 1;
3 | .search-result-item {
4 | padding: 20px 15px;
5 | display: flex;
6 | gap: 10px;
7 | .image-container {
8 | background-color: rgba(0, 0, 0, 0.05);
9 | width: 60px;
10 | height: 60px;
11 | flex-shrink: 0;
12 | img {
13 | width: 100%;
14 | height: 100%;
15 | }
16 | }
17 | .prod-details {
18 | overflow: hidden;
19 | position: relative;
20 | .name {
21 | text-overflow: ellipsis;
22 | white-space: nowrap;
23 | overflow: hidden;
24 | font-size: 16px;
25 | line-height: 1;
26 | margin-bottom: 10px;
27 | font-weight: 600;
28 | display: block;
29 | padding-right: 25px;
30 | }
31 | .text {
32 | display: flex;
33 | align-items: center;
34 | gap: 5px;
35 | font-size: 12px;
36 | font-weight: 600;
37 | .highlight {
38 | color: #8e2de2;
39 | }
40 | }
41 | svg {
42 | position: absolute;
43 | top: 0;
44 | right: 0;
45 | cursor: pointer;
46 | }
47 | .quantity-buttons {
48 | width: fit-content;
49 | display: flex;
50 | border: 1px solid rgba(0, 0, 0, 0.1);
51 | height: 30px;
52 | margin-bottom: 8px;
53 | span {
54 | font-size: 14px;
55 | width: 30px;
56 | display: flex;
57 | align-items: center;
58 | justify-content: center;
59 | cursor: pointer;
60 | color: #6b6b6b;
61 | &:nth-child(1) {
62 | font-size: 18px;
63 | border-right: 1px solid rgba(0, 0, 0, 0.1);
64 | }
65 | &:nth-child(2) {
66 | width: 40px;
67 | }
68 | &:nth-child(3) {
69 | font-size: 18px;
70 | border-left: 1px solid rgba(0, 0, 0, 0.1);
71 | }
72 | }
73 | }
74 | }
75 | &:hover {
76 | background-color: rgba(0, 0, 0, 0.05);
77 | }
78 | }
79 | }
80 |
--------------------------------------------------------------------------------
/src/components/Cart/CartItem/CartItem.jsx:
--------------------------------------------------------------------------------
1 | import React, { useContext } from "react";
2 | import { Context } from "../../../utils/context";
3 | import { MdClose } from "react-icons/md";
4 |
5 | import "./CartItem.scss";
6 | const CartItem = () => {
7 | const { cartItems, handleRemoveFromCart, handleCartProductQuantity } =
8 | useContext(Context);
9 |
10 | return (
11 |
12 | {cartItems?.map((item) => (
13 |
{}}
17 | >
18 |
19 |
25 |
26 |
27 |
{item.attributes.title}
28 |
handleRemoveFromCart(item)}
31 | />
32 |
33 |
35 | handleCartProductQuantity("dec", item)
36 | }
37 | >
38 | -
39 |
40 | {item.attributes.quantity}
41 |
43 | handleCartProductQuantity("inc", item)
44 | }
45 | >
46 | +
47 |
48 |
49 |
50 | {item.attributes.quantity}
51 | x
52 |
53 | ₹
54 | {item.attributes.price *
55 | item.attributes.quantity}
56 |
57 |
58 |
59 |
60 | ))}
61 |
62 | );
63 | };
64 |
65 | export default CartItem;
66 |
--------------------------------------------------------------------------------
/src/components/header/Header.scss:
--------------------------------------------------------------------------------
1 | @import "../../css-config/mixins.scss";
2 |
3 | .main-header {
4 | width: 100%;
5 | padding: 0 20px;
6 | z-index: 99;
7 | background-color: #212121;
8 | color: white;
9 | border-bottom: 1px solid;
10 | border-color: rgba(0, 0, 0, 0.1);
11 | @include md {
12 | padding: 0 40px;
13 | }
14 | .header-content {
15 | display: flex;
16 | justify-content: space-between;
17 | align-items: center;
18 | height: 50px;
19 | max-width: 1200px;
20 | margin: 0 auto;
21 | @include md {
22 | height: 80px;
23 | }
24 | }
25 | .left {
26 | list-style-type: none;
27 | display: none;
28 | gap: 25px;
29 | @include md {
30 | display: flex;
31 | }
32 | li {
33 | font-size: 14px;
34 | font-weight: 600;
35 | text-transform: uppercase;
36 | cursor: pointer;
37 | &:hover {
38 | opacity: 0.6;
39 | }
40 | }
41 | }
42 | .center {
43 | font-size: 22px;
44 | font-weight: 700;
45 | cursor: pointer;
46 | @include md {
47 | font-size: 34px;
48 | position: absolute;
49 | left: 50%;
50 | transform: translateX(-50%);
51 | }
52 | }
53 | .right {
54 | display: flex;
55 | align-items: center;
56 | gap: 20px;
57 | @include md {
58 | gap: 25px;
59 | }
60 | svg {
61 | font-size: 20px;
62 | cursor: pointer;
63 | @include md {
64 | font-size: 24px;
65 | }
66 | &:hover {
67 | opacity: 0.6;
68 | }
69 | }
70 | .cart-icon {
71 | position: relative;
72 | span {
73 | min-width: 20px;
74 | text-align: center;
75 | background: #8e2de2;
76 | padding: 2.5px;
77 | position: absolute;
78 | top: -5px;
79 | right: -12px;
80 | font-size: 12px;
81 | line-height: 1;
82 | border-radius: 10px;
83 | }
84 | }
85 | }
86 | &.sticky-header {
87 | background-color: #212121;
88 | color: white;
89 | position: sticky;
90 | top: 0;
91 | transform: translateY(-60px);
92 | animation: StickyHeader 0.3s ease forwards;
93 | }
94 | }
95 |
96 | @keyframes StickyHeader {
97 | 0% {
98 | transform: translateY(-60px);
99 | }
100 | 100% {
101 | transform: translateY(0);
102 | }
103 | }
104 |
--------------------------------------------------------------------------------
/src/components/Footer/Newsletter/Newsletter.scss:
--------------------------------------------------------------------------------
1 | @import "../../../css-config/mixins.scss";
2 | .newsletter-section {
3 | width: 100%;
4 | height: 400px;
5 | display: flex;
6 | align-items: center;
7 | background: #f9f9f9 url("../../../assets/newsletter-bg.jpeg");
8 | background-position: center;
9 | background-repeat: no-repeat;
10 | background-size: cover;
11 | .newsletter-content {
12 | width: fit-content;
13 | display: flex;
14 | flex-direction: column;
15 | align-items: center;
16 | margin: 0 auto;
17 | text-align: center;
18 | .text {
19 | margin-bottom: 20px;
20 | font-size: 14px;
21 | color: rgba(0, 0, 0, 0.5);
22 | }
23 | .small-text {
24 | margin-bottom: 15px;
25 | text-transform: uppercase;
26 | color: rgba(0, 0, 0, 0.5);
27 | }
28 | .big-text {
29 | margin-bottom: 20px;
30 | font-size: 22px;
31 | line-height: 30px;
32 | font-weight: 500;
33 | text-transform: uppercase;
34 | padding: 0 30px;
35 | @include md {
36 | font-size: 28px;
37 | }
38 | }
39 | .form {
40 | display: flex;
41 | gap: 5px;
42 | margin-bottom: 10px;
43 | input {
44 | width: 200px;
45 | height: 40px;
46 | border-radius: 0;
47 | border: 1px solid rgba(0, 0, 0, 0.2);
48 | padding: 0 12px;
49 | font-size: 16px;
50 | outline: none;
51 | @include md {
52 | width: 300px;
53 | }
54 | }
55 | button {
56 | outline: 0;
57 | border: 0;
58 | height: 40px;
59 | width: 100px;
60 | display: flex;
61 | align-items: center;
62 | justify-content: center;
63 | cursor: pointer;
64 | font-size: 16px;
65 | color: white;
66 | background: #8e2de2;
67 | border-bottom: 3px solid #6516aa;
68 | @include md {
69 | width: 120px;
70 | }
71 | }
72 | }
73 | .social-icons {
74 | display: flex;
75 | gap: 10px;
76 | .icon {
77 | width: 30px;
78 | height: 30px;
79 | background: rgba(0, 0, 0, 0.8);
80 | border-radius: 50%;
81 | display: flex;
82 | align-items: center;
83 | justify-content: center;
84 | color: white;
85 | }
86 | }
87 | }
88 | }
89 |
--------------------------------------------------------------------------------
/src/utils/context.js:
--------------------------------------------------------------------------------
1 | import { useEffect } from "react";
2 | import { createContext, useState } from "react";
3 | import { useLocation } from "react-router-dom";
4 |
5 | export const Context = createContext();
6 |
7 | const AppContext = ({ children }) => {
8 | const [categories, setCategories] = useState();
9 | const [products, setProducts] = useState();
10 | const [showCart, setShowCart] = useState(false);
11 | const [cartItems, setCartItems] = useState([]);
12 | const [cartCount, setCartCount] = useState(0);
13 | const [cartSubTotal, setCartSubTotal] = useState(0);
14 | const location = useLocation();
15 |
16 | useEffect(() => {
17 | window.scrollTo(0, 0);
18 | }, [location]);
19 |
20 | useEffect(() => {
21 | let count = 0;
22 | cartItems?.map((item) => (count += item.attributes.quantity));
23 | setCartCount(count);
24 |
25 | let subTotal = 0;
26 | cartItems.map(
27 | (item) =>
28 | (subTotal += item.attributes.price * item.attributes.quantity)
29 | );
30 | setCartSubTotal(subTotal);
31 | }, [cartItems]);
32 |
33 | const handleAddToCart = (product, quantity) => {
34 | let items = [...cartItems];
35 | let index = items?.findIndex((p) => p.id === product?.id);
36 | if (index !== -1) {
37 | items[index].attributes.quantity += quantity;
38 | } else {
39 | product.attributes.quantity = quantity;
40 | items = [...items, product];
41 | }
42 | setCartItems(items);
43 | };
44 |
45 | const handleRemoveFromCart = (product) => {
46 | let items = [...cartItems];
47 | items = items?.filter((p) => p.id !== product?.id);
48 | setCartItems(items);
49 | };
50 |
51 | const handleCartProductQuantity = (type, product) => {
52 | let items = [...cartItems];
53 | let index = items?.findIndex((p) => p.id === product?.id);
54 | if (type === "inc") {
55 | items[index].attributes.quantity += 1;
56 | } else if (type === "dec") {
57 | if (items[index].attributes.quantity === 1) return;
58 | items[index].attributes.quantity -= 1;
59 | }
60 | setCartItems(items);
61 | };
62 |
63 | return (
64 |
81 | {children}
82 |
83 | );
84 | };
85 |
86 | export default AppContext;
87 |
--------------------------------------------------------------------------------
/src/components/Header/Search/Search.jsx:
--------------------------------------------------------------------------------
1 | import React, { useState } from "react";
2 | import { MdClose } from "react-icons/md";
3 | import "./Search.scss";
4 | import useFetch from "../../../hooks/useFetch";
5 | import { useNavigate } from "react-router-dom";
6 |
7 | const Search = ({ setSearchModal }) => {
8 | const [query, setQuery] = useState("");
9 | const navigate = useNavigate();
10 |
11 | const onChange = (e) => {
12 | setQuery(e.target.value);
13 | };
14 |
15 | let { data } = useFetch(
16 | `/api/products?populate=*&filters[title][$contains]=${query}`
17 | );
18 |
19 | if (!query.length) {
20 | data = null;
21 | }
22 |
23 | return (
24 |
25 |
26 |
33 | setSearchModal(false)}
36 | />
37 |
38 |
39 | {!data?.data?.length && (
40 |
41 | Start typing to see products you are looking for.
42 |
43 | )}
44 |
45 | {data?.data?.map((item) => (
46 |
{
50 | navigate("/product/" + item.id);
51 | setSearchModal(false);
52 | }}
53 | >
54 |
55 |
63 |
64 |
65 |
66 | {item.attributes.title}
67 |
68 |
69 | {item.attributes.description}
70 |
71 |
72 |
73 | ))}
74 |
75 |
76 |
77 | );
78 | };
79 |
80 | export default Search;
81 |
--------------------------------------------------------------------------------
/src/components/Footer/Footer.jsx:
--------------------------------------------------------------------------------
1 | import React from "react";
2 | import "./Footer.scss";
3 | import { FaLocationArrow, FaMobileAlt, FaEnvelope } from "react-icons/fa";
4 | import Payment from "../../assets/payments.png";
5 | const Footer = () => {
6 | return (
7 |
8 |
9 |
10 |
About
11 |
12 | Voluptatem accusantium doloremque laudantium, totam rem
13 | aperiam, eaque ipsa quae ab illo inventore veritatis et
14 | quasi architecto beatae vitae dicta sunt explicabo eaque
15 | ipsa quae ab illo.
16 |
17 |
18 |
19 |
Contact
20 |
21 |
22 |
23 | Kayaloram Rd, Punnamada, Kottankulangara, Alappuzha,
24 | Kerala, 688006
25 |
26 |
27 |
28 |
29 |
Phone: 0471 272 0261
30 |
31 |
32 |
33 |
Email: store@jsdev.com
34 |
35 |
36 |
37 |
Categories
38 |
Headphones
39 |
Smart Watches
40 |
Bluetooth Speakers
41 |
Wireless Earbuds
42 |
Home Theatre
43 |
Projectors
44 |
45 |
46 |
Pages
47 |
Home
48 |
About
49 |
Privacy Policy
50 |
Returns
51 |
Terms & Conditions
52 |
Contact Us
53 |
54 |
55 |
56 |
57 |
58 | JSDEVSTORE 2022 CREATED BY JS DEV. PREMIUM E-COMMERCE
59 | SOLUTIONS.
60 |
61 |
62 |
63 |
64 |
65 | );
66 | };
67 |
68 | export default Footer;
69 |
--------------------------------------------------------------------------------
/src/components/Cart/Cart.jsx:
--------------------------------------------------------------------------------
1 | import React, { useContext } from "react";
2 | import { MdClose } from "react-icons/md";
3 | import { BsCartX } from "react-icons/bs";
4 | import { Context } from "../../utils/context";
5 | import CartItem from "./CartItem/CartItem";
6 | import { loadStripe } from "@stripe/stripe-js";
7 | import { makePaymentRequest } from "../../utils/api";
8 |
9 | import "./Cart.scss";
10 |
11 | const Cart = () => {
12 | const { cartItems, setShowCart, cartSubTotal } = useContext(Context);
13 |
14 | const stripePromise = loadStripe(
15 | process.env.REACT_APP_STRIPE_PUBLISHABLE_KEY
16 | );
17 |
18 | const handlePayment = async () => {
19 | try {
20 | const stripe = await stripePromise;
21 | const res = await makePaymentRequest.post("/api/orders", {
22 | products: cartItems,
23 | });
24 | await stripe.redirectToCheckout({
25 | sessionId: res.data.stripeSession.id,
26 | });
27 | } catch (err) {
28 | console.log(err);
29 | }
30 | };
31 |
32 | return (
33 |
34 |
setShowCart(false)}
37 | >
38 |
39 |
40 | Shopping Cart
41 | setShowCart(false)}
44 | >
45 |
46 | close
47 |
48 |
49 |
50 | {!cartItems.length && (
51 |
52 |
53 | No products in the cart.
54 | {}}>
55 | RETURN TO SHOP
56 |
57 |
58 | )}
59 |
60 | {!!cartItems.length && (
61 | <>
62 |
63 |
64 |
65 | Subtotal:
66 |
67 | ₹{cartSubTotal}
68 |
69 |
70 |
71 |
75 | Checkout
76 |
77 |
78 |
79 | >
80 | )}
81 |
82 |
83 | );
84 | };
85 |
86 | export default Cart;
87 |
--------------------------------------------------------------------------------
/src/components/Home/Banner/Banner.scss:
--------------------------------------------------------------------------------
1 | @import "../../../css-config/mixins.scss";
2 | .hero-banner {
3 | padding: 40px 0;
4 | position: relative;
5 | background-image: linear-gradient(to right, #8e2de2, #4a00e0);
6 | @include md {
7 | height: calc(100vh - 80px);
8 | }
9 | .content {
10 | height: 100%;
11 | display: flex;
12 | justify-content: flex-end;
13 | align-items: center;
14 | flex-direction: column-reverse;
15 | max-width: calc(100% - 20px);
16 | margin: 0 auto;
17 | position: relative;
18 | @include md {
19 | flex-direction: row;
20 | max-width: 1200px;
21 | }
22 | .banner-img {
23 | position: relative;
24 | z-index: 9;
25 | width: 200px;
26 | margin-bottom: 20px;
27 | @include md {
28 | width: 500px;
29 | margin-right: 60px;
30 | margin-top: 50px;
31 | margin-bottom: 0;
32 | }
33 | @include xxl {
34 | width: 600px;
35 | margin-right: 0;
36 | margin-top: 0;
37 | }
38 | }
39 | .text-content {
40 | color: white;
41 | text-align: center;
42 | display: flex;
43 | flex-direction: column;
44 | align-items: center;
45 | @include md {
46 | position: absolute;
47 | left: 50px;
48 | top: 50%;
49 | transform: translateY(-50%);
50 | }
51 | @include xxl {
52 | left: 0;
53 | }
54 | h1 {
55 | font-size: 80px;
56 | font-weight: 700;
57 | line-height: 1;
58 | color: white;
59 | margin-bottom: 20px;
60 | @include md {
61 | font-size: 180px;
62 | }
63 | }
64 | p {
65 | max-width: 300px;
66 | font-size: 14px;
67 | line-height: 20px;
68 | margin-bottom: 20px;
69 | @include md {
70 | max-width: 500px;
71 | font-size: 18px;
72 | line-height: 24px;
73 | margin-bottom: 40px;
74 | }
75 | }
76 | .ctas {
77 | display: flex;
78 | justify-content: center;
79 | gap: 20px;
80 | .banner-cta {
81 | text-transform: uppercase;
82 | font-size: 13px;
83 | font-weight: 500;
84 | width: fit-content;
85 | border: 2px solid white;
86 | padding: 10px 20px;
87 | transition: all ease 0.3s;
88 | cursor: pointer;
89 | &.v2 {
90 | background-color: white;
91 | color: black;
92 | }
93 | &:hover {
94 | opacity: 0.6;
95 | }
96 | }
97 | }
98 | }
99 | }
100 | }
101 |
--------------------------------------------------------------------------------
/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 |
--------------------------------------------------------------------------------
/src/components/Header/Search/Search.scss:
--------------------------------------------------------------------------------
1 | @import "../../../css-config/mixins.scss";
2 | .search-modal {
3 | position: fixed;
4 | width: 100%;
5 | height: 100%;
6 | z-index: 999;
7 | top: 0;
8 | left: 0;
9 | background-color: white;
10 | transform: translateY(100%);
11 | animation: slideSearchWindow 0.5s ease forwards;
12 | .form-field {
13 | width: 100%;
14 | display: flex;
15 | justify-content: center;
16 | padding: 10px 50px;
17 | border-bottom: 1px solid rgba(0, 0, 0, 0.1);
18 | position: relative;
19 | @include md {
20 | padding: 20px 0;
21 | }
22 | input {
23 | width: 100%;
24 | max-width: 1200px;
25 | height: 50px;
26 | text-align: center;
27 | font-size: 20px;
28 | font-weight: 600;
29 | color: #212121;
30 | outline: none;
31 | border: none;
32 | text-transform: uppercase;
33 | @include md {
34 | height: 80px;
35 | font-size: 48px;
36 | }
37 | &::placeholder {
38 | color: #212121;
39 | }
40 | }
41 | .close-btn {
42 | position: absolute;
43 | font-size: 25px;
44 | right: 20px;
45 | top: 50%;
46 | transform: translateY(-50%);
47 | cursor: pointer;
48 | @include md {
49 | right: 40px;
50 | font-size: 50px;
51 | }
52 | }
53 | }
54 | .search-result-content {
55 | max-width: calc(100% - 20px);
56 | margin: 0 auto;
57 | @include md {
58 | max-width: 800px;
59 | }
60 | .start-msg {
61 | text-align: center;
62 | margin-top: 20px;
63 | color: rgba(0, 0, 0, 0.5);
64 | }
65 | .search-results {
66 | height: calc(100vh - 110px);
67 | overflow: auto;
68 | margin: 20px 0;
69 | @include md {
70 | height: calc(100vh - 160px);
71 | }
72 | .search-result-item {
73 | display: flex;
74 | align-items: center;
75 | gap: 10px;
76 | padding: 10px 0;
77 | border-bottom: 1px solid rgba(0, 0, 0, 0.1);
78 | cursor: pointer;
79 | .image-container {
80 | background-color: rgba(0, 0, 0, 0.05);
81 | width: 60px;
82 | height: 60px;
83 | flex-shrink: 0;
84 | img {
85 | width: 100%;
86 | height: 100%;
87 | }
88 | }
89 | .prod-details {
90 | overflow: hidden;
91 | .name {
92 | text-overflow: ellipsis;
93 | white-space: nowrap;
94 | overflow: hidden;
95 | font-size: 16px;
96 | line-height: 1;
97 | margin-bottom: 10px;
98 | font-weight: 600;
99 | display: block;
100 | }
101 | .desc {
102 | font-size: 14px;
103 | line-height: 1;
104 | display: block;
105 | text-overflow: ellipsis;
106 | white-space: nowrap;
107 | overflow: hidden;
108 | color: rgba(0, 0, 0, 0.5);
109 | }
110 | }
111 | }
112 | }
113 | }
114 | }
115 |
116 | @keyframes slideSearchWindow {
117 | 0% {
118 | transform: translateY(100%);
119 | }
120 | 100% {
121 | transform: translateY(0);
122 | }
123 | }
124 |
--------------------------------------------------------------------------------
/src/components/SingleProduct/SingleProduct.jsx:
--------------------------------------------------------------------------------
1 | import { useContext, useState } from "react";
2 | import { Context } from "../../utils/context";
3 | import { useParams } from "react-router-dom";
4 | import useFetch from "../../hooks/useFetch";
5 | import RelatedProducts from "./RelatedProducts/RelatedProducts";
6 | import {
7 | FaFacebookF,
8 | FaTwitter,
9 | FaInstagram,
10 | FaLinkedinIn,
11 | FaPinterest,
12 | FaCartPlus,
13 | } from "react-icons/fa";
14 | import "./SingleProduct.scss";
15 |
16 | const SingleProduct = () => {
17 | const [quantity, setQuantity] = useState(1);
18 | const { id } = useParams();
19 | const { handleAddToCart } = useContext(Context);
20 | const { data } = useFetch(`/api/products?populate=*&[filters][id]=${id}`);
21 |
22 | const decrement = () => {
23 | setQuantity((prevState) => {
24 | if (prevState === 1) return 1;
25 | return prevState - 1;
26 | });
27 | };
28 | const increment = () => {
29 | setQuantity((prevState) => prevState + 1);
30 | };
31 |
32 | if (!data) return;
33 | const product = data?.data?.[0]?.attributes;
34 |
35 | return (
36 |
37 |
38 |
39 |
40 |
46 |
47 |
48 |
{product.title}
49 |
₹{product.price}
50 |
{product.description}
51 |
52 |
53 |
54 | -
55 | {quantity}
56 | +
57 |
58 |
{
61 | handleAddToCart(data?.data?.[0], quantity);
62 | setQuantity(1);
63 | }}
64 | >
65 |
66 | ADD TO CART
67 |
68 |
69 |
70 |
71 |
72 |
73 | Category:{" "}
74 |
75 | {
76 | product.categories.data[0].attributes
77 | .title
78 | }
79 |
80 |
81 |
82 | Share:
83 |
84 |
85 |
86 |
87 |
88 |
89 |
90 |
91 |
92 |
93 |
94 |
98 |
99 |
100 | );
101 | };
102 |
103 | export default SingleProduct;
104 |
--------------------------------------------------------------------------------
/src/components/Cart/Cart.scss:
--------------------------------------------------------------------------------
1 | @import "../../css-config/mixins.scss";
2 | .cart-panel {
3 | position: fixed;
4 | top: 0;
5 | left: 0;
6 | width: 100%;
7 | height: 100%;
8 | z-index: 99;
9 | display: flex;
10 | justify-content: flex-end;
11 |
12 | .opac-layer {
13 | background: rgba(0, 0, 0, 0.5);
14 | position: absolute;
15 | top: 0;
16 | left: 0;
17 | width: 100%;
18 | height: 100%;
19 | }
20 | .cart-content {
21 | width: 100%;
22 | height: 100%;
23 | background: white;
24 | position: relative;
25 | z-index: 1;
26 | display: flex;
27 | flex-direction: column;
28 | transform: translateX(100%);
29 | animation: slideCartWindow 0.3s ease forwards;
30 | @include md {
31 | width: 340px;
32 | }
33 | .cart-header {
34 | display: flex;
35 | align-items: center;
36 | justify-content: flex-end;
37 | padding: 20px 15px;
38 | border-bottom: 1px solid rgba(0, 0, 0, 0.1);
39 | .heading {
40 | flex-grow: 1;
41 | margin-bottom: 0;
42 | font-size: 20px;
43 | font-weight: 700;
44 | text-transform: uppercase;
45 | }
46 | .close-btn {
47 | display: flex;
48 | align-items: center;
49 | gap: 5px;
50 | cursor: pointer;
51 | svg {
52 | font-size: 18px;
53 | }
54 | .text {
55 | text-transform: uppercase;
56 | font-size: 14px;
57 | }
58 | &:hover {
59 | opacity: 0.5;
60 | }
61 | }
62 | }
63 |
64 | .empty-cart {
65 | display: flex;
66 | flex-direction: column;
67 | align-items: center;
68 | gap: 20px;
69 | margin-top: 100px;
70 | svg {
71 | font-size: 120px;
72 | opacity: 0.1;
73 | }
74 | span {
75 | }
76 | .return-cta {
77 | outline: 0;
78 | border: 0;
79 | height: 40px;
80 | width: 150px;
81 | display: flex;
82 | align-items: center;
83 | justify-content: center;
84 | cursor: pointer;
85 | font-size: 13px;
86 | color: white;
87 | background: #8e2de2;
88 | border-bottom: 3px solid #6516aa;
89 | svg {
90 | margin-right: 10px;
91 | }
92 | }
93 | }
94 |
95 | .cart-footer {
96 | border-top: 1px solid rgba(0, 0, 0, 0.1);
97 | .subtotal {
98 | padding: 20px 15px;
99 | border-bottom: 1px solid rgba(0, 0, 0, 0.1);
100 | display: flex;
101 | justify-content: space-between;
102 | .text {
103 | margin-bottom: 0;
104 | font-size: 20px;
105 | font-weight: 700;
106 | text-transform: uppercase;
107 | &.total {
108 | color: #8e2de2;
109 | }
110 | }
111 | }
112 | .button {
113 | padding: 20px 15px;
114 | .checkout-cta {
115 | outline: 0;
116 | border: 0;
117 | height: 50px;
118 | width: 100%;
119 | display: flex;
120 | align-items: center;
121 | justify-content: center;
122 | cursor: pointer;
123 | font-size: 16px;
124 | color: white;
125 | background: #8e2de2;
126 | border-bottom: 3px solid #6516aa;
127 | text-transform: uppercase;
128 | svg {
129 | margin-right: 10px;
130 | }
131 | }
132 | }
133 | }
134 | }
135 | }
136 |
137 | @keyframes slideCartWindow {
138 | 0% {
139 | transform: translateX(100%);
140 | }
141 | 100% {
142 | transform: translateX(0);
143 | }
144 | }
145 |
--------------------------------------------------------------------------------
/src/components/SingleProduct/SingleProduct.scss:
--------------------------------------------------------------------------------
1 | @import "../../css-config/mixins.scss";
2 | .single-product-main-content {
3 | margin: 20px 0;
4 | @include md {
5 | margin: 75px 0;
6 | }
7 | .layout {
8 | max-width: calc(100% - 20px);
9 | margin: 0 auto;
10 | @include md {
11 | max-width: 1200px;
12 | }
13 | .single-product-page {
14 | display: flex;
15 | flex-direction: column;
16 | @include md {
17 | flex-direction: row;
18 | }
19 | .left {
20 | width: 100%;
21 | background-color: rgba(0, 0, 0, 0.05);
22 | flex-shrink: 0;
23 | @include md {
24 | width: 600px;
25 | height: 600px;
26 | }
27 | img {
28 | width: 100%;
29 | display: block;
30 | }
31 | }
32 | .right {
33 | display: flex;
34 | flex-direction: column;
35 | padding-top: 20px;
36 | @include md {
37 | padding: 0 35px;
38 | }
39 | .name {
40 | font-size: 20px;
41 | line-height: 28px;
42 | margin-bottom: 20px;
43 | @include md {
44 | font-size: 24px;
45 | line-height: 32px;
46 | }
47 | }
48 | .price {
49 | font-size: 24px;
50 | line-height: 32px;
51 | margin-bottom: 20px;
52 | }
53 | .desc {
54 | font-size: 14px;
55 | line-height: 20px;
56 | margin-bottom: 20px;
57 | color: #6b6b6b;
58 | @include md {
59 | font-size: 16px;
60 | line-height: 24px;
61 | margin-bottom: 20px;
62 | }
63 | }
64 |
65 | .cart-buttons {
66 | display: flex;
67 | @include md {
68 | margin-top: 30px;
69 | }
70 | .quantity-buttons {
71 | width: fit-content;
72 | display: flex;
73 | border: 2px solid rgba(0, 0, 0, 0.2);
74 | margin-right: 10px;
75 | height: 50px;
76 | span {
77 | font-size: 18px;
78 | width: 40px;
79 | display: flex;
80 | align-items: center;
81 | justify-content: center;
82 | cursor: pointer;
83 | color: #6b6b6b;
84 | &:nth-child(1) {
85 | border-right: 2px solid rgba(0, 0, 0, 0.2);
86 | }
87 | &:nth-child(2) {
88 | width: 60px;
89 | }
90 | &:nth-child(3) {
91 | border-left: 2px solid rgba(0, 0, 0, 0.2);
92 | }
93 | }
94 | }
95 | .add-to-cart-button {
96 | outline: 0;
97 | border: 0;
98 | height: 50px;
99 | width: 180px;
100 | display: flex;
101 | align-items: center;
102 | justify-content: center;
103 | cursor: pointer;
104 | font-size: 16px;
105 | color: white;
106 | background: #8e2de2;
107 | border-bottom: 3px solid #6516aa;
108 | flex-grow: 1;
109 | @include md {
110 | flex-grow: unset;
111 | }
112 | svg {
113 | margin-right: 10px;
114 | }
115 | }
116 | }
117 |
118 | .divider {
119 | margin: 20px 0;
120 | height: 1px;
121 | width: 100%;
122 | background-color: rgba(0, 0, 0, 0.1);
123 | }
124 |
125 | .info-item {
126 | .text-bold {
127 | font-size: 18px;
128 | font-weight: 500;
129 | display: block;
130 | &:nth-child(1) {
131 | margin-bottom: 20px;
132 | }
133 | span {
134 | font-size: 16px;
135 | font-weight: 400;
136 | cursor: pointer;
137 | color: #6b6b6b;
138 | }
139 | svg {
140 | margin: 0 5px;
141 | }
142 | }
143 | }
144 | }
145 | }
146 | }
147 | }
148 |
--------------------------------------------------------------------------------