diff --git a/src/client/stores/CalculationStore/Effects/actions/calculate/validate/tables.ts b/src/client/stores/CalculationStore/Effects/actions/calculate/validate/tables.ts index 4dba0dd..63c7d8d 100644 --- a/src/client/stores/CalculationStore/Effects/actions/calculate/validate/tables.ts +++ b/src/client/stores/CalculationStore/Effects/actions/calculate/validate/tables.ts @@ -122,6 +122,49 @@ function validateInsuranceTable(this: ICalculationStore) { }, }); } + + /** + * Самый откровенный костыль в истории калькулятора, + * потому что мне сейчас лень добавлять проверку текущего значения + * в отфильтрованном списке опций в таблице, + * да и это не имеет смысла + * (связано с самой жуткой реакцией по страховке) + * + * TODO: Для нового калькулятора: + * вместо костыля сбрасывать значение КАСКО на дефолтное, если текущего значения нет в списке опций + * + */ + const leasingWithoutKasko = this.getValue('leasingWithoutKasko'); + const otherInsuranceCompany = + this.tables.tableInsurance.options?.insuranceCompany?.find(x => + x.name?.includes('ПРОЧИЕ'), + ); + if ( + !leasingWithoutKasko && + kaskoRow.insuranceCompany === otherInsuranceCompany?.value + ) { + this.setTableRow('tableInsurance', rows => + rows.findIndex(x => x?.key === 'kasko'), + )({ + insuranceCompany: { + validation: false, + }, + }); + + openNotification({ + type: 'error', + message: 'Ошибка', + description: 'Укажите страховую компанию КАСКО из списка', + }); + } else { + this.setTableRow('tableInsurance', rows => + rows.findIndex(x => x?.key === 'kasko'), + )({ + insuranceCompany: { + validation: undefined, + }, + }); + } } function validatePaymentsTable(this: ICalculationStore) { diff --git a/src/client/stores/CalculationStore/Effects/reactions/tablesReactions.ts b/src/client/stores/CalculationStore/Effects/reactions/tablesReactions.ts index 24821f5..01df5b8 100644 --- a/src/client/stores/CalculationStore/Effects/reactions/tablesReactions.ts +++ b/src/client/stores/CalculationStore/Effects/reactions/tablesReactions.ts @@ -147,6 +147,7 @@ export default [ }, }), + // самая жуткая реакция по страховке (calculationStore, calculationProcess) => ({ expression: () => { const { leasingPeriod, leasingWithoutKasko } = calculationStore.values; @@ -230,7 +231,11 @@ export default [ calculationStore.setTableRow('tableInsurance', rows => rows.findIndex(x => x?.key === 'kasko'), )({ - insuranceCompany: { filter: insuranceKaskoDefaultFilter }, + insuranceCompany: { + filter: insuranceKaskoDefaultFilter, + status: ElementStatus.Default, + }, + insCost: { status: ElementStatus.Default }, }); calculationStore.setTableRow('tableInsurance', rows =>