diff --git a/apps/web/Components/Calculation/Form/ELT/Osago.tsx b/apps/web/Components/Calculation/Form/ELT/Osago.tsx index 4135e04..bfda9a7 100644 --- a/apps/web/Components/Calculation/Form/ELT/Osago.tsx +++ b/apps/web/Components/Calculation/Form/ELT/Osago.tsx @@ -1,9 +1,11 @@ +/* eslint-disable sonarjs/cognitive-complexity */ import { PolicyTable, ReloadButton, Validation } from './Components'; import { columns } from './lib/config'; import { makeEltOsagoRequest } from './lib/make-request'; import type { Row, StoreSelector } from './types'; import { getEltOsago } from '@/api/elt/query'; import { STALE_TIME } from '@/constants/request'; +import { MAX_INSURANCE, MIN_INSURANCE } from '@/constants/values'; import { useStore } from '@/stores/hooks'; import { useApolloClient } from '@apollo/client'; import type { QueryFunctionContext } from '@tanstack/react-query'; @@ -43,10 +45,32 @@ export function Osago() { queries.forEach(({ refetch }) => { refetch().then((res) => { if (res.data) { - const { key, numCalc, premiumSum, message, skCalcId, error } = res.data; + const { key, numCalc, premiumSum, message, skCalcId } = res.data; + let { error } = res.data; + + if (premiumSum > MAX_INSURANCE) { + error ||= `Сумма по страховке превышает максимально допустимое значение по стоимости ОСАГО: ${Intl.NumberFormat( + 'ru', + { + currency: 'RUB', + style: 'currency', + } + ).format(MAX_INSURANCE)}`; + } + + if (premiumSum < MIN_INSURANCE) { + error ||= `Сумма по страховке не должна быть меньше допустимого значения по стоимости ОСАГО: ${Intl.NumberFormat( + 'ru', + { + currency: 'RUB', + style: 'currency', + } + ).format(MIN_INSURANCE)}`; + } + $tables.elt.osago.setRow({ key, - message: message || error, + message: error || message, numCalc, skCalcId, status: error ? 'error' : null,