RD map with TM and SC

This commit is contained in:
Sibunnayak 2024-09-10 16:03:28 +05:30
parent a9329eb772
commit e51d451dc7
10 changed files with 800 additions and 169 deletions

View File

@ -15,9 +15,9 @@ import { cibGmail } from "@coreui/icons";
import { createRoot } from "react-dom/client";
const setupAxios = () => {
// axios.defaults.baseURL = "http://localhost:5000";
axios.defaults.baseURL = "http://localhost:5000";
// axios.defaults.baseURL = "https://cheminova-api-2.onrender.com";
axios.defaults.baseURL = "https://api.cnapp.co.in";
// axios.defaults.baseURL = "https://api.cnapp.co.in";
axios.defaults.headers = {
"Cache-Control": "no-cache,no-store",

View File

@ -148,7 +148,8 @@ import ViewSalesCoOrdinatorTM from "./views/TerritoryManager/ViewSalesCoOrdinato
import ViewPrincipalDistributorTM from "./views/TerritoryManager/ViewPrincipalDistributorTM";
import ViewRetailDistributorTM from "./views/TerritoryManager/ViewRetailDistributor";
import AddRetailDistributor from "./views/RetailDistributors/addRetailDistributor";
import ViewPrincipalDistributorSC from "./views/SalesCoOrdinators/ViewPrincipalDistributorTM";
import ViewPrincipalDistributorSC from "./views/SalesCoOrdinators/ViewPrincipalDistributorSC";
import ViewRetailDistributorSC from "./views/SalesCoOrdinators/ViewRetailDistributorSC";
const routes = [
//dashboard
@ -246,6 +247,12 @@ const routes = [
element: ViewPrincipalDistributorSC,
navName: "SalesCoOrdinators",
},
{
path: "/view/SCretaildistributor/:id",
name: "View Retail Distributor",
element: ViewRetailDistributorSC,
navName: "SalesCoOrdinators",
},
//TerritoryManager
{
path: "/territorymanager/edit/:id",

View File

@ -24,18 +24,19 @@ const [totalPages, setTotalPages] = useState(1);
const getRetailDistributorsData = async () => {
setLoading(true);
try {
const res = await axios.get(`/api/kyc/getAllapproved/`, {
const res = await axios.get(`/api/getAllRD`, {
headers: {
Authorization: `Bearer ${token}`,
},
params: {
page: currentPage,
show: itemPerPage,
name: nameRef.current.value,
tradename: nameRef.current.value,
principaldistributor: principalDistributorRef.current.value,
},
});
setAllRetailDistributorsData(res.data?.kycs);
// console.log(res.data);
setAllRetailDistributorsData(res.data?.Retaildistributor);
setTotalData(res.data?.total_data);
setTotalPages(res.data?.total_pages);
} catch (err) {
@ -171,14 +172,14 @@ const [totalPages, setTotalPages] = useState(1);
allRetailDistributorsData.map((retailDistributor) => (
<tr key={retailDistributor._id}>
<td className="text-start">
{retailDistributor._id}
{retailDistributor.uniqueId}
</td>
<td className="text-start">
{retailDistributor.trade_name}
{retailDistributor.kycDetails.trade_name}
</td>
<td className="text-start">
{new Date(
retailDistributor.updatedAt
retailDistributor.createdAt
).toLocaleString("en-IN", {
weekday: "short",
month: "short",
@ -190,20 +191,14 @@ const [totalPages, setTotalPages] = useState(1);
})}
</td>
<td className="text-start">
{retailDistributor.principal_distributer
{retailDistributor?.principalDetails
?.name || "N/A"}
</td>
<td className="text-start">
{retailDistributor.userType ===
"TerritoryManager"
? retailDistributor.addedBy?.name || "N/A"
: "N/A"}
{retailDistributor?.mappedTMDetails?.name || "N/A"}
</td>
<td className="text-start">
{retailDistributor.userType ===
"SalesCoOrdinator"
? retailDistributor.addedBy?.name || "N/A"
: "N/A"}
{retailDistributor?.mappedSCDetails?.name || "N/A"}
</td>
<td className="text-start">
<Link

View File

@ -18,7 +18,7 @@ const SingleRetailDistributor = () => {
const fetchData = async () => {
try {
// Commented out the API call and using dummy data
const response = await axios.get(`api/kyc/get-single-kyc/${id}`, {
const response = await axios.get(`api/getRD/${id}`, {
headers: {
'Access-Control-Allow-Origin': '*',
Authorization: `Bearer ${token}`,
@ -72,27 +72,27 @@ const SingleRetailDistributor = () => {
<Grid container spacing={2}>
<Grid item xs={6}>
<Typography>
<strong>Trade Name:</strong> {retailerDetails.trade_name}
<strong>Trade Name:</strong> {retailerDetails.kyc.trade_name}
</Typography>
<Typography>
<strong>Name:</strong> {retailerDetails.name}
</Typography>
<Typography>
<strong>Address:</strong> {retailerDetails.address}
<strong>Address:</strong> {retailerDetails.kyc.address}
</Typography>
<Typography>
<strong>Town/City:</strong> {retailerDetails.city}
<strong>Town/City:</strong> {retailerDetails.kyc.city}
</Typography>
</Grid>
<Grid item xs={6}>
<Typography>
<strong>District:</strong> {retailerDetails.district}
<strong>District:</strong> {retailerDetails.kyc.district}
</Typography>
<Typography>
<strong>State:</strong> {retailerDetails.state}
<strong>State:</strong> {retailerDetails.kyc.state}
</Typography>
<Typography>
<strong>Pincode:</strong> {retailerDetails.pincode}
<strong>Pincode:</strong> {retailerDetails.kyc.pincode}
</Typography>
<Typography>
<strong>Mobile Number:</strong> {retailerDetails.mobile_number}
@ -111,31 +111,31 @@ const SingleRetailDistributor = () => {
<Grid container spacing={2}>
<Grid item xs={6}>
<Typography>
<strong>PAN Number:</strong> {retailerDetails.pan_number}
<strong>PAN Number:</strong> {retailerDetails.kyc.pan_number}
</Typography>
<Avatar
variant="square"
src={retailerDetails.pan_img.url}
src={retailerDetails.kyc.pan_img.url}
sx={{ width: 100, height: 100, mb: 2, cursor: 'pointer' }}
onClick={() => handleOpenPopup(retailerDetails.pan_img.url)}
onClick={() => handleOpenPopup(retailerDetails.kyc.pan_img.url)}
/>
<Typography>
<strong>Aadhar Number:</strong> {retailerDetails.aadhar_number}
<strong>Aadhar Number:</strong> {retailerDetails.kyc.aadhar_number}
</Typography>
<Avatar
variant="square"
src={retailerDetails.aadhar_img.url}
src={retailerDetails.kyc.aadhar_img.url}
sx={{ width: 100, height: 100, mb: 2, cursor: 'pointer' }}
onClick={() => handleOpenPopup(retailerDetails.aadhar_img.url)}
onClick={() => handleOpenPopup(retailerDetails.kyc.aadhar_img.url)}
/>
<Typography>
<strong>GST Number:</strong> {retailerDetails.gst_number}
<strong>GST Number:</strong> {retailerDetails.kyc.gst_number}
</Typography>
<Avatar
variant="square"
src={retailerDetails.gst_img.url}
src={retailerDetails.kyc.gst_img.url}
sx={{ width: 100, height: 100, mb: 2, cursor: 'pointer' }}
onClick={() => handleOpenPopup(retailerDetails.gst_img.url)}
onClick={() => handleOpenPopup(retailerDetails.kyc.gst_img.url)}
/>
</Grid>
<Grid item xs={6}>
@ -144,19 +144,19 @@ const SingleRetailDistributor = () => {
</Typography>
<Avatar
variant="square"
src={retailerDetails.pesticide_license_img.url}
src={retailerDetails.kyc.pesticide_license_img.url}
sx={{ width: 100, height: 100, mb: 2, cursor: 'pointer' }}
onClick={() => handleOpenPopup(retailerDetails.pesticide_license_img.url)}
onClick={() => handleOpenPopup(retailerDetails.kyc.pesticide_license_img.url)}
/>
<Typography>
<strong>Fertilizer License (optional):</strong>
</Typography>
{retailerDetails.fertilizer_license_img ? (
{retailerDetails.kyc.fertilizer_license_img ? (
<Avatar
variant="square"
src={retailerDetails.fertilizer_license_img.url}
sx={{ width: 100, height: 100, mb: 2, cursor: 'pointer' }}
onClick={() => handleOpenPopup(retailerDetails.fertilizer_license_img.url)}
onClick={() => handleOpenPopup(retailerDetails.kyc.fertilizer_license_img.url)}
/>
) : (
<Typography>Img not available</Typography>
@ -166,9 +166,9 @@ const SingleRetailDistributor = () => {
</Typography>
<Avatar
variant="square"
src={retailerDetails.selfie_entrance_img.url}
src={retailerDetails.kyc.selfie_entrance_img.url}
sx={{ width: 100, height: 100, mb: 2, cursor: 'pointer' }}
onClick={() => handleOpenPopup(retailerDetails.selfie_entrance_img.url)}
onClick={() => handleOpenPopup(retailerDetails.kyc.selfie_entrance_img.url)}
/>
</Grid>
</Grid>

View File

@ -289,6 +289,20 @@ const SalesCoOrdinator = () => {
PD
</button>
</Link>
<Link
to={`/view/SCretaildistributor/${salescoordinator._id}`}
>
<button
style={{
color: "white",
marginRight: "1rem",
}}
type="button"
className="btn btn-primary btn-sm waves-effect waves-light btn-table ml-2"
>
RD
</button>
</Link>
</td>
<td className="text-start">
<Link

View File

@ -47,7 +47,7 @@ const ViewPrincipalDistributorSC = () => {
}, [id, token]);
// Fetch Principal Distributors data
const getTMsprincipaldistributorData = async () => {
const getSCsprincipaldistributorData = async () => {
setLoading(true);
axios
.get(`/api/v1/getbySCId/${id}`, {
@ -79,14 +79,14 @@ const ViewPrincipalDistributorSC = () => {
};
useEffect(() => {
getTMsprincipaldistributorData();
getSCsprincipaldistributorData();
}, [success, itemPerPage, currentPage]);
// Debounced search for Principal Distributors
const debouncedSearch = useCallback(
debounce(() => {
setCurrentPage(1);
getTMsprincipaldistributorData();
getSCsprincipaldistributorData();
}, 500),
[currentPage, itemPerPage]
);
@ -286,7 +286,7 @@ const ViewPrincipalDistributorSC = () => {
backgroundColor: "#b71c1c", // Darker red on hover
},
}}
onClick={() => navigate("/territorymanagers")}
onClick={() => navigate("/salescoordinators")}
>
Back
</Button>

View File

@ -0,0 +1,573 @@
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 Dialog from "@material-ui/core/Dialog";
import DialogActions from "@material-ui/core/DialogActions";
import DialogContent from "@material-ui/core/DialogContent";
import DialogTitle from "@material-ui/core/DialogTitle";
import TextField from "@material-ui/core/TextField";
const ViewRetailDistributorSC = () => {
const token = isAutheticated();
const { id } = useParams();
const navigate = useNavigate();
const [loading, setLoading] = useState(false);
const [success, setSuccess] = useState(true);
const [retaildistributorData, setretaildistributorData] = useState([]);
const [data, setData] = useState({});
const nameRef = useRef();
const mobileRef = useRef();
const rdnameRef = useRef();
const rdmobileRef = useRef();
const [currentPage, setCurrentPage] = useState(1);
const [itemPerPage, setItemPerPage] = useState(10);
const [modalcurrentPage, setmodalCurrentPage] = useState(1);
const modalitemPerPage = 10;
const [totalData, setTotalData] = useState(0);
const [openModal, setOpenModal] = useState(false);
const [modalRetailDistributors, setmodalRetailDistributors] = useState([]);
const [modalTotalData, setmodalTotalData] = useState(0);
// Fetch territory manager data
useEffect(() => {
axios
.get(`/api/salescoordinator/getOne/${id}`, {
headers: { Authorization: `Bearer ${token}` },
})
.then((response) => setData(response.data.data))
.catch((error) => console.error("Error fetching sc data:", error));
}, [id, token]);
// Fetch Retail Distributors data
const getSCsretaildistributorData = async () => {
setLoading(true);
axios
.get(`/api/getAllRDbyscid/${id}`, {
headers: {
Authorization: `Bearer ${token}`,
},
params: {
page: currentPage,
show: itemPerPage,
tradename: nameRef.current?.value,
mobile_number: mobileRef.current?.value,
},
})
.then((res) => {
// console.log(res.data);
setretaildistributorData(res.data?.Retaildistributor);
setTotalData(res.data?.total_data);
})
.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(() => {
getSCsretaildistributorData();
}, [success, itemPerPage, currentPage]);
// Debounced search for Retail Distributors
const debouncedSearch = useCallback(
debounce(() => {
setCurrentPage(1);
getSCsretaildistributorData();
}, 500),
[currentPage, itemPerPage]
);
const handleSearchChange = useCallback(() => {
debouncedSearch();
}, [debouncedSearch]);
// Fetch Retail Distributors data for modal
const getretaildistributorData = async () => {
setLoading(true);
try {
const res = await axios.get(`/api/getAllRD`, {
headers: {
Authorization: `Bearer ${token}`,
},
params: {
page: modalcurrentPage,
show: modalitemPerPage,
tradename: rdnameRef.current?.value,
mobile_number: rdmobileRef.current?.value,
},
});
setmodalRetailDistributors(res.data?.Retaildistributor);
setmodalTotalData(res.data?.total_data);
} 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(() => {
if (openModal) {
getretaildistributorData();
}
}, [openModal, modalcurrentPage]);
// Debounced search for Retail Distributors in modal
const debouncedmodalSearch = useCallback(
debounce(() => {
setmodalCurrentPage(1);
getretaildistributorData();
}, 500),
[modalcurrentPage]
);
const handlemodalSearchChange = useCallback(() => {
debouncedmodalSearch();
}, [debouncedmodalSearch]);
const handleOpenModal = () => {
setOpenModal(true);
};
const handleCloseModal = () => {
setOpenModal(false);
};
const handlePreviousPage = () => {
if (modalcurrentPage > 1) {
setmodalCurrentPage(modalcurrentPage - 1);
}
};
const handleNextPage = () => {
if (modalRetailDistributors.length === modalitemPerPage) {
setmodalCurrentPage(modalcurrentPage + 1);
}
};
const handleDelete = (id) => {
swal({
title: "Are you sure?",
icon: "warning",
buttons: {
Yes: { text: "Yes", value: true },
Cancel: { text: "Cancel", value: "cancel" },
},
}).then((value) => {
if (value === true) {
axios
.patch(
`/api/unmap/${id}`,
{ mappedSC: true },
{
// Changed to PATCH and sent an empty body
headers: {
"Access-Control-Allow-Origin": "*",
Authorization: `Bearer ${token}`,
},
}
)
.then((res) => {
swal({
title: "Deleted",
text: "Retail Distributor Unmapped successfully!",
icon: "success",
button: "ok",
});
setSuccess((prev) => !prev);
})
.catch((err) => {
let msg = err?.response?.data?.message
? err?.response?.data?.message
: "Something went wrong!";
swal({
title: "Warning",
text: msg,
icon: "error",
button: "Retry",
dangerMode: true,
});
});
}
});
};
const handleAddRetailDistributor = async (rdid) => {
try {
await axios.put(
`/api/mapped/${rdid}`,
{ mappedSC: id },
{
headers: {
Authorization: `Bearer ${token}`,
},
}
);
swal({
title: "Success",
text: "Retail Distributor added successfully!",
icon: "success",
button: "Ok",
});
setSuccess((prev) => !prev);
handleCloseModal(); // Close modal after adding
} catch (err) {
const msg = err?.response?.data?.message || "Something went wrong!";
swal({
title: "Error",
text: msg,
icon: "error",
button: "Retry",
dangerMode: true,
});
}
};
return (
<div className="main-content">
<div className="page-content">
<div className="container-fluid">
<div className="row">
<div className="col-12">
<div className="page-title-box d-flex mb-1 align-items-center justify-content-between">
{/* Left Side with Information in Separate Columns */}
<div className="d-flex flex-column">
<div style={{ fontSize: "18px" }} className="fw-bold">
Unique ID: {data?.uniqueId}
</div>
<div style={{ fontSize: "18px" }} className="fw-bold">
Name: {data?.name}
</div>
<div style={{ fontSize: "18px" }} className="fw-bold">
Mobile Number: {data?.mobileNumber}
</div>
<div style={{ fontSize: "18px" }} className="fw-bold">
Mail: {data?.email}
</div>
</div>
{/* Right Side with the Button */}
<div className="page-title-right">
<Button
variant="contained"
color="primary"
style={{
fontWeight: "bold",
marginBottom: "1rem",
textTransform: "capitalize",
}}
onClick={handleOpenModal}
>
Add Retail Distributor
</Button>
<Button
variant="contained"
color="secondary"
style={{
fontWeight: "bold",
marginBottom: "1rem",
marginLeft: "1rem",
textTransform: "capitalize",
backgroundColor: "#d32f2f", // Red color for danger
color: "#fff",
"&:hover": {
backgroundColor: "#b71c1c", // Darker red on hover
},
}}
onClick={() => navigate("/salescoordinators")}
>
Back
</Button>
</div>
</div>
<Dialog
open={openModal}
onClose={handleCloseModal}
maxWidth="md"
fullWidth
>
<DialogTitle>Search and Add Retail Distributor</DialogTitle>
<DialogContent>
<div
style={{
display: "flex",
gap: "16px",
marginBottom: "2rem",
marginTop: "-1rem",
}}
>
<TextField
label="Retail Distributor Trade Name"
placeholder="Retail Distributor Trade name"
inputRef={rdnameRef}
onChange={handlemodalSearchChange}
disabled={loading}
style={{ flex: 1, marginRight: "16px" }}
/>
<TextField
style={{ flex: 1 }}
label="Mobile Number"
placeholder="Mobile Number"
inputRef={rdmobileRef}
onChange={handlemodalSearchChange}
disabled={loading}
/>
</div>
<div className="table-responsive table-shoot mt-3">
<table className="table table-centered table-nowrap">
<thead>
<tr>
<th>Trade Name</th>
<th>Mobile</th>
<th>Email</th>
<th>SC</th>
<th>Action</th>
</tr>
</thead>
<tbody>
{modalRetailDistributors.length > 0 ? (
modalRetailDistributors.map((RD) => (
<tr key={RD._id}>
<td>{RD.kycDetails.trade_name}</td>
<td>{RD.mobile_number}</td>
<td>{RD.email}</td>
<td>{RD.mappedSCDetails?.name || "N/A"}</td>
<td>
<Button
variant="contained"
color="primary"
onClick={() =>
handleAddRetailDistributor(RD._id)
}
>
Add
</Button>
</td>
</tr>
))
) : (
<tr>
<td colSpan="6" className="text-center">
No Retail Distributor found!
</td>
</tr>
)}
</tbody>
</table>
</div>
<div className="d-flex justify-content-between">
<div>
Showing {modalRetailDistributors?.length} of{" "}
{modalTotalData} entries
</div>
<div>
<button
onClick={handlePreviousPage}
disabled={modalcurrentPage === 1 || loading}
className="btn btn-primary"
>
Previous
</button>
<button
onClick={handleNextPage}
disabled={
modalRetailDistributors?.length < modalitemPerPage ||
loading
}
className="btn btn-primary ml-2"
>
Next
</button>
</div>
</div>
</DialogContent>
<DialogActions>
<Button onClick={handleCloseModal} color="secondary">
Cancel
</Button>
</DialogActions>
</Dialog>
</div>
</div>
<div className="row">
<div className="col-lg-12">
<div className="card">
<div className="card-body">
<div className="row ml-0 mr-0 mb-10">
<div className="col-lg-1">
<div className="dataTables_length">
<label className="w-100">
Show
<select
onChange={(e) => {
setItemPerPage(e.target.value);
setCurrentPage(1);
}}
className="form-control"
disabled={loading}
>
<option value="10">10</option>
<option value="25">25</option>
<option value="50">50</option>
<option value="100">100</option>
</select>
entries
</label>
</div>
</div>
<div className="col-lg-3">
<label>Trade Name:</label>
<input
type="text"
placeholder="Retail Distributor Trade name"
className="form-control"
ref={nameRef}
onChange={handleSearchChange}
disabled={loading}
/>
</div>
<div className="col-lg-3">
<label>Mobile Number:</label>
<input
type="text"
placeholder="Mobile Number"
className="form-control"
ref={mobileRef}
onChange={handleSearchChange}
disabled={loading}
/>
</div>
</div>
<div className="table-responsive table-shoot mt-3">
<table className="table table-centered table-nowrap">
<thead
className="thead-light"
style={{ background: "#ecdddd" }}
>
<tr>
<th className="text-start">UniqueID</th>
<th className="text-start">Trade Name</th>
<th className="text-start">Mobile</th>
<th className="text-start">Email</th>
<th className="text-start">Created On</th>
<th className="text-start">Action</th>
</tr>
</thead>
<tbody>
{loading ? (
<tr>
<td className="text-center" colSpan="6">
Loading...
</td>
</tr>
) : retaildistributorData?.length > 0 ? (
retaildistributorData?.map((RD, i) => {
return (
<tr key={i}>
<td className="text-start">{RD?.uniqueId}</td>
<td className="text-start">
{RD?.kycDetails?.trade_name}
</td>
<td className="text-start">
{RD?.mobile_number ? (
RD?.mobile_number
) : (
<small className="m-0 text-secondary">
No Phone Added!
</small>
)}
</td>
<td className="text-start">{RD?.email}</td>
<td className="text-start">
{" "}
{new Date(RD.createdAt).toLocaleString(
"en-IN",
{
weekday: "short",
month: "short",
day: "numeric",
year: "numeric",
hour: "numeric",
minute: "numeric",
hour12: true,
}
)}
</td>
<td className="text-start">
<button
type="button"
style={{ color: "white" }}
className="btn btn-danger btn-sm waves-effect waves-light btn-table ml-2"
onClick={() => handleDelete(RD._id)}
>
Delete
</button>
</td>
</tr>
);
})
) : (
<tr>
<td className="text-center" colSpan="6">
No Retail Distributor found!
</td>
</tr>
)}
</tbody>
</table>
</div>
<div className="d-flex justify-content-between">
<div>
Showing {retaildistributorData?.length} of {totalData}{" "}
entries
</div>
<div>
<button
onClick={() => setCurrentPage(currentPage - 1)}
disabled={currentPage === 1 || loading}
className="btn btn-primary"
>
Previous
</button>
<button
onClick={() => setCurrentPage(currentPage + 1)}
disabled={
retaildistributorData?.length < itemPerPage || loading
}
className="btn btn-primary ml-2"
>
Next
</button>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
);
};
export default ViewRetailDistributorSC;

View File

@ -31,9 +31,7 @@ const ViewRetailDistributorTM = () => {
const modalitemPerPage = 10;
const [totalData, setTotalData] = useState(0);
const [openModal, setOpenModal] = useState(false);
const [modalRetailDistributors, setmodalRetailDistributors] = useState(
[]
);
const [modalRetailDistributors, setmodalRetailDistributors] = useState([]);
const [modalTotalData, setModalTotalData] = useState(0);
// Fetch territory manager data
@ -50,7 +48,7 @@ const ViewRetailDistributorTM = () => {
const getTMsretaildistributorData = async () => {
setLoading(true);
axios
.get(`/api/kyc/getAllapprovedbytmid/${id}`, {
.get(`/api/getAllRDbytmid/${id}`, {
headers: {
Authorization: `Bearer ${token}`,
},
@ -58,11 +56,12 @@ const ViewRetailDistributorTM = () => {
page: currentPage,
show: itemPerPage,
tradename: nameRef.current?.value,
mobile_number: mobileRef.current?.value,
},
})
.then((res) => {
// console.log(res.data);
setretaildistributorData(res.data?.retaildistributor);
setretaildistributorData(res.data?.Retaildistributor);
setTotalData(res.data?.total_data);
})
.catch((err) => {
@ -98,19 +97,19 @@ const ViewRetailDistributorTM = () => {
const getretaildistributorData = async () => {
setLoading(true);
try {
const res = await axios.get(`/api/v1/admin/users`, {
const res = await axios.get(`/api/getAllRD`, {
headers: {
Authorization: `Bearer ${token}`,
},
params: {
page: modalcurrentPage,
show: modalitemPerPage,
name: rdnameRef.current?.value,
mobileNumber: rdmobileRef.current?.value,
tradename: rdnameRef.current?.value,
mobile_number: rdmobileRef.current?.value,
},
});
setmodalRetailDistributors(res.data?.users);
setModalTotalData(res.data?.totalUsers);
setmodalRetailDistributors(res.data?.Retaildistributor);
setModalTotalData(res.data?.total_data);
} catch (err) {
const msg = err?.response?.data?.message || "Something went wrong!";
swal({
@ -174,12 +173,17 @@ const ViewRetailDistributorTM = () => {
}).then((value) => {
if (value === true) {
axios
.patch(`/api/v1/unmap/${id}`, {}, { // Changed to PATCH and sent an empty body
.patch(
`/api/unmap/${id}`,
{ mappedTM: true },
{
// Changed to PATCH and sent an empty body
headers: {
"Access-Control-Allow-Origin": "*",
Authorization: `Bearer ${token}`,
},
})
}
)
.then((res) => {
swal({
title: "Deleted",
@ -207,8 +211,8 @@ const ViewRetailDistributorTM = () => {
const handleAddRetailDistributor = async (rdid) => {
try {
await axios.put(
`/api/v1/mappedtm/${rdid}`,
{ mappedby: id },
`/api/mapped/${rdid}`,
{ mappedTM: id },
{
headers: {
Authorization: `Bearer ${token}`,
@ -260,7 +264,7 @@ const ViewRetailDistributorTM = () => {
{/* Right Side with the Button */}
<div className="page-title-right">
{/* <Button
<Button
variant="contained"
color="primary"
style={{
@ -271,7 +275,7 @@ const ViewRetailDistributorTM = () => {
onClick={handleOpenModal}
>
Add Retail Distributor
</Button> */}
</Button>
<Button
variant="contained"
color="secondary"
@ -292,7 +296,7 @@ const ViewRetailDistributorTM = () => {
</Button>
</div>
</div>
{/* <Dialog
<Dialog
open={openModal}
onClose={handleCloseModal}
maxWidth="md"
@ -300,7 +304,14 @@ const ViewRetailDistributorTM = () => {
>
<DialogTitle>Search and Add Retail Distributor</DialogTitle>
<DialogContent>
<div style={{ display: "flex", gap: "16px", marginBottom:"2rem",marginTop:"-1rem" }}>
<div
style={{
display: "flex",
gap: "16px",
marginBottom: "2rem",
marginTop: "-1rem",
}}
>
<TextField
label="Retail Distributor Trade Name"
placeholder="Retail Distributor Trade name"
@ -324,7 +335,8 @@ const ViewRetailDistributorTM = () => {
<tr>
<th>Trade Name</th>
<th>Mobile</th>
<th>Approved PD</th>
<th>Email</th>
<th>TM</th>
<th>Action</th>
</tr>
</thead>
@ -332,9 +344,10 @@ const ViewRetailDistributorTM = () => {
{modalRetailDistributors.length > 0 ? (
modalRetailDistributors.map((RD) => (
<tr key={RD._id}>
<td>{RD.trade_name}</td>
<td>{RD.kycDetails.trade_name}</td>
<td>{RD.mobile_number}</td>
<td>{RD.principal_distributer?.name}</td>
<td>{RD.email}</td>
<td>{RD.mappedTMDetails?.name || "N/A"}</td>
<td>
<Button
variant="contained"
@ -374,8 +387,8 @@ const ViewRetailDistributorTM = () => {
<button
onClick={handleNextPage}
disabled={
modalRetailDistributors?.length <
modalitemPerPage || loading
modalRetailDistributors?.length < modalitemPerPage ||
loading
}
className="btn btn-primary ml-2"
>
@ -389,7 +402,7 @@ const ViewRetailDistributorTM = () => {
Cancel
</Button>
</DialogActions>
</Dialog> */}
</Dialog>
</div>
</div>
@ -430,7 +443,7 @@ const ViewRetailDistributorTM = () => {
disabled={loading}
/>
</div>
{/* <div className="col-lg-3">
<div className="col-lg-3">
<label>Mobile Number:</label>
<input
type="text"
@ -440,7 +453,7 @@ const ViewRetailDistributorTM = () => {
onChange={handleSearchChange}
disabled={loading}
/>
</div> */}
</div>
</div>
<div className="table-responsive table-shoot mt-3">
@ -450,12 +463,12 @@ const ViewRetailDistributorTM = () => {
style={{ background: "#ecdddd" }}
>
<tr>
<th className="text-start">ID</th>
<th className="text-start">UniqueID</th>
<th className="text-start">Trade Name</th>
<th className="text-start">Approved PD</th>
<th className="text-start">Mobile</th>
<th className="text-start">Email</th>
<th className="text-start">Created On</th>
{/* <th className="text-start">Action</th> */}
<th className="text-start">Action</th>
</tr>
</thead>
@ -470,9 +483,10 @@ const ViewRetailDistributorTM = () => {
retaildistributorData?.map((RD, i) => {
return (
<tr key={i}>
<td className="text-start">{RD?._id}</td>
<td className="text-start">{RD?.trade_name}</td>
<td className="text-start">{RD?.principal_distributer?.name}</td>
<td className="text-start">{RD?.uniqueId}</td>
<td className="text-start">
{RD?.kycDetails?.trade_name}
</td>
<td className="text-start">
{RD?.mobile_number ? (
RD?.mobile_number
@ -482,9 +496,13 @@ const ViewRetailDistributorTM = () => {
</small>
)}
</td>
<td className="text-start"> {new Date(
RD.updatedAt
).toLocaleString("en-IN", {
<td className="text-start">{RD?.email}</td>
<td className="text-start">
{" "}
{new Date(RD.createdAt).toLocaleString(
"en-IN",
{
weekday: "short",
month: "short",
day: "numeric",
@ -492,8 +510,10 @@ const ViewRetailDistributorTM = () => {
hour: "numeric",
minute: "numeric",
hour12: true,
})}</td>
{/* <td className="text-start">
}
)}
</td>
<td className="text-start">
<button
type="button"
style={{ color: "white" }}
@ -502,7 +522,7 @@ const ViewRetailDistributorTM = () => {
>
Delete
</button>
</td> */}
</td>
</tr>
);
})
@ -532,8 +552,7 @@ const ViewRetailDistributorTM = () => {
<button
onClick={() => setCurrentPage(currentPage + 1)}
disabled={
retaildistributorData?.length < itemPerPage ||
loading
retaildistributorData?.length < itemPerPage || loading
}
className="btn btn-primary ml-2"
>

View File

@ -10,6 +10,7 @@ const Dashboard = () => {
const [users, setUsers] = useState([]);
const [salescoordinator, setSalescoordinator] = useState([]);
const [territorymanager, setTerritorymanager] = useState([]);
const [retaildistributor, setRetaildistributor] = useState([]);
const token = isAutheticated();
const getAllUsers = async () => {
@ -40,6 +41,15 @@ const Dashboard = () => {
// console.log(res.data)
setTerritorymanager(res.data.total_data);
};
const getAllretaildistributor = async () => {
let res = await axios.get(`/api/getAllRD`, {
headers: {
Authorization: `Bearer ${token}`,
},
});
// console.log(res.data)
setRetaildistributor(res.data.total_data);
};
// //2nd
// const [category, setCategory] = useState([]);
// const getAllCategory = async () => {
@ -141,6 +151,7 @@ const Dashboard = () => {
getAllUsers();
getAllsalescoordinator();
getAllterritorymanager();
getAllretaildistributor();
// getAllCategory();
// getAllProduct();
// getAllRequests();
@ -151,6 +162,7 @@ const Dashboard = () => {
users={users}
salescoordinator={salescoordinator}
territorymanager={territorymanager}
retaildistributor={retaildistributor}
// category={category}
// product={product}
// Requests={Requests}

View File

@ -18,7 +18,7 @@ import axios from "axios";
{
/* <BeatLoader color="#36d7b7" /> */
}
const WidgetsDropdown = ({ users,salescoordinator,territorymanager }) => {
const WidgetsDropdown = ({ users,salescoordinator,territorymanager,retaildistributor }) => {
// const WidgetsDropdown = ({ users, category, product, Requests }) => {
// const token = isAutheticated();
// const [orders, setOrders] = useState([]);
@ -138,6 +138,17 @@ const WidgetsDropdown = ({ users,salescoordinator,territorymanager }) => {
/>
</CCol>
</CRow>
<h4>Retail Distributor</h4>
<CRow>
<CCol sm={6} lg={3}>
<CWidgetStatsA
className="mb-4"
color="primary"
value={<>{retaildistributor}</>}
title="Total Reatil Distributor"
/>
</CCol>
</CRow>
<h4>Sales Coordinator</h4>
<CRow>
<CCol sm={6} lg={3}>