diff --git a/apps/web/graphql/crm.types.ts b/apps/web/graphql/crm.types.ts index 4eeee4d..fb796b3 100644 --- a/apps/web/graphql/crm.types.ts +++ b/apps/web/graphql/crm.types.ts @@ -127,7 +127,7 @@ export type GetTarif_ProcessConfiguratorQueryVariables = Exact<{ }>; -export type GetTarif_ProcessConfiguratorQuery = { __typename?: 'Query', evo_tarif: { __typename?: 'evo_tarif', evo_irr: number | null, evo_graphtype_exception: Array | null } | null }; +export type GetTarif_ProcessConfiguratorQuery = { __typename?: 'Query', evo_tarif: { __typename?: 'evo_tarif', evo_irr: number | null, evo_graphtype_exception: Array | null, evo_seasons_type_exception: Array | null } | null }; export type GetLeaseObjectTypes_ProcessConfiguratorQueryVariables = Exact<{ [key: string]: never; }>; diff --git a/apps/web/process/configurator/lib/query.ts b/apps/web/process/configurator/lib/query.ts index 14e052e..211dbc1 100644 --- a/apps/web/process/configurator/lib/query.ts +++ b/apps/web/process/configurator/lib/query.ts @@ -6,6 +6,7 @@ export const QUERY_GET_TARIF = gql` evo_tarif(evo_tarifid: $tarifId) { evo_irr evo_graphtype_exception + evo_seasons_type_exception } } `; diff --git a/apps/web/process/configurator/reactions/filters.ts b/apps/web/process/configurator/reactions/filters.ts index 7a9a814..d140f2e 100644 --- a/apps/web/process/configurator/reactions/filters.ts +++ b/apps/web/process/configurator/reactions/filters.ts @@ -2,7 +2,9 @@ import { gql } from '@apollo/client'; import type * as CRMTypes from 'graphql/crm.types'; import { reaction } from 'mobx'; +import { SEASON_TYPES } from 'process/payments/lib/seasons-constants'; import type { ReactionsContext } from 'process/types'; +import { diff } from 'radash'; import { normalizeOptions } from 'tools'; import { QUERY_GET_TARIF } from '../lib/query'; @@ -302,4 +304,49 @@ export default function commonReactions({ store, apolloClient }: ReactionsContex $calculation.element('radioGraphType').setOptions(filteredGraphTypes); } ); + + /** + * в поле Тип дегрессии/сезонности selectSeasonType должны отображаться только те значения, + * которых нет в массиве поля "Недопустимые Типы дегрессий/сезонности" evo_seasons_type_exception + * (добавить в текущую фильтрацию поля) + */ + reaction( + () => ({ + tarif: $calculation.element('selectTarif').getValue(), + graphType: $calculation.element('radioGraphType').getValue(), + }), + async ({ tarif, graphType }) => { + let evo_tarif: CRMTypes.GetTarif_ProcessConfiguratorQuery['evo_tarif'] = null; + + if (tarif) { + const { data } = await apolloClient.query< + CRMTypes.GetTarif_ProcessConfiguratorQuery, + CRMTypes.GetTarif_ProcessConfiguratorQueryVariables + >({ + query: QUERY_GET_TARIF, + variables: { + tarifId: tarif, + }, + }); + + ({ evo_tarif } = data); + } + + const seasonTypesExeption = evo_tarif?.evo_seasons_type_exception || []; + let seasonTypes: Array = []; + + if (graphType === 100_000_001 || graphType === 100_000_003) { + seasonTypes = SEASON_TYPES[graphType]; + } + + const allowedSeasonTypes = diff(seasonTypes, seasonTypesExeption); + + const filteredSeasonTypesOptions = $calculation + .element('selectSeasonType') + .getOptions() + .filter((seasonTypeOption) => allowedSeasonTypes.includes(seasonTypeOption.value)); + + $calculation.element('selectSeasonType').setOptions(filteredSeasonTypesOptions); + } + ); }