From cccd5e7556c387a2e85baa62e4f065cdb09a8f12 Mon Sep 17 00:00:00 2001 From: vigdorov Date: Thu, 10 Sep 2020 23:07:44 +0300 Subject: [PATCH] =?UTF-8?q?HM-129.=20HM-130.=20=D0=98=D1=81=D0=BF=D1=80?= =?UTF-8?q?=D0=B0=D0=B2=D0=BB=D0=B5=D0=BD=D1=8B=20=D0=BE=D1=88=D0=B8=D0=B1?= =?UTF-8?q?=D0=BA=D0=B8=20=D0=BF=D1=80=D0=B8=20=D1=81=D0=BC=D0=B5=D0=BD?= =?UTF-8?q?=D0=B5=20=D0=BF=D0=B0=D1=80=D0=BE=D0=BB=D1=8F=20=D0=B2=20=D0=9B?= =?UTF-8?q?=D0=B8=D1=87=D0=BD=D0=BE=D0=BC=20=D0=BA=D0=B0=D0=B1=D0=B8=D0=BD?= =?UTF-8?q?=D0=B5=D1=82=D0=B5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../profile-content/ProfileContent.js | 23 ++++++++++++------- .../components/profile-content/consts.js | 9 ++++++++ 2 files changed, 24 insertions(+), 8 deletions(-) diff --git a/src/pages/profile/components/profile-content/ProfileContent.js b/src/pages/profile/components/profile-content/ProfileContent.js index 5ac01b9..48c0510 100644 --- a/src/pages/profile/components/profile-content/ProfileContent.js +++ b/src/pages/profile/components/profile-content/ProfileContent.js @@ -1,7 +1,7 @@ import Component from '../../../../core/components/component/Component'; import FormControl from '../../../../core/components/form-control/FormControl'; import {FORM_TYPES, EVENTS} from '../../../../core/consts'; -import {INPUT_IDS, LABELS} from './consts'; +import {INPUT_IDS, LABELS, ERRORS} from './consts'; import notify from '../../../../services/NotifyService'; import profileServiceApi from '../../../../api/ProfileServiceAPI'; @@ -48,22 +48,22 @@ class ProfileContent extends Component { const newPasswordRepeat = this.newPasswordRepeat.getValue(); if (!oldPassword) { - this.oldPassword.setError('Заполните старый пароль'); + this.oldPassword.setError(ERRORS.TYPED_OLD_PASSWORD); } if (!newPassword) { - this.newPassword.setError('Заполните новый пароль'); + this.newPassword.setError(ERRORS.TYPED_NEW_PASSWORD); } const isEqualPassword = newPassword === newPasswordRepeat; if (!isEqualPassword) { - this.newPassword.setError('Пароли не совпадают'); - this.newPasswordRepeat.setError('Пароли не совпадают'); + this.newPassword.setError(ERRORS.PASSWORD_NOT_EQUAL); + this.newPasswordRepeat.setError(ERRORS.PASSWORD_NOT_EQUAL); } if (!newPasswordRepeat) { - this.newPasswordRepeat.setError('Повторите новый пароль'); + this.newPasswordRepeat.setError(ERRORS.REPEAT_PASSWORD); } return this.form.checkValidity() && isEqualPassword; @@ -81,9 +81,16 @@ class ProfileContent extends Component { if (this.validateInputs()) { const oldPassword = this.oldPassword.getValue(); const newPassword = this.newPassword.getValue(); - await profileServiceApi.changePassword(oldPassword, newPassword); + try { + await profileServiceApi.changePassword(oldPassword, newPassword); + } catch (e) { + if (e?.response?.data?.message === ERRORS.NOT_CORRECT_PASSWORD) { + this.oldPassword.setError(ERRORS.NOT_CORRECT_PASSWORD); + } + throw new Error(e); + } this.clearForm(); - notify.success('Пароль успешно изменен'); + notify.success(LABELS.SUCCESS_CHANGE_PASSWORD); } } diff --git a/src/pages/profile/components/profile-content/consts.js b/src/pages/profile/components/profile-content/consts.js index edcf068..c9068fc 100644 --- a/src/pages/profile/components/profile-content/consts.js +++ b/src/pages/profile/components/profile-content/consts.js @@ -11,4 +11,13 @@ export const LABELS = { OLD_PASSWORD_PLACEHOLDER: 'Введите старый пароль', NEW_PASSWORD_PLACEHOLDER: 'Введите новый пароль', NEW_PASSWORD_REPEAT_PLACEHOLDER: 'Введите новый пароль еще раз', + SUCCESS_CHANGE_PASSWORD: '', +}; + +export const ERRORS = { + TYPED_OLD_PASSWORD: 'Заполните старый пароль', + TYPED_NEW_PASSWORD: 'Заполните новый пароль', + PASSWORD_NOT_EQUAL: 'Пароли не совпадают', + REPEAT_PASSWORD: 'Повторите новый пароль', + NOT_CORRECT_PASSWORD: 'Не верный старый пароль', };