├── my-app ├── src │ ├── components │ │ ├── Admin │ │ │ ├── UpdateOrder.js │ │ │ ├── createproduct.css │ │ │ ├── Dashboard.js │ │ │ ├── UsersList.js │ │ │ ├── AdminSideBar.js │ │ │ ├── OrderList.js │ │ │ ├── ProductList.js │ │ │ └── MainData.js │ │ ├── Products │ │ │ ├── products.css │ │ │ ├── NoProduct.js │ │ │ └── Product.js │ │ ├── layout │ │ │ ├── categories │ │ │ │ ├── category.css │ │ │ │ ├── Category.js │ │ │ │ └── category.json │ │ │ ├── Header │ │ │ │ ├── header.css │ │ │ │ ├── SearchBar.js │ │ │ │ ├── Secondarydropdown.js │ │ │ │ ├── Primarydropdown.js │ │ │ │ └── Header.js │ │ │ ├── MetaData.js │ │ │ ├── Loader │ │ │ │ └── Loader.js │ │ │ └── footer │ │ │ │ ├── Footer.js │ │ │ │ └── footer.json │ │ ├── cart │ │ │ ├── EmptyCart.js │ │ │ ├── Cart.js │ │ │ └── CartItem.js │ │ ├── home │ │ │ ├── Bannerslider │ │ │ │ ├── carousel.css │ │ │ │ └── BannerSlider.js │ │ │ ├── Home.js │ │ │ ├── productslider │ │ │ │ ├── Product.js │ │ │ │ └── Productslider.js │ │ │ └── dealcontainer │ │ │ │ ├── TopProducts.js │ │ │ │ └── dealcontainer.js │ │ ├── productdetials │ │ │ └── Modal.js │ │ ├── orders │ │ │ ├── Order.js │ │ │ ├── PaymentSucess.js │ │ │ ├── OrderSidebar.js │ │ │ ├── Orders.js │ │ │ └── CheckoutItem.js │ │ ├── Wishlist │ │ │ ├── Wishitem.js │ │ │ └── Wishlist.js │ │ ├── Invoice │ │ │ ├── Invoice.js │ │ │ └── InvoiceContent.js │ │ └── User │ │ │ ├── Account.js │ │ │ ├── Sidebar.js │ │ │ ├── Login.js │ │ │ └── Register.js │ ├── man.gif │ ├── assets │ │ ├── banner2.png │ │ ├── banner3.png │ │ ├── banner4.png │ │ ├── bannner.jpg │ │ ├── dslr.webp │ │ ├── empty.webp │ │ ├── banner1.webp │ │ ├── emptywish.png │ │ ├── register.png │ │ ├── register.webp │ │ └── no-products.png │ ├── constants │ │ ├── WishlistConstants.js │ │ ├── CartConstants.js │ │ ├── UserConstants.js │ │ ├── OrderConstants.js │ │ └── ProductConstants.js │ ├── setupTests.js │ ├── Axios.js │ ├── actions │ │ ├── WishActions.js │ │ ├── CartActions.js │ │ ├── UserActions.js │ │ ├── OrderActions.js │ │ └── ProductActions.js │ ├── utils │ │ └── CategorySearch.js │ ├── reportWebVitals.js │ ├── index.css │ ├── Routes │ │ └── ProtectedRoutes.js │ ├── Reducers │ │ ├── WishReducer.js │ │ ├── CartReducer.js │ │ ├── UserReducer.js │ │ ├── OrderReducer.js │ │ └── ProductReducer.js │ ├── index.js │ ├── Store.js │ └── App.js ├── public │ ├── robots.txt │ ├── favicon.ico │ ├── logo192.png │ ├── logo512.png │ ├── manifest.json │ └── index.html ├── tailwind.config.js ├── .gitignore ├── package.json └── README.md ├── server ├── .gitignore ├── middleware │ ├── aysnchandler.js │ ├── error.js │ └── auth.js ├── vercel.json ├── utils │ ├── errorhandler.js │ ├── jsonwebtoken.js │ ├── apifeatures.js │ └── sendEmails.js ├── config │ ├── redis.js │ ├── example.env │ └── database.js ├── routes │ ├── paymentroute.js │ ├── orderroutes.js │ ├── userroutes.js │ └── productroutes.js ├── models │ ├── usermodel.js │ ├── ProductModel.js │ └── ordermodel.js ├── controllers │ ├── paymentcontroller.js │ ├── ordercontroller.js │ ├── usercontroller.js │ └── productcontroller.js ├── app.js └── package.json └── README.md /my-app/src/components/Admin/UpdateOrder.js: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /server/.gitignore: -------------------------------------------------------------------------------- 1 | /node_modules 2 | /config/app.env -------------------------------------------------------------------------------- /my-app/public/robots.txt: -------------------------------------------------------------------------------- 1 | # https://www.robotstxt.org/robotstxt.html 2 | User-agent: * 3 | Disallow: 4 | -------------------------------------------------------------------------------- /my-app/src/man.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/maheshpatil132/flipkart-clone/HEAD/my-app/src/man.gif -------------------------------------------------------------------------------- /my-app/public/favicon.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/maheshpatil132/flipkart-clone/HEAD/my-app/public/favicon.ico -------------------------------------------------------------------------------- /my-app/public/logo192.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/maheshpatil132/flipkart-clone/HEAD/my-app/public/logo192.png -------------------------------------------------------------------------------- /my-app/public/logo512.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/maheshpatil132/flipkart-clone/HEAD/my-app/public/logo512.png -------------------------------------------------------------------------------- /my-app/src/assets/banner2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/maheshpatil132/flipkart-clone/HEAD/my-app/src/assets/banner2.png -------------------------------------------------------------------------------- /my-app/src/assets/banner3.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/maheshpatil132/flipkart-clone/HEAD/my-app/src/assets/banner3.png -------------------------------------------------------------------------------- /my-app/src/assets/banner4.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/maheshpatil132/flipkart-clone/HEAD/my-app/src/assets/banner4.png -------------------------------------------------------------------------------- /my-app/src/assets/bannner.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/maheshpatil132/flipkart-clone/HEAD/my-app/src/assets/bannner.jpg -------------------------------------------------------------------------------- /my-app/src/assets/dslr.webp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/maheshpatil132/flipkart-clone/HEAD/my-app/src/assets/dslr.webp -------------------------------------------------------------------------------- /my-app/src/assets/empty.webp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/maheshpatil132/flipkart-clone/HEAD/my-app/src/assets/empty.webp -------------------------------------------------------------------------------- /my-app/src/assets/banner1.webp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/maheshpatil132/flipkart-clone/HEAD/my-app/src/assets/banner1.webp -------------------------------------------------------------------------------- /my-app/src/assets/emptywish.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/maheshpatil132/flipkart-clone/HEAD/my-app/src/assets/emptywish.png -------------------------------------------------------------------------------- /my-app/src/assets/register.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/maheshpatil132/flipkart-clone/HEAD/my-app/src/assets/register.png -------------------------------------------------------------------------------- /my-app/src/assets/register.webp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/maheshpatil132/flipkart-clone/HEAD/my-app/src/assets/register.webp -------------------------------------------------------------------------------- /my-app/src/assets/no-products.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/maheshpatil132/flipkart-clone/HEAD/my-app/src/assets/no-products.png -------------------------------------------------------------------------------- /my-app/src/constants/WishlistConstants.js: -------------------------------------------------------------------------------- 1 | export const AddWishItem = "AddWishItem" 2 | export const RemoveWishItem = "AddWishItem" -------------------------------------------------------------------------------- /server/middleware/aysnchandler.js: -------------------------------------------------------------------------------- 1 | module.exports = (thefunc)=>(req,res,next)=>{ 2 | Promise.resolve(thefunc(req,res,next)).catch(next) 3 | } -------------------------------------------------------------------------------- /my-app/src/components/Products/products.css: -------------------------------------------------------------------------------- 1 | .products{ 2 | display: grid; 3 | grid-template-columns: repeat( auto-fit , minmax(15rem,1fr)); 4 | 5 | } -------------------------------------------------------------------------------- /my-app/src/components/layout/categories/category.css: -------------------------------------------------------------------------------- 1 | .menu:hover .submenu{ 2 | display: flex; 3 | flex-direction: column; 4 | } 5 | .submenu{ 6 | display: none; 7 | } -------------------------------------------------------------------------------- /server/vercel.json: -------------------------------------------------------------------------------- 1 | { 2 | "version": 2, 3 | "name": "music-album", 4 | "builds": [ 5 | { "src": "app.js", "use": "@vercel/node" } 6 | ], 7 | "routes": [ 8 | { "src": "/(.*)", "dest": "/app.js" } 9 | ] 10 | } -------------------------------------------------------------------------------- /my-app/src/components/Admin/createproduct.css: -------------------------------------------------------------------------------- 1 | .img:hover .delete{ 2 | display: flex; 3 | } 4 | 5 | 6 | .delete{ 7 | box-shadow:0px 0px 50px 100px rgba(0, 0, 0, 0.349); 8 | background: rgba(0, 0, 0, 0.452); 9 | display: none; 10 | } -------------------------------------------------------------------------------- /my-app/src/constants/CartConstants.js: -------------------------------------------------------------------------------- 1 | export const AddToCart = "AddToCart" 2 | export const RemoveToCart = "RemoveToCart" 3 | export const ClearCartItems = "ClearCartItems" 4 | export const ClearError = "ClearError" 5 | export const Save_ShipingInfo = "Save_ShipingInfo" -------------------------------------------------------------------------------- /my-app/src/setupTests.js: -------------------------------------------------------------------------------- 1 | // jest-dom adds custom jest matchers for asserting on DOM nodes. 2 | // allows you to do things like: 3 | // expect(element).toHaveTextContent(/react/i) 4 | // learn more: https://github.com/testing-library/jest-dom 5 | import '@testing-library/jest-dom'; 6 | -------------------------------------------------------------------------------- /server/utils/errorhandler.js: -------------------------------------------------------------------------------- 1 | class ErrorHandler extends Error { 2 | constructor(message, status){ 3 | super(message); 4 | this.status = status 5 | 6 | Error.captureStackTrace(this,this.constructor) 7 | } 8 | 9 | } 10 | 11 | module.exports = ErrorHandler -------------------------------------------------------------------------------- /my-app/src/Axios.js: -------------------------------------------------------------------------------- 1 | import axios from 'axios' 2 | 3 | // For Production, Create .env file and put your backend api URL in that, OR use localhost url 4 | export const Axios = axios.create({ 5 | baseURL : process.env.REACT_APP_BACKEND_URL, 6 | // baseURL : 'http://localhost:4000/', 7 | withCredentials:true 8 | }) -------------------------------------------------------------------------------- /my-app/tailwind.config.js: -------------------------------------------------------------------------------- 1 | /** @type {import('tailwindcss').Config} */ 2 | module.exports = { 3 | content: [ 4 | "./src/**/*.{js,jsx,ts,tsx}", 5 | ], 6 | theme: { 7 | extend: { 8 | colors:{ 9 | 'primary':'#2874f0', 10 | 'secondary':'#172337' 11 | } 12 | }, 13 | }, 14 | plugins: [], 15 | } 16 | -------------------------------------------------------------------------------- /my-app/src/actions/WishActions.js: -------------------------------------------------------------------------------- 1 | import { AddWishItem } from "../constants/WishlistConstants" 2 | 3 | 4 | export const AddWish = ( data ) => (dispatch , getState) =>{ 5 | dispatch({ 6 | type : AddWishItem, 7 | payload : data 8 | }) 9 | 10 | localStorage.setItem("wishitems" , JSON.stringify(getState().WishList.wishItems)) 11 | } -------------------------------------------------------------------------------- /my-app/src/components/layout/Header/header.css: -------------------------------------------------------------------------------- 1 | /* header css file */ 2 | 3 | 4 | .dropdown::before{ 5 | content: ''; 6 | height: 20px; 7 | width: 20px; 8 | background-color: white; 9 | transform: rotate(45deg); 10 | position: absolute; 11 | left: 44%; 12 | top: -.5rem; 13 | border-radius: .01rem; 14 | z-index: -1; 15 | } 16 | -------------------------------------------------------------------------------- /my-app/src/components/layout/MetaData.js: -------------------------------------------------------------------------------- 1 | import React from 'react' 2 | import {Helmet} from "react-helmet"; 3 | 4 | const MetaData = ({title}) => { 5 | return ( 6 |
7 | 8 | 9 | {title} 10 | 11 |
12 | ) 13 | } 14 | 15 | export default MetaData -------------------------------------------------------------------------------- /server/config/redis.js: -------------------------------------------------------------------------------- 1 | const {Redis} = require('ioredis'); 2 | const dotenv = require('dotenv') 3 | 4 | exports.connectToRedis =async () => { 5 | const redis = new Redis({ 6 | port: process.env.Redis_Port, 7 | host: `${process.env.Redis_host}`, 8 | password: `${process.env.Redis_Password}`, 9 | }) 10 | 11 | return redis 12 | } 13 | 14 | -------------------------------------------------------------------------------- /my-app/src/components/layout/Loader/Loader.js: -------------------------------------------------------------------------------- 1 | import React from 'react' 2 | import CircularProgress from '@mui/material/CircularProgress'; 3 | 4 | const Loader = () => { 5 | return ( 6 |
7 | 8 |
9 | ) 10 | } 11 | 12 | export default Loader -------------------------------------------------------------------------------- /my-app/src/utils/CategorySearch.js: -------------------------------------------------------------------------------- 1 | 2 | export const categoryfilter = (array , category) =>{ 3 | const updated = array.filter((elem)=>{ 4 | return elem.category === category 5 | }) 6 | 7 | const remaining = array.filter((elem)=>{ 8 | return !updated.includes(elem) 9 | }) 10 | // console.log(updated); 11 | // return [...updated , ...remaining]; 12 | return updated; 13 | } -------------------------------------------------------------------------------- /server/config/example.env: -------------------------------------------------------------------------------- 1 | MONGO_URL = Your Mongo db URL 2 | PORT = 5000 3 | JWT = write your Jwt_secret_key 4 | Cookie_Expire = 5 5 | cloud_name = cloudinary cloud name 6 | api_key = cloudinary key 7 | api_secret = cloudinary secret ket 8 | Frontend_URL = http://localhost:3000 or you can write your hosted frontend url 9 | 10 | Razor_key = razorpay_key 11 | Razor_Secure = razorpay_secure key 12 | 13 | 14 | -------------------------------------------------------------------------------- /my-app/.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 | .env 8 | 9 | # testing 10 | /coverage 11 | 12 | # production 13 | /build 14 | 15 | # misc 16 | .DS_Store 17 | .env.local 18 | .env.development.local 19 | .env.test.local 20 | .env.production.local 21 | 22 | npm-debug.log* 23 | yarn-debug.log* 24 | yarn-error.log* 25 | -------------------------------------------------------------------------------- /my-app/src/reportWebVitals.js: -------------------------------------------------------------------------------- 1 | const reportWebVitals = onPerfEntry => { 2 | if (onPerfEntry && onPerfEntry instanceof Function) { 3 | import('web-vitals').then(({ getCLS, getFID, getFCP, getLCP, getTTFB }) => { 4 | getCLS(onPerfEntry); 5 | getFID(onPerfEntry); 6 | getFCP(onPerfEntry); 7 | getLCP(onPerfEntry); 8 | getTTFB(onPerfEntry); 9 | }); 10 | } 11 | }; 12 | 13 | export default reportWebVitals; 14 | -------------------------------------------------------------------------------- /server/config/database.js: -------------------------------------------------------------------------------- 1 | const mongoose = require('mongoose'); 2 | 3 | 4 | const connect = () =>{ 5 | mongoose.set('strictQuery', false); 6 | 7 | mongoose.connect(`${process.env.MONGO_URL}`, { 8 | useNewUrlParser: true, 9 | useUnifiedTopology: true 10 | }).then(()=>{ 11 | console.log("database is connected"); 12 | }).catch((err)=>{ 13 | console.log(err) 14 | }) 15 | } 16 | 17 | 18 | module.exports = {connect} -------------------------------------------------------------------------------- /server/utils/jsonwebtoken.js: -------------------------------------------------------------------------------- 1 | 2 | 3 | exports.sendtoken = (user, status , res)=>{ 4 | 5 | const token = user.generatetoken(); 6 | 7 | const options = { 8 | httpOnly: true, 9 | expires: new Date( Date.now() + process.env.Cookie_Expire * 60 * 60 * 24 * 1000), 10 | secure: true, 11 | httpOnly: true, 12 | sameSite: 'none' 13 | } 14 | 15 | res.status(status).cookie('token', token , options).json({ 16 | sucess : true, 17 | user : user 18 | }) 19 | } -------------------------------------------------------------------------------- /my-app/src/components/Products/NoProduct.js: -------------------------------------------------------------------------------- 1 | import React from 'react' 2 | import NoProd from '../../assets/no-products.png' 3 | 4 | const NoProduct = () => { 5 | return ( 6 |
7 | No Products 8 |

Sorry, no results found!

9 |
Please check the spelling or try searching for something else
10 |
11 | ) 12 | } 13 | 14 | export default NoProduct -------------------------------------------------------------------------------- /my-app/src/index.css: -------------------------------------------------------------------------------- 1 | @tailwind base; 2 | @tailwind components; 3 | @tailwind utilities; 4 | 5 | @import url('https://fonts.googleapis.com/css2?family=Inter:wght@200;300;400&family=Nunito+Sans:wght@200;300;400&family=Nunito:ital,wght@0,200;0,300;0,400;0,500;1,600&family=Poppins:ital,wght@0,100;0,200;0,300;0,400;0,500;0,600;1,400;1,500&family=Roboto+Slab:wght@100;200;300;400&family=Roboto:wght@300&display=swap'); 6 | 7 | html{ 8 | font-size: 95%; 9 | scroll-behavior: smooth; 10 | } 11 | 12 | body{ 13 | font-family: 'Roboto', sans-serif; 14 | background-color: #f4f5f7; 15 | } 16 | 17 | -------------------------------------------------------------------------------- /my-app/src/Routes/ProtectedRoutes.js: -------------------------------------------------------------------------------- 1 | import React from 'react' 2 | import { useSelector } from 'react-redux'; 3 | import { Navigate } from 'react-router-dom'; 4 | 5 | const ProtectedRoutes = ({ children, isAdmin }) => { 6 | const { loading, isAuthenticated, user } = useSelector(state => state.User); 7 | return ( 8 | <> 9 | {loading === false && ( 10 | isAuthenticated === false ? : isAdmin ? user.role !== "admin" ? : children : children 11 | )} 12 | 13 | ) 14 | } 15 | 16 | export default ProtectedRoutes -------------------------------------------------------------------------------- /my-app/public/manifest.json: -------------------------------------------------------------------------------- 1 | { 2 | "short_name": "React App", 3 | "name": "Create React App Sample", 4 | "icons": [ 5 | { 6 | "src": "favicon.ico", 7 | "sizes": "64x64 32x32 24x24 16x16", 8 | "type": "image/x-icon" 9 | }, 10 | { 11 | "src": "logo192.png", 12 | "type": "image/png", 13 | "sizes": "192x192" 14 | }, 15 | { 16 | "src": "logo512.png", 17 | "type": "image/png", 18 | "sizes": "512x512" 19 | } 20 | ], 21 | "start_url": ".", 22 | "display": "standalone", 23 | "theme_color": "#000000", 24 | "background_color": "#ffffff" 25 | } 26 | -------------------------------------------------------------------------------- /my-app/src/components/cart/EmptyCart.js: -------------------------------------------------------------------------------- 1 | import React from 'react' 2 | import {NavLink} from 'react-router-dom' 3 | import empty from '../../assets/empty.webp' 4 | 5 | const EmptyCart = () => { 6 | return ( 7 |
8 |
9 | 10 |
11 |

Look Like your cart is Empty !

12 | 13 | 14 |
15 | ) 16 | } 17 | 18 | export default EmptyCart -------------------------------------------------------------------------------- /server/routes/paymentroute.js: -------------------------------------------------------------------------------- 1 | const express = require('express'); 2 | const { processpayment, PaymentPublishKey, paymentverification, generateinvoice } = require('../controllers/paymentcontroller'); 3 | const {Authorization, authorizerole }= require('../middleware/auth') 4 | 5 | const app = express.Router(); 6 | 7 | 8 | exports.ProcessPayment = app.post('/process/payment' , Authorization , processpayment); 9 | exports.PaymentVerification = app.post('/paymentverification' , Authorization , paymentverification); 10 | exports.PublishKey = app.get('/process/publishkey' , Authorization , PaymentPublishKey); 11 | exports.GenerateIvoice = app.get('/generate/invoice' , Authorization, generateinvoice); 12 | 13 | 14 | 15 | -------------------------------------------------------------------------------- /server/middleware/error.js: -------------------------------------------------------------------------------- 1 | const ErrorHandler = require("../utils/errorhandler"); 2 | 3 | const errorhandle = (err, req, res, next) => { 4 | err.status = err.status || 500; 5 | err.message = err.message || "internal server error" 6 | 7 | 8 | 9 | if (err.name == 'CastError') { 10 | err.message = "Resource not Found", 11 | err.status = 500 12 | } 13 | 14 | if (err.code == 11000) { 15 | const message = `This ${Object.keys(err.keyValue)} are alreadey Exist` 16 | err = new ErrorHandler(message, 400) 17 | } 18 | 19 | res.status(err.status).json({ 20 | error: err.message, 21 | status: false 22 | }) 23 | } 24 | 25 | module.exports = errorhandle -------------------------------------------------------------------------------- /my-app/public/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 12 | 13 | 14 | 15 | Flipkart Clone - Mahesh 16 | 17 | 18 | 19 |
20 | 21 | 22 | 23 | -------------------------------------------------------------------------------- /server/routes/orderroutes.js: -------------------------------------------------------------------------------- 1 | const express = require('express'); 2 | const { createorder, updateorder, deleteorder, myorder, getorder, getallorder } = require('../controllers/ordercontroller'); 3 | const {Authorization, authorizerole } = require('../middleware/auth') 4 | const app = express.Router() 5 | 6 | 7 | 8 | exports.CreateOrder = app.post('/create/order', Authorization , createorder) 9 | exports.UpdateOrder = app.put('/update/order/:id', Authorization , updateorder) 10 | exports.DeleteOrder = app.delete('/delete/order/:id', Authorization , authorizerole('admin'), deleteorder) 11 | exports.MyOrders = app.get('/get/myorders', Authorization , myorder) 12 | exports.Getorder = app.get('/order/:id', Authorization , getorder) 13 | exports.GetAllOrders = app.get('/getall/orders', Authorization , authorizerole('admin'), getallorder) 14 | -------------------------------------------------------------------------------- /my-app/src/components/home/Bannerslider/carousel.css: -------------------------------------------------------------------------------- 1 | .slick-prev, 2 | .slick-next { 3 | height: 100px; 4 | width: 50px; 5 | background-color: white; 6 | display: flex; 7 | justify-content: center; 8 | align-items: center; 9 | /* border: .1px solid rgb(207, 205, 205); */ 10 | box-shadow: 2.5px 1px #f1f1f1; 11 | z-index: 1; 12 | } 13 | 14 | .slick-prev:hover{ 15 | background-color: white; 16 | } 17 | .slick-next:hover{ 18 | background-color: white; 19 | } 20 | 21 | .slick-prev { 22 | left: 0; 23 | border-top-right-radius: .3rem; 24 | border-bottom-right-radius: .3rem; 25 | } 26 | 27 | .slick-next { 28 | right: 0; 29 | border-top-left-radius: .3rem; 30 | border-bottom-left-radius: .3rem; 31 | } 32 | 33 | .slick-next::before, 34 | .slick-prev::before { 35 | display: none; 36 | } -------------------------------------------------------------------------------- /my-app/src/constants/UserConstants.js: -------------------------------------------------------------------------------- 1 | export const Login_Req = "Login_Req" 2 | export const Login_Success = "Login_Success" 3 | export const Login_Fail = "Login_Fail" 4 | export const Register_Req = "Register_Req" 5 | export const Register_Success = "Register_Success" 6 | export const Register_Fail = "Register_Fail" 7 | export const Clear_Error = "Clear_Error" 8 | export const All_User_Request = "All_User_Request" 9 | export const All_User_Success = "All_User_Succeess" 10 | export const All_User_Fail = "All_User_Fail" 11 | export const Load_User_Request = "Load_User_Request" 12 | export const Load_User_Sucess = "Load_User_Sucess " 13 | export const Load_User_Fail = "Load_User_Fail" 14 | export const Logout_User_Request = "Logout_User_Request" 15 | export const Logout_User_Sucess = "Logout_User_Sucess" 16 | export const Logout_User_Fail = "Logout_User_Fail" -------------------------------------------------------------------------------- /my-app/src/Reducers/WishReducer.js: -------------------------------------------------------------------------------- 1 | import { AddWishItem } from "../constants/WishlistConstants" 2 | 3 | const initialState = { 4 | wishItems : localStorage.getItem('wishitems') ? JSON.parse(localStorage.getItem('wishitems')) : [] 5 | } 6 | 7 | export const wishReducer =(state = initialState , action) => { 8 | const item = action.payload 9 | switch(action.type){ 10 | case AddWishItem : 11 | const isExist = state.wishItems.find((e)=> e._id === item._id) 12 | if(isExist){ 13 | return{ 14 | ...state, 15 | wishItems : state.wishItems.filter((e)=> e._id !== item._id), 16 | 17 | } 18 | }else{ 19 | return{ 20 | ...state, 21 | wishItems : [...state.wishItems , item] 22 | } 23 | } 24 | 25 | default : return state 26 | } 27 | } -------------------------------------------------------------------------------- /server/middleware/auth.js: -------------------------------------------------------------------------------- 1 | 2 | const jwt = require('jsonwebtoken'); 3 | const ErrorHandler = require('../utils/errorhandler'); 4 | const aysnchandler = require('./aysnchandler'); 5 | const UserModel = require('../models/usermodel') 6 | 7 | 8 | exports.Authorization = aysnchandler(async(req,res,next)=>{ 9 | const {token} = req.cookies 10 | 11 | 12 | if(!token){ 13 | return next(new ErrorHandler('Please Login First before Moving further', 400)) 14 | } 15 | 16 | const decode = jwt.verify(token , process.env.JWT) 17 | 18 | req.user = await UserModel.findById(decode.id) 19 | 20 | next() 21 | 22 | }) 23 | 24 | exports.authorizerole = (...roles)=>{ 25 | return (req,res,next)=>{ 26 | if(!roles.includes(req.user.role)){ 27 | return next( new ErrorHandler('You are not Allowed to Access This Route', 300)) 28 | } 29 | next() 30 | } 31 | 32 | 33 | } -------------------------------------------------------------------------------- /my-app/src/components/Admin/Dashboard.js: -------------------------------------------------------------------------------- 1 | import React, { useEffect } from 'react' 2 | import AdminSideBar from './AdminSideBar' 3 | import { useSelector } from 'react-redux'; 4 | import { useNavigate } from 'react-router-dom'; 5 | 6 | 7 | const Dashboard = ({children ,activeTab}) => { 8 | const navigate = useNavigate() 9 | const {user} = useSelector(state=>state.User); 10 | 11 | useEffect(()=>{ 12 | if(!user){ 13 | navigate('/login') 14 | } 15 | } , [navigate , user]) 16 | return ( 17 |
18 | 19 |
20 | {/* chart container -1 */} 21 |
22 | { children } 23 |
24 | {/* chart container -1 */} 25 | 26 |
27 |
28 | ) 29 | } 30 | 31 | export default Dashboard -------------------------------------------------------------------------------- /my-app/src/index.js: -------------------------------------------------------------------------------- 1 | import React from 'react'; 2 | import ReactDOM from 'react-dom/client'; 3 | import './index.css'; 4 | import App from './App'; 5 | import reportWebVitals from './reportWebVitals'; 6 | import { 7 | BrowserRouter as Router, 8 | } from "react-router-dom"; 9 | import {Provider} from 'react-redux' 10 | import store from './Store'; 11 | import { SnackbarProvider } from 'notistack'; 12 | const root = ReactDOM.createRoot(document.getElementById('root')); 13 | root.render( 14 | 15 | 16 | 17 | 22 | 23 | 24 | 25 | 26 | 27 | ); 28 | 29 | // If you want to start measuring performance in your app, pass a function 30 | // to log results (for example: reportWebVitals(console.log)) 31 | // or send to an analytics endpoint. Learn more: https://bit.ly/CRA-vitals 32 | reportWebVitals(); 33 | -------------------------------------------------------------------------------- /server/routes/userroutes.js: -------------------------------------------------------------------------------- 1 | const express = require('express'); 2 | const { createuser, loginuser, updateuser, logoutuser, adminupdateuser, deleteuser, getalluser, getuser, admingetuser } = require('../controllers/usercontroller'); 3 | const { Authorization, authorizerole } = require('../middleware/auth') 4 | const app = express.Router() 5 | 6 | 7 | 8 | exports.CreateUser = app.post('/create/user', createuser) 9 | exports.LoginUser = app.post('/login/user', loginuser) 10 | exports.UpdateUser = app.put('/update/user', Authorization, updateuser) 11 | exports.LogoutUser = app.get('/logout/user', Authorization, logoutuser) 12 | exports.GetUser = app.get('/me/user',Authorization,getuser) 13 | 14 | // admin routes 15 | exports.AdminUpdateuser = app.put('/admin/update/user/:id', Authorization, authorizerole('admin'), adminupdateuser) 16 | exports.AdminRemoveUser = app.delete('/admin/delete/user/:id', Authorization , authorizerole('admin'), deleteuser) 17 | exports.GetAllUSer = app.get('/getall/user', Authorization , authorizerole('admin'), getalluser) 18 | exports.AdminGetUser = app.get('/admin/getuser/:id', Authorization , authorizerole('admin'), admingetuser) -------------------------------------------------------------------------------- /my-app/src/constants/OrderConstants.js: -------------------------------------------------------------------------------- 1 | export const New_Order_Request = "New_Order_Request" 2 | export const New_Order_Success = "New_Order_Success" 3 | export const New_Order_Fail = "New_Order_Fail" 4 | 5 | 6 | export const My_Order_Request = "My_Order_Request" 7 | export const My_Order_Sucess = "My_Order_Sucess" 8 | export const My_Order_Fail = "My_Order_Fail" 9 | 10 | 11 | export const Order_Detial_Request = "Order_Detial_Request" 12 | export const Order_Detial_Sucess = "Order_Detial_Sucess" 13 | export const Order_Detial_Fail = "Order_Detial_Fail" 14 | 15 | 16 | export const Admin_Orders_Request = "Admin_Orders_Request" 17 | export const Admin_Orders_Sucess = "Admin_Orders_Sucess" 18 | export const Admin_Orders_Fail = "Admin_Orders_Fail" 19 | 20 | 21 | export const Update_Order_Request = "Update_Order_Request" 22 | export const Update_Order_Sucess = "Update_Order_Sucess" 23 | export const Update_Order_Fail = "Update_Order_Fail" 24 | 25 | export const Delete_Order_Request = "Delete_Order_Request" 26 | export const Delete_Order_Sucess = "Delete_Order_Sucess" 27 | export const Delete_Order_Fail = "Delete_Order_Fail" 28 | 29 | 30 | export const Clear_Error = "Clear_Error" -------------------------------------------------------------------------------- /my-app/src/Store.js: -------------------------------------------------------------------------------- 1 | 2 | import { configureStore } from '@reduxjs/toolkit' 3 | import { CreateProduct, ProductsReducer, Product_detial_reducer , ProductReducer, newReviewReducer, Top_Product_Reducer} from './Reducers/ProductReducer'; 4 | import { CartReducer } from './Reducers/CartReducer'; 5 | import { wishReducer } from './Reducers/WishReducer'; 6 | import { AlluserReducer, UserReducer } from './Reducers/UserReducer'; 7 | import { AdminOrdersReducer, MyordersReducer, NewOrderReducer, OrderDetialReducer } from './Reducers/OrderReducer'; 8 | 9 | 10 | 11 | 12 | const store = configureStore({ 13 | 14 | reducer:{ 15 | AllProducts : ProductsReducer, 16 | TopProducts : Top_Product_Reducer, 17 | ProductDetial : Product_detial_reducer, 18 | Cart : CartReducer, 19 | WishList: wishReducer, 20 | User:UserReducer, 21 | AllUser : AlluserReducer, 22 | CreateProduct : CreateProduct, 23 | Neworder : NewOrderReducer, 24 | Myorders : MyordersReducer, 25 | OrderDetial : OrderDetialReducer, 26 | AllOrders : AdminOrdersReducer, 27 | newReview: newReviewReducer, 28 | }, 29 | 30 | 31 | 32 | 33 | } ); 34 | export default store; -------------------------------------------------------------------------------- /my-app/src/components/home/Home.js: -------------------------------------------------------------------------------- 1 | import React, { Suspense } from 'react' 2 | import Category from '../layout/categories/Category' 3 | import BannerSlider from './Bannerslider/BannerSlider' 4 | import TopProducts from './dealcontainer/TopProducts' 5 | import MetaData from '../layout/MetaData'; 6 | 7 | const SliderComponent = React.lazy(() => import('./productslider/Productslider')); 8 | 9 | 10 | const Home = () => { 11 | return ( 12 |
13 | 14 | 15 | {/* benner slider */} 16 |
17 | 18 | 19 | {/* deal container */} 20 | 21 | Loading...
}> 22 |
23 | {/* */} 24 | 25 | 26 | 27 | {/* */} 28 |
29 | 30 | 31 | 32 | 33 | 34 | {/* footer */} 35 | 36 |
37 | 38 | 39 | ) 40 | } 41 | 42 | export default Home -------------------------------------------------------------------------------- /server/routes/productroutes.js: -------------------------------------------------------------------------------- 1 | const express = require('express'); 2 | const { getallproduct, createproduct, updateproduct, deleteproduct, getproduct, addreview, getallreview, deletereview, Admingetallproducts, gettopproducts } = require('../controllers/productcontroller'); 3 | const {Authorization, authorizerole }= require('../middleware/auth') 4 | const app = express.Router(); 5 | 6 | 7 | exports.CreateProduct = app.post('/create/product', Authorization , authorizerole('admin'), createproduct) 8 | exports.GetAllProduct = app.get('/getall/products', getallproduct) 9 | exports.UpdateProduct = app.put('/update/product/:id', Authorization , authorizerole('admin'), updateproduct) 10 | exports.DeleteProduct = app.delete('/delete/product/:id', Authorization , authorizerole('admin'), deleteproduct) 11 | exports.GetProduct = app.get('/product/:id', getproduct) 12 | exports.AddReview = app.put('/add/review', Authorization , addreview) 13 | exports.GetAllReview = app.get('/getall/review', getallreview) 14 | exports.DeleteReview = app.get('/delete/review', Authorization , deletereview) 15 | exports.AdminGetAllProducts = app.get('/admin/products', Authorization , authorizerole('admin'), Admingetallproducts) 16 | exports.GetTopSellProducts = app.get('/top/products', gettopproducts) -------------------------------------------------------------------------------- /my-app/src/components/layout/Header/SearchBar.js: -------------------------------------------------------------------------------- 1 | import React, { useEffect, useState } from 'react' 2 | import SearchIcon from '@mui/icons-material/Search'; 3 | import { useLocation, useNavigate } from 'react-router-dom'; 4 | 5 | const SearchBar = () => { 6 | const [keyword, setKeyword] = useState('') 7 | 8 | const {pathname} = useLocation() 9 | 10 | 11 | const navigate = useNavigate() 12 | const handlesubmit = (e)=>{ 13 | e.preventDefault(); 14 | navigate(`/search?name=${keyword}`) 15 | } 16 | 17 | useEffect(()=>{ 18 | if(pathname !== '/search') 19 | setKeyword('') 20 | },[pathname]) 21 | 22 | 23 | return ( 24 |
handlesubmit(e)} className=' w-[400px] text-black flex px-4 p-1.5 rounded items-center bg-white '> 25 | { setKeyword(e.target.value) }} 27 | value={keyword} 28 | type="text" 29 | name='search' 30 | placeholder='Search for Products , Brand and Categories' 31 | className=' rounded outline-none flex-1 py-1 w-4/6 bg-transparent text-base' /> 32 |
33 | 34 |
35 |
36 | ) 37 | } 38 | 39 | export default SearchBar -------------------------------------------------------------------------------- /server/models/usermodel.js: -------------------------------------------------------------------------------- 1 | const mongoose = require('mongoose'); 2 | const jwt = require('jsonwebtoken'); 3 | const bcrypt = require('bcrypt'); 4 | 5 | const UserModel = new mongoose.Schema({ 6 | name:{ 7 | type:String, 8 | required:true 9 | }, 10 | email:{ 11 | type:String, 12 | required:true, 13 | unique:true 14 | }, 15 | password:{ 16 | type:String, 17 | required:true 18 | }, 19 | mobile:{ 20 | type:Number, 21 | required:true, 22 | length:10 23 | }, 24 | createdAt:{ 25 | type:Date, 26 | default:Date.now() 27 | }, 28 | role:{ 29 | type:String, 30 | default:'user' 31 | } 32 | 33 | }) 34 | 35 | UserModel.pre('save', async function (next) { 36 | if (!this.isModified('password')) { 37 | next() 38 | } 39 | this.password = await bcrypt.hash(this.password, 10) 40 | }) 41 | 42 | UserModel.methods.generatetoken = function(){ 43 | const token = jwt.sign({id:this._id}, process.env.JWT) 44 | return token 45 | } 46 | 47 | 48 | UserModel.methods.comparepassword = function(enteredpassword){ 49 | return bcrypt.compare(enteredpassword , this.password) 50 | } 51 | 52 | 53 | 54 | module.exports = mongoose.model('user',UserModel) -------------------------------------------------------------------------------- /my-app/src/components/productdetials/Modal.js: -------------------------------------------------------------------------------- 1 | import { Box, Typography } from '@mui/material' 2 | import React, { useState } from 'react' 3 | 4 | const Modal = () => { 5 | const [open, setOpen] = useState(true) 6 | const handleClose = () => setOpen(false); 7 | const style = { 8 | position: 'absolute', 9 | top: '50%', 10 | left: '50%', 11 | transform: 'translate(-50%, -50%)', 12 | width: 400, 13 | bgcolor: 'background.paper', 14 | border: '2px solid #000', 15 | boxShadow: 24, 16 | p: 4, 17 | }; 18 | return ( 19 |
20 | 26 | 27 | 28 | Text in a modal 29 | 30 | 31 | Duis mollis, est non commodo luctus, nisi erat porttitor ligula. 32 | 33 | 34 | 35 |
36 | ) 37 | } 38 | 39 | export default Modal -------------------------------------------------------------------------------- /my-app/src/actions/CartActions.js: -------------------------------------------------------------------------------- 1 | import { AddToCart, ClearCartItems, ClearError, RemoveToCart, Save_ShipingInfo } from "../constants/CartConstants" 2 | 3 | 4 | export const AddCart = (data , quantity = 1) => async(dispatch ,getState)=> { 5 | // console.log(data); 6 | dispatch({ 7 | type:AddToCart, 8 | product: {data , quantity} 9 | }) 10 | 11 | // console.log(getState().Cart.Products); 12 | 13 | localStorage.setItem("cartItems" , JSON.stringify(getState().Cart.Products)) 14 | 15 | } 16 | 17 | export const RemoveCart = (id , quatity = 1) => (dispatch , getState)=>{ 18 | 19 | dispatch({ 20 | type:RemoveToCart, 21 | product:id, 22 | quatity 23 | }) 24 | 25 | 26 | localStorage.setItem("cartItems" , JSON.stringify(getState().Cart.Products)) 27 | 28 | 29 | 30 | } 31 | 32 | 33 | export const ClearCart = () => (dispatch , getState)=>{ 34 | dispatch({ 35 | type:ClearCartItems 36 | }) 37 | localStorage.removeItem("cartItems") 38 | } 39 | 40 | 41 | export const ClearErrors = () => (dispatch , getState)=>{ 42 | dispatch({ 43 | type:ClearError 44 | }) 45 | } 46 | 47 | 48 | export const save_shippingindfo = (data) =>(dispatch)=> { 49 | dispatch({ 50 | type : Save_ShipingInfo, 51 | payload : data 52 | }) 53 | 54 | localStorage.setItem('shippingInfo', JSON.stringify(data)); 55 | } 56 | 57 | 58 | -------------------------------------------------------------------------------- /my-app/src/Reducers/CartReducer.js: -------------------------------------------------------------------------------- 1 | import { ClearCartItems, ClearError, RemoveToCart, Save_ShipingInfo } from "../constants/CartConstants"; 2 | 3 | const initialState = { 4 | Products : localStorage.getItem('cartItems') ? JSON.parse( localStorage.getItem("cartItems")) : [], 5 | shipinginfo :localStorage.getItem('shippingInfo') ? JSON.parse( localStorage.getItem("shippingInfo")) : {} 6 | } 7 | 8 | export const CartReducer = ( state = initialState , action )=>{ 9 | const item = action.product 10 | switch(action.type){ 11 | case "AddToCart" : 12 | const isExist = state.Products.find((e)=>e.data._id === item.data._id); 13 | if(isExist){ 14 | return{ 15 | ...state, 16 | Products : state.Products.map((e)=> 17 | e.data._id === isExist.data._id ? item : e 18 | ) 19 | } 20 | }else{ 21 | 22 | return { 23 | ...state, 24 | Products : [...state.Products , item] 25 | } 26 | } 27 | 28 | case RemoveToCart : 29 | return{ 30 | ...state, 31 | Products: state.Products.filter((e)=>e.data._id !== item) 32 | } 33 | 34 | case ClearCartItems : 35 | return { 36 | Products : [] 37 | } 38 | 39 | case ClearError : 40 | return { 41 | error : null 42 | } 43 | case Save_ShipingInfo : return { 44 | ...state, 45 | shipinginfo : action.payload 46 | } 47 | 48 | 49 | default : return state 50 | 51 | } 52 | 53 | } -------------------------------------------------------------------------------- /my-app/src/components/layout/Header/Secondarydropdown.js: -------------------------------------------------------------------------------- 1 | import React from 'react' 2 | import NotificationsIcon from '@mui/icons-material/Notifications'; 3 | import GetAppIcon from '@mui/icons-material/GetApp'; 4 | import AutoGraphIcon from '@mui/icons-material/AutoGraph'; 5 | import LiveHelpIcon from '@mui/icons-material/LiveHelp'; 6 | 7 | const Secondarydropdown = () => { 8 | const nav = [ 9 | { 10 | title:"Notification Preference", 11 | icon:, 12 | redirect:"kakakkakkakakk" 13 | }, 14 | { 15 | title:"24X7 customer care", 16 | icon:, 17 | redirect:"kakakkakkakakk" 18 | }, { 19 | title:"Advertise", 20 | icon:, 21 | redirect:"kakakkakkakakk" 22 | }, { 23 | title:"Download App", 24 | icon:, 25 | redirect:"kakakkakkakakk" 26 | }, 27 | ] 28 | return ( 29 |
30 | { 31 | 32 | nav.map((elem,index)=>{ 33 | return( 34 | 35 |
36 | {elem.icon} 37 |
{elem.title}
38 |
39 | 40 | ) 41 | }) 42 | } 43 |
44 | ) 45 | } 46 | 47 | export default Secondarydropdown -------------------------------------------------------------------------------- /server/utils/apifeatures.js: -------------------------------------------------------------------------------- 1 | 2 | 3 | class ApiFeatures { 4 | constructor(query, querystr) { 5 | this.query = query; 6 | this.querystr = querystr 7 | } 8 | 9 | search() { 10 | 11 | const keyword = this.querystr.name ? 12 | { 13 | // title : { 14 | // $regex: this.querystr.name, 15 | // $options: 'i' 16 | // } 17 | 18 | $or: [ 19 | { title: { $regex: this.querystr.name, $options: "i" }}, 20 | { brand: { $regex: this.querystr.name, $options: "i" }}, 21 | { category: { $regex: this.querystr.name, $options: "i" }}, 22 | ] 23 | } 24 | : {} 25 | 26 | this.query = this.query.find({...keyword }) 27 | return this 28 | } 29 | 30 | filter(){ 31 | 32 | const querycopy = {...this.querystr} 33 | 34 | const removefield = ['page','name','limit'] 35 | 36 | removefield.forEach(el => {delete querycopy[el]}) 37 | 38 | let querystr = JSON.stringify(querycopy) 39 | 40 | querystr = querystr.replace(/\b(gt|gte|lt|lte)\b/g , key=> `$${key}`) 41 | 42 | this.query = this.query.find(JSON.parse(querystr)) 43 | 44 | 45 | return this 46 | 47 | } 48 | 49 | 50 | pagination(result){ 51 | 52 | const currentpage = Number(this.querystr.page)|| 1; 53 | 54 | const skip = (currentpage -1)*result 55 | 56 | this.query = this.query.skip(skip).limit(result) 57 | 58 | return this 59 | } 60 | } 61 | 62 | 63 | 64 | module.exports = ApiFeatures -------------------------------------------------------------------------------- /my-app/src/components/layout/categories/Category.js: -------------------------------------------------------------------------------- 1 | import React from 'react' 2 | import categories from './category.json' 3 | import ExpandMoreIcon from '@mui/icons-material/ExpandMore'; 4 | import './category.css' 5 | 6 | const Category = () => { 7 | 8 | 9 | const show=()=>{ 10 | 11 | } 12 | 13 | return ( 14 |
15 | 16 | { 17 | categories.map((elem,index)=>{ 18 | return( 19 |
20 |

{elem.title}

21 | { 22 | elem.sub ? : '' 23 | } 24 | 25 | { 26 | elem.sub && 27 | 28 |
29 | { 30 | elem.sub.map((e,i)=>{ 31 | return( 32 |

{e}

33 | ) 34 | }) 35 | } 36 |
37 | } 38 | 39 |
40 | ) 41 | }) 42 | } 43 |
44 | ) 45 | } 46 | 47 | export default Category -------------------------------------------------------------------------------- /server/utils/sendEmails.js: -------------------------------------------------------------------------------- 1 | const nodemailer = require('nodemailer'); 2 | 3 | // Create a Nodemailer transporter 4 | const transporter = nodemailer.createTransport({ 5 | host: 'smtp.elasticemail.com', 6 | port: 2525, // Elastic Email SMTP port 7 | secure: false, // true for 465, false for other ports 8 | auth: { 9 | user: process.env.SenderEmail, 10 | pass: process.env.ElasticEmail_key, 11 | }, 12 | }); 13 | 14 | 15 | // html content 16 | const htmlContent = (username)=>{ 17 | return `

Verify Your Email Address

18 |
19 |

20 |

Dear ${username},

21 |

Thank you for signing up with Flipkart Clone. To 22 | ensure the security of your account and to enjoy 23 | the full benefits of our services, please verify 24 | your email address by clicking the link below: 25 |

26 | ` 27 | } 28 | 29 | 30 | exports.sendEmail = async ( email , username )=>{ 31 | 32 | // Email content 33 | const mailOptions = { 34 | from: 'maheshpatilhp132@gmail.com', 35 | to: 'maheshpatilkg132@gmail.com', 36 | subject: 'Please Verify your Email Address', 37 | html: htmlContent(username) 38 | }; 39 | 40 | // Send the email 41 | transporter.sendMail(mailOptions, function (error, info) { 42 | if (error) { 43 | console.error('Error sending email: ' + error); 44 | } else { 45 | console.log('Email sent: ' + info.response); 46 | } 47 | }); 48 | 49 | } 50 | -------------------------------------------------------------------------------- /my-app/src/components/Products/Product.js: -------------------------------------------------------------------------------- 1 | import React from 'react' 2 | import StarIcon from '@mui/icons-material/Star'; 3 | 4 | 5 | const Product = ({data}) => { 6 | return ( 7 |
8 | 9 |
10 |
11 | images 12 |
13 |
14 |

{ data.title.length > 40 ? data.title.slice(0 , 40)+'...' : data.title}

15 |
16 |
17 |

{data.rating &&data.rating.toFixed(2)}

18 | 19 |
20 |

Reviews ({data.reviews.length})

21 |
22 | 23 |

Rs. {data.price} 24 | 25 | Rs. { data.cureted_price} 26 | 27 | { (((data.cureted_price - data.price)/data.cureted_price) * 100).toFixed(2) }% 28 | 29 |

30 |
31 |
32 | 33 |
34 | ) 35 | } 36 | 37 | export default Product -------------------------------------------------------------------------------- /server/models/ProductModel.js: -------------------------------------------------------------------------------- 1 | const mongoose = require('mongoose'); 2 | 3 | const ProductModel = new mongoose.Schema({ 4 | title:{ 5 | type:String, 6 | required :true 7 | }, 8 | decr:{ 9 | type:String, 10 | }, 11 | rating:{ 12 | type:Number, 13 | default:0 14 | }, 15 | numrev :{ 16 | type:Number, 17 | default:0 18 | }, 19 | stock:{ 20 | type:Number, 21 | default:1 22 | }, 23 | images:[{ 24 | url:{ 25 | type:String, 26 | required:true 27 | }, 28 | public_id:{ 29 | type:String 30 | } 31 | }], 32 | reviews:[{ 33 | user:{ 34 | type:mongoose.SchemaTypes.ObjectId, 35 | ref:'user', 36 | required:true 37 | }, 38 | name:{ 39 | type :String, 40 | required : true 41 | }, 42 | rate:{ 43 | type:Number, 44 | required:true 45 | }, 46 | Comment:{ 47 | type:String, 48 | required:true 49 | }, 50 | date:{ 51 | type:Date, 52 | default:Date.now() 53 | } 54 | }], 55 | sell:{ 56 | type:Number, 57 | default:0 58 | }, 59 | waranty:{ 60 | type:String 61 | }, 62 | brand:{ 63 | type:String 64 | }, 65 | cureted_price:{ 66 | type:Number, 67 | required:true 68 | }, 69 | price:{ 70 | type:Number, 71 | required:true 72 | }, 73 | features:[], 74 | category:{ 75 | type:String, 76 | required:true 77 | } 78 | }) 79 | 80 | 81 | 82 | module.exports = mongoose.model('product',ProductModel) -------------------------------------------------------------------------------- /my-app/src/constants/ProductConstants.js: -------------------------------------------------------------------------------- 1 | export const Product_Request = "Product_Request" 2 | export const Product_Success = "Product_success" 3 | export const Product_Fail = "Product_Fail" 4 | 5 | export const Product_Detials_Request = "Product_Detials_Request" 6 | export const Product_Detials_Success = "Product_Detials_Success" 7 | export const Product_Detials_Fail = "Product_Detials_Fail" 8 | 9 | export const Search_Product_Request = "Search_Product_Request" 10 | export const Search_Product_Success = "Search_Product_Success" 11 | export const Search_Product_Fail = "Search_Product_Fail" 12 | 13 | export const Admin_Product_Request = "Admin_Product_Request" 14 | export const Admin_Product_Success = "Admin_Product_Success" 15 | export const Admin_Product_FAil = "Admin_Product_Fail" 16 | 17 | export const Create_Product_Request = "Create_Product_Request" 18 | export const Create_Product_Success = "Create_Product_Success" 19 | export const Create_Product_Fail = "Create_Product_Fail" 20 | 21 | export const Update_Product_Request = "Update_Product_Request" 22 | export const Upadate_Product_Success = "Update_Product_Success" 23 | export const Update_Product_Fail = "Update_Product_Fail" 24 | 25 | export const New_Review_Request = "New_Review_Request" 26 | export const New_Review_Sucess = "New_Review_Sucess" 27 | export const New_Review_Fail = "New_Review_Fail" 28 | export const New_Review_Reset = "New_Review_Reset" 29 | 30 | export const Delete_Product_Request = "Delete_Product_Request" 31 | export const Delete_Product_Sucess = "Delete_Product_Sucess" 32 | export const Delete_Product_Fail = "Delete_Product_Fail" 33 | 34 | export const Top_Product_Request = "Top_Product_Request" 35 | export const Top_Product_Success = "Top_Product_success" 36 | export const Top_Product_Fail = "Top_Product_Fail" 37 | 38 | export const Clear_Error = "CLear_Error" -------------------------------------------------------------------------------- /my-app/src/components/orders/Order.js: -------------------------------------------------------------------------------- 1 | import React from 'react' 2 | import { NavLink } from 'react-router-dom' 3 | 4 | const Order = ({order}) => { 5 | 6 | const colors = { 7 | processing : 'bg-orange-100 text-orange-500', 8 | delivered : 'bg-green-100 text-green-500' 9 | } 10 | 11 | return ( 12 |
13 |
14 | 15 |
16 | 17 |
18 | 19 | {/* description */} 20 |
21 |

{ (order.orderitems[0].name).slice(0, 30)+'....'}

22 |

quantity : {order.orderitems[0].quantity}

23 |

Price : Rs. {order.orderitems[0].price}

24 |
25 | {/* description */} 26 | 27 |
28 | 29 | 30 | 31 |
32 | 33 | {/* 79 | 80 | mockup 81 | mockups 82 | 83 | 84 | 85 | 86 |
87 | 88 |

📬 Contact

89 | 90 | If you want to contact me, you can reach me through below handles. 91 | 92 | [![linkedin](https://img.shields.io/badge/LinkedIn-0077B5?style=for-the-badge&logo=linkedin&logoColor=white)](https://www.linkedin.com/in/mahesh-patil-bb4ba5218/) 93 | 94 | © 2023 Mahesh Patil 95 | -------------------------------------------------------------------------------- /my-app/src/Reducers/OrderReducer.js: -------------------------------------------------------------------------------- 1 | import { Admin_Orders_Fail, Admin_Orders_Request, Admin_Orders_Sucess, Clear_Error, Delete_Order_Fail, Delete_Order_Request, Delete_Order_Sucess, My_Order_Fail, My_Order_Request, My_Order_Sucess, New_Order_Fail, New_Order_Request, New_Order_Success, Order_Detial_Fail, Order_Detial_Request, Order_Detial_Sucess, Update_Order_Fail, Update_Order_Request, Update_Order_Sucess } from "../constants/OrderConstants"; 2 | 3 | 4 | export const NewOrderReducer = (state = { order:{}} , action)=>{ 5 | 6 | 7 | switch(action.type){ 8 | 9 | case New_Order_Request : 10 | return{ 11 | loading : true, 12 | } 13 | case New_Order_Success:{ 14 | return { 15 | ...state, 16 | loading : false, 17 | order : action.payload 18 | } 19 | } 20 | 21 | case New_Order_Fail:{ 22 | return{ 23 | ...state, 24 | loading:false, 25 | error : action.payload 26 | } 27 | } 28 | 29 | case Clear_Error:{ 30 | return{ 31 | ...state, 32 | error : null 33 | } 34 | } 35 | 36 | default : return state 37 | } 38 | } 39 | 40 | 41 | 42 | 43 | export const MyordersReducer = (state = { orders : [] } , action) =>{ 44 | switch(action.type){ 45 | 46 | case My_Order_Request : 47 | return { 48 | loading : true, 49 | } 50 | 51 | case My_Order_Sucess : { 52 | return { 53 | ...state, 54 | loading : false, 55 | orders : action.payload 56 | } 57 | } 58 | 59 | case My_Order_Fail : { 60 | return { 61 | ...state, 62 | loading : false, 63 | error : action.payload 64 | } 65 | } 66 | 67 | default : return state 68 | 69 | } 70 | 71 | } 72 | 73 | 74 | export const OrderDetialReducer = (state = { order : {} } , action) =>{ 75 | 76 | switch(action.type){ 77 | 78 | case Order_Detial_Request : 79 | return { 80 | loading : true, 81 | } 82 | 83 | case Order_Detial_Sucess : { 84 | return { 85 | ...state, 86 | loading : false, 87 | order : action.payload 88 | } 89 | } 90 | 91 | case Order_Detial_Fail : { 92 | return { 93 | ...state, 94 | loading : false, 95 | error : action.payload 96 | } 97 | } 98 | 99 | case Update_Order_Request : { 100 | return { 101 | loading : true, 102 | isUpdated : false 103 | } 104 | } 105 | 106 | case Update_Order_Sucess : { 107 | return { 108 | ...state, 109 | loading : false, 110 | isUpdated : true 111 | } 112 | } 113 | 114 | case Update_Order_Fail : { 115 | return { 116 | loading : false, 117 | error : action.payload , 118 | isUpdated : false 119 | } 120 | } 121 | 122 | case Clear_Error : { 123 | return{ 124 | loading : false, 125 | error : null 126 | } 127 | } 128 | 129 | default : return state 130 | 131 | } 132 | 133 | } 134 | 135 | 136 | export const AdminOrdersReducer = (state = { orders : [] } , action) =>{ 137 | switch(action.type){ 138 | 139 | case Admin_Orders_Request : 140 | return { 141 | loading : true, 142 | orders : [ ] 143 | } 144 | 145 | case Admin_Orders_Sucess : { 146 | return { 147 | ...state, 148 | loading : false, 149 | orders : action.payload 150 | } 151 | } 152 | 153 | case Admin_Orders_Fail : { 154 | return { 155 | ...state, 156 | loading : false, 157 | error : action.payload 158 | } 159 | } 160 | 161 | case Delete_Order_Request : return { 162 | loading : true, 163 | isDeleted : false, 164 | orders : [] 165 | } 166 | 167 | case Delete_Order_Sucess : { 168 | return{ 169 | ...state , 170 | loading : false, 171 | isDeleted : true, 172 | orders : [] 173 | } 174 | } 175 | 176 | case Delete_Order_Fail : { 177 | return{ 178 | ...state , 179 | loading : false, 180 | isDeleted : false, 181 | orders : [] 182 | } 183 | } 184 | 185 | default : return state 186 | 187 | } 188 | 189 | } -------------------------------------------------------------------------------- /my-app/src/components/Invoice/InvoiceContent.js: -------------------------------------------------------------------------------- 1 | import React, { useEffect, useState } from 'react' 2 | 3 | const InvoiceContent = ({ invoiceData }) => { 4 | 5 | const [totalamount, setTotalamount] = useState(0) 6 | 7 | 8 | useEffect(()=>{ 9 | const calculateTotal = () => { 10 | return setTotalamount(invoiceData && invoiceData.items && invoiceData.items.reduce((total, item) => total + item.quantity * item.price, 0)); 11 | }; 12 | calculateTotal() 13 | },[invoiceData]) 14 | 15 | 16 | return ( 17 |
18 |
19 |
20 | 21 |
22 |

Invoice

23 |

Date: {invoiceData.date}

24 |
25 |
26 |
27 |
28 |

From : {invoiceData.from}

29 |

To : {invoiceData.to}

30 |
31 | 32 | 33 |
34 |

Shipping Address

35 |

Address : {invoiceData && invoiceData.shiping && invoiceData.shiping.address}

36 |

pincode : {invoiceData && invoiceData.shiping && invoiceData.shiping.pincode}

37 |

state : {invoiceData && invoiceData.shiping && invoiceData.shiping.state}

38 |

country : {invoiceData && invoiceData.shiping && invoiceData.shiping.country}

39 |
40 | 41 |
42 |

Payment Information

43 |

Payment Id : {invoiceData && invoiceData.paymentinfo && invoiceData.paymentinfo.id}

44 |

Payment status : {invoiceData && invoiceData.paymentinfo && invoiceData.paymentinfo.status}

45 | 46 |
47 | 48 |

Products Information

49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | {invoiceData && invoiceData.items && invoiceData.items.map((item, index) => ( 60 | 61 | 62 | 63 | 64 | 65 | 66 | ))} 67 | 68 | 69 | 70 | 71 | 72 | 73 | 74 | 75 | 76 | 77 | 78 | 79 | 80 | 81 | 82 | 83 | 86 | 87 | 88 |
ItemQuantityPriceTotal
{item.name}{item.quantity}Rs.{item.price}Rs.{item.quantity * item.price}
TaxRs.{ invoiceData.shipingprice}
DeliveryRs.{invoiceData.taxprice}
Total 84 | Rs.{totalamount + invoiceData.taxprice + invoiceData.shipingprice} 85 |
89 |
90 |

Authorized Signature

91 |
92 | signature 93 |
94 |

Seller

95 |
96 |
97 | {/*
98 |

Total: ${calculateTotal(invoiceData.items)}

99 |
*/} 100 |
101 |
102 | ) 103 | } 104 | 105 | export default InvoiceContent -------------------------------------------------------------------------------- /my-app/src/App.js: -------------------------------------------------------------------------------- 1 | import { Route, Routes } from "react-router-dom"; 2 | import Home from "./components/home/Home"; 3 | import Footer from "./components/layout/footer/Footer"; 4 | import Header from "./components/layout/Header/Header"; 5 | import ProductDetials from "./components/productdetials/ProductDetials"; 6 | import Produtcs from "./components/Products/Produtcs"; 7 | import Cart from "./components/cart/Cart"; 8 | import Register from "./components/User/Register"; 9 | import Login from "./components/User/Login"; 10 | import Account from "./components/User/Account"; 11 | import Wishlist from "./components/Wishlist/Wishlist"; 12 | import Orders from "./components/orders/Orders"; 13 | import CheckoutOrder from "./components/orders/CheckoutOrder"; 14 | import Dashboard from "./components/Admin/Dashboard"; 15 | import MainData from "./components/Admin/MainData"; 16 | import OrderList from "./components/Admin/OrderList"; 17 | import ProductList from "./components/Admin/ProductList"; 18 | import CreateProduct from "./components/Admin/CreateProduct"; 19 | import UpdateProduct from "./components/Admin/UpdateProduct"; 20 | import UsersList from "./components/Admin/UsersList"; 21 | import PaymentSucess from "./components/orders/PaymentSucess"; 22 | import OrderDetial from "./components/orders/OrderDetial"; 23 | import { useDispatch, useSelector } from "react-redux"; 24 | import { useEffect } from "react"; 25 | import { Clear_Errors, LoadUser } from "./actions/UserActions"; 26 | import Invoice from "./components/Invoice/Invoice"; 27 | import ProtectedRoutes from "./Routes/ProtectedRoutes"; 28 | 29 | 30 | 31 | function App() { 32 | 33 | const dispatch = useDispatch(); 34 | 35 | useEffect(()=>{ 36 | 37 | dispatch(LoadUser()) 38 | 39 | 40 | },[dispatch]) 41 | 42 | 43 | return ( 44 |
45 |
46 | 47 | }/> 48 | 49 | }/> 50 | }/> 51 | }/> 52 | }/> 53 | }/> 54 | }/> 55 | }/> 56 | }/> 57 | }/> 58 | }/> 59 | }/> 60 | }/> 61 | 63 | 64 | 65 | 66 | } 67 | /> 68 | 69 | 72 | 73 | 74 | 75 | } 76 | /> 77 | 80 | 81 | 82 | 83 | 84 | } 85 | /> 86 | 89 | 90 | 91 | 92 | 93 | }/> 94 | 97 | 98 | 99 | 100 | 101 | }/> 102 | 103 | 106 | 107 | 108 | 109 | 110 | }/> 111 | 112 | 115 | 116 | 117 | 118 | 119 | }/> 120 | 123 | 124 | 125 | 126 | 127 | }/> 128 | 129 | 130 |
131 |
132 | ); 133 | } 134 | 135 | export default App; 136 | -------------------------------------------------------------------------------- /my-app/src/Reducers/ProductReducer.js: -------------------------------------------------------------------------------- 1 | import { Admin_Product_FAil, Admin_Product_Request, Admin_Product_Success, Create_Product_Fail, Create_Product_Request, Create_Product_Success, Product_Detials_Fail, Product_Detials_Request, Product_Detials_Success, Product_Fail, Product_Request, Product_Success, Update_Product_Request ,Upadate_Product_Success , Update_Product_Fail, New_Review_Request, New_Review_Sucess, New_Review_Fail, New_Review_Reset, Clear_Error, Delete_Product_Request, Delete_Product_Sucess, Delete_Product_Fail, Top_Product_Request, Top_Product_Success, Top_Product_Fail } from "../constants/ProductConstants"; 2 | 3 | 4 | 5 | // search products 6 | // electornics products 7 | // similar 8 | 9 | export const ProductsReducer = ( state = { products : [] } , action )=>{ 10 | switch(action.type){ 11 | 12 | case Product_Request : return { 13 | loading : true, 14 | products : {} 15 | } 16 | case Product_Success : return { 17 | ...state, 18 | loading : false, 19 | products : { 20 | ...state.products, 21 | [action.producttype] : action.payload.products 22 | }, 23 | ProductCount : action.payload.productCount 24 | } 25 | case Product_Fail : return { 26 | loading : false, 27 | products : {}, 28 | error : action.payload 29 | } 30 | case Admin_Product_Request : return { 31 | loading : true, 32 | adminproducts : [] 33 | } 34 | case Admin_Product_Success : return { 35 | ...state, 36 | loading : false, 37 | adminproducts : action.payload.products, 38 | ProductCount : action.payload.productCount 39 | } 40 | case Admin_Product_FAil : return { 41 | loading : false, 42 | adminproducts : [], 43 | error : action.payload 44 | } 45 | 46 | case Delete_Product_Request : return { 47 | loading : true, 48 | isDeleted : false, 49 | products : [] 50 | } 51 | 52 | case Delete_Product_Sucess : { 53 | return{ 54 | ...state , 55 | loading : false, 56 | isDeleted : true, 57 | products : [] 58 | } 59 | } 60 | 61 | case Delete_Product_Fail : { 62 | return{ 63 | ...state , 64 | loading : false, 65 | isDeleted : false, 66 | products : [] 67 | } 68 | } 69 | default : return state 70 | 71 | } 72 | } 73 | 74 | 75 | export const Product_detial_reducer = ( state = { product:[] } , action) =>{ 76 | 77 | switch (action.type) { 78 | case Product_Detials_Request : return{ 79 | ...state, 80 | loading : true, 81 | isUpdated:false 82 | 83 | } 84 | case Product_Detials_Success : return { 85 | loading:false, 86 | product : action.payload, 87 | isUpdated:false 88 | } 89 | case Product_Detials_Fail : return { 90 | loading:false, 91 | error : action.error, 92 | isUpdated:false 93 | } 94 | 95 | case Update_Product_Request : return { 96 | ...state, 97 | loading : true, 98 | isUpdated: action.isUpdated 99 | } 100 | 101 | case Upadate_Product_Success : return{ 102 | ...state, 103 | loading:false, 104 | isUpdated: action.isUpdated, 105 | product : action.payload 106 | } 107 | 108 | case Update_Product_Fail : return{ 109 | ...state, 110 | loading:false, 111 | isUpdated:false, 112 | error : action.payload 113 | } 114 | 115 | default : return state 116 | 117 | } 118 | } 119 | 120 | 121 | export const CreateProduct = (state = { product : {}},action)=>{ 122 | switch(action.type){ 123 | case Create_Product_Request : return { 124 | loading : true, 125 | sucess:false 126 | } 127 | 128 | case Create_Product_Success : return{ 129 | ...state, 130 | loading:false, 131 | product : action.payload, 132 | sucess : true, 133 | } 134 | 135 | case Create_Product_Fail : return{ 136 | ...state, 137 | loading:false, 138 | error : action.payload, 139 | sucess : false 140 | } 141 | 142 | default : return state 143 | 144 | } 145 | 146 | 147 | } 148 | 149 | 150 | export const newReviewReducer = (state = {}, { type, payload }) => { 151 | switch (type) { 152 | case New_Review_Request: 153 | return { 154 | ...state, 155 | loading: true, 156 | }; 157 | case New_Review_Sucess: 158 | return { 159 | loading: false, 160 | success: payload, 161 | }; 162 | case New_Review_Fail: 163 | return { 164 | ...state, 165 | loading: false, 166 | error: payload, 167 | }; 168 | 169 | case New_Review_Reset : 170 | return{ 171 | ...state, 172 | success : false 173 | } 174 | case Clear_Error: 175 | return { 176 | ...state, 177 | error: null, 178 | }; 179 | 180 | default: 181 | return state; 182 | } 183 | } 184 | 185 | 186 | 187 | export const Top_Product_Reducer = ( state = { products:[] } , action) =>{ 188 | 189 | switch (action.type) { 190 | case Top_Product_Request : return{ 191 | loading : true, 192 | products: [] 193 | } 194 | case Top_Product_Success : return { 195 | loading:false, 196 | products : action.payload 197 | } 198 | case Top_Product_Fail : return { 199 | loading:false, 200 | error : action.error 201 | } 202 | 203 | 204 | default : return state 205 | 206 | } 207 | } 208 | 209 | 210 | -------------------------------------------------------------------------------- /my-app/src/actions/ProductActions.js: -------------------------------------------------------------------------------- 1 | import { Axios } from '../Axios' 2 | import { Admin_Product_FAil, Admin_Product_Request, Admin_Product_Success, Clear_Error, Create_Product_Fail, Create_Product_Request, Create_Product_Success, Delete_Product_Fail, Delete_Product_Request, Delete_Product_Sucess, New_Review_Fail, New_Review_Request, New_Review_Reset, New_Review_Sucess, Product_Detials_Fail, Product_Detials_Request, Product_Detials_Success ,Product_Fail, Product_Request, Product_Success, Top_Product_Fail, Top_Product_Request, Top_Product_Success, Upadate_Product_Success, Update_Product_Fail, Update_Product_Request} from '../constants/ProductConstants' 3 | 4 | export const getproduct = (key = " " , min , max , page=1 , category , rating , prodtype ) => async ( dispatch )=>{ 5 | try { 6 | dispatch({ 7 | type : Product_Request 8 | }) 9 | let link 10 | if(category){ 11 | link = `/getall/products?name=${key}&page=${page}&category=${category}` 12 | }else{ 13 | link = `/getall/products?name=${key}&page=${page}&price[gte]=${min}&price[lte]=${max}&rating[gte]=${rating}` 14 | } 15 | const {data} = await Axios.get(link) 16 | 17 | // console.log(data); 18 | dispatch({ 19 | type:Product_Success, 20 | payload:data, 21 | producttype: prodtype 22 | }) 23 | 24 | } catch (error) { 25 | dispatch({ 26 | type:Product_Fail, 27 | error: error 28 | }) 29 | } 30 | 31 | } 32 | 33 | 34 | export const getproddetials = (id) => async(dispatch)=>{ 35 | try { 36 | dispatch({ 37 | type : Product_Detials_Request 38 | }) 39 | 40 | const {data} = await Axios.get(`/product/${id}`) 41 | 42 | dispatch({ 43 | type:Product_Detials_Success, 44 | payload:data.product, 45 | }) 46 | } catch (error) { 47 | dispatch({ 48 | type:Product_Detials_Fail, 49 | error:error 50 | }) 51 | } 52 | } 53 | 54 | 55 | 56 | // get top products 57 | export const GetTopProducts = () => async(dispatch)=>{ 58 | try { 59 | dispatch({ 60 | type : Top_Product_Request 61 | }) 62 | 63 | const {data} = await Axios.get(`/top/products`) 64 | 65 | dispatch({ 66 | type:Top_Product_Success, 67 | payload:data.products, 68 | }) 69 | } catch (error) { 70 | dispatch({ 71 | type: Top_Product_Fail, 72 | error:error 73 | }) 74 | } 75 | } 76 | 77 | 78 | 79 | 80 | 81 | // Admin Actions 82 | 83 | export const AdminGetProducts = () =>async(dispatch)=>{ 84 | try { 85 | dispatch({ 86 | type : Admin_Product_Request 87 | }) 88 | 89 | let link = `/admin/products` 90 | const {data} = await Axios.get(link) 91 | 92 | dispatch({ 93 | type:Admin_Product_Success, 94 | payload:data, 95 | }) 96 | 97 | } catch (error) { 98 | dispatch({ 99 | type:Admin_Product_FAil, 100 | error: error 101 | }) 102 | } 103 | 104 | } 105 | 106 | 107 | export const CreateProducts = (formdata) => async(dispatch)=>{ 108 | try { 109 | 110 | dispatch({ 111 | type: Create_Product_Request 112 | }) 113 | 114 | // const config = { headers : { "Content-Type" : "application/json" } } 115 | 116 | const {data} = await Axios.post('/create/product', formdata ) 117 | 118 | dispatch({ 119 | type:Create_Product_Success, 120 | payload : data 121 | }) 122 | } catch (error) { 123 | console.log(error); 124 | dispatch({ 125 | type: Create_Product_Fail, 126 | payload:error.response.data.error 127 | }) 128 | } 129 | } 130 | 131 | 132 | export const newReview = (reviewData) => async (dispatch) => { 133 | try { 134 | dispatch({ type: New_Review_Request }); 135 | const config = { header: { "Content-Type": "application/json" } } 136 | const { data } = await Axios.put("/add/review", reviewData, config); 137 | console.log(data); 138 | dispatch({ 139 | type: New_Review_Sucess, 140 | payload: data.sucess, 141 | }); 142 | } catch (error) { 143 | dispatch({ 144 | type: New_Review_Fail, 145 | payload: error.response.data.message, 146 | }); 147 | } 148 | } 149 | 150 | 151 | 152 | export const UpdateProducts = (formdata ,id) => async(dispatch)=>{ 153 | try { 154 | 155 | dispatch({ 156 | type: Update_Product_Request, 157 | isUpdated : false 158 | }) 159 | 160 | // const config = { headers : { "Content-Type" : "application/json" } } 161 | 162 | const {data} = await Axios.put(`/update/product/${id}`, formdata ) 163 | console.log(data); 164 | dispatch({ 165 | type: Upadate_Product_Success, 166 | payload : data.product, 167 | isUpdated : true 168 | }) 169 | } catch (error) { 170 | dispatch({ 171 | type: Update_Product_Fail, 172 | payload:error.responce 173 | }) 174 | } 175 | } 176 | 177 | 178 | export const Delete_Product = (id) => async(dispatch) => { 179 | try { 180 | 181 | dispatch({ 182 | type : Delete_Product_Request 183 | }) 184 | 185 | 186 | const {data} = await Axios.delete(`/delete/product/${id}`) 187 | console.log(data); 188 | dispatch({ 189 | type : Delete_Product_Sucess, 190 | }) 191 | } catch (error) { 192 | console.log(error); 193 | dispatch({ 194 | type : Delete_Product_Fail , 195 | payload : error.responce 196 | }) 197 | } 198 | } 199 | 200 | 201 | export const ClearError = () => (dispatch) => { 202 | dispatch({ 203 | type : Clear_Error 204 | }) 205 | } 206 | 207 | export const Reset_Review = () => (dispatch) => { 208 | dispatch({ 209 | type : New_Review_Reset 210 | }) 211 | } 212 | 213 | 214 | 215 | 216 | // categorywise search products 217 | 218 | 219 | 220 | 221 | 222 | 223 | 224 | -------------------------------------------------------------------------------- /my-app/src/components/Admin/MainData.js: -------------------------------------------------------------------------------- 1 | import React, { useEffect } from 'react' 2 | import { Bar, Doughnut, Line, Pie } from "react-chartjs-2"; 3 | import { Chart, elements } from 'chart.js/auto'; 4 | import ShoppingCartIcon from '@mui/icons-material/ShoppingCart'; 5 | import PermContactCalendarIcon from '@mui/icons-material/PermContactCalendar'; 6 | import { Avatar, IconButton } from '@mui/material' 7 | import Inventory from '@mui/icons-material/Inventory' 8 | import CurrencyRupeeIcon from '@mui/icons-material/CurrencyRupee'; 9 | import { useDispatch, useSelector } from 'react-redux'; 10 | import { AdminGetProducts } from '../../actions/ProductActions'; 11 | import { AdminGetUsers } from '../../actions/UserActions'; 12 | import { AdminGetOrders } from '../../actions/OrderActions'; 13 | 14 | 15 | 16 | const MainData = () => { 17 | 18 | 19 | const dispatch = useDispatch() 20 | const {adminproducts, ProductCount} = useSelector(state=>state.AllProducts) 21 | const { users} = useSelector(state=>state.AllUser) 22 | const { orders} = useSelector(state=>state.AllOrders) 23 | 24 | 25 | let totalamount = orders?.reduce((total, order) => total + order.totalprice, 0); 26 | 27 | 28 | const months = ['January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December'] 29 | 30 | const lables = ['processing', 'delivered' , 'canceled'] 31 | 32 | const data = { 33 | labels: lables, 34 | // datasets is an array of objects where each object represents a set of data to display corresponding to the labels above. for brevity, we'll keep it at one object 35 | datasets: [ 36 | { 37 | label: 'Popularity of colours', 38 | data: lables.map((elem , index)=> orders && orders.reduce((total , curr)=> { 39 | if(curr.orderstatus === elem){ 40 | total++; 41 | } 42 | return total 43 | } , 0) ), 44 | // you can set indiviual colors for each bar 45 | backgroundColor: [ 46 | 'orange', 47 | '#98fb98', 48 | '#f1807e', 49 | ], 50 | borderWidth: 1, 51 | width: 1, 52 | height: 1 53 | 54 | } 55 | ] 56 | } 57 | 58 | let date = new Date() 59 | 60 | 61 | const bardata = { 62 | labels: months, 63 | // datasets is an array of objects where each object represents a set of data to display corresponding to the labels above. for brevity, we'll keep it at one object 64 | datasets: [ 65 | { 66 | label: `Sales in ${date.getFullYear()}`, 67 | data: months.map((m, i) => orders?.filter((od) => new Date(od.createdAt).getMonth() === i && new Date(od.createdAt).getFullYear() === date.getFullYear()).reduce((total, od) => total + od.totalprice, 0)) 68 | , 69 | // you can set indiviual colors for each bar 70 | backgroundColor: [ 71 | 'lightblue' 72 | ], 73 | borderWidth: 1, 74 | borderRadius: 4 75 | 76 | }, 77 | { 78 | label: `Sales in ${date.getFullYear() - 1}`, 79 | data: months.map((m, i) => orders?.filter((od) => new Date(od.createdAt).getMonth() === i && new Date(od.createdAt).getFullYear() === date.getFullYear() - 2).reduce((total, od) => total + od.totalPrice, 0)), 80 | // you can set indiviual colors for each bar 81 | backgroundColor: [ 82 | 'blue' 83 | ], 84 | borderWidth: 1, 85 | borderRadius: 4 86 | 87 | 88 | } 89 | ] 90 | } 91 | 92 | 93 | let outofstock = 0; 94 | adminproducts && adminproducts.forEach((elem)=>{ 95 | if(elem.stock<=0){ 96 | outofstock = outofstock + 1; 97 | } 98 | }) 99 | 100 | 101 | const piedata = { 102 | labels: ['stock', 'Out of stock'], 103 | // datasets is an array of objects where each object represents a set of data to display corresponding to the labels above. for brevity, we'll keep it at one object 104 | datasets: [ 105 | { 106 | label: 'Popularity of colours', 107 | data: [ adminproducts && adminproducts.length - outofstock, outofstock], 108 | // you can set indiviual colors for each bar 109 | backgroundColor: [ 110 | 'lightblue', 111 | '#ff9ab4' 112 | ], 113 | borderWidth: 1, 114 | width: 1, 115 | height: 1 116 | 117 | } 118 | ] 119 | 120 | 121 | } 122 | 123 | 124 | 125 | 126 | useEffect(()=>{ 127 | dispatch(AdminGetProducts()) 128 | dispatch(AdminGetUsers()) 129 | dispatch(AdminGetOrders()) 130 | },[dispatch]) 131 | 132 | return ( 133 |
134 | 135 | {/*