refactor: fixed dirty values in edit user form

This commit is contained in:
Sergey Yarkov 2021-11-05 22:43:16 +03:00
parent 6d72fdb1c3
commit 479a6291eb
2 changed files with 3 additions and 8 deletions

View File

@ -79,8 +79,8 @@ const UpdateUserForm: React.FC<UpdateUserFormPropsType> = ({ onClose, isOpen, me
last_name: editingUser && editingUser.last_name, last_name: editingUser && editingUser.last_name,
email: editingUser && editingUser.email, email: editingUser && editingUser.email,
role: editingUser && editingUser.roles[0].slug, role: editingUser && editingUser.roles[0].slug,
login: null, login: '',
password: null, password: '',
}, },
}); });
const isMountedRef = useIsMountedRef(); const isMountedRef = useIsMountedRef();

View File

@ -84,8 +84,6 @@ export default class UserStore {
try { try {
const result = await this.userService.create(data); const result = await this.userService.create(data);
console.log(`[${this.constructor.name}]: ${result.message}`, result);
if (this.users !== null) { if (this.users !== null) {
/** /**
* Fetch updated users data with new pagination data * Fetch updated users data with new pagination data
@ -103,11 +101,10 @@ export default class UserStore {
try { try {
const result = await this.userService.update(id, params); const result = await this.userService.update(id, params);
console.log(`[${this.constructor.name}]: ${result.message}`, result);
runInAction(() => { runInAction(() => {
if (this.users !== null) { if (this.users !== null) {
const userIndex = this.users.findIndex(user => user.id === id); const userIndex = this.users.findIndex(user => user.id === id);
if (userIndex !== -1) { if (userIndex !== -1) {
this.users[userIndex] = result.data; this.users[userIndex] = result.data;
} }
@ -130,8 +127,6 @@ export default class UserStore {
try { try {
const result = await this.userService.delete(id); const result = await this.userService.delete(id);
console.log(`[${this.constructor.name}]: ${result.message}`, result);
if (this.users !== null) { if (this.users !== null) {
/** /**
* Fetch updated users data with new pagination data * Fetch updated users data with new pagination data