diff --git a/apps/web/Components/Calculation/Form/ELT/Kasko.tsx b/apps/web/Components/Calculation/Form/ELT/Kasko.tsx index 77583cc..589f5a8 100644 --- a/apps/web/Components/Calculation/Form/ELT/Kasko.tsx +++ b/apps/web/Components/Calculation/Form/ELT/Kasko.tsx @@ -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() { diff --git a/apps/web/Components/Calculation/Form/ELT/Osago.tsx b/apps/web/Components/Calculation/Form/ELT/Osago.tsx index 54a27a0..96d32ac 100644 --- a/apps/web/Components/Calculation/Form/ELT/Osago.tsx +++ b/apps/web/Components/Calculation/Form/ELT/Osago.tsx @@ -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() { diff --git a/apps/web/Components/Calculation/Form/ELT/lib/make-request.ts b/apps/web/Components/Calculation/Form/ELT/lib/make-request.ts index afb2d7f..e4e9a4d 100644 --- a/apps/web/Components/Calculation/Form/ELT/lib/make-request.ts +++ b/apps/web/Components/Calculation/Form/ELT/lib/make-request.ts @@ -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, - companyId: string + row: Row ): Promise { 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, - companyId: string + row: Row ): Promise { const { $calculation } = store; @@ -696,7 +697,7 @@ export async function makeEltKaskoRequest( // }, // ], }, - companyIds: [companyId], + companyIds: [row.id], preparams: { brandId, kladr, diff --git a/apps/web/process/load-kp/reactions.ts b/apps/web/process/load-kp/reactions.ts index 902b315..c4a03df 100644 --- a/apps/web/process/load-kp/reactions.ts +++ b/apps/web/process/load-kp/reactions.ts @@ -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);