Commit 30d550a6 authored by Florent POITTEVIN's avatar Florent POITTEVIN
Browse files

feat: display general validation error message on deposit

parent ad397065
......@@ -65,6 +65,7 @@ import {
KeyValue,
MappingObjectUtil,
OrderEnum,
OverrideProperty,
PropertyName,
ResourceNameSpace,
SolidifyValidator,
......@@ -182,6 +183,11 @@ export class DepositFormPresentational extends SharedAbstractFormPresentational<
lastSelectionContributorLocalStorageKey: LocalStorageEnum = LocalStorageEnum.multiSelectLastSelectionContributor;
@OverrideProperty()
protected _listFieldNameToDisplayErrorInToast: string[] = [
this.formDefinition.organizationalUnitId,
];
get metadataVersionEnum(): typeof Enums.Deposit.MetadataVersionEnum {
return Enums.Deposit.MetadataVersionEnum;
}
......
......@@ -15,6 +15,7 @@ import {
ErrorDto,
ResourceAction,
TypeDefaultAction,
ValidationErrorDto,
} from "solidify-frontend";
const state = LocalStateEnum.deposit;
......@@ -234,7 +235,7 @@ export namespace DepositAction {
export class SubmitFail {
static readonly type: string = `[${state}] Submit Fail`;
constructor() {
constructor(public listValidationError?: ValidationErrorDto[]) {
}
}
......
......@@ -109,6 +109,7 @@ import {
defaultAssociationRemoteStateInitValue,
defaultResourceStateInitValue,
ErrorDto,
ErrorHelper,
HttpStatus,
isEmptyArray,
isNonEmptyString,
......@@ -454,7 +455,7 @@ export class DepositState extends ResourceLogoState<DepositStateModel, Deposit>
}
}),
catchError(error => {
ctx.dispatch(new DepositAction.SubmitFail());
ctx.dispatch(new DepositAction.SubmitFail(ErrorHelper.extractValidationErrors(error)));
throw new SolidifyStateError(this, error);
}),
);
......@@ -468,7 +469,19 @@ export class DepositState extends ResourceLogoState<DepositStateModel, Deposit>
@Action(DepositAction.SubmitFail)
submitFail(ctx: StateContext<DepositStateModel>, action: DepositAction.SubmitFail): void {
this.notificationService.showError(MARK_AS_TRANSLATABLE("deposit.notification.submit.fail"));
let errorsMessage = StringUtil.stringEmpty;
if (isNotNullNorUndefined(action.listValidationError)) {
const errorMessageSeparator = ". ";
action.listValidationError.forEach(validationError => {
if (isNonEmptyString(errorsMessage)) {
errorsMessage = errorMessageSeparator;
}
if (isNotNullNorUndefined(validationError.errorMessages)) {
errorsMessage = errorsMessage + validationError.errorMessages.join(errorMessageSeparator);
}
});
}
this.notificationService.showError(MARK_AS_TRANSLATABLE("deposit.notification.submit.fail"), {errors: errorsMessage});
}
@Action(DepositAction.Approve)
......
......@@ -48,6 +48,8 @@ export abstract class SharedAbstractFormPresentational<TResource extends BaseRes
@HostBinding("class.readonly")
private _readonly: boolean;
protected _listFieldNameToDisplayErrorInToast: string[] = [];
@Input()
set readonly(value: boolean) {
this._readonly = value;
......@@ -197,6 +199,7 @@ export abstract class SharedAbstractFormPresentational<TResource extends BaseRes
model: model,
formControl: this.form,
changeDetectorRef: this._changeDetectorRef,
listFieldNameToDisplayErrorInToast: this._listFieldNameToDisplayErrorInToast,
});
}
......
......@@ -762,7 +762,7 @@
"update": "Dépôt mis à jour avec succès"
},
"submit": {
"fail": "Il y a eu une erreur lors de la soumission du dépôt",
"fail": "Il y a eu une erreur lors de la soumission du dépôt. {{errors}}",
"success": "Dépôt soumis"
}
},
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment