🐛 Fixed validation errors for duplicate members (#15362)

closes: #15292

- Remove banner error and show duplicate member validation error inline
- Add property: 'email' to member API validation error
This commit is contained in:
Hakim Razalan 2022-09-09 00:29:48 +08:00 committed by GitHub
parent 7084217d3d
commit a440076a12
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 18 additions and 4 deletions

View File

@ -187,9 +187,21 @@ export default class MemberController extends Controller {
return member;
} catch (error) {
if (error) {
this.notifications.showAPIError(error, {key: 'member.save'});
if (error === undefined) {
// Validation error
return;
}
if (error.payload && error.payload.errors) {
for (const payloadError of error.payload.errors) {
if (payloadError.type === 'ValidationError' && payloadError.property && (payloadError.context || payloadError.message)) {
member.errors.add(payloadError.property, payloadError.context || payloadError.message);
member.hasValidated.pushObject(payloadError.property);
}
}
}
throw error;
}
}

View File

@ -259,7 +259,8 @@ module.exports = class MemberBREADService {
if (error.code && error.message.toLowerCase().indexOf('unique') !== -1) {
throw new errors.ValidationError({
message: tpl(messages.memberAlreadyExists),
context: 'Attempting to add member with existing email address'
context: 'Attempting to add member with existing email address',
property: 'email'
});
}
throw error;
@ -316,7 +317,8 @@ module.exports = class MemberBREADService {
if (error.code && error.message.toLowerCase().indexOf('unique') !== -1) {
throw new errors.ValidationError({
message: tpl(messages.memberAlreadyExists),
context: 'Attempting to edit member with existing email address'
context: 'Attempting to edit member with existing email address',
property: 'email'
});
}