fix GetInsuranceCompany request

reset elt on load-kp
This commit is contained in:
vchikalkin 2023-05-10 12:38:00 +03:00
parent d1665d3995
commit 654cd58c45
4 changed files with 46 additions and 32 deletions

View File

@ -23,20 +23,24 @@ export function Kasko() {
const apolloClient = useApolloClient();
const queries = useQueries({
queries: rows.map(({ key, id, ...row }) => ({
enabled: false,
initialData: { id, key, ...row, error: '', kaskoSum: 0, sum: 0 },
queryFn: async (context: QueryFunctionContext) => {
const payload = await makeEltKaskoRequest({ apolloClient, store }, id);
const res = await getEltKasko(payload, context);
const companyRes = res[id];
queries: rows.map((row) => {
const { id, key } = row;
return { ...companyRes, id, key };
},
queryKey: ['elt', 'kasko', id],
refetchOnWindowFocus: false,
staleTime: STALE_TIME,
})),
return {
enabled: false,
initialData: { ...row, error: '', kaskoSum: 0, sum: 0 },
queryFn: async (context: QueryFunctionContext) => {
const payload = await makeEltKaskoRequest({ apolloClient, store }, row);
const res = await getEltKasko(payload, context);
const companyRes = res[id];
return { ...companyRes, id, key };
},
queryKey: ['elt', 'kasko', id],
refetchOnWindowFocus: false,
staleTime: STALE_TIME,
};
}),
});
async function handleOnClick() {

View File

@ -23,20 +23,24 @@ export function Osago() {
const apolloClient = useApolloClient();
const queries = useQueries({
queries: rows.map(({ key, id, ...row }) => ({
enabled: false,
initialData: { id, key, ...row, error: '', premiumSum: 0 },
queryFn: async (context: QueryFunctionContext) => {
const payload = await makeEltOsagoRequest({ apolloClient, store }, id);
const res = await getEltOsago(payload, context);
const companyRes = res[id];
queries: rows.map((row) => {
const { id, key } = row;
return { ...companyRes, id, key };
},
queryKey: ['elt', 'osago', id],
refetchOnWindowFocus: false,
staleTime: STALE_TIME,
})),
return {
enabled: false,
initialData: { ...row, error: '', premiumSum: 0 },
queryFn: async (context: QueryFunctionContext) => {
const payload = await makeEltOsagoRequest({ apolloClient, store }, row);
const res = await getEltOsago(payload, context);
const companyRes = res[id];
return { ...companyRes, id, key };
},
queryKey: ['elt', 'osago', id],
refetchOnWindowFocus: false,
staleTime: STALE_TIME,
};
}),
});
async function handleOnClick() {

View File

@ -1,5 +1,6 @@
/* eslint-disable sonarjs/cognitive-complexity */
/* eslint-disable complexity */
import type { Row } from '../types';
import type { RequestEltKasko, RequestEltOsago } from '@/api/elt/types';
import * as CRMTypes from '@/graphql/crm.types';
import type { ProcessContext } from '@/process/types';
@ -9,7 +10,7 @@ const getSpecified = (value: unknown) => value !== null && value !== undefined;
export async function makeEltOsagoRequest(
{ store, apolloClient }: Pick<ProcessContext, 'apolloClient' | 'store'>,
companyId: string
row: Row
): Promise<RequestEltOsago> {
const { $calculation, $tables } = store;
@ -32,7 +33,7 @@ export async function makeEltOsagoRequest(
data: { account: insuranceCompany },
} = await apolloClient.query({
query: CRMTypes.GetInsuranceCompanyDocument,
variables: { accountId: companyId },
variables: { accountId: row.key },
});
if (insuranceCompany?.evo_legal_region_calc === true) {
const regionId = $calculation.element('selectLegalClientRegion').getValue();
@ -271,7 +272,7 @@ export async function makeEltOsagoRequest(
ownerType: 1,
tsToRegistrationPlace: 0,
},
companyIds: [companyId],
companyIds: [row.id],
preparams: {
brandId,
kladr,
@ -282,7 +283,7 @@ export async function makeEltOsagoRequest(
export async function makeEltKaskoRequest(
{ store, apolloClient }: Pick<ProcessContext, 'apolloClient' | 'store'>,
companyId: string
row: Row
): Promise<RequestEltKasko> {
const { $calculation } = store;
@ -696,7 +697,7 @@ export async function makeEltKaskoRequest(
// },
// ],
},
companyIds: [companyId],
companyIds: [row.id],
preparams: {
brandId,
kladr,

View File

@ -63,7 +63,12 @@ export function common({ store, trpcClient, apolloClient }: ProcessContext) {
if (fingap) $tables.fingap.setSelectedKeys(fingap.keys);
initElt().then(() => {
initElt().then((initialValues) => {
if (initialValues) {
$tables.elt.kasko.setRows(initialValues.kasko);
$tables.elt.osago.setRows(initialValues.osago);
}
if (elt?.kasko) {
$tables.elt.kasko.setRow(elt.kasko);
$tables.elt.kasko.setSelectedKey(elt.kasko.key);