From 776c2354be028bb69d5c1f3a93e4f77d79f8ffd9 Mon Sep 17 00:00:00 2001 From: vchikalkin Date: Thu, 23 Feb 2023 18:00:29 +0300 Subject: [PATCH] process/gibdd: fix reactions --- apps/web/process/gibdd/reactions.ts | 88 ++++++++++++++++++++++++++++- 1 file changed, 86 insertions(+), 2 deletions(-) diff --git a/apps/web/process/gibdd/reactions.ts b/apps/web/process/gibdd/reactions.ts index c1c5cae..f12540f 100644 --- a/apps/web/process/gibdd/reactions.ts +++ b/apps/web/process/gibdd/reactions.ts @@ -319,6 +319,32 @@ export function common({ store, apolloClient, queryClient }: ProcessContext) { } ); + reaction( + () => $calculation.element('selectRegistration').getValue(), + async (registrationId) => { + if (!registrationId) { + $calculation.element('labelRegistrationDescription').resetValue(); + + return; + } + + const { + data: { evo_addproduct_type }, + } = await apolloClient.query({ + query: CRMTypes.GetAddProductTypeDocument, + variables: { addproductTypeId: registrationId }, + }); + + if (evo_addproduct_type?.evo_description) { + $calculation + .element('labelRegistrationDescription') + .setValue(evo_addproduct_type?.evo_description); + } else { + $calculation.element('labelRegistrationDescription').resetValue(); + } + } + ); + reaction( () => $calculation.element('selectLegalClientRegion').getValue(), async (regionId) => { @@ -471,13 +497,71 @@ export function common({ store, apolloClient, queryClient }: ProcessContext) { const town = evo_towns?.find((x) => x?.evo_fias_id === evo_city_fias_id); if (town) { $calculation.element('selectLegalClientTown').setValue(town.value).block(); - $calculation.element('selectTownRegistration').setValue(town.value).block(); } else { $calculation.element('selectLegalClientTown').resetValue().unblock(); - $calculation.element('selectTownRegistration').resetValue().unblock(); } } else { $calculation.element('selectLegalClientTown').resetValue().unblock(); + } + } + ); + + reaction( + () => $calculation.$values.getValues(['regionRegistration', 'objectRegistration']), + async ({ regionRegistration: regionId, objectRegistration }) => { + if (!regionId) { + $calculation.element('selectTownRegistration').resetValue().unblock(); + + return; + } + + const leadid = $calculation.element('selectLead').getValue(); + const opportunityid = $calculation.element('selectOpportunity').getValue(); + + let evo_city_fias_id: string | undefined; + + if (leadid) { + const { + data: { lead }, + } = await apolloClient.query({ + query: CRMTypes.GetLeadDocument, + variables: { leadid }, + }); + + if (lead?.accountidData?.evo_address_legalidData?.evo_city_fias_id) + evo_city_fias_id = lead?.accountidData?.evo_address_legalidData?.evo_city_fias_id; + } + + if (opportunityid) { + const { + data: { opportunity }, + } = await apolloClient.query({ + query: CRMTypes.GetOpportunityDocument, + variables: { opportunityid }, + }); + + if ( + !evo_city_fias_id && + opportunity?.accountidData?.evo_address_legalidData?.evo_city_fias_id + ) + evo_city_fias_id = opportunity?.accountidData?.evo_address_legalidData?.evo_city_fias_id; + } + + if (evo_city_fias_id && objectRegistration === 100_000_000) { + const { + data: { evo_towns }, + } = await apolloClient.query({ + query: CRMTypes.GetTownsDocument, + variables: { regionId }, + }); + + const town = evo_towns?.find((x) => x?.evo_fias_id === evo_city_fias_id); + if (town) { + $calculation.element('selectTownRegistration').setValue(town.value).block(); + } else { + $calculation.element('selectTownRegistration').resetValue().unblock(); + } + } else { $calculation.element('selectTownRegistration').resetValue().unblock(); } }