update change password
This commit is contained in:
@@ -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: () => <ToastBox message={res?.data?.message} />,
|
||||
});
|
||||
handleClose();
|
||||
} else if (res?.error.statusCode === 400) {
|
||||
} else if (res?.error) {
|
||||
toast({
|
||||
render: () => (
|
||||
<ToastBox message={res?.error?.data?.message} status={"error"} />
|
||||
),
|
||||
});
|
||||
}
|
||||
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 = ({
|
||||
<CustomAlertDialog
|
||||
isOpen={alert}
|
||||
onClose={() => setAlert(false)}
|
||||
alertHandler={handleSubmit(onSubmit)}
|
||||
alertHandler={onSubmit}
|
||||
message={"Are you sure you want to change the password?"}
|
||||
isLoading={isLoading}
|
||||
/>
|
||||
|
||||
Reference in New Issue
Block a user