- fixed preview of the application;
This commit is contained in:
@@ -6,6 +6,7 @@ import { head, isEmpty, isNil, pathOr, sum } from 'ramda';
|
|||||||
// components
|
// components
|
||||||
import DefaultCell from './components/DefaultCell';
|
import DefaultCell from './components/DefaultCell';
|
||||||
import LastRowCell from './components/LastRowCell';
|
import LastRowCell from './components/LastRowCell';
|
||||||
|
import getNumberFormatted from '../../../../../helpers/getNumberFormatted';
|
||||||
|
|
||||||
const RenderTable = ({ tableValue = {}, columnsCfg, lastRowCfg, setTableValueFn, disabled }) => {
|
const RenderTable = ({ tableValue = {}, columnsCfg, lastRowCfg, setTableValueFn, disabled }) => {
|
||||||
const rows = pathOr([], ['rows'], tableValue)
|
const rows = pathOr([], ['rows'], tableValue)
|
||||||
@@ -31,7 +32,7 @@ const RenderTable = ({ tableValue = {}, columnsCfg, lastRowCfg, setTableValueFn,
|
|||||||
.map(v => isEmpty(v) || isNil(v) ? 0 : v);
|
.map(v => isEmpty(v) || isNil(v) ? 0 : v);
|
||||||
|
|
||||||
if (cellValue === 'sum') {
|
if (cellValue === 'sum') {
|
||||||
total = sum(getAllRowsValues);
|
total = getNumberFormatted(sum(getAllRowsValues));
|
||||||
} else {
|
} else {
|
||||||
total = 0;
|
total = 0;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
import { head, isEmpty, isNil, sum } from 'ramda';
|
import { head, isEmpty, isNil, sum } from 'ramda';
|
||||||
|
import getNumberFormatted from '../../../../../../../helpers/getNumberFormatted';
|
||||||
|
|
||||||
const LastRowCell = ({columnId, lastRowCfg, columnMeta = {}, getColumnDataFn}) => {
|
const LastRowCell = ({columnId, lastRowCfg, columnMeta = {}, getColumnDataFn}) => {
|
||||||
const cellData = head(lastRowCfg.filter(o => !isNil(o[columnId])));
|
const cellData = head(lastRowCfg.filter(o => !isNil(o[columnId])));
|
||||||
@@ -9,7 +10,7 @@ const LastRowCell = ({columnId, lastRowCfg, columnMeta = {}, getColumnDataFn}) =
|
|||||||
.map(v => isEmpty(v) || isNil(v) ? 0 : v);
|
.map(v => isEmpty(v) || isNil(v) ? 0 : v);
|
||||||
|
|
||||||
if (cellValue === 'sum') {
|
if (cellValue === 'sum') {
|
||||||
cellValue = sum(getAllRowsValues);
|
cellValue = getNumberFormatted(sum(getAllRowsValues));
|
||||||
} else {
|
} else {
|
||||||
cellValue = 0;
|
cellValue = 0;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
import React, { useState, useEffect, useRef, useMemo } from 'react';
|
import React, { useState, useEffect, useRef, useMemo } from 'react';
|
||||||
import { __, sprintf } from '@wordpress/i18n';
|
import { __, sprintf } from '@wordpress/i18n';
|
||||||
import { useParams } from 'react-router-dom';
|
import { useParams } from 'react-router-dom';
|
||||||
import { head, isEmpty, pathOr } from 'ramda';
|
import { head, isEmpty, isNil, pathOr } from 'ramda';
|
||||||
import { useForm } from 'react-hook-form';
|
import { useForm } from 'react-hook-form';
|
||||||
import 'quill/dist/quill.core.css';
|
import 'quill/dist/quill.core.css';
|
||||||
|
|
||||||
@@ -33,6 +33,11 @@ import { Toast } from 'primereact/toast';
|
|||||||
import { Messages } from 'primereact/messages';
|
import { Messages } from 'primereact/messages';
|
||||||
import ApplicationSteps from '../BandoApplication/ApplicationSteps';
|
import ApplicationSteps from '../BandoApplication/ApplicationSteps';
|
||||||
import BlockingOverlay from '../../components/BlockingOverlay';
|
import BlockingOverlay from '../../components/BlockingOverlay';
|
||||||
|
import { klona } from 'klona';
|
||||||
|
import getTokens from '../../helpers/getTokens';
|
||||||
|
import renderWithDataVars from '../../helpers/renderWithDataVars';
|
||||||
|
import { evaluate } from 'mathjs';
|
||||||
|
import equal from 'fast-deep-equal';
|
||||||
|
|
||||||
const BandoApplicationPreview = () => {
|
const BandoApplicationPreview = () => {
|
||||||
const { id } = useParams();
|
const { id } = useParams();
|
||||||
@@ -55,7 +60,8 @@ const BandoApplicationPreview = () => {
|
|||||||
trigger,
|
trigger,
|
||||||
register,
|
register,
|
||||||
getValues,
|
getValues,
|
||||||
reset
|
reset,
|
||||||
|
watch
|
||||||
} = useForm({
|
} = useForm({
|
||||||
defaultValues: useMemo(() => {
|
defaultValues: useMemo(() => {
|
||||||
return formInitialData ? formInitialData : {}
|
return formInitialData ? formInitialData : {}
|
||||||
@@ -77,6 +83,7 @@ const BandoApplicationPreview = () => {
|
|||||||
}
|
}
|
||||||
const activeStepIndex = activeStep - 1;
|
const activeStepIndex = activeStep - 1;
|
||||||
const values = getValues();
|
const values = getValues();
|
||||||
|
const formValues = watch();
|
||||||
|
|
||||||
const onValidate = () => {
|
const onValidate = () => {
|
||||||
const applId = getApplicationId();
|
const applId = getApplicationId();
|
||||||
@@ -252,6 +259,43 @@ const BandoApplicationPreview = () => {
|
|||||||
iconPos="right"/>
|
iconPos="right"/>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
let updatedFormValues = klona(formValues);
|
||||||
|
let context = {};
|
||||||
|
|
||||||
|
// 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 (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]);
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (formInitialData) {
|
if (formInitialData) {
|
||||||
//reset();
|
//reset();
|
||||||
@@ -301,9 +345,13 @@ const BandoApplicationPreview = () => {
|
|||||||
const text = head(o.settings.filter(o => o.name === 'text'));
|
const text = head(o.settings.filter(o => o.name === 'text'));
|
||||||
const placeholder = head(o.settings.filter(o => o.name === 'placeholder'));
|
const placeholder = head(o.settings.filter(o => o.name === 'placeholder'));
|
||||||
const options = head(o.settings.filter(o => o.name === 'options'));
|
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 step = head(o.settings.filter(o => o.name === 'step'));
|
||||||
const mime = head(o.settings.filter(o => o.name === 'mime'));
|
const mime = head(o.settings.filter(o => o.name === 'mime'));
|
||||||
|
const formula = head(o.settings.filter(o => o.name === 'formula'));
|
||||||
let mimeValue = '';
|
let mimeValue = '';
|
||||||
|
|
||||||
if (mime) {
|
if (mime) {
|
||||||
@@ -339,6 +387,7 @@ const BandoApplicationPreview = () => {
|
|||||||
</div>
|
</div>
|
||||||
: <FormField
|
: <FormField
|
||||||
key={o.id}
|
key={o.id}
|
||||||
|
readOnly={formula && !isEmpty(formula.value)}
|
||||||
type={o.name}
|
type={o.name}
|
||||||
disabled={o.name === 'fileupload' || 'DRAFT' !== applicationStatus}
|
disabled={o.name === 'fileupload' || 'DRAFT' !== applicationStatus}
|
||||||
fieldName={o.id}
|
fieldName={o.id}
|
||||||
|
|||||||
Reference in New Issue
Block a user