HM-132. Исправлена ошибка при которой нельзя было менять пользователей

This commit is contained in:
2020-09-10 22:11:31 +03:00
parent 00a2c29a09
commit f70de4f43d
2 changed files with 20 additions and 8 deletions

View File

@ -40,6 +40,7 @@ class UsersPage extends Component {
}); });
this.addSubscribe(this.usersForm, EVENTS.SAVE_USER, async (user) => { this.addSubscribe(this.usersForm, EVENTS.SAVE_USER, async (user) => {
console.log({user})
await usersServiceApi.update(user); await usersServiceApi.update(user);
this.initPage(); this.initPage();
}); });

View File

@ -85,20 +85,20 @@ class UserViewForm extends Component {
} }
]; ];
this.addEventListener(this.cancelButton, 'click', () => { this.addEventListener(this.cancelButton, EVENTS.CLICK, () => {
routeService.pushQuery({}, true); routeService.pushQuery({}, true);
}); });
this.addEventListener(this.editButton, 'click', () => { this.addEventListener(this.editButton, EVENTS.CLICK, () => {
routeService.pushQuery({mode: MODES.Edit}); routeService.pushQuery({mode: MODES.Edit});
}); });
this.addEventListener(this.form, 'submit', (event) => { this.addEventListener(this.form, EVENTS.SUBMIT, (event) => {
event.preventDefault(); event.preventDefault();
}); });
this.addEventListener(this.createButton, 'click', this.createUser); this.addEventListener(this.createButton, EVENTS.CLICK, this.createUser);
this.addEventListener(this.saveButton, 'click', this.saveUser); this.addEventListener(this.saveButton, EVENTS.CLICK, this.saveUser);
this.addEventListener(this.deleteButton, 'click', this.deleteUser); this.addEventListener(this.deleteButton, EVENTS.CLICK, this.deleteUser);
this.addSubscribe(routeService, EVENTS.ROUTE_SEARCH_CHANGE, ({query}) => { this.addSubscribe(routeService, EVENTS.ROUTE_SEARCH_CHANGE, ({query}) => {
const {mode, login} = query; const {mode, login} = query;
@ -128,7 +128,7 @@ class UserViewForm extends Component {
}); });
} }
validateInputs = () => { validateInputs = (isEditMode) => {
this.form.classList.add('was-validated'); this.form.classList.add('was-validated');
const login = this.login.getValue(); const login = this.login.getValue();
@ -147,6 +147,10 @@ class UserViewForm extends Component {
return ''; return '';
})(); })();
if (isEditMode) {
this.password.setError('');
}
this.login.setError(loginErrorMessage); this.login.setError(loginErrorMessage);
return this.form.checkValidity(); return this.form.checkValidity();
@ -174,7 +178,9 @@ class UserViewForm extends Component {
} }
saveUser = () => { saveUser = () => {
if (this.validateInputs()) { console.log('save')
if (this.validateInputs(true)) {
console.log('valid')
this.next(EVENTS.SAVE_USER, { this.next(EVENTS.SAVE_USER, {
login: this.login.getValue(), login: this.login.getValue(),
avatar: this.avatar.getValue(), avatar: this.avatar.getValue(),
@ -214,6 +220,11 @@ class UserViewForm extends Component {
const isShow = mode === MODES.Create; const isShow = mode === MODES.Create;
this.password.setValue(''); this.password.setValue('');
this.password.mainNode.style.display = isShow ? 'block' : 'none'; 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) => { setLogin = (mode, login) => {