diff --git a/src/routes.js b/src/routes.js index 0105581..b6704bd 100644 --- a/src/routes.js +++ b/src/routes.js @@ -154,7 +154,6 @@ import ViewRetailDistributorPD from "./views/PrincipalDistributors/ViewRetailDis import MapRD from "./views/RetailDistributors/MapRD"; import PendingOrders from "./views/orders/pendingOrders"; import ViewInvoices from "./views/orders/viewInoices"; -import Stocks from "./views/PrincipalDistributors/Stock"; import SingleDistributorOrder from "./views/RetailDistributors/DistributorOrders"; import DistributorStocks from "./views/RetailDistributors/DistributorStock"; const routes = [ @@ -440,12 +439,6 @@ const routes = [ element: ViewRetailDistributorPD, navName: "PrincipalDistributor", }, - { - path: "/pd-stock/:id", - name: "view Stock", - element: Stocks, - navName: "PrincipalDistributor", - }, //Inventory { path: "/inventory", diff --git a/src/views/PrincipalDistributors/Stock.js b/src/views/PrincipalDistributors/Stock.js deleted file mode 100644 index cc743da..0000000 --- a/src/views/PrincipalDistributors/Stock.js +++ /dev/null @@ -1,513 +0,0 @@ -import React, { useState, useEffect, useRef, useCallback } from "react"; -import { Link, useParams } from "react-router-dom"; -import axios from "axios"; -import Button from "@material-ui/core/Button"; -import { useNavigate } from "react-router-dom"; -import { isAutheticated } from "src/auth"; -import swal from "sweetalert"; -import debounce from "lodash.debounce"; -import { Typography } from "@mui/material"; -const Stocks = () => { - const token = isAutheticated(); - const navigate = useNavigate(); - const { id } = useParams(); - const [loading, setLoading] = useState(false); - const [productsData, setProductsData] = useState([]); - const [categories, setCategories] = useState([]); - const [brands, setBrands] = useState([]); - const [user, setUser] = useState(null); - - const nameRef = useRef(); - const categoryRef = useRef(); - const brandRef = useRef(); - - const [currentPage, setCurrentPage] = useState(1); - const [itemPerPage, setItemPerPage] = useState(10); - const [totalData, setTotalData] = useState(0); - // Fetch User Details - const getUserDetails = useCallback(async () => { - try { - const response = await axios.get(`/api/v1/admin/user/${id}`, { - headers: { - Authorization: `Bearer ${token}`, - }, - }); - setUser(response.data.user); - } catch (error) { - swal({ - title: "Warning", - text: error.message, - icon: "error", - button: "Close", - dangerMode: true, - }); - } - }, [id, token]); - - // Call getUserDetails on component mount - useEffect(() => { - getUserDetails(); - }, [getUserDetails]); - - const getProductsData = async () => { - setLoading(true); - try { - const response = await axios.get(`/api/pd/stock/${id}`, { - headers: { - Authorization: `Bearer ${token}`, - }, - params: { - page: currentPage, - show: itemPerPage, - name: nameRef.current?.value || "", - category: categoryRef.current?.value || "", - brand: brandRef.current?.value || "", - }, - }); - // console.log(response.data); - setProductsData(response.data?.products || []); - setTotalData(response.data?.totalProducts || 0); - } catch (err) { - const msg = err?.response?.data?.msg || "Something went wrong!"; - swal({ - title: "Error", - text: msg, - icon: "error", - button: "Retry", - dangerMode: true, - }); - } finally { - setLoading(false); - } - }; - - const getCatagories = () => { - axios - .get(`/api/category/getCategories`, { - headers: { - "Access-Control-Allow-Origin": "*", - Authorization: `Bearer ${token}`, - }, - }) - .then((res) => { - // console.log(res?.data?.categories); - setCategories(res?.data?.categories); - }); - }; - const getBrands = () => { - axios - .get(`/api/brand/getBrands`, { - headers: { - "Access-Control-Allow-Origin": "*", - Authorization: `Bearer ${token}`, - }, - }) - .then((res) => { - // console.log(res?.data?.brands); - setBrands(res?.data?.brands); - }); - }; - - const [currencyDetails, setCurrencyDetails] = useState(null); - - const getCurrency = async () => { - try { - const response = await axios.get("/api/currency/getall", { - // headers: { - // Authorization: `Bearer ${token}`, - // }, - }); - - if (response.status === 200) { - setCurrencyDetails(response?.data?.currency[0]); - } - } catch (error) { - console.log(error); - } - }; - useEffect(() => { - getCatagories(); - getCurrency(); - getBrands(); - }, []); - - useEffect(() => { - getProductsData(); - }, [itemPerPage, currentPage]); - - const debouncedSearch = useCallback( - debounce(() => { - setCurrentPage(1); - getProductsData(); - }, 500), - [] - ); - - const handleSearchChange = () => { - debouncedSearch(); - }; - return ( -
Image | -SKU | -Product | -Category Name | -Brand Name | -Price | -Added On | -Stock | -
---|---|---|---|---|---|---|---|
- Loading... - | -|||||||
- {product?.image &&
- product?.image?.length !== 0 ? (
- <>
-
-
- )}
- No -image -uploaded! - |
- {product.SKU} | -{product.name} | -- {product.category !== "" - ? product.category - : "Category Not selected "} - | -- {product.brand !== "" - ? product.brand - : "Brand Not selected "} - | -- {currencyDetails?.CurrencySymbol} - {product?.price} - | -- {new Date(product.createdAt).toLocaleString( - "en-IN", - { - weekday: "short", - month: "short", - day: "numeric", - year: "numeric", - hour: "numeric", - minute: "numeric", - hour12: true, - } - )} - | -{product.stock} | -
- No Product Available...- |
-