From a9e6b9ac06d834112311f5afceebc6124c48b0dd Mon Sep 17 00:00:00 2001 From: Zhayvoronok Kateryna <1gayv425@gmail.com> Date: Thu, 12 Dec 2024 16:34:44 +0200 Subject: [PATCH] fixed error output if currentPassword is incorrect --- src/constants/request.ts | 3 +- .../ChangePasswordModal.tsx | 51 +++---------------- src/services/auth-service.ts | 10 +--- 3 files changed, 8 insertions(+), 56 deletions(-) diff --git a/src/constants/request.ts b/src/constants/request.ts index 68530801f..720d33d9d 100644 --- a/src/constants/request.ts +++ b/src/constants/request.ts @@ -15,8 +15,7 @@ export const URLs = { confirm: '/auth/confirm-email', forgotPassword: '/auth/forgot-password', resetPassword: '/auth/reset-password', - changePassword: '/auth/change-password', - validatePassword: '/auth/validate-password' + changePassword: '/auth/change-password' }, users: { get: '/users', diff --git a/src/containers/edit-profile/password-security-tab/change-password-modal/ChangePasswordModal.tsx b/src/containers/edit-profile/password-security-tab/change-password-modal/ChangePasswordModal.tsx index 7b5158b3e..04dc33306 100644 --- a/src/containers/edit-profile/password-security-tab/change-password-modal/ChangePasswordModal.tsx +++ b/src/containers/edit-profile/password-security-tab/change-password-modal/ChangePasswordModal.tsx @@ -51,51 +51,16 @@ const ChangePasswordModal = () => { title: 'titles.confirmTitle', check: true }) - if (confirmed) { - resetErrors() + if (!confirmed) return + try { await sendChangedPassword({ password: data.password, currentPassword: data.currentPassword }) + } catch (err) { + data.currentPassword = '' } } - // const handleSubmitChangePassword = async () => { - // try { - // const response = await AuthService.validateCurrentPassword( - // userId, - // data.currentPassword - // ) - // console.log(response) - // if (!response.data.isValid) { - // handleErrors( - // 'currentPassword', - // t('common.errorMessages.incorrectCurrentPassword') - // ) - // return - // } - // const confirmed = await checkConfirmation({ - // message: t( - // 'editProfilePage.profile.passwordSecurityTab.changePasswordConfirm' - // ), - // title: 'titles.confirmTitle', - // check: true, - // }); - // if (!confirmed) { - // return; - // } - // resetErrors(); - // await sendChangedPassword({ - // password: data.password, - // currentPassword: data.currentPassword, - // }); - // } catch (error) { - // console.error('Error during validateCurrentPassword:', error); - // handleErrors( - // 'currentPassword', - // t('common.errorMessages.incorrectCurrentPassword') - // ); - // } - // } const handleResponse = () => { dispatch( openAlert({ @@ -129,14 +94,12 @@ const ChangePasswordModal = () => { const { loading, fetchData: sendChangedPassword } = useAxios({ service: changePassword, onResponse: handleResponse, - // onResponseError: handleResponseError, - onResponseError: (error) => { - console.error('Error from service:', error) + onResponseError: (error: ErrorResponse) => { handleResponseError(error) + throw error }, fetchOnMount: false }) - const { data, handleSubmit, @@ -151,7 +114,6 @@ const ChangePasswordModal = () => { initialValues: initialValues, validations: validations }) - console.log(errors) const { inputVisibility: currentPasswordVisibility, showInputText: showCurrentPassword @@ -195,7 +157,6 @@ const ChangePasswordModal = () => { > => { + ): Promise => { return axiosClient.patch( createUrlPath(URLs.auth.changePassword, userId), params ) - }, - validateCurrentPassword: ( - userId: string, - currentPassword: string - ): Promise> => { - console.log(currentPassword) - const url = createUrlPath(URLs.auth.validatePassword, userId) - return axiosClient.post(url, { currentPassword }) } }