From aaa8cadc02c91f731bbbc4af1415a5f3894a6399 Mon Sep 17 00:00:00 2001 From: vchikalkin Date: Mon, 5 Jun 2023 11:31:40 +0300 Subject: [PATCH] fix: reset result values after create-kp with recalc --- .../web/process/calculate/reactions/common.ts | 14 +++- apps/web/process/create-kp/action.ts | 24 ++++++- .../lead-opportunity/reactions/common.ts | 65 ++++++++----------- apps/web/process/load-kp/reactions.ts | 3 +- 4 files changed, 63 insertions(+), 43 deletions(-) diff --git a/apps/web/process/calculate/reactions/common.ts b/apps/web/process/calculate/reactions/common.ts index 2d8cc72..64f67f7 100644 --- a/apps/web/process/calculate/reactions/common.ts +++ b/apps/web/process/calculate/reactions/common.ts @@ -41,7 +41,7 @@ export default function reactions({ store, apolloClient }: ProcessContext) { ); disposableReaction( - () => $process.has('Calculate'), + () => $process.has('Calculate') || $process.has('CreateKP'), () => { const values = $calculation.$values.getValues(); @@ -63,6 +63,18 @@ export default function reactions({ store, apolloClient }: ProcessContext) { 'tarif', 'rate', 'creditRate', + 'recalcWithRevision', + 'quote', + 'depreciationGroup', + 'registrationDescription', + 'leaseObjectCount', + 'kpUrl', + 'leadUrl', + 'quoteUrl', + 'opportunityUrl', + 'subsidySum', + 'insKaskoPriceLeasePeriod', + 'leaseObjectRiskName', ]), }; }, diff --git a/apps/web/process/create-kp/action.ts b/apps/web/process/create-kp/action.ts index 55e4ba1..e511efc 100644 --- a/apps/web/process/create-kp/action.ts +++ b/apps/web/process/create-kp/action.ts @@ -1,5 +1,6 @@ -import { updateSelectQuote } from '../lead-opportunity/reactions/common'; import type { ProcessContext } from '../types'; +import * as CRMTypes from '@/graphql/crm.types'; +import { normalizeOptions } from '@/utils/entity'; import { toJS } from 'mobx'; import { notification } from 'ui/elements'; @@ -50,14 +51,31 @@ export function action({ store, trpcClient, apolloClient }: ProcessContext) { } else { $results.setPayments(res.data.resultPayments); $results.setValues(res.data.resultValues); - $calculation.$values.setValues(res.data.values); + $calculation.$values.setValues({ ...res.data.values, recalcWithRevision: false }); notification.success({ key, message: successMessage, }); - await updateSelectQuote({ apolloClient, store }); + const leadid = $calculation.element('selectLead').getValue(); + + if (leadid) { + const { + data: { quotes }, + } = await apolloClient.query({ + fetchPolicy: 'network-only', + query: CRMTypes.GetQuotesDocument, + variables: { + leadid, + }, + }); + + $calculation + .element('selectQuote') + .setOptions(normalizeOptions(quotes)) + .setValue(values.quote); + } } }) .catch((error) => { diff --git a/apps/web/process/lead-opportunity/reactions/common.ts b/apps/web/process/lead-opportunity/reactions/common.ts index 052b1aa..3f41284 100644 --- a/apps/web/process/lead-opportunity/reactions/common.ts +++ b/apps/web/process/lead-opportunity/reactions/common.ts @@ -89,44 +89,33 @@ export default function reactions({ store, apolloClient }: ProcessContext) { reaction( () => $calculation.$values.getValues(['recalcWithRevision', 'lead']), - async () => { - await updateSelectQuote({ apolloClient, store }); + async ({ lead: leadid, recalcWithRevision }) => { + if (leadid) { + const { + data: { quotes }, + } = await apolloClient.query({ + fetchPolicy: 'network-only', + query: CRMTypes.GetQuotesDocument, + variables: { + leadid, + }, + }); + + if (recalcWithRevision) { + const filteredQuotes = quotes?.filter( + (quote) => + quote?.evo_recalc_limit && + quote.evo_recalc_limit > 0 && + quote.evo_statuscodeidData?.evo_id === '2.3' && + !quote.evo_purchases_participation + ); + $calculation.element('selectQuote').setOptions(normalizeOptions(filteredQuotes)); + } else { + $calculation.element('selectQuote').setOptions(normalizeOptions(quotes)); + } + } else { + $calculation.element('selectQuote').reset(); + } } ); } - -export async function updateSelectQuote({ - store, - apolloClient, -}: Pick) { - const { $calculation } = store; - const leadid = $calculation.element('selectLead').getValue(); - const recalcWithRevision = $calculation.element('cbxRecalcWithRevision').getValue(); - - if (leadid) { - const { - data: { quotes }, - } = await apolloClient.query({ - fetchPolicy: 'network-only', - query: CRMTypes.GetQuotesDocument, - variables: { - leadid, - }, - }); - - if (recalcWithRevision) { - const filteredQuotes = quotes?.filter( - (quote) => - quote?.evo_recalc_limit && - quote.evo_recalc_limit > 0 && - quote.evo_statuscodeidData?.evo_id === '2.3' && - !quote.evo_purchases_participation - ); - $calculation.element('selectQuote').setOptions(normalizeOptions(filteredQuotes)); - } else { - $calculation.element('selectQuote').setOptions(normalizeOptions(quotes)); - } - } else { - $calculation.element('selectQuote').reset(); - } -} diff --git a/apps/web/process/load-kp/reactions.ts b/apps/web/process/load-kp/reactions.ts index 38cf7a8..17df36d 100644 --- a/apps/web/process/load-kp/reactions.ts +++ b/apps/web/process/load-kp/reactions.ts @@ -17,7 +17,8 @@ export function common({ store, trpcClient, apolloClient }: ProcessContext) { () => { const quote = $calculation.element('selectQuote').getOption(); - if (!quote || $process.has('LoadKP')) return; + if (!quote || $process.has('LoadKP') || $process.has('Calculate') || $process.has('CreateKP')) + return; $process.add('LoadKP');