diff --git a/src/client/constants/Calculation/tablesTitles.ts b/src/client/constants/Calculation/tablesTitles.ts new file mode 100644 index 0000000..fc5d336 --- /dev/null +++ b/src/client/constants/Calculation/tablesTitles.ts @@ -0,0 +1,10 @@ +import { TableNames } from 'core/types/Calculation/Store/tables'; + +const tablesTitles: { + [table in TableNames]?: string; +} = { + tableInsurance: 'Таблица страхования', + tablePayments: 'Таблица платежей', +}; + +export default tablesTitles; diff --git a/src/client/stores/CalculationStore/Effects/action.ts b/src/client/stores/CalculationStore/Effects/action.ts index de2d089..7682640 100644 --- a/src/client/stores/CalculationStore/Effects/action.ts +++ b/src/client/stores/CalculationStore/Effects/action.ts @@ -14,7 +14,7 @@ import checkValidation from './lib/checkValidation'; import customValues from './lib/customValues'; import prepareCalculationData from './lib/prepareData'; import results from './lib/results'; -import validateElements from './lib/validateElements'; +import validate from './lib/validate'; const cleanResults = () => { for (let resultValue of resultsValues) { @@ -268,14 +268,22 @@ const actions: TAction = { }, calculate: async () => { - validateElements(); - const { elements } = checkValidation(); - if (elements.length > 0) { - openNotification({ - type: 'error', - title: 'Ошибка во время расчета графика', - description: 'Некорректно заполнены поля: ' + elements.join(', '), - })(); + validate(); + const { elements, tables } = checkValidation(); + if (elements.length > 0 || tables.length > 0) { + if (elements.length > 0) + openNotification({ + type: 'error', + title: 'Ошибка во время расчета графика', + description: 'Некорректно заполнены поля: ' + elements.join(', '), + })(); + + if (tables.length > 0) + openNotification({ + type: 'error', + title: 'Ошибка во время расчета графика', + description: 'Некорректно заполнены таблицы: ' + tables.join(', '), + })(); return; } diff --git a/src/client/stores/CalculationStore/Effects/lib/checkValidation.ts b/src/client/stores/CalculationStore/Effects/lib/checkValidation.ts index 644a94f..bbd513c 100644 --- a/src/client/stores/CalculationStore/Effects/lib/checkValidation.ts +++ b/src/client/stores/CalculationStore/Effects/lib/checkValidation.ts @@ -1,4 +1,6 @@ +import { toJS } from 'mobx'; import elementsTitles from 'client/constants/Calculation/elementsTitles'; +import tablesTitles from 'client/constants/Calculation/tablesTitles'; import CalculationStore from 'client/stores/CalculationStore'; export default () => { @@ -11,5 +13,20 @@ export default () => { } }); - return { elements }; + let tables: string[] = []; + const { tables: storeTables } = CalculationStore; + + const jsTables = toJS(storeTables); + + Object.keys(jsTables).forEach(tableName => { + if ( + jsTables[tableName].rows.some(row => + Object.keys(row).some(propName => row[propName].validation === false), + ) + ) { + tables.push(tablesTitles[tableName]); + } + }); + + return { elements, tables }; }; diff --git a/src/client/stores/CalculationStore/Effects/lib/validateElements.ts b/src/client/stores/CalculationStore/Effects/lib/validate.ts similarity index 95% rename from src/client/stores/CalculationStore/Effects/lib/validateElements.ts rename to src/client/stores/CalculationStore/Effects/lib/validate.ts index 406cee6..9256d15 100644 --- a/src/client/stores/CalculationStore/Effects/lib/validateElements.ts +++ b/src/client/stores/CalculationStore/Effects/lib/validate.ts @@ -35,12 +35,12 @@ const validateElement = (elementName, condition) => { if (condition) { CalculationStore.setValidation(elementName, false); } else { - //TODO: antidote in reactions + //TODO: antidote in reactions CalculationStore.setValidation(elementName, true); } }; -export default () => { +const validateElements = () => { Object.keys(elementsValidations).forEach(elementName => { validateElement( elementName, @@ -48,3 +48,7 @@ export default () => { ); }); }; + +export default () => { + validateElements(); +};