From 662b04be0f2fdd643c76ee104c6f6d7588d3d29f Mon Sep 17 00:00:00 2001 From: obarykina Date: Wed, 7 Feb 2024 15:42:52 +0300 Subject: [PATCH] merge branch release/dyn-3965_filter-telematic-electric-car --- apps/web/process/add-product/reactions.ts | 102 ++++++++++++++-------- 1 file changed, 65 insertions(+), 37 deletions(-) diff --git a/apps/web/process/add-product/reactions.ts b/apps/web/process/add-product/reactions.ts index 7af6f15..80003ad 100644 --- a/apps/web/process/add-product/reactions.ts +++ b/apps/web/process/add-product/reactions.ts @@ -1,3 +1,4 @@ +/* eslint-disable sonarjs/cognitive-complexity */ import { createValidationReaction } from '../tools'; import type { ProcessContext } from '../types'; import { createValidationSchema } from './validation'; @@ -212,8 +213,8 @@ export default function reactions({ store, apolloClient }: ProcessContext) { ); reaction( - () => $calculation.$values.getValues(['recalcWithRevision', 'leaseObjectType']), - async ({ recalcWithRevision, leaseObjectType: leaseObjectTypeId }) => { + () => $calculation.$values.getValues(['recalcWithRevision', 'leaseObjectType', 'engineType']), + async ({ recalcWithRevision, leaseObjectType: leaseObjectTypeId, engineType }) => { if (recalcWithRevision === false) { $calculation .element('selectRequirementTelematic') @@ -223,28 +224,34 @@ export default function reactions({ store, apolloClient }: ProcessContext) { ) ); - if (leaseObjectTypeId) { - const { - data: { evo_leasingobject_type }, - } = await apolloClient.query({ - query: CRMTypes.GetLeaseObjectTypeDocument, - variables: { leaseObjectTypeId }, - }); + if (engineType === 100_000_003) { + $calculation.element('selectRequirementTelematic').setValue(100_000_003).block(); + } else { + $calculation.element('selectRequirementTelematic').unblock(); - if (evo_leasingobject_type?.evo_id === '8') { - $calculation - .element('selectRequirementTelematic') - .setOptions( - selectRequirementTelematic.filter((x) => - [100_000_000, 100_000_001].includes(x.value) - ) - ); - } + if (leaseObjectTypeId) { + const { + data: { evo_leasingobject_type }, + } = await apolloClient.query({ + query: CRMTypes.GetLeaseObjectTypeDocument, + variables: { leaseObjectTypeId }, + }); - if (evo_leasingobject_type?.evo_id === '11') { - $calculation.element('selectRequirementTelematic').setValue(100_000_002).block(); - } else { - $calculation.element('selectRequirementTelematic').unblock(); + if (evo_leasingobject_type?.evo_id === '8') { + $calculation + .element('selectRequirementTelematic') + .setOptions( + selectRequirementTelematic.filter((x) => + [100_000_000, 100_000_001].includes(x.value) + ) + ); + } + + if (evo_leasingobject_type?.evo_id === '11') { + $calculation.element('selectRequirementTelematic').setValue(100_000_002).block(); + } else { + $calculation.element('selectRequirementTelematic').unblock(); + } } } } else { @@ -262,8 +269,14 @@ export default function reactions({ store, apolloClient }: ProcessContext) { 'requirementTelematic', 'recalcWithRevision', 'leaseObjectType', + 'engineType', ]), - async ({ requirementTelematic, recalcWithRevision, leaseObjectType: leaseObjectTypeId }) => { + async ({ + requirementTelematic, + recalcWithRevision, + leaseObjectType: leaseObjectTypeId, + engineType, + }) => { const currentDate = dayjs().utc(false).toISOString(); const { data: { evo_addproduct_types: trackerTypes }, @@ -294,21 +307,36 @@ export default function reactions({ store, apolloClient }: ProcessContext) { ); } - if (leaseObjectTypeId) { - const { - data: { evo_leasingobject_type }, - } = await apolloClient.query({ - query: CRMTypes.GetLeaseObjectTypeDocument, - variables: { leaseObjectTypeId }, - }); + if (engineType === 100_000_003) { + filteredTelematicTypes = telematicTypes?.filter( + (x) => + x?.evo_controls_program?.includes(100_000_003) && + x.label?.toLowerCase().includes('аво') && + !x.label?.toLowerCase().includes('pro') + ); - if (evo_leasingobject_type?.evo_id === '11') { - filteredTelematicTypes = telematicTypes?.filter( - (x) => - x?.evo_controls_program?.includes(100_000_002) && - x.label?.toLowerCase().includes('delta') && - !x.label?.toLowerCase().includes('pro') - ); + $calculation.element('selectTracker').resetValue().block(); + $calculation.element('selectTelematic').block(); + } else { + $calculation.element('selectTracker').unblock(); + $calculation.element('selectTelematic').unblock(); + + if (leaseObjectTypeId) { + const { + data: { evo_leasingobject_type }, + } = await apolloClient.query({ + query: CRMTypes.GetLeaseObjectTypeDocument, + variables: { leaseObjectTypeId }, + }); + + if (evo_leasingobject_type?.evo_id === '11') { + filteredTelematicTypes = telematicTypes?.filter( + (x) => + x?.evo_controls_program?.includes(100_000_002) && + x.label?.toLowerCase().includes('delta') && + !x.label?.toLowerCase().includes('pro') + ); + } } }