import React, { useState, useEffect, useCallback, useRef } from "react"; import { Link } from "react-router-dom"; import { useNavigate } from "react-router-dom"; import axios from "axios"; import Button from "@material-ui/core/Button"; import { isAutheticated } from "src/auth"; import swal from "sweetalert"; import debounce from "lodash.debounce"; const RetailDistributor = () => { const token = isAutheticated(); const Navigate = useNavigate(); const [loading, setLoading] = useState(false); const [allRetailDistributorsData, setAllRetailDistributorsData] = useState( [] ); const nameRef = useRef(); const principalDistributorRef = useRef(); const [totalPages, setTotalPages] = useState(1); const [currentPage, setCurrentPage] = useState(1); const [itemPerPage, setItemPerPage] = useState(10); const [totalData, setTotalData] = useState(0); const getRetailDistributorsData = async () => { setLoading(true); try { const res = await axios.get(`/api/getAllRDandorder`, { headers: { Authorization: `Bearer ${token}`, }, params: { page: currentPage, show: itemPerPage, tradename: nameRef.current.value, principaldistributor: principalDistributorRef.current.value, }, }); // console.log(res.data); setAllRetailDistributorsData(res.data?.Retaildistributor); setTotalData(res.data?.total_data); setTotalPages(res.data?.total_pages); } catch (err) { const msg = err?.response?.data?.message || "Something went wrong!"; swal({ title: "Error", text: msg, icon: "error", button: "Retry", dangerMode: true, }); } finally { setLoading(false); } }; useEffect(() => { getRetailDistributorsData(); }, [itemPerPage, currentPage]); const debouncedSearch = useCallback( debounce(() => { setCurrentPage(1); getRetailDistributorsData(); }, 500), [] ); const handleSearchChange = () => { debouncedSearch(); }; return (
Retailers
{loading ? ( ) : allRetailDistributorsData.length > 0 ? ( allRetailDistributorsData.map((retailDistributor) => ( )) ) : ( )}
ID Trade Name Created On Principal Distributor Territory Manager Sales Coordinator Orders Mapping Action
Loading...
{retailDistributor.uniqueId} {retailDistributor.kycDetails.trade_name} {new Date( retailDistributor.createdAt ).toLocaleString("en-IN", { // weekday: "short", month: "short", day: "numeric", year: "numeric", // hour: "numeric", // minute: "numeric", // hour12: true, })} {retailDistributor?.principalDetails?.name || "N/A"} {retailDistributor?.mappedTMDetails?.name || "N/A"} {retailDistributor?.mappedSCDetails?.name || "N/A"}
No Retailer found!
); }; export default RetailDistributor;