leasing-object: загрузка списка selectConfiguration

+ валидация
This commit is contained in:
vchikalkin 2023-01-25 15:15:49 +03:00
parent 93d4c31d0c
commit 50a1fb07cd
7 changed files with 67 additions and 4 deletions

View File

@ -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<Scalars['Uuid']>;
}>;
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; }>;

View File

@ -32,4 +32,5 @@ export default function injectDefaultReactions(context) {
subsidyReactions.computedReactions(context);
subsidyReactions.commonReactions(context);
leasingObject.common(context);
leasingObject.validation(context);
}

View File

@ -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,
},
};

View File

@ -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));
}
);
}

View File

@ -1,2 +1,3 @@
/* eslint-disable import/prefer-default-export */
export { default as common } from './common';
export { default as validation } from './validation';

View File

@ -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,
}
);
}

View File

@ -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<Values.ElementsTypes[E]>[]) => {
this.$options.setOptions(elementName, options);