diff --git a/src/views/SalesCoOrdinators/SalesCoOrdinator.js b/src/views/SalesCoOrdinators/SalesCoOrdinator.js
index cad844a..c53887f 100644
--- a/src/views/SalesCoOrdinators/SalesCoOrdinator.js
+++ b/src/views/SalesCoOrdinators/SalesCoOrdinator.js
@@ -214,6 +214,7 @@ const SalesCoOrdinator = () => {
Email |
Verify |
Register On |
+ Mapping |
Action |
@@ -264,16 +265,32 @@ const SalesCoOrdinator = () => {
{new Date(
salescoordinator.createdAt
).toLocaleString("en-IN", {
- weekday: "short",
+ // weekday: "short",
month: "short",
day: "numeric",
year: "numeric",
- hour: "numeric",
- minute: "numeric",
- hour12: true,
+ // hour: "numeric",
+ // minute: "numeric",
+ // hour12: true,
})}
+
+
+
+ |
+
diff --git a/src/views/SalesCoOrdinators/ViewPrincipalDistributorTM.js b/src/views/SalesCoOrdinators/ViewPrincipalDistributorTM.js
new file mode 100644
index 0000000..7ad117b
--- /dev/null
+++ b/src/views/SalesCoOrdinators/ViewPrincipalDistributorTM.js
@@ -0,0 +1,548 @@
+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 ViewPrincipalDistributorSC = () => {
+ const token = isAutheticated();
+ const { id } = useParams();
+ const navigate = useNavigate();
+ const [loading, setLoading] = useState(false);
+ const [success, setSuccess] = useState(true);
+ const [principaldistributorData, setprincipaldistributorData] = useState([]);
+ const [data, setData] = useState({});
+ const nameRef = useRef();
+ const mobileRef = useRef();
+ const pdnameRef = useRef();
+ const pdmobileRef = 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 [modalPrincipalDistributors, setmodalPrincipalDistributors] = 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 Principal Distributors data
+ const getTMsprincipaldistributorData = async () => {
+ setLoading(true);
+ axios
+ .get(`/api/v1/getbySCId/${id}`, {
+ headers: {
+ Authorization: `Bearer ${token}`,
+ },
+ params: {
+ page: currentPage,
+ show: itemPerPage,
+ name: nameRef.current?.value,
+ mobileNumber: mobileRef.current?.value,
+ },
+ })
+ .then((res) => {
+ setprincipaldistributorData(res.data?.principaldistributor);
+ 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(() => {
+ getTMsprincipaldistributorData();
+ }, [success, itemPerPage, currentPage]);
+
+ // Debounced search for Principal Distributors
+ const debouncedSearch = useCallback(
+ debounce(() => {
+ setCurrentPage(1);
+ getTMsprincipaldistributorData();
+ }, 500),
+ [currentPage, itemPerPage]
+ );
+
+ const handleSearchChange = useCallback(() => {
+ debouncedSearch();
+ }, [debouncedSearch]);
+ // Fetch Principal Distributors data for modal
+ const getprincipaldistributorData = async () => {
+ setLoading(true);
+ try {
+ const res = await axios.get(`/api/v1/admin/users`, {
+ headers: {
+ Authorization: `Bearer ${token}`,
+ },
+ params: {
+ page: modalcurrentPage,
+ show: modalitemPerPage,
+ name: pdnameRef.current?.value,
+ mobileNumber: pdmobileRef.current?.value,
+ },
+ });
+ setmodalPrincipalDistributors(res.data?.users);
+ setModalTotalData(res.data?.totalUsers);
+ } 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) {
+ getprincipaldistributorData();
+ }
+ }, [openModal, modalcurrentPage]);
+
+ // Debounced search for Principal Distributors in modal
+ const debouncedmodalSearch = useCallback(
+ debounce(() => {
+ setmodalCurrentPage(1);
+ getprincipaldistributorData();
+ }, 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 (modalPrincipalDistributors.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/v1/unmapSC/${id}`, {}, { // Changed to PATCH and sent an empty body
+ headers: {
+ "Access-Control-Allow-Origin": "*",
+ Authorization: `Bearer ${token}`,
+ },
+ })
+ .then((res) => {
+ swal({
+ title: "Deleted",
+ text: "Principal 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 handleAddPrincipalDistributor = async (pdid) => {
+ try {
+ await axios.put(
+ `/api/v1/mappedSC/${pdid}`,
+ { mappedbySC: id },
+ {
+ headers: {
+ Authorization: `Bearer ${token}`,
+ },
+ }
+ );
+ swal({
+ title: "Success",
+ text: "Principal 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 */}
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ Unique Id |
+ SBU |
+ Name |
+ Mobile No. |
+ Email |
+ Action |
+
+
+
+
+ {loading ? (
+
+
+ Loading...
+ |
+
+ ) : principaldistributorData?.length > 0 ? (
+ principaldistributorData?.map((PD, i) => {
+ return (
+
+ {PD?.uniqueId} |
+ {PD?.SBU} |
+ {PD?.name} |
+ {PD?.phone} |
+
+ {PD?.email ? (
+ PD?.email
+ ) : (
+
+ No Email Added!
+
+ )}
+ |
+
+
+ |
+
+ );
+ })
+ ) : (
+
+
+ No Principal Distributor found!
+ |
+
+ )}
+
+
+
+
+
+ Showing {principaldistributorData?.length} of {totalData}{" "}
+ entries
+
+
+
+
+
+
+
+
+
+
+
+
+
+ );
+};
+
+export default ViewPrincipalDistributorSC;
diff --git a/src/views/TerritoryManager/TerritoryManager.js b/src/views/TerritoryManager/TerritoryManager.js
index f76faae..e5566b4 100644
--- a/src/views/TerritoryManager/TerritoryManager.js
+++ b/src/views/TerritoryManager/TerritoryManager.js
@@ -214,6 +214,7 @@ const TerritoryManager = () => {
| Email |
Verify |
Register On |
+ Mapping |
Action |
@@ -264,13 +265,13 @@ const TerritoryManager = () => {
{new Date(
territorymanager.createdAt
).toLocaleString("en-IN", {
- weekday: "short",
+ // weekday: "short",
month: "short",
day: "numeric",
year: "numeric",
- hour: "numeric",
- minute: "numeric",
- hour12: true,
+ // hour: "numeric",
+ // minute: "numeric",
+ // hour12: true,
})}
@@ -316,6 +317,8 @@ const TerritoryManager = () => {
RD
+ |
+
|