44 lines
825 B
TypeScript
44 lines
825 B
TypeScript
import notification from 'Elements/notification';
|
|
import { makeAutoObservable, observable } from 'mobx';
|
|
|
|
type Params = {
|
|
err_key: string;
|
|
err_title: string;
|
|
};
|
|
|
|
export default class Validation {
|
|
params: Params;
|
|
messages = observable<string>([]);
|
|
|
|
constructor(params: Params) {
|
|
makeAutoObservable(this);
|
|
this.params = params;
|
|
}
|
|
|
|
getMessages() {
|
|
return this.messages;
|
|
}
|
|
|
|
addError = (message: string) => {
|
|
this.messages.push(message);
|
|
|
|
const messageIndex = this.messages.length;
|
|
|
|
const removeError = () => {
|
|
this.messages.splice(messageIndex - 1, 1);
|
|
};
|
|
|
|
notification.error({
|
|
key: this.params.err_key,
|
|
message: this.params.err_title,
|
|
description: message,
|
|
});
|
|
|
|
return removeError;
|
|
};
|
|
|
|
clearErrors = () => {
|
|
this.messages.clear();
|
|
};
|
|
}
|