apps/web: get selectTarif options on load-kp

This commit is contained in:
vchikalkin 2024-02-08 10:56:30 +03:00
parent 46c0b305b6
commit 47b57c0c73
4 changed files with 26 additions and 4 deletions

View File

@ -8,6 +8,7 @@ import * as CRMTypes from '@/graphql/crm.types';
import { getKPData as getKPDataPrice } from '@/process/price/get-kp-data';
import { getKPData as getKPDataSubsidy } from '@/process/subsidy/get-kp-data';
import { createCurrencyUtility } from '@/utils/currency';
import { normalizeOptions } from '@/utils/entity';
import { gql } from '@apollo/client';
// eslint-disable-next-line @typescript-eslint/no-unused-vars
@ -53,6 +54,8 @@ export async function getKPData({ values }: GetQuoteInputData): Promise<GetQuote
const { getTarifs, getRates, getPriceChange } = helper({ apolloClient });
let tarif = defaultValues.tarif;
let evo_tarif: unknown = null;
if (
quote?.evo_delivery_time !== null &&
quote?.evo_delivery_time !== undefined &&
@ -65,7 +68,7 @@ export async function getKPData({ values }: GetQuoteInputData): Promise<GetQuote
quote?.evo_leasingobject_used !== undefined &&
quote?.evo_leasingobject_used !== null
) {
const { evo_tarif } = await getTarifs({
const data = await getTarifs({
deliveryTime: quote?.evo_delivery_time,
firstPaymentPerc: quote?.evo_first_payment_perc,
floatingRate: quote?.evo_floating_rate ?? false,
@ -77,9 +80,11 @@ export async function getKPData({ values }: GetQuoteInputData): Promise<GetQuote
product: quote?.evo_baseproductid,
});
if (evo_tarif?.evo_tarifid) {
tarif = evo_tarif.evo_tarifid;
if (data?.evo_tarif?.evo_tarifid) {
tarif = data?.evo_tarif.evo_tarifid;
}
({ evo_tarif } = data);
}
let maxPriceChange = quote?.evo_max_price_change ?? defaultValues.maxPriceChange;
@ -125,6 +130,9 @@ export async function getKPData({ values }: GetQuoteInputData): Promise<GetQuote
const { evo_rate } = await getRates({ tarif });
return {
options: {
selectTarif: evo_tarif ? normalizeOptions([evo_tarif]) : [],
},
values: {
IRR_Perc: quote?.evo_msfo_irr ?? defaultValues.IRR_Perc,
clientType: quote?.evo_client_typeid,

View File

@ -2,6 +2,7 @@
import eltHelper from '../elt/lib/helper';
import { message } from '@/Components/Common/Notification';
import type { ProcessContext } from '@/process/types';
import { normalizeOptions } from '@/utils/entity';
import { reaction } from 'mobx';
import { omit } from 'radash';
@ -36,7 +37,13 @@ export function common({ store, trpcClient, apolloClient }: ProcessContext) {
...$calculation.$values.getValues(['lead', 'opportunity', 'recalcWithRevision']),
},
})
.then(({ values, payments, insurance, fingap, elt }) => {
.then(({ values, payments, insurance, fingap, elt, options }) => {
if (options?.selectTarif) {
$calculation.element('selectTarif').setOptions(normalizeOptions(options.selectTarif));
} else {
$calculation.element('selectTarif').resetOptions();
}
$calculation.$values.setValues(
omit(values, [
'lead',

View File

@ -81,6 +81,7 @@ export const quoteRouter = router({
const insurance = processData.find((x) => x.insurance)?.insurance ?? defaultInsurance;
const fingap = processData.find((x) => x.fingap)?.fingap ?? defaultFingap;
const elt = processData.find((x) => x.elt)?.elt;
const options = processData[0].options;
return {
values,
@ -88,6 +89,7 @@ export const quoteRouter = router({
insurance,
fingap,
elt,
options,
};
}),

View File

@ -51,6 +51,11 @@ export const GetQuoteOutputDataSchema = z
.optional(),
fingap: FinGAPSchema,
insurance: InsuranceSchema,
options: z
.object({
selectTarif: z.unknown().array(),
})
.optional(),
payments: PaymentsSchema,
values: ValuesSchema,
})