Compare commits

...

5 Commits

Author SHA1 Message Date
vchikalkin
5549c1305f api/elt: add query timeout (1 minute) 2023-07-31 14:10:15 +03:00
vchikalkin
85a9fdd44e ELT: disable retry failed queries 2023-07-31 13:59:09 +03:00
vchikalkin
80a0105a5a ELT: add initial row obj 2023-07-31 13:42:01 +03:00
vchikalkin
94a39925d5 ELT: disable reload button by $process 2023-07-31 12:46:32 +03:00
vchikalkin
5f7586bb0d process/load-kp: run initElt before getQuote 2023-07-31 12:42:07 +03:00
8 changed files with 86 additions and 87 deletions

View File

@ -7,7 +7,7 @@ import { Flex } from 'ui/grid';
export const ReloadButton = observer(
({ storeSelector, onClick }: { onClick: () => void; storeSelector: StoreSelector }) => {
const { $tables } = useStore();
const { $tables, $process } = useStore();
const { validation, getRows: rows } = storeSelector($tables.elt);
const hasErrors = validation.hasErrors;
@ -16,7 +16,12 @@ export const ReloadButton = observer(
<Flex justifyContent="center">
<Button
onClick={onClick}
disabled={hasErrors}
disabled={
hasErrors ||
$process.has('LoadKP') ||
$process.has('Calculate') ||
$process.has('CreateKP')
}
loading={rows.some((x) => x.status === 'fetching')}
shape="circle"
icon={<ReloadOutlined rev="" />}

View File

@ -8,6 +8,7 @@ import { STALE_TIME } from '@/constants/request';
import { MAX_FRANCHISE, MAX_INSURANCE, MIN_INSURANCE } from '@/constants/values';
import helper from '@/process/elt/lib/helper';
import { useStore } from '@/stores/hooks';
import { defaultRow } from '@/stores/tables/elt/default-values';
import { useApolloClient } from '@apollo/client';
import type { QueryFunctionContext } from '@tanstack/react-query';
import { useQueries } from '@tanstack/react-query';
@ -16,6 +17,18 @@ import { Flex } from 'ui/grid';
const storeSelector: StoreSelector = ({ kasko }) => kasko;
const initialData = {
...defaultRow,
error: null,
kaskoSum: 0,
paymentPeriods: [
{
kaskoSum: 0,
},
],
sum: 0,
};
export const Kasko = observer(() => {
const store = useStore();
const { $tables, $calculation } = store;
@ -26,22 +39,12 @@ export const Kasko = observer(() => {
const queries = useQueries({
queries: $tables.elt.kasko.getRows.map((row) => {
const { id, key } = row;
const { id, key, name } = row;
return {
cacheTime: 0,
enabled: false,
initialData: {
...row,
error: '',
kaskoSum: 0,
paymentPeriods: [
{
kaskoSum: 0,
},
],
sum: 0,
},
initialData: { ...initialData, id, key, name },
queryFn: async (context: QueryFunctionContext) => {
const payload = await makeEltKaskoRequest({ apolloClient, store }, row);
const res = await getEltKasko(payload, context);
@ -49,30 +52,14 @@ export const Kasko = observer(() => {
if (res) {
const companyRes = res?.[id];
return { ...companyRes, id, key };
return { ...companyRes, id, key, name };
}
return {
error: null,
id,
kaskoSum: 0,
key,
message: null,
numCalc: 0,
paymentPeriods: [
{
kaskoSum: 0,
},
],
requestId: '',
skCalcId: '',
status: null,
sum: 0,
totalFranchise: 0,
};
return { ...initialData, id, key, name };
},
queryKey: ['elt', 'kasko', id],
refetchOnWindowFocus: false,
retry: false,
staleTime: STALE_TIME,
};
}),
@ -152,14 +139,10 @@ export const Kasko = observer(() => {
.catch((error) => {
if (data?.key)
$tables.elt.kasko.setRow({
...defaultRow,
key: data?.key,
message: error,
numCalc: 0,
requestId: '',
skCalcId: '',
status: 'error',
sum: 0,
totalFranchise: 0,
});
});
});

View File

@ -8,6 +8,7 @@ import { STALE_TIME } from '@/constants/request';
import { MAX_INSURANCE, MIN_INSURANCE } from '@/constants/values';
import helper from '@/process/elt/lib/helper';
import { useStore } from '@/stores/hooks';
import { defaultRow } from '@/stores/tables/elt/default-values';
import { useApolloClient } from '@apollo/client';
import type { QueryFunctionContext } from '@tanstack/react-query';
import { useQueries } from '@tanstack/react-query';
@ -16,6 +17,13 @@ import { Flex } from 'ui/grid';
const storeSelector: StoreSelector = ({ osago }) => osago;
const initialData = {
...defaultRow,
error: null,
premiumSum: 0,
sum: 0,
};
export const Osago = observer(() => {
const store = useStore();
const { $tables } = store;
@ -26,12 +34,12 @@ export const Osago = observer(() => {
const queries = useQueries({
queries: $tables.elt.osago.getRows.map((row) => {
const { id, key } = row;
const { id, key, name } = row;
return {
cacheTime: 0,
enabled: false,
initialData: { ...row, error: '', premiumSum: 0 },
initialData: { ...initialData, id, key, name },
queryFn: async (context: QueryFunctionContext) => {
const payload = await makeEltOsagoRequest({ apolloClient, store }, row);
const res = await getEltOsago(payload, context);
@ -39,23 +47,14 @@ export const Osago = observer(() => {
if (res) {
const companyRes = res?.[id];
return { ...companyRes, id, key };
return { ...companyRes, id, key, name };
}
return {
error: null,
id,
key,
message: null,
numCalc: 0,
premiumSum: 0,
skCalcId: '',
status: null,
sum: 0,
};
return { ...initialData, id, key, name };
},
queryKey: ['elt', 'osago', id],
refetchOnWindowFocus: false,
retry: false,
staleTime: STALE_TIME,
};
}),
@ -71,7 +70,7 @@ export const Osago = observer(() => {
.map((x) => x.value);
queries
.filter(({ data }) => data?.key && osagoCompanyIds.includes(data.key))
.filter(({ data }) => data?.key && osagoCompanyIds.includes(data?.key))
.forEach(({ refetch, data }) => {
if (data?.key) $tables.elt.osago.setRow({ key: data?.key, status: 'fetching' });
@ -114,12 +113,10 @@ export const Osago = observer(() => {
.catch((error) => {
if (data?.key)
$tables.elt.osago.setRow({
...defaultRow,
key: data?.key,
message: error,
numCalc: 0,
skCalcId: '',
status: 'error',
sum: 0,
});
});
});

View File

@ -1,5 +1,6 @@
import type * as ELT from './types';
import getUrls from '@/config/urls';
import { TIMEOUT } from '@/constants/request';
import { withHandleError } from '@/utils/axios';
import type { QueryFunctionContext } from '@tanstack/react-query';
import axios from 'axios';
@ -8,12 +9,16 @@ const { URL_ELT_KASKO, URL_ELT_OSAGO } = getUrls();
export async function getEltOsago(payload: ELT.RequestEltOsago, { signal }: QueryFunctionContext) {
return withHandleError(
axios.post<ELT.ResponseEltOsago>(URL_ELT_OSAGO, payload, { signal }).then(({ data }) => data)
axios
.post<ELT.ResponseEltOsago>(URL_ELT_OSAGO, payload, { signal, timeout: TIMEOUT })
.then(({ data }) => data)
);
}
export async function getEltKasko(payload: ELT.RequestEltKasko, { signal }: QueryFunctionContext) {
return withHandleError(
axios.post<ELT.ResponseEltKasko>(URL_ELT_KASKO, payload, { signal }).then(({ data }) => data)
axios
.post<ELT.ResponseEltKasko>(URL_ELT_KASKO, payload, { signal, timeout: TIMEOUT })
.then(({ data }) => data)
);
}

View File

@ -8,3 +8,9 @@ export const STALE_TIME = dayjs
hours: 1,
})
.asMilliseconds();
export const TIMEOUT = dayjs
.duration({
minutes: 1,
})
.asMilliseconds();

View File

@ -1,6 +1,7 @@
import type { ProcessContext } from '../../types';
import type { Row } from '@/Components/Calculation/Form/ELT/types';
import * as CRMTypes from '@/graphql/crm.types';
import { defaultRow } from '@/stores/tables/elt/default-values';
export default function helper({
apolloClient,
@ -39,34 +40,22 @@ export default function helper({
: Boolean(x?.evo_id_elt)
)
.map((x) => ({
...defaultRow,
id:
evo_leasingobject_type?.evo_id &&
['6', '9', '10'].includes(evo_leasingobject_type?.evo_id)
? x?.evo_id_elt_smr
: x?.evo_id_elt,
key: x?.value,
message: null,
name: x?.label,
numCalc: 0,
requestId: '',
skCalcId: '',
status: null,
sum: 0,
totalFranchise: 0,
})) || []) as Row[],
osago: (accounts
?.filter((x) => x?.evo_type_ins_policy?.includes(100_000_001) && x?.evo_id_elt_osago)
.map((x) => ({
...defaultRow,
id: x?.evo_id_elt_osago,
key: x?.value,
message: null,
name: x?.label,
numCalc: 0,
requestId: '',
skCalcId: '',
status: null,
sum: 0,
totalFranchise: 0,
})) || []) as Row[],
};
},

View File

@ -15,7 +15,7 @@ export function common({ store, trpcClient, apolloClient, user }: ProcessContext
reaction(
() => $calculation.$values.getValue('quote'),
() => {
async () => {
const quote = $calculation.element('selectQuote').getOption();
if (!quote || $process.has('LoadKP') || $process.has('Calculate') || $process.has('CreateKP'))
@ -28,6 +28,8 @@ export function common({ store, trpcClient, apolloClient, user }: ProcessContext
key,
});
const eltInitialValues = await initElt();
trpcClient.getQuote
.query({
values: {
@ -65,21 +67,19 @@ export function common({ store, trpcClient, apolloClient, user }: ProcessContext
if (fingap) $tables.fingap.setSelectedKeys(fingap.keys);
initElt().then((initialValues) => {
if (initialValues) {
$tables.elt.kasko.setRows(initialValues.kasko);
$tables.elt.osago.setRows(initialValues.osago);
}
if (eltInitialValues) {
$tables.elt.kasko.setRows(eltInitialValues.kasko);
$tables.elt.osago.setRows(eltInitialValues.osago);
}
if (elt?.kasko) {
$tables.elt.kasko.setRow(elt.kasko);
$tables.elt.kasko.setSelectedKey(elt.kasko.key);
}
if (elt?.osago) {
$tables.elt.osago.setRow(elt.osago);
$tables.elt.osago.setSelectedKey(elt.osago.key);
}
});
if (elt?.kasko) {
$tables.elt.kasko.setRow(elt.kasko);
$tables.elt.kasko.setSelectedKey(elt.kasko.key);
}
if (elt?.osago) {
$tables.elt.osago.setRow(elt.osago);
$tables.elt.osago.setSelectedKey(elt.osago.key);
}
message.success({
content: `КП ${quote.label} загружено`,

View File

@ -0,0 +1,14 @@
import type * as ELT from '@/Components/Calculation/Form/ELT/types';
export const defaultRow: ELT.Row = {
id: '',
key: '',
message: null,
name: '',
numCalc: 0,
requestId: '',
skCalcId: '',
status: null,
sum: 0,
totalFranchise: 0,
};