diff --git a/src/pages/users/components/page/Page.js b/src/pages/users/components/page/Page.js index cbc5696..ae620bf 100644 --- a/src/pages/users/components/page/Page.js +++ b/src/pages/users/components/page/Page.js @@ -40,6 +40,7 @@ class UsersPage extends Component { }); this.addSubscribe(this.usersForm, EVENTS.SAVE_USER, async (user) => { + console.log({user}) await usersServiceApi.update(user); this.initPage(); }); diff --git a/src/pages/users/components/user-view-form/UserViewForm.js b/src/pages/users/components/user-view-form/UserViewForm.js index f42dc7a..2a44012 100644 --- a/src/pages/users/components/user-view-form/UserViewForm.js +++ b/src/pages/users/components/user-view-form/UserViewForm.js @@ -85,20 +85,20 @@ class UserViewForm extends Component { } ]; - this.addEventListener(this.cancelButton, 'click', () => { + this.addEventListener(this.cancelButton, EVENTS.CLICK, () => { routeService.pushQuery({}, true); }); - this.addEventListener(this.editButton, 'click', () => { + this.addEventListener(this.editButton, EVENTS.CLICK, () => { routeService.pushQuery({mode: MODES.Edit}); }); - this.addEventListener(this.form, 'submit', (event) => { + this.addEventListener(this.form, EVENTS.SUBMIT, (event) => { event.preventDefault(); }); - this.addEventListener(this.createButton, 'click', this.createUser); - this.addEventListener(this.saveButton, 'click', this.saveUser); - this.addEventListener(this.deleteButton, 'click', this.deleteUser); + this.addEventListener(this.createButton, EVENTS.CLICK, this.createUser); + this.addEventListener(this.saveButton, EVENTS.CLICK, this.saveUser); + this.addEventListener(this.deleteButton, EVENTS.CLICK, this.deleteUser); this.addSubscribe(routeService, EVENTS.ROUTE_SEARCH_CHANGE, ({query}) => { const {mode, login} = query; @@ -128,7 +128,7 @@ class UserViewForm extends Component { }); } - validateInputs = () => { + validateInputs = (isEditMode) => { this.form.classList.add('was-validated'); const login = this.login.getValue(); @@ -147,6 +147,10 @@ class UserViewForm extends Component { return ''; })(); + if (isEditMode) { + this.password.setError(''); + } + this.login.setError(loginErrorMessage); return this.form.checkValidity(); @@ -174,7 +178,9 @@ class UserViewForm extends Component { } saveUser = () => { - if (this.validateInputs()) { + console.log('save') + if (this.validateInputs(true)) { + console.log('valid') this.next(EVENTS.SAVE_USER, { login: this.login.getValue(), avatar: this.avatar.getValue(), @@ -214,6 +220,11 @@ class UserViewForm extends Component { const isShow = mode === MODES.Create; this.password.setValue(''); this.password.mainNode.style.display = isShow ? 'block' : 'none'; + if (isShow) { + this.login.mainNode.after(this.password.mainNode); + } else { + this.mainNode.appendChild(this.password.mainNode); + } } setLogin = (mode, login) => {