From 5d2c28f6ca7712a0ac9d6e9ba2d7588176c9da08 Mon Sep 17 00:00:00 2001
From: YasinShaikh123 <123150391+YasinShaikh123@users.noreply.github.com>
Date: Thu, 12 Dec 2024 13:52:55 +0530
Subject: [PATCH] update change password
---
src/Pages/ChangePassword.jsx | 26 +++++++++++++++++++++-----
1 file changed, 21 insertions(+), 5 deletions(-)
diff --git a/src/Pages/ChangePassword.jsx b/src/Pages/ChangePassword.jsx
index 59b8a0d..20e6ea1 100644
--- a/src/Pages/ChangePassword.jsx
+++ b/src/Pages/ChangePassword.jsx
@@ -56,6 +56,11 @@ const ChangePassword = ({
const [isLoading, setIsLoading] = useState(false);
const [alert, setAlert] = useState(false);
const [showCurrentPassword, setShowCurrentPassword] = useState(false);
+ const [input, setInput] = useState({
+ oldPassword: "",
+ newPassword: "",
+ confirmNewPassword: "",
+ });
const [showNewPassword, setShowNewPassword] = useState(false);
const [showConfirmPassword, setShowConfirmPassword] = useState(false);
const toast = useToast();
@@ -74,22 +79,27 @@ const ChangePassword = ({
});
// Form submit handler
- const onSubmit = async (data) => {
+ const onSubmit = async () => {
setIsLoading(true);
try {
- const res = await updatePassword(data); // Assuming API request works as expected
+ const res = await updatePassword(input); // Assuming API request works as expected
if (res?.data?.statusCode === 200) {
toast({
render: () => ,
});
handleClose();
- } else if (res?.error.statusCode === 400) {
+ } else if (res?.error) {
toast({
render: () => (
),
});
}
+ setInput({
+ oldPassword: "",
+ newPassword: "",
+ confirmNewPassword: "",
+ });
} catch (error) {
console.error(error);
} finally {
@@ -97,6 +107,11 @@ const ChangePassword = ({
}
};
+ const handleAlert = (data) => {
+ setAlert(true);
+ setInput(data);
+ };
+
// Handle modal close
const handleClose = () => {
setAlert(false);
@@ -210,7 +225,8 @@ const ChangePassword = ({
rounded={"sm"}
colorScheme="forestGreen"
size="sm"
- onClick={() => setAlert(true)}
+ // onClick={() => setAlert(true)}
+ onClick={handleSubmit(handleAlert)}
isLoading={isLoading}
>
Save
@@ -222,7 +238,7 @@ const ChangePassword = ({
setAlert(false)}
- alertHandler={handleSubmit(onSubmit)}
+ alertHandler={onSubmit}
message={"Are you sure you want to change the password?"}
isLoading={isLoading}
/>