From af56bb2566133187ec3467317caa41c71ab70ee4 Mon Sep 17 00:00:00 2001 From: vchikalkin Date: Fri, 27 Nov 2020 14:27:55 +0300 Subject: [PATCH] validate insurance table onCalculate --- .../CalculationStore/Effects/lib/validate.ts | 34 +++++++++++++++++++ 1 file changed, 34 insertions(+) diff --git a/src/client/stores/CalculationStore/Effects/lib/validate.ts b/src/client/stores/CalculationStore/Effects/lib/validate.ts index 9256d15..ac797c0 100644 --- a/src/client/stores/CalculationStore/Effects/lib/validate.ts +++ b/src/client/stores/CalculationStore/Effects/lib/validate.ts @@ -49,6 +49,40 @@ const validateElements = () => { }); }; +const validateTables = () => { + const tableInsurance = CalculationStore.tables.tableInsurance; + + const kaskoRowIndex = tableInsurance.rows.findIndex( + x => x.policyType?.value === 'КАСКО', + ); + const osagoRowIndex = tableInsurance.rows.findIndex( + x => x.policyType?.value === 'ОСАГО', + ); + + const condition = + !CalculationStore.tables.tableInsurance.rows[kaskoRowIndex].insuranceCompany + ?.value || + !CalculationStore.tables.tableInsurance.rows[osagoRowIndex].insuranceCompany + ?.value; + + CalculationStore.setTableRows( + 'tableInsurance', + 0, + )([ + { + insuranceCompany: { + validation: !condition, + }, + }, + { + insuranceCompany: { + validation: !condition, + }, + }, + ]); +}; + export default () => { validateElements(); + validateTables(); };