diff --git a/package.json b/package.json index 90df6a6..7edb643 100644 --- a/package.json +++ b/package.json @@ -4,24 +4,24 @@ "private": true, "dependencies": { "@babel/plugin-proposal-private-property-in-object": "7.21.11", - "@babel/preset-react": "7.25.9", + "@babel/preset-react": "7.26.3", "@date-fns/tz": "1.2.0", "@emailjs/browser": "4.4.1", - "@emotion/styled": "11.13.5", - "@number-flow/react": "0.4.2", - "@sentry/browser": "8.42.0", + "@emotion/styled": "11.14.0", + "@number-flow/react": "0.5.5", + "@sentry/browser": "8.51.0", "@stomp/stompjs": "7.0.0", - "@tanstack/react-table": "8.20.5", - "@wordpress/i18n": "5.13.0", - "@wordpress/react-i18n": "4.13.0", + "@tanstack/react-table": "8.20.6", + "@wordpress/i18n": "5.16.0", + "@wordpress/react-i18n": "4.16.0", "codice-fiscale-js": "2.3.22", "copy-to-clipboard": "3.3.3", "deep-object-diff": "1.1.9", - "dompurify": "3.2.2", + "dompurify": "3.2.3", "expression-language": "^1.2.0", "fast-deep-equal": "3.1.3", - "hotkeys-js": "3.13.7", - "html-react-parser": "5.1.18", + "hotkeys-js": "3.13.9", + "html-react-parser": "5.2.2", "jwt-decode": "4.0.0", "klona": "2.0.6", "leader-line-new": "1.1.9", @@ -30,15 +30,15 @@ "mustache": "^4.2.0", "object-path-immutable": "4.1.2", "primeicons": "7.0.0", - "primereact": "10.8.5", + "primereact": "10.9.2", "quill": "2.0.3", "ramda": "0.30.1", "react": "18.3.1", "react-dnd": "16.0.1", "react-dnd-html5-backend": "16.0.1", "react-dom": "18.3.1", - "react-hook-form": "7.53.2", - "react-router-dom": "7.0.1", + "react-hook-form": "7.54.2", + "react-router-dom": "7.1.3", "react-scripts": "5.0.1", "recharts": "2.15.0", "sockjs-client": "^1.6.1", @@ -47,14 +47,14 @@ "zustand-x": "3.0.4" }, "devDependencies": { - "@babel/cli": "7.25.9", - "@babel/core": "7.26.0", + "@babel/cli": "7.26.4", + "@babel/core": "7.26.7", "@babel/plugin-syntax-jsx": "7.25.9", - "@wordpress/babel-plugin-makepot": "6.13.0", + "@wordpress/babel-plugin-makepot": "6.16.0", "babel-plugin-macros": "3.1.0", "node-wp-i18n": "1.2.7", - "sass": "1.81.0", - "sass-loader": "16.0.3" + "sass": "1.83.4", + "sass-loader": "16.0.4" }, "scripts": { "start": "GENERATE_SOURCEMAP=false react-scripts start", diff --git a/src/pages/BandoApplication/index.js b/src/pages/BandoApplication/index.js index 4067d02..965a2dd 100644 --- a/src/pages/BandoApplication/index.js +++ b/src/pages/BandoApplication/index.js @@ -543,37 +543,39 @@ const BandoApplication = () => { : ['.p7m']; useEffect(() => { - if (!isEmpty(fieldsWithVars) && !isEmpty(fieldsWithFormula)) { - const updatedFormValues = klona(formValues); - let context = {}; + let updatedFormValues = klona(formValues); + let context = {}; - // eslint-disable-next-line array-callback-return - Object.keys(updatedFormValues).map(fieldId => { - if (!isNil(fieldsWithFormula[fieldId])) { - const formula = fieldsWithFormula[fieldId]; - context = getTokens(formula) - .filter(v => !['false', 'null', 'true'].includes(v)) - .reduce((acc, cur) => { - acc[cur] = isNil(context[cur]) ? 0 : context[cur]; - return acc; - }, {}); - const mathFormula = renderWithDataVars(formula, context); - try { - updatedFormValues[fieldId] = evaluate(mathFormula); - } catch (e) { - console.log('Error in math formula: "', mathFormula, '"', e.message); - updatedFormValues[fieldId] = 0; - } - } - if (!isNil(fieldsWithVars[fieldId])) { - context[fieldsWithVars[fieldId]] = updatedFormValues[fieldId] - } - }); + // eslint-disable-next-line array-callback-return + formData.map((o) => { + const variable = head(o.settings.filter(o => o.name === 'variable')); + const formula = head(o.settings.filter(o => o.name === 'formula')); - if (!isEmpty(updatedFormValues) && !equal(updatedFormValues, formValues)) { - reset(updatedFormValues); + if (formula && !isEmpty(formula.value)) { + context = getTokens(formula.value) + .filter(v => !['false', 'null', 'true'].includes(v)) + .reduce((acc, cur) => { + acc[cur] = isNil(context[cur]) ? 0 : context[cur]; + return acc; + }, context); + const mathFormula = renderWithDataVars(formula.value, context); + try { + updatedFormValues[o.id] = evaluate(mathFormula); + } catch (e) { + console.log('Error in math formula: "', mathFormula, '"', e.message); + updatedFormValues[o.id] = 0; + } } + if (variable && !isEmpty(variable.value)) { + context[variable.value[0]] = 'criteria_table' === o.name + ? pathOr(0, [o.id, 'total'], updatedFormValues) + : pathOr(0, [o.id], updatedFormValues); + } + }); + + if (!isEmpty(updatedFormValues) && !equal(updatedFormValues, formValues)) { + reset(updatedFormValues); } }, [formValues]); @@ -663,7 +665,10 @@ const BandoApplication = () => { const text = head(o.settings.filter(o => o.name === 'text')); const placeholder = head(o.settings.filter(o => o.name === 'placeholder')); const options = head(o.settings.filter(o => o.name === 'options')); - const tableColumns = head(o.settings.filter(o => o.name === 'table_columns')); + let tableColumns = head(o.settings.filter(o => o.name === 'table_columns')); + if (!tableColumns) { + tableColumns = head(o.settings.filter(o => o.name === 'criteria_table_columns')); + } const step = head(o.settings.filter(o => o.name === 'step')); const mime = head(o.settings.filter(o => o.name === 'mime')); const formula = head(o.settings.filter(o => o.name === 'formula')); diff --git a/src/pages/BandoFormsPreview/index.js b/src/pages/BandoFormsPreview/index.js index 7da1102..332700f 100644 --- a/src/pages/BandoFormsPreview/index.js +++ b/src/pages/BandoFormsPreview/index.js @@ -40,8 +40,6 @@ const BandoFormsPreview = () => { const navigate = useNavigate(); const [formData, setFormData] = useState([]); const [formName, setFormName] = useState(''); - const [fieldsWithVars, setFieldsWithVars] = useState({}); - const [fieldsWithFormula, setFieldsWithFormula] = useState({}); const isAsyncRequest = useStore().main.isAsyncRequest(); const { control,