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 (
<div className="main-content">
<div className="page-content">
@ -486,6 +510,13 @@ const principalDistributor = () => {
</button>
</Link>
</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>
</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 (
<div className="main-content">
<div className="page-content">
@ -215,7 +238,6 @@ const RetailDistributor = () => {
size="small"
onClick={handleDownloadReport}
disabled={loading}
>
Download Report
</Button>
@ -360,11 +382,20 @@ const RetailDistributor = () => {
>
<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
</button>
</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>
</td>
</tr>

View File

@ -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 (
<div className="main-content">
<div className="page-content">
@ -333,6 +357,15 @@ const SalesCoOrdinator = () => {
>
Delete
</button>
<button
type="button"
className="btn btn-info btn-sm waves-effect waves-light btn-table"
onClick={() =>
handleReset(salescoordinator._id)
}
>
Reset
</button>
</td>
</tr>
);

View File

@ -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",
});

View File

@ -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 (
<div className="main-content">
<div className="page-content">
@ -225,7 +249,9 @@ const TerritoryManager = () => {
<th style={{ width: "17%" }}>Email</th>
<th style={{ width: "6%" }}>Verify</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%" }}>
Action
</th>
@ -341,6 +367,15 @@ const TerritoryManager = () => {
>
Delete
</button>
<button
type="button"
className="btn btn-info btn-sm waves-effect waves-light btn-table"
onClick={() =>
handleReset(territorymanager._id)
}
>
Reset
</button>
</td>
</tr>
);