Skip to content

Commit

Permalink
Change Password Requirement for IEC Security
Browse files Browse the repository at this point in the history
  • Loading branch information
sude-dewi committed Aug 19, 2024
1 parent 8edbe8c commit a7b4fee
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 45 deletions.
60 changes: 26 additions & 34 deletions packages/react-components/src/Accounts/Accounts.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -128,45 +128,37 @@ const Accounts: React.FC<UserGroupProps> = ({ host, token, userGroupsDefaultSele
setRows(changedRows);
};

const handleSubmit = (row, isNew = false) => {
const handleError = (error, action) => {
try {
if (error instanceof Error) {
const errorMessage = error.message;

const parsedError = JSON.parse(errorMessage);
const firstErrorMessage = parsedError.errors[0]?.description;
setErrorMessage(firstErrorMessage);
} else {
console.log(`${action}: Received non-Error object:`, error);
}
} catch (e) {
console.log(`${action}: Failed to parse error response.`, e);
const handleError = (error, action) => {
try {
if (error instanceof Error) {
const errorMessage = error.message;
const parsedError = JSON.parse(errorMessage);
const firstErrorMessage = parsedError.errors[0]?.description;
setErrorMessage(firstErrorMessage);
} else {
console.log(`${action}: Received non-Error object:`, error);
}
} catch (e) {
console.log(`${action}: Failed to parse error response.`, e);
}
};

const handleSubmit = (row, isNew = false) => {
const onSuccess = () => {
setErrorMessage('');
fetchData();
};


const onError = (error) => {
handleError(error, isNew ? 'Create Account' : 'Update Account');
};

if (isNew) {
return createAccount(host, token, { ...row }).subscribe(
() => {
setErrorMessage('');
fetchData();
},
(error) => {
handleError(error, 'Create Account');
}
);
return createAccount(host, token, { ...row }).subscribe(onSuccess, onError);
} else {
return updateAccount(host, token, { ...row }).subscribe(
() => {
setErrorMessage('');
fetchData();
},
(error) => {
handleError(error, 'Update Account');
}
);
return updateAccount(host, token, { ...row }).subscribe(onSuccess, onError);
}
};
};

const handleDelete = (row) => {
deleteAccount(host, token, row.id).subscribe(
Expand Down
20 changes: 9 additions & 11 deletions packages/react-components/src/common/Table/PopupEditing.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -129,17 +129,15 @@ const PopupEditing = React.memo(

if (isNew) {
commitAddedRows({ rowIds });
onSave(editedRow, isNew);
} else {
onSave(editedRow);
if (errorMessage !== '') {
onSave(editedRow);
stopEditRows({ rowIds });
commitChangedRows({ rowIds });
} else {
onSave(editedRow);
}
}
}

if (errorMessage !== '') {
stopEditRows({ rowIds });
commitChangedRows({ rowIds });
}

onSave(editedRow, isNew);

} catch (error) {
console.error('Error applying changes:', error);
cancelChanges();
Expand Down

0 comments on commit a7b4fee

Please sign in to comment.