From edcb4cd7b916344220bd3aa5ba99368f06025fe7 Mon Sep 17 00:00:00 2001 From: Swapnil Bendal <84583651+Swapnil155@users.noreply.github.com> Date: Fri, 20 Dec 2024 20:00:13 +0530 Subject: [PATCH] [fixed] - changes password --- src/Pages/ChangePassword.jsx | 27 +++++++++++++++++++-------- 1 file changed, 19 insertions(+), 8 deletions(-) diff --git a/src/Pages/ChangePassword.jsx b/src/Pages/ChangePassword.jsx index 82d7b62..e532216 100644 --- a/src/Pages/ChangePassword.jsx +++ b/src/Pages/ChangePassword.jsx @@ -16,14 +16,13 @@ import { Stack, useToast, } from "@chakra-ui/react"; -import * as yup from "yup"; -import React, { useState, useContext } from "react"; -import { useForm } from "react-hook-form"; import { yupResolver } from "@hookform/resolvers/yup"; +import React, { useState } from "react"; +import { useForm } from "react-hook-form"; +import * as yup from "yup"; import CustomAlertDialog from "../Components/CustomAlertDialog"; import ToastBox from "../Components/ToastBox"; import { useUpdatePasswordMutation } from "../Services/change.password.service"; -import { all } from "axios"; // Validation schema const passwordSchema = yup.object().shape({ @@ -53,12 +52,18 @@ const ChangePassword = ({ actionId, setActionId, }) => { + const initialValue = { + oldPassword: "", + newPassword: "", + confirmNewPassword: "", + }; const [isLoading, setIsLoading] = useState(false); const [alert, setAlert] = useState(false); const [showCurrentPassword, setShowCurrentPassword] = useState(false); const [showNewPassword, setShowNewPassword] = useState(false); const [showConfirmPassword, setShowConfirmPassword] = useState(false); const toast = useToast(); + const [input, setInput] = useState(initialValue); const [updatePassword] = useUpdatePasswordMutation(); @@ -74,10 +79,10 @@ 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: () => , @@ -98,6 +103,11 @@ const ChangePassword = ({ } }; + const handleSubmitFrom = (data) => { + setAlert(true); + setInput(data); + }; + // Handle modal close const handleClose = () => { setAlert(false); @@ -211,7 +221,8 @@ const ChangePassword = ({ rounded={"sm"} colorScheme="forestGreen" size="sm" - onClick={() => setAlert(true)} + // onClick={() => setAlert(true)} + onClick={handleSubmit(handleSubmitFrom)} isLoading={isLoading} > Save @@ -223,7 +234,7 @@ const ChangePassword = ({ setAlert(false)} - alertHandler={handleSubmit(onSubmit)} + alertHandler={onSubmit} message={"Are you sure you want to change the password?"} isLoading={isLoading} />