selectModel: загрузка списка и фильтрация
This commit is contained in:
parent
2782df536c
commit
b8539c4cc5
@ -231,6 +231,34 @@ export type GetQuoteUrlQueryVariables = Exact<{
|
||||
|
||||
export type GetQuoteUrlQuery = { __typename?: 'Query', entity: { __typename?: 'quote', link: string | null } | null };
|
||||
|
||||
export type GetModelsQueryVariables = Exact<{
|
||||
brandid: Scalars['Uuid'];
|
||||
}>;
|
||||
|
||||
|
||||
export type GetModelsQuery = { __typename?: 'Query', evo_models: Array<{ __typename?: 'evo_model', evo_modelid: string | null, evo_vehicle_type: number | null, label: string | null, value: string | null } | null> | null };
|
||||
|
||||
export type GetModelsFilterDataLeaseObjectTypeQueryVariables = Exact<{
|
||||
leaseObjectTypeId: Scalars['Uuid'];
|
||||
}>;
|
||||
|
||||
|
||||
export type GetModelsFilterDataLeaseObjectTypeQuery = { __typename?: 'Query', leaseObjectType: { __typename?: 'evo_leasingobject_type', evo_vehicle_type: Array<number> | null } | null };
|
||||
|
||||
export type GetModelsFilterDataSubsidyQueryVariables = Exact<{
|
||||
subsidyId: Scalars['Uuid'];
|
||||
}>;
|
||||
|
||||
|
||||
export type GetModelsFilterDataSubsidyQuery = { __typename?: 'Query', subsidy: { __typename?: 'evo_subsidy', evo_models: Array<{ __typename?: 'evo_model', evo_modelid: string | null } | null> | null } | null };
|
||||
|
||||
export type GetModelsFilterDataImportProgramQueryVariables = Exact<{
|
||||
importProgramId: Scalars['Uuid'];
|
||||
}>;
|
||||
|
||||
|
||||
export type GetModelsFilterDataImportProgramQuery = { __typename?: 'Query', importProgram: { __typename?: 'evo_subsidy', evo_models: Array<{ __typename?: 'evo_model', evo_modelid: string | null } | null> | null } | null };
|
||||
|
||||
export type GetLeasingWithoutKaskoOptionsQueryVariables = Exact<{ [key: string]: never; }>;
|
||||
|
||||
|
||||
|
||||
@ -2,6 +2,7 @@ import loadKpReactions from 'process/load-kp/reactions';
|
||||
import * as calculateReactions from '../../calculate/reactions';
|
||||
import * as fingapReactions from '../../fingap/reactions';
|
||||
import * as leadOpportunityReactions from '../../lead-opportunity/reactions';
|
||||
import * as leasingObject from '../../leasing-object/reactions';
|
||||
import * as leasingWithoutKaskoReactions from '../../leasing-without-kasko/reactions';
|
||||
import paymentsReactions from '../../payments/reactions';
|
||||
import * as priceReactions from '../../price/reactions';
|
||||
@ -30,4 +31,5 @@ export default function injectDefaultReactions(context) {
|
||||
leasingWithoutKaskoReactions.common(context);
|
||||
subsidyReactions.computedReactions(context);
|
||||
subsidyReactions.commonReactions(context);
|
||||
leasingObject.common(context);
|
||||
}
|
||||
|
||||
169
apps/web/process/leasing-object/reactions/common.ts
Normal file
169
apps/web/process/leasing-object/reactions/common.ts
Normal file
@ -0,0 +1,169 @@
|
||||
/* eslint-disable @typescript-eslint/naming-convention */
|
||||
import { gql } from '@apollo/client';
|
||||
import type * as CRMTypes from 'graphql/crm.types';
|
||||
import { autorun } from 'mobx';
|
||||
import type { ReactionsContext } from 'process/types';
|
||||
import { normalizeOptions } from 'tools';
|
||||
|
||||
const QUERY_GET_MODELS = gql`
|
||||
query GetModels($brandid: Uuid!) {
|
||||
evo_models(statecode: 0, evo_brandid: $brandid) {
|
||||
label: evo_name
|
||||
value: evo_modelid
|
||||
evo_modelid
|
||||
evo_vehicle_type
|
||||
}
|
||||
}
|
||||
`;
|
||||
|
||||
const QUERY_GET_LEASE_OBJECT_TYPE = gql`
|
||||
query GetModelsFilterDataLeaseObjectType($leaseObjectTypeId: Uuid!) {
|
||||
leaseObjectType: evo_leasingobject_type(evo_leasingobject_typeid: $leaseObjectTypeId) {
|
||||
evo_vehicle_type
|
||||
}
|
||||
}
|
||||
`;
|
||||
|
||||
const QUERY_GET_SUBSIDY = gql`
|
||||
query GetModelsFilterDataSubsidy($subsidyId: Uuid!) {
|
||||
subsidy: evo_subsidy(evo_subsidyid: $subsidyId) {
|
||||
evo_models {
|
||||
evo_modelid
|
||||
}
|
||||
}
|
||||
}
|
||||
`;
|
||||
|
||||
const QUERY_GET_IMPORT_PROGRAM = gql`
|
||||
query GetModelsFilterDataImportProgram($importProgramId: Uuid!) {
|
||||
importProgram: evo_subsidy(evo_subsidyid: $importProgramId) {
|
||||
evo_models {
|
||||
evo_modelid
|
||||
}
|
||||
}
|
||||
}
|
||||
`;
|
||||
|
||||
export default function commonReactions({ store, apolloClient }: ReactionsContext) {
|
||||
const { $calculation } = store;
|
||||
|
||||
autorun(
|
||||
async () => {
|
||||
const {
|
||||
brand: brandId,
|
||||
subsidy: subsidyId,
|
||||
importProgram: importProgramId,
|
||||
leaseObjectType: leaseObjectTypeId,
|
||||
} = $calculation.$values.values;
|
||||
if (!brandId) {
|
||||
$calculation.element('selectModel').reset();
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
const {
|
||||
data: { evo_models },
|
||||
} = await apolloClient.query<CRMTypes.GetModelsQuery, CRMTypes.GetModelsQueryVariables>({
|
||||
query: QUERY_GET_MODELS,
|
||||
variables: {
|
||||
brandid: brandId,
|
||||
},
|
||||
});
|
||||
|
||||
let models = evo_models;
|
||||
|
||||
if (!models) {
|
||||
$calculation.element('selectModel').reset();
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
if (leaseObjectTypeId) {
|
||||
const {
|
||||
data: { leaseObjectType },
|
||||
} = await apolloClient.query<
|
||||
CRMTypes.GetModelsFilterDataLeaseObjectTypeQuery,
|
||||
CRMTypes.GetModelsFilterDataLeaseObjectTypeQueryVariables
|
||||
>({
|
||||
query: QUERY_GET_LEASE_OBJECT_TYPE,
|
||||
variables: {
|
||||
leaseObjectTypeId,
|
||||
},
|
||||
});
|
||||
|
||||
models = models?.filter((model) => {
|
||||
if (
|
||||
model?.evo_vehicle_type &&
|
||||
leaseObjectType?.evo_vehicle_type?.includes(model.evo_vehicle_type)
|
||||
) {
|
||||
return model;
|
||||
}
|
||||
|
||||
return false;
|
||||
});
|
||||
}
|
||||
|
||||
if (subsidyId) {
|
||||
const {
|
||||
data: { subsidy },
|
||||
} = await apolloClient.query<
|
||||
CRMTypes.GetModelsFilterDataSubsidyQuery,
|
||||
CRMTypes.GetModelsFilterDataSubsidyQueryVariables
|
||||
>({
|
||||
query: QUERY_GET_SUBSIDY,
|
||||
variables: {
|
||||
subsidyId,
|
||||
},
|
||||
});
|
||||
|
||||
models = models?.filter((model) => {
|
||||
if (
|
||||
model &&
|
||||
(!subsidy?.evo_models?.length ||
|
||||
subsidy?.evo_models?.filter(
|
||||
(subsidy_evo_model) => subsidy_evo_model?.evo_modelid === model.evo_modelid
|
||||
)?.length)
|
||||
) {
|
||||
return model;
|
||||
}
|
||||
|
||||
return false;
|
||||
});
|
||||
}
|
||||
|
||||
if (importProgramId) {
|
||||
const {
|
||||
data: { importProgram },
|
||||
} = await apolloClient.query<
|
||||
CRMTypes.GetModelsFilterDataImportProgramQuery,
|
||||
CRMTypes.GetModelsFilterDataImportProgramQueryVariables
|
||||
>({
|
||||
query: QUERY_GET_IMPORT_PROGRAM,
|
||||
variables: {
|
||||
importProgramId,
|
||||
},
|
||||
});
|
||||
|
||||
models = models?.filter((model) => {
|
||||
if (
|
||||
model &&
|
||||
(!importProgram?.evo_models?.length ||
|
||||
importProgram?.evo_models?.filter(
|
||||
(importProgram_evo_model) =>
|
||||
importProgram_evo_model?.evo_modelid === model.evo_modelid
|
||||
)?.length)
|
||||
) {
|
||||
return model;
|
||||
}
|
||||
|
||||
return false;
|
||||
});
|
||||
}
|
||||
|
||||
$calculation.element('selectModel').setOptions(normalizeOptions(models));
|
||||
},
|
||||
{
|
||||
delay: 10,
|
||||
}
|
||||
);
|
||||
}
|
||||
2
apps/web/process/leasing-object/reactions/index.js
Normal file
2
apps/web/process/leasing-object/reactions/index.js
Normal file
@ -0,0 +1,2 @@
|
||||
/* eslint-disable import/prefer-default-export */
|
||||
export { default as common } from './common';
|
||||
Loading…
x
Reference in New Issue
Block a user