diff --git a/src/index.js b/src/index.js index 0ab534a..8a829f2 100644 --- a/src/index.js +++ b/src/index.js @@ -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", diff --git a/src/routes.js b/src/routes.js index 5dcb0dc..88e1013 100644 --- a/src/routes.js +++ b/src/routes.js @@ -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", diff --git a/src/views/RetailDistributors/RetailDistributor.js b/src/views/RetailDistributors/RetailDistributor.js index b617b8c..102ff54 100644 --- a/src/views/RetailDistributors/RetailDistributor.js +++ b/src/views/RetailDistributors/RetailDistributor.js @@ -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) => ( - {retailDistributor._id} + {retailDistributor.uniqueId} - {retailDistributor.trade_name} + {retailDistributor.kycDetails.trade_name} {new Date( - retailDistributor.updatedAt + retailDistributor.createdAt ).toLocaleString("en-IN", { weekday: "short", month: "short", @@ -190,20 +191,14 @@ const [totalPages, setTotalPages] = useState(1); })} - {retailDistributor.principal_distributer + {retailDistributor?.principalDetails ?.name || "N/A"} - {retailDistributor.userType === - "TerritoryManager" - ? retailDistributor.addedBy?.name || "N/A" - : "N/A"} + {retailDistributor?.mappedTMDetails?.name || "N/A"} - {retailDistributor.userType === - "SalesCoOrdinator" - ? retailDistributor.addedBy?.name || "N/A" - : "N/A"} + {retailDistributor?.mappedSCDetails?.name || "N/A"} { 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 = () => { - Trade Name: {retailerDetails.trade_name} + Trade Name: {retailerDetails.kyc.trade_name} Name: {retailerDetails.name} - Address: {retailerDetails.address} + Address: {retailerDetails.kyc.address} - Town/City: {retailerDetails.city} + Town/City: {retailerDetails.kyc.city} - District: {retailerDetails.district} + District: {retailerDetails.kyc.district} - State: {retailerDetails.state} + State: {retailerDetails.kyc.state} - Pincode: {retailerDetails.pincode} + Pincode: {retailerDetails.kyc.pincode} Mobile Number: {retailerDetails.mobile_number} @@ -111,31 +111,31 @@ const SingleRetailDistributor = () => { - PAN Number: {retailerDetails.pan_number} + PAN Number: {retailerDetails.kyc.pan_number} handleOpenPopup(retailerDetails.pan_img.url)} + onClick={() => handleOpenPopup(retailerDetails.kyc.pan_img.url)} /> - Aadhar Number: {retailerDetails.aadhar_number} + Aadhar Number: {retailerDetails.kyc.aadhar_number} handleOpenPopup(retailerDetails.aadhar_img.url)} + onClick={() => handleOpenPopup(retailerDetails.kyc.aadhar_img.url)} /> - GST Number: {retailerDetails.gst_number} + GST Number: {retailerDetails.kyc.gst_number} handleOpenPopup(retailerDetails.gst_img.url)} + onClick={() => handleOpenPopup(retailerDetails.kyc.gst_img.url)} /> @@ -144,19 +144,19 @@ const SingleRetailDistributor = () => { handleOpenPopup(retailerDetails.pesticide_license_img.url)} + onClick={() => handleOpenPopup(retailerDetails.kyc.pesticide_license_img.url)} /> Fertilizer License (optional): - {retailerDetails.fertilizer_license_img ? ( + {retailerDetails.kyc.fertilizer_license_img ? ( handleOpenPopup(retailerDetails.fertilizer_license_img.url)} + onClick={() => handleOpenPopup(retailerDetails.kyc.fertilizer_license_img.url)} /> ) : ( Img not available @@ -166,9 +166,9 @@ const SingleRetailDistributor = () => { handleOpenPopup(retailerDetails.selfie_entrance_img.url)} + onClick={() => handleOpenPopup(retailerDetails.kyc.selfie_entrance_img.url)} /> diff --git a/src/views/SalesCoOrdinators/SalesCoOrdinator.js b/src/views/SalesCoOrdinators/SalesCoOrdinator.js index c53887f..f6ae423 100644 --- a/src/views/SalesCoOrdinators/SalesCoOrdinator.js +++ b/src/views/SalesCoOrdinators/SalesCoOrdinator.js @@ -289,6 +289,20 @@ const SalesCoOrdinator = () => { PD + + + { }, [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 diff --git a/src/views/SalesCoOrdinators/ViewRetailDistributorSC.js b/src/views/SalesCoOrdinators/ViewRetailDistributorSC.js new file mode 100644 index 0000000..fcd1223 --- /dev/null +++ b/src/views/SalesCoOrdinators/ViewRetailDistributorSC.js @@ -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 ( +
+
+
+
+
+
+ {/* Left Side with Information in Separate Columns */} +
+
+ Unique ID: {data?.uniqueId} +
+
+ Name: {data?.name} +
+
+ Mobile Number: {data?.mobileNumber} +
+
+ Mail: {data?.email} +
+
+ + {/* Right Side with the Button */} +
+ + +
+
+ + Search and Add Retail Distributor + +
+ + +
+
+ + + + + + + + + + + + {modalRetailDistributors.length > 0 ? ( + modalRetailDistributors.map((RD) => ( + + + + + + + + )) + ) : ( + + + + )} + +
Trade NameMobileEmailSCAction
{RD.kycDetails.trade_name}{RD.mobile_number}{RD.email}{RD.mappedSCDetails?.name || "N/A"} + +
+ No Retail Distributor found! +
+
+
+
+ Showing {modalRetailDistributors?.length} of{" "} + {modalTotalData} entries +
+
+ + +
+
+
+ + + +
+
+
+ +
+
+
+
+
+
+
+ +
+
+
+ + +
+
+ + +
+
+ +
+ + + + + + + + + + + + + + {loading ? ( + + + + ) : retaildistributorData?.length > 0 ? ( + retaildistributorData?.map((RD, i) => { + return ( + + + + + + + + + + ); + }) + ) : ( + + + + )} + +
UniqueIDTrade NameMobileEmailCreated OnAction
+ Loading... +
{RD?.uniqueId} + {RD?.kycDetails?.trade_name} + + {RD?.mobile_number ? ( + RD?.mobile_number + ) : ( + + No Phone Added! + + )} + {RD?.email} + {" "} + {new Date(RD.createdAt).toLocaleString( + "en-IN", + { + weekday: "short", + month: "short", + day: "numeric", + year: "numeric", + hour: "numeric", + minute: "numeric", + hour12: true, + } + )} + + +
+ No Retail Distributor found! +
+
+
+
+ Showing {retaildistributorData?.length} of {totalData}{" "} + entries +
+
+ + +
+
+
+
+
+
+
+
+
+ ); +}; + +export default ViewRetailDistributorSC; diff --git a/src/views/TerritoryManager/ViewRetailDistributor.js b/src/views/TerritoryManager/ViewRetailDistributor.js index c2f8253..723e4cc 100644 --- a/src/views/TerritoryManager/ViewRetailDistributor.js +++ b/src/views/TerritoryManager/ViewRetailDistributor.js @@ -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 - headers: { - "Access-Control-Allow-Origin": "*", - Authorization: `Bearer ${token}`, - }, - }) + .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 */}
- {/* */} +
- {/* { > Search and Add Retail Distributor -
- - -
-
- - - - - - - - - - - {modalRetailDistributors.length > 0 ? ( - modalRetailDistributors.map((RD) => ( - - - - - - - )) - ) : ( - - + + + )} + +
Trade NameMobileApproved PDAction
{RD.trade_name}{RD.mobile_number}{RD.principal_distributer?.name} - -
- No Retail Distributor found! +
+ + +
+
+ + + + + + + + + + + + {modalRetailDistributors.length > 0 ? ( + modalRetailDistributors.map((RD) => ( + + + + + + - )} - -
Trade NameMobileEmailTMAction
{RD.kycDetails.trade_name}{RD.mobile_number}{RD.email}{RD.mappedTMDetails?.name || "N/A"} +
+ )) + ) : ( +
+ No Retail Distributor found! +
+
+
+
+ Showing {modalRetailDistributors?.length} of{" "} + {modalTotalData} entries
-
-
- Showing {modalRetailDistributors?.length} of{" "} - {modalTotalData} entries -
-
- - -
+
+ +
+
-
*/} + @@ -430,7 +443,7 @@ const ViewRetailDistributorTM = () => { disabled={loading} /> - {/*
+
{ onChange={handleSearchChange} disabled={loading} /> -
*/} +
@@ -450,12 +463,12 @@ const ViewRetailDistributorTM = () => { style={{ background: "#ecdddd" }} > - ID + UniqueID Trade Name - Approved PD Mobile + Email Created On - {/* Action */} + Action @@ -470,9 +483,10 @@ const ViewRetailDistributorTM = () => { retaildistributorData?.map((RD, i) => { return ( - {RD?._id} - {RD?.trade_name} - {RD?.principal_distributer?.name} + {RD?.uniqueId} + + {RD?.kycDetails?.trade_name} + {RD?.mobile_number ? ( RD?.mobile_number @@ -482,18 +496,24 @@ const ViewRetailDistributorTM = () => { )} - {new Date( - RD.updatedAt - ).toLocaleString("en-IN", { - weekday: "short", - month: "short", - day: "numeric", - year: "numeric", - hour: "numeric", - minute: "numeric", - hour12: true, - })} - {/* + + {RD?.email} + + {" "} + {new Date(RD.createdAt).toLocaleString( + "en-IN", + { + weekday: "short", + month: "short", + day: "numeric", + year: "numeric", + hour: "numeric", + minute: "numeric", + hour12: true, + } + )} + + - */} + ); }) @@ -532,8 +552,7 @@ const ViewRetailDistributorTM = () => {