From 7a0e8977b367cfdf497ed2070d75b0516be66c27 Mon Sep 17 00:00:00 2001 From: Sibunnayak Date: Wed, 20 Nov 2024 09:47:19 +0530 Subject: [PATCH] reset password of TM,SC,PD and Retailer added --- .../principalDistributor.js | 31 ++++++++++++++++ .../RetailDistributors/RetailDistributor.js | 35 +++++++++++++++++- .../SalesCoOrdinators/SalesCoOrdinator.js | 33 +++++++++++++++++ .../TerritoryManager/EditTerritoryManager.js | 4 +- .../TerritoryManager/TerritoryManager.js | 37 ++++++++++++++++++- 5 files changed, 135 insertions(+), 5 deletions(-) diff --git a/src/views/PrincipalDistributors/principalDistributor.js b/src/views/PrincipalDistributors/principalDistributor.js index 07808ad..b393c61 100644 --- a/src/views/PrincipalDistributors/principalDistributor.js +++ b/src/views/PrincipalDistributors/principalDistributor.js @@ -158,6 +158,30 @@ const principalDistributor = () => { }); } }; + const handleReset = async (id) => { + try { + const response = await axios.put( + `/api/v1/user/reset-password/${id}`, + {}, // No body content required for this request + { + headers: { + Authorization: `Bearer ${token}`, + }, + } + ); + + if (response.data.success) { + toast.success( + "Password reset successfully! Email sent to Territory Manager." + ); + } + } catch (error) { + toast.error( + error.response?.data?.message || + "Failed to reset the password. Please try again." + ); + } + }; return (
@@ -486,6 +510,13 @@ const principalDistributor = () => {
+ )) diff --git a/src/views/RetailDistributors/RetailDistributor.js b/src/views/RetailDistributors/RetailDistributor.js index 144a326..14d32f3 100644 --- a/src/views/RetailDistributors/RetailDistributor.js +++ b/src/views/RetailDistributors/RetailDistributor.js @@ -119,7 +119,30 @@ const RetailDistributor = () => { }); } }; + const handleReset = async (id) => { + try { + const response = await axios.put( + `/api/rd/reset-password/${id}`, + {}, // No body content required for this request + { + headers: { + Authorization: `Bearer ${token}`, + }, + } + ); + if (response.data.success) { + toast.success( + "Password reset successfully! Email sent to Territory Manager." + ); + } + } catch (error) { + toast.error( + error.response?.data?.message || + "Failed to reset the password. Please try again." + ); + } + }; return (
@@ -215,7 +238,6 @@ const RetailDistributor = () => { size="small" onClick={handleDownloadReport} disabled={loading} - > Download Report @@ -360,11 +382,20 @@ const RetailDistributor = () => { > +
diff --git a/src/views/SalesCoOrdinators/SalesCoOrdinator.js b/src/views/SalesCoOrdinators/SalesCoOrdinator.js index 7bd91df..7fb286c 100644 --- a/src/views/SalesCoOrdinators/SalesCoOrdinator.js +++ b/src/views/SalesCoOrdinators/SalesCoOrdinator.js @@ -6,6 +6,7 @@ import { useNavigate } from "react-router-dom"; import { isAutheticated } from "src/auth"; import swal from "sweetalert"; import debounce from "lodash.debounce"; +import { toast } from "react-hot-toast"; const SalesCoOrdinator = () => { const token = isAutheticated(); @@ -110,7 +111,30 @@ const SalesCoOrdinator = () => { } }); }; + const handleReset = async (id) => { + try { + const response = await axios.put( + `/api/salescoordinator/reset-password/${id}`, + {}, // No body content required for this request + { + headers: { + Authorization: `Bearer ${token}`, + }, + } + ); + if (response.data.success) { + toast.success( + "Password reset successfully! Email sent to Territory Manager." + ); + } + } catch (error) { + toast.error( + error.response?.data?.message || + "Failed to reset the password. Please try again." + ); + } + }; return (
@@ -333,6 +357,15 @@ const SalesCoOrdinator = () => { > Delete + ); diff --git a/src/views/TerritoryManager/EditTerritoryManager.js b/src/views/TerritoryManager/EditTerritoryManager.js index 718260d..6c7c621 100644 --- a/src/views/TerritoryManager/EditTerritoryManager.js +++ b/src/views/TerritoryManager/EditTerritoryManager.js @@ -58,7 +58,7 @@ const EditTerritoryManager = () => { otp: "", }); } catch (error) { - console.error("Error fetching sales coordinator data: ", error); + console.error("Error fetching terri tory manager data: ", error); } }; @@ -84,7 +84,7 @@ const EditTerritoryManager = () => { .then((response) => { swal({ title: "Success", - text: "Sales coordinator information updated successfully!", + text: "Territory Manager information updated successfully!", icon: "success", button: "OK", }); diff --git a/src/views/TerritoryManager/TerritoryManager.js b/src/views/TerritoryManager/TerritoryManager.js index 4dee2ff..44be7a1 100644 --- a/src/views/TerritoryManager/TerritoryManager.js +++ b/src/views/TerritoryManager/TerritoryManager.js @@ -6,6 +6,7 @@ import { useNavigate } from "react-router-dom"; import { isAutheticated } from "src/auth"; import swal from "sweetalert"; import debounce from "lodash.debounce"; +import { toast } from "react-hot-toast"; const TerritoryManager = () => { const token = isAutheticated(); @@ -110,7 +111,30 @@ const TerritoryManager = () => { } }); }; + const handleReset = async (id) => { + try { + const response = await axios.put( + `/api/territorymanager/reset-password/${id}`, + {}, // No body content required for this request + { + headers: { + Authorization: `Bearer ${token}`, + }, + } + ); + if (response.data.success) { + toast.success( + "Password reset successfully! Email sent to Territory Manager." + ); + } + } catch (error) { + toast.error( + error.response?.data?.message || + "Failed to reset the password. Please try again." + ); + } + }; return (
@@ -225,7 +249,9 @@ const TerritoryManager = () => { Email Verify Register On - Mapping + + Mapping + Action @@ -341,6 +367,15 @@ const TerritoryManager = () => { > Delete + );