initial public commit
This commit is contained in:
32
ui/src/stores/errors.js
Normal file
32
ui/src/stores/errors.js
Normal file
@@ -0,0 +1,32 @@
|
||||
import { writable } from "svelte/store";
|
||||
import CommonHelper from "@/utils/CommonHelper";
|
||||
|
||||
export const errors = writable({});
|
||||
|
||||
/**
|
||||
* @param {Object} newErrors
|
||||
*/
|
||||
export function setErrors(newErrors) {
|
||||
errors.set(newErrors || {});
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {String} name
|
||||
* @param {String|Array} message
|
||||
*/
|
||||
export function addError(name, message) {
|
||||
errors.update((e) => {
|
||||
CommonHelper.setByPath(e, name, CommonHelper.sentenize(message))
|
||||
return e;
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {String} name
|
||||
*/
|
||||
export function removeError(name) {
|
||||
errors.update((e) => {
|
||||
CommonHelper.deleteByPath(e, name);
|
||||
return e;
|
||||
});
|
||||
}
|
||||
Reference in New Issue
Block a user