merge fix/dyn-3167_elt

This commit is contained in:
vchikalkin 2023-08-01 10:03:10 +03:00
parent 903b32084a
commit 565cabb9bd
8 changed files with 86 additions and 87 deletions

View File

@ -7,7 +7,7 @@ import { Flex } from 'ui/grid';
export const ReloadButton = observer( export const ReloadButton = observer(
({ storeSelector, onClick }: { onClick: () => void; storeSelector: StoreSelector }) => { ({ storeSelector, onClick }: { onClick: () => void; storeSelector: StoreSelector }) => {
const { $tables } = useStore(); const { $tables, $process } = useStore();
const { validation, getRows: rows } = storeSelector($tables.elt); const { validation, getRows: rows } = storeSelector($tables.elt);
const hasErrors = validation.hasErrors; const hasErrors = validation.hasErrors;
@ -16,7 +16,12 @@ export const ReloadButton = observer(
<Flex justifyContent="center"> <Flex justifyContent="center">
<Button <Button
onClick={onClick} onClick={onClick}
disabled={hasErrors} disabled={
hasErrors ||
$process.has('LoadKP') ||
$process.has('Calculate') ||
$process.has('CreateKP')
}
loading={rows.some((x) => x.status === 'fetching')} loading={rows.some((x) => x.status === 'fetching')}
shape="circle" shape="circle"
icon={<ReloadOutlined rev="" />} 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 { MAX_FRANCHISE, MAX_INSURANCE, MIN_INSURANCE } from '@/constants/values';
import helper from '@/process/elt/lib/helper'; import helper from '@/process/elt/lib/helper';
import { useStore } from '@/stores/hooks'; import { useStore } from '@/stores/hooks';
import { defaultRow } from '@/stores/tables/elt/default-values';
import { useApolloClient } from '@apollo/client'; import { useApolloClient } from '@apollo/client';
import type { QueryFunctionContext } from '@tanstack/react-query'; import type { QueryFunctionContext } from '@tanstack/react-query';
import { useQueries } 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 storeSelector: StoreSelector = ({ kasko }) => kasko;
const initialData = {
...defaultRow,
error: null,
kaskoSum: 0,
paymentPeriods: [
{
kaskoSum: 0,
},
],
sum: 0,
};
export const Kasko = observer(() => { export const Kasko = observer(() => {
const store = useStore(); const store = useStore();
const { $tables, $calculation } = store; const { $tables, $calculation } = store;
@ -26,22 +39,12 @@ export const Kasko = observer(() => {
const queries = useQueries({ const queries = useQueries({
queries: $tables.elt.kasko.getRows.map((row) => { queries: $tables.elt.kasko.getRows.map((row) => {
const { id, key } = row; const { id, key, name } = row;
return { return {
cacheTime: 0, cacheTime: 0,
enabled: false, enabled: false,
initialData: { initialData: { ...initialData, id, key, name },
...row,
error: '',
kaskoSum: 0,
paymentPeriods: [
{
kaskoSum: 0,
},
],
sum: 0,
},
queryFn: async (context: QueryFunctionContext) => { queryFn: async (context: QueryFunctionContext) => {
const payload = await makeEltKaskoRequest({ apolloClient, store }, row); const payload = await makeEltKaskoRequest({ apolloClient, store }, row);
const res = await getEltKasko(payload, context); const res = await getEltKasko(payload, context);
@ -49,30 +52,14 @@ export const Kasko = observer(() => {
if (res) { if (res) {
const companyRes = res?.[id]; const companyRes = res?.[id];
return { ...companyRes, id, key }; return { ...companyRes, id, key, name };
} }
return { return { ...initialData, id, key, name };
error: null,
id,
kaskoSum: 0,
key,
message: null,
numCalc: 0,
paymentPeriods: [
{
kaskoSum: 0,
},
],
requestId: '',
skCalcId: '',
status: null,
sum: 0,
totalFranchise: 0,
};
}, },
queryKey: ['elt', 'kasko', id], queryKey: ['elt', 'kasko', id],
refetchOnWindowFocus: false, refetchOnWindowFocus: false,
retry: false,
staleTime: STALE_TIME, staleTime: STALE_TIME,
}; };
}), }),
@ -152,14 +139,10 @@ export const Kasko = observer(() => {
.catch((error) => { .catch((error) => {
if (data?.key) if (data?.key)
$tables.elt.kasko.setRow({ $tables.elt.kasko.setRow({
...defaultRow,
key: data?.key, key: data?.key,
message: error, message: error,
numCalc: 0,
requestId: '',
skCalcId: '',
status: 'error', 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 { MAX_INSURANCE, MIN_INSURANCE } from '@/constants/values';
import helper from '@/process/elt/lib/helper'; import helper from '@/process/elt/lib/helper';
import { useStore } from '@/stores/hooks'; import { useStore } from '@/stores/hooks';
import { defaultRow } from '@/stores/tables/elt/default-values';
import { useApolloClient } from '@apollo/client'; import { useApolloClient } from '@apollo/client';
import type { QueryFunctionContext } from '@tanstack/react-query'; import type { QueryFunctionContext } from '@tanstack/react-query';
import { useQueries } 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 storeSelector: StoreSelector = ({ osago }) => osago;
const initialData = {
...defaultRow,
error: null,
premiumSum: 0,
sum: 0,
};
export const Osago = observer(() => { export const Osago = observer(() => {
const store = useStore(); const store = useStore();
const { $tables } = store; const { $tables } = store;
@ -26,12 +34,12 @@ export const Osago = observer(() => {
const queries = useQueries({ const queries = useQueries({
queries: $tables.elt.osago.getRows.map((row) => { queries: $tables.elt.osago.getRows.map((row) => {
const { id, key } = row; const { id, key, name } = row;
return { return {
cacheTime: 0, cacheTime: 0,
enabled: false, enabled: false,
initialData: { ...row, error: '', premiumSum: 0 }, initialData: { ...initialData, id, key, name },
queryFn: async (context: QueryFunctionContext) => { queryFn: async (context: QueryFunctionContext) => {
const payload = await makeEltOsagoRequest({ apolloClient, store }, row); const payload = await makeEltOsagoRequest({ apolloClient, store }, row);
const res = await getEltOsago(payload, context); const res = await getEltOsago(payload, context);
@ -39,23 +47,14 @@ export const Osago = observer(() => {
if (res) { if (res) {
const companyRes = res?.[id]; const companyRes = res?.[id];
return { ...companyRes, id, key }; return { ...companyRes, id, key, name };
} }
return { return { ...initialData, id, key, name };
error: null,
id,
key,
message: null,
numCalc: 0,
premiumSum: 0,
skCalcId: '',
status: null,
sum: 0,
};
}, },
queryKey: ['elt', 'osago', id], queryKey: ['elt', 'osago', id],
refetchOnWindowFocus: false, refetchOnWindowFocus: false,
retry: false,
staleTime: STALE_TIME, staleTime: STALE_TIME,
}; };
}), }),
@ -71,7 +70,7 @@ export const Osago = observer(() => {
.map((x) => x.value); .map((x) => x.value);
queries queries
.filter(({ data }) => data?.key && osagoCompanyIds.includes(data.key)) .filter(({ data }) => data?.key && osagoCompanyIds.includes(data?.key))
.forEach(({ refetch, data }) => { .forEach(({ refetch, data }) => {
if (data?.key) $tables.elt.osago.setRow({ key: data?.key, status: 'fetching' }); if (data?.key) $tables.elt.osago.setRow({ key: data?.key, status: 'fetching' });
@ -114,12 +113,10 @@ export const Osago = observer(() => {
.catch((error) => { .catch((error) => {
if (data?.key) if (data?.key)
$tables.elt.osago.setRow({ $tables.elt.osago.setRow({
...defaultRow,
key: data?.key, key: data?.key,
message: error, message: error,
numCalc: 0,
skCalcId: '',
status: 'error', status: 'error',
sum: 0,
}); });
}); });
}); });

View File

@ -1,5 +1,6 @@
import type * as ELT from './types'; import type * as ELT from './types';
import getUrls from '@/config/urls'; import getUrls from '@/config/urls';
import { TIMEOUT } from '@/constants/request';
import { withHandleError } from '@/utils/axios'; import { withHandleError } from '@/utils/axios';
import type { QueryFunctionContext } from '@tanstack/react-query'; import type { QueryFunctionContext } from '@tanstack/react-query';
import axios from 'axios'; 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) { export async function getEltOsago(payload: ELT.RequestEltOsago, { signal }: QueryFunctionContext) {
return withHandleError( 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) { export async function getEltKasko(payload: ELT.RequestEltKasko, { signal }: QueryFunctionContext) {
return withHandleError( 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, hours: 1,
}) })
.asMilliseconds(); .asMilliseconds();
export const TIMEOUT = dayjs
.duration({
minutes: 1,
})
.asMilliseconds();

View File

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

View File

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