import React, { useState, useEffect, useRef, useCallback } from "react"; import { Link } from "react-router-dom"; import Button from "@material-ui/core/Button"; import { useNavigate } from "react-router-dom"; import axios from "axios"; import { isAutheticated } from "src/auth"; import swal from "sweetalert"; import OrderDetails from "./orderDetails"; import debounce from "lodash.debounce"; const principalDistributor = () => { const token = isAutheticated(); const navigate = useNavigate(); const [loading, setLoading] = useState(true); const [loading1, setLoading1] = useState(true); const [success, setSuccess] = useState(true); const [users, setUsers] = useState([]); const [totalPages, setTotalPages] = useState(1); const [currentPage, setCurrentPage] = useState(1); const [itemPerPage, setItemPerPage] = useState(10); const [totalData, setTotalData] = useState(0); const nameRef = useRef(); const SBURef = useRef(); const getUsers = async () => { setLoading(true); try { const res = await axios.get(`/api/v1/admin/pd`, { headers: { Authorization: `Bearer ${token}`, }, params: { page: currentPage, show: itemPerPage, name: nameRef.current.value, SBU: SBURef.current.value, }, }); // console.log(res.data); setUsers(res.data.users); setTotalData(res.data?.total_data); setTotalPages(res.data?.total_pages); } catch (error) { swal({ title: error, text: "please login to access the resource or refresh the page ", icon: "error", button: "Retry", dangerMode: true, }); } finally { setLoading(false); } }; useEffect(() => { getUsers(); }, [itemPerPage, currentPage]); const debouncedSearch = useCallback( debounce(() => { setCurrentPage(1); getUsers(); }, 500), [] ); const handleSearchChange = () => { debouncedSearch(); }; // console.log(users); // const handleDelete = (id) => { // swal({ // title: "Are you sure?", // icon: "error", // buttons: { // Yes: { text: "Yes", value: true }, // Cancel: { text: "Cancel", value: "cancel" }, // }, // }).then((value) => { // if (value === true) { // axios // .delete(`/api/user-address/deleteAddress/${id}`, { // headers: { // "Access-Control-Allow-Origin": "*", // Authorization: `Bearer ${token}`, // }, // }) // .then((res) => { // swal({ // title: "Deleted", // text: "Address Deleted successfully!", // icon: "success", // button: "ok", // }); // setSuccess((prev) => !prev); // }) // .catch((err) => { // swal({ // title: "Warning", // text: "Something went wrong!", // icon: "error", // button: "Retry", // dangerMode: true, // }); // }); // } // }); // }; return (
Unique Id | SBU | Name | Date Registered | Last Purchase | Orders | Mapping | Action | |||
---|---|---|---|---|---|---|---|---|---|---|
Loading.... |
||||||||||
{user.uniqueId} | {user.SBU ? user.SBU : "N/A"} | {user.name} | {user.email} | {new Date(user.createdAt).toLocaleString( "en-IN", { // weekday: "short", month: "short", day: "numeric", year: "numeric", // hour: "numeric", // minute: "numeric", // hour12: true, } )} | {user.lastOrderDate ? new Date(user.lastOrderDate).toLocaleString( "en-IN", { month: "short", day: "numeric", year: "numeric", } ) : "No purchase"} | {/* {loading1 && ( <> | loading... | loading... | > )}{/* */} | |
No Principal Distributor found! |