page/index: separate data requests

This commit is contained in:
Chika 2022-07-18 13:03:02 +03:00
parent 7c0ca4feb3
commit 698ab9eb96
5 changed files with 175 additions and 90 deletions

View File

@ -6,7 +6,14 @@ import Output from 'Components/Output';
import Head from 'next/head';
import * as agentsReactions from 'process/agents/reactions';
import * as calculateReactions from 'process/calculate/reactions';
import { getInsuranceData, getMainData, getOwnerData } from 'process/init/get-data';
import {
getAddProductTypes,
getBrands,
getDealers,
getInsuranceData,
getMainData,
getOwnerData,
} from 'process/init/get-data';
import * as leadOpportunityReactions from 'process/lead-opportunity/reactions';
import paymentsReactions from 'process/payments/reactions';
import { useEffect } from 'react';
@ -57,6 +64,18 @@ function Home() {
store.$calculation.$options.setManyOptions(options);
});
getBrands(apolloClient).then(({ options }) => {
store.$calculation.$options.setManyOptions(options);
});
getDealers(apolloClient).then(({ options }) => {
store.$calculation.$options.setManyOptions(options);
});
getAddProductTypes(apolloClient).then(({ options }) => {
store.$calculation.$options.setManyOptions(options);
});
getInsuranceData(apolloClient).then(({ tables }) => {
store.$tables.insurance.setManyRowOptions(tables.insurance);
});

18
process/init/__generated__/GetBrands.ts generated Normal file
View File

@ -0,0 +1,18 @@
/* tslint:disable */
/* eslint-disable */
// @generated
// This file was automatically generated and should not be edited.
// ====================================================
// GraphQL query operation: GetBrands
// ====================================================
export interface GetBrands_selectBrand {
__typename: "evo_brand";
label: string | null;
value: any | null;
}
export interface GetBrands {
selectBrand: (GetBrands_selectBrand | null)[] | null;
}

21
process/init/__generated__/GetDealers.ts generated Normal file
View File

@ -0,0 +1,21 @@
/* tslint:disable */
/* eslint-disable */
// @generated
// This file was automatically generated and should not be edited.
// ====================================================
// GraphQL query operation: GetDealers
// ====================================================
export interface GetDealers_selectDealer {
__typename: "account";
label: string | null;
value: any | null;
}
export interface GetDealers {
/**
* Контрагенты. statecode по умолчанию 0
*/
selectDealer: (GetDealers_selectDealer | null)[] | null;
}

View File

@ -26,18 +26,6 @@ export interface GetMainOptions_selectLeaseObjectType {
value: any | null;
}
export interface GetMainOptions_selectBrand {
__typename: "evo_brand";
label: string | null;
value: any | null;
}
export interface GetMainOptions_selectDealer {
__typename: "account";
label: string | null;
value: any | null;
}
export interface GetMainOptions_selectGPSBrand {
__typename: "evo_gps_brand";
label: string | null;
@ -51,11 +39,6 @@ export interface GetMainOptions {
selectSupplierCurrency: (GetMainOptions_selectSupplierCurrency | null)[] | null;
selectProduct: (GetMainOptions_selectProduct | null)[] | null;
selectLeaseObjectType: (GetMainOptions_selectLeaseObjectType | null)[] | null;
selectBrand: (GetMainOptions_selectBrand | null)[] | null;
/**
* Контрагенты. statecode по умолчанию 0
*/
selectDealer: (GetMainOptions_selectDealer | null)[] | null;
selectGPSBrand: (GetMainOptions_selectGPSBrand | null)[] | null;
}

View File

@ -6,6 +6,8 @@ import utc from 'dayjs/plugin/utc';
import { getDomainName } from 'services/user/tools';
import type { User } from 'services/user/types';
import type { GetAddproductTypes } from './__generated__/GetAddproductTypes';
import type { GetBrands } from './__generated__/GetBrands';
import type { GetDealers } from './__generated__/GetDealers';
import type { GetInsuranceData } from './__generated__/GetInsuranceData';
import type { GetMainOptions } from './__generated__/GetMainOptions';
import type { GetOwnerData, GetOwnerDataVariables } from './__generated__/GetOwnerData';
@ -27,6 +29,19 @@ const QUERY_GET_OWNER_DATA = gql`
}
`;
export async function getOwnerData(apolloClient: ApolloClient<NormalizedCache>, user: User) {
const { data: ownerData } = await apolloClient.query<GetOwnerData, GetOwnerDataVariables>({
query: QUERY_GET_OWNER_DATA,
variables: {
domainname: getDomainName(user),
},
});
return {
options: ownerData,
};
}
const QUERY_GET_MAIN_OPTIONS = gql`
query GetMainOptions($currentDate: DateTime) {
selectSupplierCurrency: transactioncurrencies {
@ -50,16 +65,6 @@ const QUERY_GET_MAIN_OPTIONS = gql`
value: evo_leasingobject_typeid
}
selectBrand: evo_brands(statecode: 0) {
label: evo_name
value: evo_brandid
}
selectDealer: accounts(evo_account_type: [100000001], statecode: 0, evo_legal_form: 100000001) {
label: name
value: accountid
}
selectGPSBrand: evo_gps_brands(statecode: 0) {
label: evo_name
value: evo_gps_brandid
@ -90,61 +95,6 @@ const QUERY_GET_REGIONS = gql`
}
`;
const QUERY_GET_ADDPRODUCT_TYPES = gql`
query GetAddproductTypes {
evo_addproduct_types(statecode: 0) {
label: evo_name
value: evo_addproduct_typeid
evo_graph_price
evo_product_type
}
}
`;
const QUERY_GET_INSURANCE_DATA = gql`
query GetInsuranceData($evo_account_type: [Int!]) {
osago: accounts(
evo_account_type: $evo_account_type
evo_type_ins_policy: [100000001]
statecode: 0
) {
value: accountid
label: name
}
kasko: accounts(
evo_account_type: $evo_account_type
evo_type_ins_policy: [100000000]
statecode: 0
) {
value: accountid
label: name
}
fingap: accounts(
evo_account_type: $evo_account_type
evo_type_ins_policy: [100000002]
statecode: 0
) {
value: accountid
label: name
}
}
`;
export async function getOwnerData(apolloClient: ApolloClient<NormalizedCache>, user: User) {
const { data: ownerData } = await apolloClient.query<GetOwnerData, GetOwnerDataVariables>({
query: QUERY_GET_OWNER_DATA,
variables: {
domainname: getDomainName(user),
},
});
return {
options: ownerData,
};
}
export async function getMainData(apolloClient: ApolloClient<object>) {
// prettier-ignore
const { data: mainOptions } = await apolloClient.query<GetMainOptions>({
@ -160,7 +110,6 @@ export async function getMainData(apolloClient: ApolloClient<object>) {
currentDate: dayjs().utc().toISOString(),
},
});
const selectSubsidy = subsidies.evo_subsidies?.filter(
(x) => x?.evo_subsidy_type && [100_000_000, 100_000_001].includes(x?.evo_subsidy_type)
);
@ -177,6 +126,76 @@ export async function getMainData(apolloClient: ApolloClient<object>) {
const selectObjectRegionRegistration = regions.evo_regions;
const selectLegalClientRegion = regions.evo_regions;
return {
options: {
...mainOptions,
selectSubsidy,
selectImportProgram,
selectRegionRegistration,
selectObjectRegionRegistration,
selectLegalClientRegion,
},
};
}
const QUERY_GET_BRANDS = gql`
query GetBrands {
selectBrand: evo_brands(statecode: 0) {
label: evo_name
value: evo_brandid
}
}
`;
export async function getBrands(apolloClient: ApolloClient<object>) {
const {
data: { selectBrand },
} = await apolloClient.query<GetBrands>({
query: QUERY_GET_BRANDS,
});
return {
options: {
selectBrand,
},
};
}
const QUERY_GET_DEALERS = gql`
query GetDealers {
selectDealer: accounts(evo_account_type: [100000001], statecode: 0, evo_legal_form: 100000001) {
label: name
value: accountid
}
}
`;
export async function getDealers(apolloClient: ApolloClient<object>) {
const {
data: { selectDealer },
} = await apolloClient.query<GetDealers>({
query: QUERY_GET_DEALERS,
});
return {
options: {
selectDealer,
},
};
}
const QUERY_GET_ADDPRODUCT_TYPES = gql`
query GetAddproductTypes {
evo_addproduct_types(statecode: 0) {
label: evo_name
value: evo_addproduct_typeid
evo_graph_price
evo_product_type
}
}
`;
export async function getAddProductTypes(apolloClient: ApolloClient<object>) {
const { data: addproductTypes } = await apolloClient.query<GetAddproductTypes>({
query: QUERY_GET_ADDPRODUCT_TYPES,
});
@ -215,12 +234,6 @@ export async function getMainData(apolloClient: ApolloClient<object>) {
return {
options: {
...mainOptions,
selectSubsidy,
selectImportProgram,
selectRegionRegistration,
selectObjectRegionRegistration,
selectLegalClientRegion,
selectRegistration,
selectTechnicalCard,
selectTelematic,
@ -230,6 +243,37 @@ export async function getMainData(apolloClient: ApolloClient<object>) {
};
}
const QUERY_GET_INSURANCE_DATA = gql`
query GetInsuranceData($evo_account_type: [Int!]) {
osago: accounts(
evo_account_type: $evo_account_type
evo_type_ins_policy: [100000001]
statecode: 0
) {
value: accountid
label: name
}
kasko: accounts(
evo_account_type: $evo_account_type
evo_type_ins_policy: [100000000]
statecode: 0
) {
value: accountid
label: name
}
fingap: accounts(
evo_account_type: $evo_account_type
evo_type_ins_policy: [100000002]
statecode: 0
) {
value: accountid
label: name
}
}
`;
export async function getInsuranceData(apolloClient: ApolloClient<object>) {
const { data: insuranceData } = await apolloClient.query<GetInsuranceData>({
query: QUERY_GET_INSURANCE_DATA,