From 2d1d8a380d812ec64afdb8ec2628564e38a57c79 Mon Sep 17 00:00:00 2001 From: pawan-dot <71133473+pawan-dot@users.noreply.github.com> Date: Thu, 12 May 2022 16:40:44 +0530 Subject: [PATCH] add commerce --- package.json | 4 + public/index.html | 12 +- src/App.js | 7 +- src/_nav.js | 21 ++ src/components/AppFooter.js | 2 +- src/components/AppSidebar.js | 2 +- src/components/AppSidebarNav.js | 20 +- src/data.js | 18 ++ src/index.js | 7 + src/routes.js | 8 + src/views/Commerce/Coupons.js | 0 src/views/Commerce/Editproducts.js | 326 +++++++++++++++++++++++++++++ src/views/Commerce/Products.js | 289 +++++++++++++++++++++++++ src/views/Profile/Profile.js | 2 +- 14 files changed, 705 insertions(+), 13 deletions(-) create mode 100644 src/data.js create mode 100644 src/views/Commerce/Coupons.js create mode 100644 src/views/Commerce/Editproducts.js create mode 100644 src/views/Commerce/Products.js diff --git a/package.json b/package.json index 132d40c..e4c48bf 100644 --- a/package.json +++ b/package.json @@ -39,6 +39,7 @@ "@coreui/utils": "^1.3.1", "@wojtekmaj/enzyme-adapter-react-17": "^0.6.5", "axios": "^0.25.0", + "bootstrap": "^5.1.3", "chart.js": "^3.6.0", "classnames": "^2.3.1", "core-js": "^3.19.1", @@ -51,10 +52,13 @@ "react-dom": "^17.0.2", "react-redux": "^7.2.6", "react-router-dom": "^5.3.0", + "react-spinners": "^0.11.0", "redux": "4.1.2", "serve": "^13.0.2", "simplebar-react": "^2.3.6", + "sweetalert": "^2.1.2", "sweetalert2": "^11.4.0", + "webpack": "^4.44.2", "xlsx": "^0.18.0" }, "devDependencies": { diff --git a/public/index.html b/public/index.html index fe8831b..523f748 100644 --- a/public/index.html +++ b/public/index.html @@ -15,13 +15,15 @@ - Courier + Cafe-Appy2Meet + + + + + + @@ -48,6 +55,9 @@ To begin the development, run `npm start` or `yarn start`. To create a production bundle, use `npm run build` or `yarn build`. --> + + + \ No newline at end of file diff --git a/src/App.js b/src/App.js index cb06d2f..6da4010 100644 --- a/src/App.js +++ b/src/App.js @@ -9,7 +9,7 @@ const loading = (
) - +// import EditProducts from './views/Commerce/Editproducts' // Containers const DefaultLayout = React.lazy(() => import('./layout/DefaultLayout')) @@ -28,6 +28,11 @@ class App extends Component { } /> } /> } /> + + + + + {/* } /> */} {/* , + items: [ + { + component: CNavItem, + name: 'Products', + to: '/comproducts', + }, + { + component: CNavItem, + name: 'Coupons', + to: '/comcoupon', + }, + + ], + }, + // { // component: CNavGroup, // name: 'Profile', diff --git a/src/components/AppFooter.js b/src/components/AppFooter.js index ab5aada..f8077fa 100644 --- a/src/components/AppFooter.js +++ b/src/components/AppFooter.js @@ -8,7 +8,7 @@ const AppFooter = () => { {/* CoreUI */} - © 2021 Courier. + {new Date().getFullYear()} © Appy2Meet. {/*
Powered by diff --git a/src/components/AppSidebar.js b/src/components/AppSidebar.js index 85ee00a..d2f80fb 100644 --- a/src/components/AppSidebar.js +++ b/src/components/AppSidebar.js @@ -31,7 +31,7 @@ const AppSidebar = () => { > {/* */} -

Courier

+

Appy2Meet

{/* */}
diff --git a/src/components/AppSidebarNav.js b/src/components/AppSidebarNav.js index db6e3bd..21d30ae 100644 --- a/src/components/AppSidebarNav.js +++ b/src/components/AppSidebarNav.js @@ -16,6 +16,7 @@ export const AppSidebarNav = ({ items }) => { {badge.text} )} + ) } @@ -24,17 +25,20 @@ export const AppSidebarNav = ({ items }) => { const { component, name, badge, icon, ...rest } = item const Component = component return ( - + + - {navLink(name, icon, badge)} - + key={index} + {...rest} + > + {navLink(name, icon, badge)} + + ) } const navGroup = (item, index) => { diff --git a/src/data.js b/src/data.js new file mode 100644 index 0000000..37d2514 --- /dev/null +++ b/src/data.js @@ -0,0 +1,18 @@ +// export const API = "https://mantur-server.herokuapp.com"; +// export const API = "https://api.tellytell.com"; +// export const API = "http://localhost:5000"; +// export const API = "https://popstoreeee.herokuapp.com"; + +import { useEffect } from 'react'; + +//export const API = 'https://dating-api-server.herokuapp.com'; +// export const API = 'http://localhost:5000'; + +export const buildType = 'development'; +// export const buildType = 'production' + +export const useLogger = (...params) => { + useEffect(() => { + console.log(...params); + }, [params]); +}; diff --git a/src/index.js b/src/index.js index b977723..7db204c 100644 --- a/src/index.js +++ b/src/index.js @@ -1,3 +1,9 @@ +// import 'bootstrap/dist/css/bootstrap.min.css'; +// import "bootstrap/dist/js/bootstrap.js"; + +// import "bootstrap"; +// import "bootstrap/dist/css/bootstrap.css"; +// import "bootstrap/dist/js/bootstrap.js"; import 'react-app-polyfill/stable' import 'core-js' import React from 'react' @@ -10,6 +16,7 @@ import axios from 'axios' const setupAxios = () => { axios.defaults.baseURL = 'https://dating-api-server.herokuapp.com'; + //axios.defaults.baseURL = 'http://localhost:5000' axios.defaults.headers = { 'Cache-Control': 'no-cache,no-store', 'Pragma': 'no-cache', diff --git a/src/routes.js b/src/routes.js index eadac6b..6359e63 100644 --- a/src/routes.js +++ b/src/routes.js @@ -1,4 +1,6 @@ import React from 'react' +import Products from './views/Commerce/Products' +import EditProducts from './views/Commerce/Editproducts' const AirwaysBill = React.lazy(() => import('./views/AirwaysBill/AirwaysBill')) const EditBill = React.lazy(() => import('./views/AirwaysBill/EditBill')) @@ -70,6 +72,12 @@ const routes = [ { path: '/register', name: 'Change Password', component: Register }, { path: '/edit', name: 'Change Password', component: EditProfile }, { path: '/profile', name: 'Change Password', component: Profile }, + + //product route + { path: '/comproducts/edit/:id', name: 'Product Edit', component: EditProducts }, + { path: '/comproducts', name: 'Courier Products', component: Products }, + , + //// { path: '/courier', name: 'Courier', component: Courier }, { path: '/editcourier/:id', name: ' Edit Courier', component: EditCourier }, { path: '/addcourier', name: 'Courier / Add Courier', component: AddCourier }, diff --git a/src/views/Commerce/Coupons.js b/src/views/Commerce/Coupons.js new file mode 100644 index 0000000..e69de29 diff --git a/src/views/Commerce/Editproducts.js b/src/views/Commerce/Editproducts.js new file mode 100644 index 0000000..d742054 --- /dev/null +++ b/src/views/Commerce/Editproducts.js @@ -0,0 +1,326 @@ +import axios from "axios"; +import React, { useCallback, useEffect, useState } from "react"; +// import { API } from "../../data"; +import { isAutheticated } from "../../auth"; +import ClipLoader from "react-spinners/ClipLoader"; +import swal from 'sweetalert'; + +// import "bootstrap"; +// import "bootstrap/dist/css/bootstrap.css"; +// import "bootstrap/dist/js/bootstrap.js"; +import { Link, useParams } from "react-router-dom"; +import { useHistory } from "react-router-dom"; + +function EditProducts() { + const { token } = isAutheticated(); + + let history = useHistory(); + + + const [state, setstate] = useState({ + title: "", + description: "", + status: "", + tax: "", + price: "", + taxes: [], + loading: false, + }); + + const { id } = useParams(); + // console.log(id) + + const { title, description, status, tax, price, taxes, loading } = state; + + const changeState = (newState) => + setstate((prevState) => ({ ...prevState, ...newState })); + + const fetchTax = useCallback(async () => { + let res = await axios.get(`/api/tax/view_tax`, { + headers: { + Authorization: `Bearer ${token}`, + }, + }); + + if (res.status === 200) changeState({ taxes: res.data }); + }, [token]); + + const fetchProduct = useCallback(async () => { + const res = await axios.get(`/api/product/${id}`, { + headers: { + Authorization: `Bearer ${token}`, + }, + }); + + console.log(res.data); + + if (res.status === 200) changeState({ ...res.data }); + }, [id, token]); + + useEffect(() => { + fetchTax(); + fetchProduct(); + }, [fetchTax, fetchProduct]); + + useEffect(() => { + if (!(typeof tax === "object")) return; + changeState({ tax: tax.name }); + }, [tax]); + + const handleSubmit = async () => { + if (!(title || description || tax || price)) { + alert("Please fill required field "); + return; + } + changeState({ loading: true }); + + let res = await axios.put( + `/api/product/${id}`, + { + title, + description, + status, + tax: taxes.find((taxObj) => taxObj.name === tax)?._id, + price, + }, + { + headers: { + Authorization: `Bearer ${token}`, + }, + } + ); + if (res.status === 200) window.location.reload(); + + changeState({ loading: false }); + swal("Edit successfully!"); + history.goBack() + }; + const onCancel = () => { + // window.location = "/comproducts"; + history.goBack() + + }; + + + + const handleChange = (e) => { + const { name, value } = e.target; + + changeState({ [name]: value }); + }; + + return ( +
+
+
+ {/* */} +
+
+
+

Edit {title} Product

+
+
    +
  1. + Dating App +
  2. +
  3. Commerce
  4. +
  5. + Edit Product +
  6. +
+
+
+
+
+ {/* */} + + {/* */} +
+
+
+ + +
+
+
+ {/* */} + + {/* */} +
+ {/* */} +
+
+
+
+
+
+
+
+
+ + +
+
+
+
+
+
+ +
+ +
+
+
+
+
+
+
+
+
+
+ {/* */} + + {/* */} +
+
+
+
+
+
+ {/*
+
+
+ + +
+
+
*/} + +
+
+
+ + +
+
+
+
+
+
+
+
+
+ {/* */} +
+
+ {/* */} +
+
+
+
+
+
+
+
+
+ + +
+
+
+
+
+
+
+
+
+ {/* */} +
+
+ {/* */} +
+ {/* */} + {/*
*/} +
+ ); +} + +export default EditProducts; diff --git a/src/views/Commerce/Products.js b/src/views/Commerce/Products.js new file mode 100644 index 0000000..acd4690 --- /dev/null +++ b/src/views/Commerce/Products.js @@ -0,0 +1,289 @@ +import axios from "axios"; +import React, { useEffect, useState, useCallback, useMemo } from "react"; +import { Link } from "react-router-dom"; +// import { API } from "../../data"; +import { isAutheticated } from "../../auth"; + +function Products() { + const [state, setState] = useState({ + products: [], + page: 1, + limit: 10, + totalProducts: 0, + pages: 1, + }); + + window.scrollTo({ behavior: "smooth", top: "0px" }); + + const { products, page, limit, totalProducts, pages } = state; + + const changeState = (newState) => + setState((prevState) => ({ ...prevState, ...newState })); + + const { token } = isAutheticated(); + + const getProducts = useCallback(async () => { + let res = await axios.get( + `/api/product?page=${page}&limit=${limit}`, + { + headers: { + Authorization: `Bearer ${token}`, + }, + } + ); + + changeState({ + ...res.data, + pages: Math.ceil(res.data.totalProducts / limit), + }); + }, [limit, page, token]); + + useEffect(() => { + getProducts(); + }, [getProducts]); + + const getTotalPages = useMemo(() => { + const length = pages > 1 ? pages : totalProducts ? 1 : 0; + return Array.from({ length }, (_, i) => i + 1); + }, [pages, totalProducts]); + + // console.log(getTotalPages); + + const handleDelete = async (id) => { + let status = window.confirm("Do you want to delete"); + if (!status) return; + + let res = await axios.delete(`/api/product/${id}`, { + headers: { + Authorization: `Bearer ${token}`, + }, + }); + if (res.status === 200) window.location.reload(); + }; + + const toggleStatus = async (id) => { + let status = window.confirm("Do you want to delete"); + if (!status) { + return; + } + let res = await axios.get(`/api/product/setStatus/${id}`, { + headers: { + Authorization: `Bearer ${token}`, + }, + }); + if (res.status === 200) window.location.reload(); + }; + + return ( +
+
+
+ {/* */} +
+
+
+

Commerce - Products

+ +
+
    +
  1. + Dating App +
  2. +
  3. Commerce - Products
  4. +
+
+
+
+
+ {/* */} + +
+
+
+
+
+ {/*
+
+ +
+
*/} + {/* */} +
+
+ + + + + + + + + + + {products.map( + ({ title, _id, price, status }) => + title && ( + + + + + + + ) + )} + +
NamePriceStatusActions
{title}{price} + + {status ? "Live" : "Suspended"} + + + + + + + + + +
+
+ + {/*
+
+
+ Showing{" "} + {!totalProducts + ? totalProducts + : page * limit - (limit - 1)}{" "} + to{" "} + {totalProducts > limit + ? limit * page > totalProducts + ? totalProducts + : limit * page + : totalProducts}{" "} + of {totalProducts} entries +
+
+ +
+
+
    +
  • + +
  • + + {getTotalPages.map((pageNo) => { + return ( +
  • + +
  • + ); + })} + +
  • + +
  • +
+
+
+
*/} + + {/* */} +
+
+
+
+
+ {/* */} +
+
+ ); +} + +export default Products; diff --git a/src/views/Profile/Profile.js b/src/views/Profile/Profile.js index 581fa6b..4181527 100644 --- a/src/views/Profile/Profile.js +++ b/src/views/Profile/Profile.js @@ -74,4 +74,4 @@ const Profile = () => { ) } -export default Profile \ No newline at end of file +export default Profile