diff --git a/apps/web/graphql/crm.types.ts b/apps/web/graphql/crm.types.ts index c071d90..1651645 100644 --- a/apps/web/graphql/crm.types.ts +++ b/apps/web/graphql/crm.types.ts @@ -231,6 +231,13 @@ export type GetQuoteUrlQueryVariables = Exact<{ export type GetQuoteUrlQuery = { __typename?: 'Query', entity: { __typename?: 'quote', link: string | null } | null }; +export type GetLeasingObjectDataFromQuoteQueryVariables = Exact<{ + quoteId: Scalars['Uuid']; +}>; + + +export type GetLeasingObjectDataFromQuoteQuery = { __typename?: 'Query', quote: { __typename?: 'quote', evo_brandid: string | null, evo_modelid: string | null, evo_leasingobject_typeid: string | null } | null }; + export type GetModels_ProcessLeasingObjectQueryVariables = Exact<{ brandid: Scalars['Uuid']; }>; diff --git a/apps/web/process/leasing-object/get-kp-data.ts b/apps/web/process/leasing-object/get-kp-data.ts new file mode 100644 index 0000000..10ea8fd --- /dev/null +++ b/apps/web/process/leasing-object/get-kp-data.ts @@ -0,0 +1,53 @@ +/* eslint-disable @typescript-eslint/naming-convention */ +import { gql } from '@apollo/client'; +import initializeApollo from 'apollo/client'; +import type * as CRMTypes from 'graphql/crm.types'; +import type { GetQuoteDataInput, GetQuoteDataOutput } from '../load-kp/types'; + +const QUERY_GET_LEASING_OBJECT_DATA_FROM_QUOTE = gql` + query GetLeasingObjectDataFromQuote($quoteId: Uuid!) { + quote(quoteId: $quoteId) { + evo_brandid + evo_modelid + evo_leasingobject_typeid + } + } +`; + +export type Quote = NonNullable; + +type QuoteLeasingObjectProcessData = { + values: Partial; +}; + +export default async function getLeasingObjectDataFromKP({ + values: { quote: quoteId }, +}: GetQuoteDataInput): Promise { + const apolloClient = initializeApollo(); + + const { + data: { quote }, + } = await apolloClient.query< + CRMTypes.GetLeasingObjectDataFromQuoteQuery, + CRMTypes.GetLeasingObjectDataFromQuoteQueryVariables + >({ + query: QUERY_GET_LEASING_OBJECT_DATA_FROM_QUOTE, + variables: { + quoteId, + }, + }); + + if (!quote) { + throw new Error('Quote is empty'); + } + + const { evo_brandid, evo_modelid, evo_leasingobject_typeid } = quote; + + return { + values: { + brand: evo_brandid, + model: evo_modelid, + leaseObjectType: evo_leasingobject_typeid, + }, + }; +} diff --git a/apps/web/process/leasing-object/reactions/common.ts b/apps/web/process/leasing-object/reactions/common.ts index 897bab6..98fc369 100644 --- a/apps/web/process/leasing-object/reactions/common.ts +++ b/apps/web/process/leasing-object/reactions/common.ts @@ -1,7 +1,7 @@ /* eslint-disable @typescript-eslint/naming-convention */ import { gql } from '@apollo/client'; import type * as CRMTypes from 'graphql/crm.types'; -import { autorun } from 'mobx'; +import { autorun, reaction } from 'mobx'; import type { ReactionsContext } from 'process/types'; import { intersects } from 'radash'; import { normalizeOptions } from 'tools'; @@ -341,4 +341,13 @@ export default function commonReactions({ store, apolloClient }: ReactionsContex delay: 10, } ); + + reaction( + () => $calculation.element('selectLeaseObjectType').getValue(), + (leaseObjctType) => { + if (!leaseObjctType) { + $calculation.element('selectBrand').resetValue(); + } + } + ); } diff --git a/apps/web/trpc/routers/quote.ts b/apps/web/trpc/routers/quote.ts index f40f2f9..5cade17 100644 --- a/apps/web/trpc/routers/quote.ts +++ b/apps/web/trpc/routers/quote.ts @@ -1,6 +1,7 @@ import defaultValues from 'config/default-values'; import { defaultValues as defaultInsuranceValues } from 'config/tables/insurance-table'; import getFingapDataFromKP from 'process/fingap/get-kp-data'; +import getLeasingObjectDataFromKP from 'process/leasing-object/get-kp-data'; import { GetQuoteDataInputSchema, GetQuoteDataOutputSchema } from 'process/load-kp/types'; import getPaymentsDataFromKP from 'process/payments/get-kp-data'; import getSupplierAgentsDataFromKP from 'process/supplier-agent/get-kp-values'; @@ -16,6 +17,7 @@ const quoteRouter = t.router({ .query(async ({ input }) => { const { values: supplierAgentsValues } = await getSupplierAgentsDataFromKP(input); const { values: paymentsValues, payments } = await getPaymentsDataFromKP(input); + const { values: leasingObjectValues } = await getLeasingObjectDataFromKP(input); const { fingap, insurance: fingapInsurance } = await getFingapDataFromKP(input); return { @@ -23,6 +25,7 @@ const quoteRouter = t.router({ ...defaultValues, ...supplierAgentsValues, ...paymentsValues, + ...leasingObjectValues, }, payments, insurance: {