From fd1b021008bb604783c07fe45f1821ca52e8d0ea Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C5=82=20Ska=C5=82ka?= Date: Thu, 14 Sep 2023 15:55:33 +0200 Subject: [PATCH] delete FormHelper.js --- src/libs/FormHelper.js | 50 ------------------------------------------ 1 file changed, 50 deletions(-) delete mode 100644 src/libs/FormHelper.js diff --git a/src/libs/FormHelper.js b/src/libs/FormHelper.js deleted file mode 100644 index feab0f44acea..000000000000 --- a/src/libs/FormHelper.js +++ /dev/null @@ -1,50 +0,0 @@ -import _ from 'underscore'; -import lodashGet from 'lodash/get'; -import lodashUnset from 'lodash/unset'; -import lodashCloneDeep from 'lodash/cloneDeep'; - -class FormHelper { - constructor({errorPath, setErrors}) { - this.errorPath = errorPath; - this.setErrors = setErrors; - this.getErrors = this.getErrors.bind(this); - this.clearError = this.clearError.bind(this); - this.clearErrors = this.clearErrors.bind(this); - } - - /** - * @param {Object} props - * @returns {Object} - */ - getErrors(props) { - return lodashGet(props, this.errorPath, {}); - } - - /** - * @param {Object} props - * @param {String[]} paths - */ - clearErrors(props, paths) { - const errors = this.getErrors(props); - const pathsWithErrors = _.filter(paths, (path) => lodashGet(errors, path, false)); - if (_.size(pathsWithErrors) === 0) { - // No error found for this path - return; - } - - // Clear the existing errors - const newErrors = lodashCloneDeep(errors); - _.forEach(pathsWithErrors, (path) => lodashUnset(newErrors, path)); - this.setErrors(newErrors); - } - - /** - * @param {Object} props - * @param {String} path - */ - clearError(props, path) { - this.clearErrors(props, [path]); - } -} - -export default FormHelper;