reset password of TM,SC,PD and Retailer added

This commit is contained in:
Sibunnayak 2024-11-20 09:47:19 +05:30
parent f2ebae81b0
commit 7a0e8977b3
5 changed files with 135 additions and 5 deletions

View File

@ -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 ( return (
<div className="main-content"> <div className="main-content">
<div className="page-content"> <div className="page-content">
@ -486,6 +510,13 @@ const principalDistributor = () => {
</button> </button>
</Link> </Link>
</div> </div>
<button
type="button"
className="btn btn-info btn-sm waves-effect waves-light btn-table mt-1"
onClick={() => handleReset(user._id)}
>
Reset
</button>
</td> </td>
</tr> </tr>
)) ))

View File

@ -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 ( return (
<div className="main-content"> <div className="main-content">
<div className="page-content"> <div className="page-content">
@ -215,7 +238,6 @@ const RetailDistributor = () => {
size="small" size="small"
onClick={handleDownloadReport} onClick={handleDownloadReport}
disabled={loading} disabled={loading}
> >
Download Report Download Report
</Button> </Button>
@ -360,11 +382,20 @@ const RetailDistributor = () => {
> >
<button <button
type="button" type="button"
className="btn btn-info btn-sm waves-effect waves-light btn-table mt-1 ml-0 ml-lg-2" className="btn btn-info btn-sm waves-effect waves-light btn-table mt-1 ml-0 ml-lg-1"
> >
Edit Edit
</button> </button>
</Link> </Link>
<button
type="button"
className="btn btn-info btn-sm waves-effect waves-light btn-table mt-1 ml-0 ml-lg-1"
onClick={() =>
handleReset(retailDistributor._id)
}
>
Reset
</button>
</div> </div>
</td> </td>
</tr> </tr>

View File

@ -6,6 +6,7 @@ import { useNavigate } from "react-router-dom";
import { isAutheticated } from "src/auth"; import { isAutheticated } from "src/auth";
import swal from "sweetalert"; import swal from "sweetalert";
import debounce from "lodash.debounce"; import debounce from "lodash.debounce";
import { toast } from "react-hot-toast";
const SalesCoOrdinator = () => { const SalesCoOrdinator = () => {
const token = isAutheticated(); 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 ( return (
<div className="main-content"> <div className="main-content">
<div className="page-content"> <div className="page-content">
@ -333,6 +357,15 @@ const SalesCoOrdinator = () => {
> >
Delete Delete
</button> </button>
<button
type="button"
className="btn btn-info btn-sm waves-effect waves-light btn-table"
onClick={() =>
handleReset(salescoordinator._id)
}
>
Reset
</button>
</td> </td>
</tr> </tr>
); );

View File

@ -58,7 +58,7 @@ const EditTerritoryManager = () => {
otp: "", otp: "",
}); });
} catch (error) { } 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) => { .then((response) => {
swal({ swal({
title: "Success", title: "Success",
text: "Sales coordinator information updated successfully!", text: "Territory Manager information updated successfully!",
icon: "success", icon: "success",
button: "OK", button: "OK",
}); });

View File

@ -6,6 +6,7 @@ import { useNavigate } from "react-router-dom";
import { isAutheticated } from "src/auth"; import { isAutheticated } from "src/auth";
import swal from "sweetalert"; import swal from "sweetalert";
import debounce from "lodash.debounce"; import debounce from "lodash.debounce";
import { toast } from "react-hot-toast";
const TerritoryManager = () => { const TerritoryManager = () => {
const token = isAutheticated(); 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 ( return (
<div className="main-content"> <div className="main-content">
<div className="page-content"> <div className="page-content">
@ -225,7 +249,9 @@ const TerritoryManager = () => {
<th style={{ width: "17%" }}>Email</th> <th style={{ width: "17%" }}>Email</th>
<th style={{ width: "6%" }}>Verify</th> <th style={{ width: "6%" }}>Verify</th>
<th style={{ width: "10%" }}>Register On</th> <th style={{ width: "10%" }}>Register On</th>
<th className="text-center" style={{ width: "17%" }}>Mapping</th> <th className="text-center" style={{ width: "17%" }}>
Mapping
</th>
<th className="text-center" style={{ width: "13%" }}> <th className="text-center" style={{ width: "13%" }}>
Action Action
</th> </th>
@ -341,6 +367,15 @@ const TerritoryManager = () => {
> >
Delete Delete
</button> </button>
<button
type="button"
className="btn btn-info btn-sm waves-effect waves-light btn-table"
onClick={() =>
handleReset(territorymanager._id)
}
>
Reset
</button>
</td> </td>
</tr> </tr>
); );