From 50a1fb07cd20e696fa96ac2c32836b7b3a0cc945 Mon Sep 17 00:00:00 2001 From: vchikalkin Date: Wed, 25 Jan 2023 15:15:49 +0300 Subject: [PATCH] =?UTF-8?q?leasing-object:=20=D0=B7=D0=B0=D0=B3=D1=80?= =?UTF-8?q?=D1=83=D0=B7=D0=BA=D0=B0=20=D1=81=D0=BF=D0=B8=D1=81=D0=BA=D0=B0?= =?UTF-8?q?=20selectConfiguration=20+=20=D0=B2=D0=B0=D0=BB=D0=B8=D0=B4?= =?UTF-8?q?=D0=B0=D1=86=D0=B8=D1=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- apps/web/graphql/crm.types.ts | 9 ++++- .../process/init/inject-reactions/default.js | 1 + .../web/process/leasing-object/get-kp-data.ts | 4 ++- .../leasing-object/reactions/common.ts | 35 +++++++++++++++++-- .../process/leasing-object/reactions/index.js | 1 + .../leasing-object/reactions/validation.ts | 19 ++++++++++ apps/web/stores/calculation/index.ts | 2 ++ 7 files changed, 67 insertions(+), 4 deletions(-) create mode 100644 apps/web/process/leasing-object/reactions/validation.ts diff --git a/apps/web/graphql/crm.types.ts b/apps/web/graphql/crm.types.ts index 1651645..3bf206c 100644 --- a/apps/web/graphql/crm.types.ts +++ b/apps/web/graphql/crm.types.ts @@ -236,7 +236,7 @@ export type GetLeasingObjectDataFromQuoteQueryVariables = Exact<{ }>; -export type GetLeasingObjectDataFromQuoteQuery = { __typename?: 'Query', quote: { __typename?: 'quote', evo_brandid: string | null, evo_modelid: string | null, evo_leasingobject_typeid: string | null } | null }; +export type GetLeasingObjectDataFromQuoteQuery = { __typename?: 'Query', quote: { __typename?: 'quote', evo_brandid: string | null, evo_modelid: string | null, evo_equipmentid: string | null, evo_leasingobject_typeid: string | null } | null }; export type GetModels_ProcessLeasingObjectQueryVariables = Exact<{ brandid: Scalars['Uuid']; @@ -278,6 +278,13 @@ export type GetProduct_ProcessLeasingObjectQueryVariables = Exact<{ export type GetProduct_ProcessLeasingObjectQuery = { __typename?: 'Query', evo_baseproduct: { __typename?: 'evo_baseproduct', evo_brands: Array<{ __typename?: 'evo_brand', evo_brandid: string | null } | null> | null } | null }; +export type GetConfigurations_ProcessLeasingObjectQueryVariables = Exact<{ + modelId: InputMaybe; +}>; + + +export type GetConfigurations_ProcessLeasingObjectQuery = { __typename?: 'Query', evo_equipments: Array<{ __typename?: 'evo_equipment', label: string | null, value: string | null } | null> | null }; + export type GetLeasingWithoutKaskoOptionsQueryVariables = Exact<{ [key: string]: never; }>; diff --git a/apps/web/process/init/inject-reactions/default.js b/apps/web/process/init/inject-reactions/default.js index 062f2f6..6849d97 100644 --- a/apps/web/process/init/inject-reactions/default.js +++ b/apps/web/process/init/inject-reactions/default.js @@ -32,4 +32,5 @@ export default function injectDefaultReactions(context) { subsidyReactions.computedReactions(context); subsidyReactions.commonReactions(context); leasingObject.common(context); + leasingObject.validation(context); } diff --git a/apps/web/process/leasing-object/get-kp-data.ts b/apps/web/process/leasing-object/get-kp-data.ts index 10ea8fd..6932c72 100644 --- a/apps/web/process/leasing-object/get-kp-data.ts +++ b/apps/web/process/leasing-object/get-kp-data.ts @@ -9,6 +9,7 @@ const QUERY_GET_LEASING_OBJECT_DATA_FROM_QUOTE = gql` quote(quoteId: $quoteId) { evo_brandid evo_modelid + evo_equipmentid evo_leasingobject_typeid } } @@ -41,12 +42,13 @@ export default async function getLeasingObjectDataFromKP({ throw new Error('Quote is empty'); } - const { evo_brandid, evo_modelid, evo_leasingobject_typeid } = quote; + const { evo_brandid, evo_modelid, evo_equipmentid, evo_leasingobject_typeid } = quote; return { values: { brand: evo_brandid, model: evo_modelid, + configuration: evo_equipmentid, 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 98fc369..0268629 100644 --- a/apps/web/process/leasing-object/reactions/common.ts +++ b/apps/web/process/leasing-object/reactions/common.ts @@ -72,6 +72,15 @@ const QUERY_GET_PRODUCT = gql` } `; +const QUERY_GET_CONFIGURATIONS = gql` + query GetConfigurations_ProcessLeasingObject($modelId: Uuid) { + evo_equipments(statecode: 0, evo_modelid: $modelId) { + label: evo_name + value: evo_equipmentid + } + } +`; + export default function commonReactions({ store, apolloClient }: ReactionsContext) { const { $calculation } = store; @@ -344,10 +353,32 @@ export default function commonReactions({ store, apolloClient }: ReactionsContex reaction( () => $calculation.element('selectLeaseObjectType').getValue(), - (leaseObjctType) => { - if (!leaseObjctType) { + (leaseObjectTypeId) => { + if (!leaseObjectTypeId) { $calculation.element('selectBrand').resetValue(); } } ); + + reaction( + () => $calculation.element('selectModel').getValue(), + async (modelId) => { + if (!modelId) { + $calculation.element('selectConfiguration').reset(); + + return; + } + + const { + data: { evo_equipments }, + } = await apolloClient.query< + CRMTypes.GetConfigurations_ProcessLeasingObjectQuery, + CRMTypes.GetConfigurations_ProcessLeasingObjectQueryVariables + >({ + query: QUERY_GET_CONFIGURATIONS, + }); + + $calculation.element('selectConfiguration').setOptions(normalizeOptions(evo_equipments)); + } + ); } diff --git a/apps/web/process/leasing-object/reactions/index.js b/apps/web/process/leasing-object/reactions/index.js index 1e2e8e6..cdd6b5e 100644 --- a/apps/web/process/leasing-object/reactions/index.js +++ b/apps/web/process/leasing-object/reactions/index.js @@ -1,2 +1,3 @@ /* eslint-disable import/prefer-default-export */ export { default as common } from './common'; +export { default as validation } from './validation'; diff --git a/apps/web/process/leasing-object/reactions/validation.ts b/apps/web/process/leasing-object/reactions/validation.ts new file mode 100644 index 0000000..dd6b952 --- /dev/null +++ b/apps/web/process/leasing-object/reactions/validation.ts @@ -0,0 +1,19 @@ +import { autorun } from 'mobx'; +import type { ReactionsContext } from 'process/types'; + +export default function validationReactions({ store }: ReactionsContext) { + const { $calculation } = store; + + autorun( + () => { + const selectConfiguration = $calculation.element('selectConfiguration'); + selectConfiguration.validate({ + invalid: selectConfiguration.getOptions()?.length > 0 && !selectConfiguration.getValue(), + message: 'Не заполнено поле', + }); + }, + { + delay: 10, + } + ); +} diff --git a/apps/web/stores/calculation/index.ts b/apps/web/stores/calculation/index.ts index 1ac6432..ca7f63f 100644 --- a/apps/web/stores/calculation/index.ts +++ b/apps/web/stores/calculation/index.ts @@ -82,6 +82,8 @@ export default class CalculationStore { return this.$options.getOptions(elementName)?.find((x) => x.value === value); }, + getOptions: () => this.$options.getOptions(elementName), + setOptions: (options: BaseOption[]) => { this.$options.setOptions(elementName, options);