From adf186d8daec133e5c0b7acb0784d750a7f1d2ff Mon Sep 17 00:00:00 2001 From: Chika Date: Wed, 5 Oct 2022 17:01:11 +0300 Subject: [PATCH] process/payments: prepare for season graphtype --- process/payments/reactions.ts | 25 +++++++++++++++---------- process/payments/validation.ts | 11 +++++++++++ 2 files changed, 26 insertions(+), 10 deletions(-) diff --git a/process/payments/reactions.ts b/process/payments/reactions.ts index 38ae867..c91be25 100644 --- a/process/payments/reactions.ts +++ b/process/payments/reactions.ts @@ -4,7 +4,7 @@ import type { ApolloClient } from '@apollo/client'; import type { QueryClient } from '@tanstack/react-query'; import { selectSeasonType } from 'config/default-options'; import { reaction, toJS } from 'mobx'; -import { last } from 'radash/dist/array'; +import type { CalculationOptions } from 'stores/calculation/options/types'; import type RootStore from 'stores/root'; import type { Row } from 'stores/tables/payments/types'; import validatePaymentsTable from './validation'; @@ -188,7 +188,10 @@ export default function paymentsReactions( /** * Дегрессия */ - const degressionSeasonTypes = [100_000_003, 100_000_004, 100_000_005, 100_000_006, 100_000_007]; + const degressionSeasonTypes = new Set([ + 100_000_003, 100_000_004, 100_000_005, 100_000_006, 100_000_007, + ]); + const seasonSeasonTypes = new Set([100_000_000, 100_000_001, 100_000_002]); reaction( () => { @@ -197,17 +200,19 @@ export default function paymentsReactions( return graphType; }, (graphType) => { - if (!graphType || graphType !== 100_000_001) { - $calculation.setElementOptions('selectSeasonType', []); + let selectSeasonTypeOptions: CalculationOptions['selectSeasonType'] = []; - return; + if (graphType === 100_000_001) { + selectSeasonTypeOptions = selectSeasonType.filter((option) => + degressionSeasonTypes.has(option.value) + ); + } else if (graphType === 100_000_003) { + selectSeasonTypeOptions = selectSeasonType.filter((option) => + seasonSeasonTypes.has(option.value) + ); } - - const selectSeasonTypeOptions = selectSeasonType.filter((option) => - degressionSeasonTypes.includes(option.value) - ); $calculation.setElementOptions('selectSeasonType', selectSeasonTypeOptions); - $calculation.setElementValue('selectSeasonType', last(degressionSeasonTypes)); + $calculation.resetElementValue('selectSeasonType'); } ); diff --git a/process/payments/validation.ts b/process/payments/validation.ts index 2dc4e6b..1fd41f1 100644 --- a/process/payments/validation.ts +++ b/process/payments/validation.ts @@ -11,6 +11,9 @@ export default function validatePaymentsTable( switch (values.graphType) { // Дегрессия case 100_000_001: + if (!values.seasonType) { + return 'Не выбран тип дегрессии'; + } /** * в таблице платежей в столбце Соотношение платежей для строк с 2 до "Срок лизинга-1" минимальное значение должно быть равно 3 */ @@ -71,6 +74,14 @@ export default function validatePaymentsTable( break; + case 100_000_003: { + if (!values.seasonType) { + return 'Не выбран тип сезонности'; + } + + break; + } + // Легкий старт case 100_000_004: { const targetPayments = payments.slice(1, 4);