diff --git a/src/client/Components/Calculation/ELT/Content/Components/Controls/BottomControls.jsx b/src/client/Components/Calculation/ELT/Content/Components/Controls/BottomControls.jsx new file mode 100644 index 0000000..e486652 --- /dev/null +++ b/src/client/Components/Calculation/ELT/Content/Components/Controls/BottomControls.jsx @@ -0,0 +1,33 @@ +import { message } from 'antd'; +import Button from 'client/Elements/Button'; +import { useStores } from 'client/hooks/useStores'; +import { Process } from 'core/types/Calculation/Store/process'; +import { ElementStatus } from 'core/types/statuses'; + +const BottomControls = ({ insType, onSelectRow, selectedKey }) => { + const { calculationStore } = useStores(); + const { ELTStore } = calculationStore.stores; + const handleSelectRow = () => { + const { calculationProcess } = calculationStore.stores; + calculationProcess.addProcess(Process.ELT); + ELTStore[insType].setKey(selectedKey); + onSelectRow.call(calculationStore, insType, selectedKey); + calculationProcess.deleteProcess(Process.ELT); + + message.success({ content: 'Выбранный расчет ЭЛТ применен' }); + }; + + return ( + -); - -const ContentWrapper = styled(Flex)` - width: 550px !important; -`; - -export default ({ children, ...props }) => ( - - - {children} - - -); diff --git a/src/client/Components/Calculation/ELT/Content/Kasko/Kasko.stories.jsx b/src/client/Components/Calculation/ELT/Content/Kasko/Kasko.stories.jsx index d6650b3..c4ebe16 100644 --- a/src/client/Components/Calculation/ELT/Content/Kasko/Kasko.stories.jsx +++ b/src/client/Components/Calculation/ELT/Content/Kasko/Kasko.stories.jsx @@ -1,5 +1,5 @@ import InsTable from '../InsTable'; -import tableConfig from '../lib/config'; +import tableConfig from '../lib/config/table'; export default { title: 'Components/Calculation/ELT/Kasko', diff --git a/src/client/Components/Calculation/ELT/Content/Kasko/index.jsx b/src/client/Components/Calculation/ELT/Content/Kasko/index.jsx index 5d26e12..7b9a425 100644 --- a/src/client/Components/Calculation/ELT/Content/Kasko/index.jsx +++ b/src/client/Components/Calculation/ELT/Content/Kasko/index.jsx @@ -1,17 +1,17 @@ -import InsContent from '../Components/InsContent'; -import tableConfig from '../lib/config'; -import getData from '../lib/getData'; +import buildELTContent from '../build'; +import { fetchData } from '../lib/requests'; import composeRequest from './lib/composeRequest'; +import tableConfig from './lib/config'; import convertEltResult from './lib/convertEltResult'; import onSelectRow from './lib/onSelectRow'; import { requiredFields } from './lib/validation'; const insType = 'kasko'; -export default InsContent({ +export default buildELTContent({ title: 'КАСКО', insType, - getData: getData(insType, composeRequest, convertEltResult), + fetchData: fetchData(insType, composeRequest, convertEltResult), onSelectRow, tableConfig, requiredFields, diff --git a/src/client/Components/Calculation/ELT/Content/Kasko/lib/composeRequest.ts b/src/client/Components/Calculation/ELT/Content/Kasko/lib/composeRequest.ts index 2ab8f07..d14ff8c 100644 --- a/src/client/Components/Calculation/ELT/Content/Kasko/lib/composeRequest.ts +++ b/src/client/Components/Calculation/ELT/Content/Kasko/lib/composeRequest.ts @@ -1,6 +1,6 @@ import { currentDate } from 'core/tools/date'; import { ICalculationStore } from 'core/types/Calculation/Store/index'; -import { isNull } from 'lodash'; +import { get, isNull } from 'lodash'; const mapEngineType = { 100000000: '0', @@ -37,8 +37,9 @@ const mapCategory = { const getSpecified = value => !isNull(value); export default function (this: ICalculationStore) { - const regionName = this.getOption('selectRegionRegistration')?.evo_name; - const cityName = this.getOption('selectTownRegistration')?.evo_name; + const region = this.getOption('selectRegionRegistration'); + const city = this.getOption('selectTownRegistration'); + const kladr = get(city, 'evo_kladr_id') || get(region, 'evo_kladr_id'); const brandId = this.getOption('selectBrand')?.evo_id; const modelId = this.getOption('selectModel')?.evo_id; @@ -57,7 +58,7 @@ export default function (this: ICalculationStore) { const cost = this.getValue('leaseObjectPrice') - this.getValue('supplierDiscountRub'); - const franchise = this.getValue('insFranchise'); + const franchise = parseInt(this.getValue('insFranchise') || 0); const franchiseSpecified = getSpecified(franchise); const puuMark = this.getOption('selectGPSBrand')?.evo_id; const puuModel = this.getOption('selectGPSModel')?.evo_id; @@ -108,19 +109,11 @@ export default function (this: ICalculationStore) { ? '11635' : '0'; - const globalLimitSum = this.getTableRowValues('tableInsurance', 2, 'value') - .insCost - ? 1000000 - : 0; - const globalLimitSumSpecified = getSpecified(globalLimitSum); - const limitSumId = globalLimitSum + ''; - - const INN = this.getValue('INNForCalc') || '' + ''; + const INN = `${this.getValue('INNForCalc')}`; return { preparams: { - regionName, - cityName, + kladr, brandId, modelId, }, @@ -170,8 +163,6 @@ export default function (this: ICalculationStore) { classification, }, drivers: [{ age, experience, sex, sexSpecified }], - GO: { limitSumId, globalLimitSum, globalLimitSumSpecified }, - NS: { LimitSum: '1000000' }, Insurer: { SubjectType: 1, SubjectTypeSpecified: true, diff --git a/src/client/Components/Calculation/ELT/Content/Kasko/lib/config/columns.ts b/src/client/Components/Calculation/ELT/Content/Kasko/lib/config/columns.ts new file mode 100644 index 0000000..7485c9a --- /dev/null +++ b/src/client/Components/Calculation/ELT/Content/Kasko/lib/config/columns.ts @@ -0,0 +1,23 @@ +import { formatMoney } from 'core/tools/format'; + +const columns: { title: string; dataIndex: string; [key: string]: any }[] = [ + { + title: 'Страховая компания', + dataIndex: 'name', + }, + { + title: 'Сумма', + dataIndex: 'kaskoSum', + //@ts-ignore + sorter: (a, b) => a.kaskoSum || 0 - b.kaskoSum || 0, + sortDirections: ['descend', 'ascend'], + render: value => formatMoney(value, 'RUB'), + }, + { + title: 'Франшиза', + dataIndex: 'totalFranchise', + render: value => formatMoney(value, 'RUB'), + }, +]; + +export default columns; diff --git a/src/client/Components/Calculation/ELT/Content/Kasko/lib/config/index.ts b/src/client/Components/Calculation/ELT/Content/Kasko/lib/config/index.ts new file mode 100644 index 0000000..6cbcbbf --- /dev/null +++ b/src/client/Components/Calculation/ELT/Content/Kasko/lib/config/index.ts @@ -0,0 +1,4 @@ +import tableConfig from '../../../lib/config/table'; +import columns from './columns'; + +export default { columns, ...tableConfig }; diff --git a/src/client/Components/Calculation/ELT/Content/Kasko/lib/convertEltResult.js b/src/client/Components/Calculation/ELT/Content/Kasko/lib/convertEltResult.js index 8e73af2..e9d6734 100644 --- a/src/client/Components/Calculation/ELT/Content/Kasko/lib/convertEltResult.js +++ b/src/client/Components/Calculation/ELT/Content/Kasko/lib/convertEltResult.js @@ -1,21 +1,6 @@ import { get, pick } from 'lodash'; -const mapKaskoSums = [ - { - sumTitle: 'КАСКО', - sumPath: 'paymentPeriods[0].kaskoSum', - }, - { - sumTitle: 'ДГО', - sumPath: 'paymentPeriods[0].goSum', - }, - { - sumTitle: 'НС', - sumPath: 'paymentPeriods[0].nsSum', - }, -]; - -export default function (resultCompany, key) { +export default function (resultCompany, key, { leasingPeriod }) { if (!resultCompany || Object.keys(resultCompany).length === 0) { return; } @@ -25,23 +10,17 @@ export default function (resultCompany, key) { ['message', 'requestId', 'skCalcId'], '', ); - const sumsFromResult = Object.fromEntries( - ['kaskoSum', 'goSum', 'nsSum', 'premiumSum'].map(x => [ - x, - get(resultCompany, 'paymentPeriods[0].' + x, 0), - ]), - ); + + const sumsFromResult = pick(resultCompany, ['totalFranchise'], 0); + + const kaskoSumSource = + leasingPeriod < 16 ? 'kaskoSum' : 'paymentPeriods[0].kaskoSum'; + const kaskoSum = get(resultCompany, kaskoSumSource, 0); return { key, - sumType: 'premiumSum', - sumTitle: 'Премия по договору', ...dataFromResult, ...sumsFromResult, - children: mapKaskoSums.map(({ sumPath, ...x }) => ({ - key, - ...x, - premiumSum: get(resultCompany, sumPath, 0), - })), + kaskoSum, }; } diff --git a/src/client/Components/Calculation/ELT/Content/Kasko/lib/onSelectRow.ts b/src/client/Components/Calculation/ELT/Content/Kasko/lib/onSelectRow.ts index df7c96f..62428c9 100644 --- a/src/client/Components/Calculation/ELT/Content/Kasko/lib/onSelectRow.ts +++ b/src/client/Components/Calculation/ELT/Content/Kasko/lib/onSelectRow.ts @@ -8,7 +8,10 @@ export default function ( const selectedRow = this.stores.ELTStore[insType].list.find( x => x.key === selectedKey, ); - const { accountid, kaskoSum, goSum, nsSum } = selectedRow; + const { accountid, kaskoSum, totalFranchise } = selectedRow; + + this.setValue('insFranchise', totalFranchise); + this.setTableRows( 'tableInsurance', 1, @@ -19,17 +22,17 @@ export default function ( }, insCost: { value: kaskoSum }, }, - { - insuranceCompany: { - value: accountid, - }, - insCost: { value: goSum }, - }, - { - insuranceCompany: { - value: accountid, - }, - insCost: { value: nsSum }, - }, + // { + // insuranceCompany: { + // value: accountid, + // }, + // insCost: { value: goSum }, + // }, + // { + // insuranceCompany: { + // value: accountid, + // }, + // insCost: { value: nsSum }, + // }, ]); } diff --git a/src/client/Components/Calculation/ELT/Content/Kasko/lib/validation.ts b/src/client/Components/Calculation/ELT/Content/Kasko/lib/validation.ts index 223ed45..b9561d6 100644 --- a/src/client/Components/Calculation/ELT/Content/Kasko/lib/validation.ts +++ b/src/client/Components/Calculation/ELT/Content/Kasko/lib/validation.ts @@ -5,9 +5,15 @@ export const requiredFields: ElementsNames[] = [ 'selectTownRegistration', 'selectBrand', 'selectModel', + 'cbxLeaseObjectUsed', 'tbxLeaseObjectYear', 'tbxLeaseObjectMotorPower', + 'selectEngineType', 'tbxLeasingPeriod', 'tbxLeaseObjectPrice', + 'tbxSupplierDiscountRub', + 'tbxInsFranchise', 'selectLeaseObjectCategory', + 'selectLeaseObjectUseFor', + 'tbxINNForCalc', ]; diff --git a/src/client/Components/Calculation/ELT/Content/Osago/index.jsx b/src/client/Components/Calculation/ELT/Content/Osago/index.jsx index 8d384cd..aca7123 100644 --- a/src/client/Components/Calculation/ELT/Content/Osago/index.jsx +++ b/src/client/Components/Calculation/ELT/Content/Osago/index.jsx @@ -1,17 +1,17 @@ -import InsContent from '../Components/InsContent'; -import tableConfig from '../lib/config'; -import getData from '../lib/getData'; +import buildELTContent from '../build'; +import { fetchData } from '../lib/requests'; import composeRequest from './lib/composeRequest'; +import tableConfig from './lib/config'; import convertEltResult from './lib/convertEltResult'; import onSelectRow from './lib/onSelectRow'; import { requiredFields } from './lib/validation'; const insType = 'osago'; -export default InsContent({ +export default buildELTContent({ title: 'ОСАГО', insType, - getData: getData(insType, composeRequest, convertEltResult), + fetchData: fetchData(insType, composeRequest, convertEltResult), onSelectRow, tableConfig, requiredFields, diff --git a/src/client/Components/Calculation/ELT/Content/Osago/lib/composeRequest.ts b/src/client/Components/Calculation/ELT/Content/Osago/lib/composeRequest.ts index 988b755..cde4973 100644 --- a/src/client/Components/Calculation/ELT/Content/Osago/lib/composeRequest.ts +++ b/src/client/Components/Calculation/ELT/Content/Osago/lib/composeRequest.ts @@ -1,6 +1,6 @@ import { currentDate } from 'core/tools/date'; import { ICalculationStore } from 'core/types/Calculation/Store'; -import { isNull } from 'lodash'; +import { get, isNull } from 'lodash'; const mapCategory = { 100000000: 'A', @@ -11,7 +11,7 @@ const mapCategory = { }; const mapSubCategoryBuilder = (leaseObjectUseFor, maxMass, countSeats) => ({ - 100000000: () => '0', + 100000000: '0', 100000001: () => { if (leaseObjectUseFor === 100000001) { return '11'; @@ -39,8 +39,9 @@ const mapSubCategoryBuilder = (leaseObjectUseFor, maxMass, countSeats) => ({ const getSpecified = value => !isNull(value); export default function (this: ICalculationStore) { - const regionName = this.getOption('selectRegionRegistration')?.evo_name; - const cityName = this.getOption('selectTownRegistration')?.evo_name; + const region = this.getOption('selectRegionRegistration'); + const city = this.getOption('selectTownRegistration'); + const kladr = get(city, 'evo_kladr_id') || get(region, 'evo_kladr_id'); const brandId = this.getOption('selectBrand')?.evo_id; const modelId = this.getOption('selectModel')?.evo_id; @@ -54,19 +55,20 @@ export default function (this: ICalculationStore) { : '0'; let category = '0'; - if (Object.keys(mapCategory).includes(leaseObjectCategory)) { - category = mapCategory[leaseObjectCategory]; + if (Object.keys(mapCategory).includes(`${leaseObjectCategory}`)) { + category = mapCategory[`${leaseObjectCategory}`]; } const leaseObjectUseFor = this.getValue('leaseObjectUseFor'); const maxMass = this.getValue('maxMass'); const countSeats = this.getValue('countSeats'); + const mapSubCategory = mapSubCategoryBuilder( leaseObjectUseFor, maxMass, countSeats, ); - const subCategory = mapSubCategory[leaseObjectCategory]; + const subCategory = mapSubCategory[leaseObjectCategory](); let seatingCapacity = 0; if (leaseObjectCategory === 100000003) { @@ -87,13 +89,11 @@ export default function (this: ICalculationStore) { resident: 1, country: 'Российская Федерация', region: 'Москва', - district: '0', + // district: '0', city: 'Москва', cityKladr: '7700000000000', street: 'ул. Котляковская', - streetKladr: '0', house: '8', - korpus: '0', flat: '337', }; @@ -106,19 +106,27 @@ export default function (this: ICalculationStore) { factAddress: address, phone: '8 (800) 333-75-75', email: 'client@evoleasing.ru', + subjectType: 1, + subjectTypeSpecified: true, + opf: 1, + opfSpecified: true, }; return { preparams: { - regionName, - cityName, + kladr, brandId, modelId, }, ELTParams: { + driversCount: 0, tsToRegistrationPlace: 0, contractBeginDate: currentDate, duration: 12, + insurerType: 1, + ownerType: 1, + contractOptionId: 1, + contractStatusId: 13, carInfo: { mark, model, @@ -126,10 +134,6 @@ export default function (this: ICalculationStore) { vehiclePower, tsType: { category, subCategory }, vehicle: { - regNumber: '0', - bodyNumber: '0', - chassisNumber: '0', - VIN: '0', seatingCapacity, seatingCapacitySpecified, maxAllowedMass, diff --git a/src/client/Components/Calculation/ELT/Content/lib/config/columns.ts b/src/client/Components/Calculation/ELT/Content/Osago/lib/config/columns.ts similarity index 50% rename from src/client/Components/Calculation/ELT/Content/lib/config/columns.ts rename to src/client/Components/Calculation/ELT/Content/Osago/lib/config/columns.ts index 2450641..d4c2901 100644 --- a/src/client/Components/Calculation/ELT/Content/lib/config/columns.ts +++ b/src/client/Components/Calculation/ELT/Content/Osago/lib/config/columns.ts @@ -1,20 +1,17 @@ -export type KaskoDataNames = 'name' | 'sumTitle' | 'premiumSum'; +import { formatMoney } from 'core/tools/format'; -const columns: { title: string; dataIndex: KaskoDataNames }[] = [ +const columns: { title: string; dataIndex: string; [key: string]: any }[] = [ { title: 'Страховая компания', dataIndex: 'name', }, - { - title: '', - dataIndex: 'sumTitle', - }, { title: 'Сумма', dataIndex: 'premiumSum', //@ts-ignore - sorter: (a, b) => a.premiumSum - b.premiumSum, + sorter: (a, b) => a.premiumSum || 0 - b.premiumSum || 0, sortDirections: ['descend', 'ascend'], + render: value => formatMoney(value), }, ]; diff --git a/src/client/Components/Calculation/ELT/Content/Osago/lib/config/index.ts b/src/client/Components/Calculation/ELT/Content/Osago/lib/config/index.ts new file mode 100644 index 0000000..6cbcbbf --- /dev/null +++ b/src/client/Components/Calculation/ELT/Content/Osago/lib/config/index.ts @@ -0,0 +1,4 @@ +import tableConfig from '../../../lib/config/table'; +import columns from './columns'; + +export default { columns, ...tableConfig }; diff --git a/src/client/Components/Calculation/ELT/Content/Osago/lib/validation.ts b/src/client/Components/Calculation/ELT/Content/Osago/lib/validation.ts index 223ed45..fc43ff6 100644 --- a/src/client/Components/Calculation/ELT/Content/Osago/lib/validation.ts +++ b/src/client/Components/Calculation/ELT/Content/Osago/lib/validation.ts @@ -9,5 +9,10 @@ export const requiredFields: ElementsNames[] = [ 'tbxLeaseObjectMotorPower', 'tbxLeasingPeriod', 'tbxLeaseObjectPrice', + 'selectLeaseObjectUseFor', + 'tbxMaxMass', + 'tbxCountSeats', + 'cbxWithTrailer', 'selectLeaseObjectCategory', + 'tbxINNForCalc', ]; diff --git a/src/client/Components/Calculation/ELT/Content/build.jsx b/src/client/Components/Calculation/ELT/Content/build.jsx new file mode 100644 index 0000000..0bf5a7e --- /dev/null +++ b/src/client/Components/Calculation/ELT/Content/build.jsx @@ -0,0 +1,28 @@ +import { Flex } from 'client/UIKit/grid'; +import { useState } from 'react'; +import styled from 'styled-components'; +import { BottomControls, TopControls } from './Components/Controls'; +import InsTable from './Components/InsTable'; + +const ContentWrapper = styled(Flex)` + flex-direction: column; + width: 100%; !important +`; + +const buildELTContent = ({ tableConfig, ...params }) => props => { + const [selectedKey, selectKey] = useState(); + return ( + + + + + + ); +}; + +export default buildELTContent; diff --git a/src/client/Components/Calculation/ELT/Content/index.jsx b/src/client/Components/Calculation/ELT/Content/index.jsx index 38e1cea..3c5b34f 100644 --- a/src/client/Components/Calculation/ELT/Content/index.jsx +++ b/src/client/Components/Calculation/ELT/Content/index.jsx @@ -1,18 +1,14 @@ import { Flex } from 'client/UIKit/grid'; -import mq from 'client/UIKit/mq'; import styled from 'styled-components'; import Kasko from './Kasko'; import Osago from './Osago'; const ContentDivider = styled.div` margin: 16px 0; - ${mq.laptopHD` - margin: 0 16px; - `} `; export default () => ( - + diff --git a/src/client/Components/Calculation/ELT/Content/lib/config/index.ts b/src/client/Components/Calculation/ELT/Content/lib/config/table.ts similarity index 62% rename from src/client/Components/Calculation/ELT/Content/lib/config/index.ts rename to src/client/Components/Calculation/ELT/Content/lib/config/table.ts index f6add11..b399cec 100644 --- a/src/client/Components/Calculation/ELT/Content/lib/config/index.ts +++ b/src/client/Components/Calculation/ELT/Content/lib/config/table.ts @@ -1,15 +1,13 @@ import { TableProps } from 'antd'; -import columns from './columns'; export default { - columns, rowSelection: { hideSelectAll: true, type: 'radio', }, expandable: { - // rowExpandable: record => record.message || record.children, - // expandedRowRender: record => record.message, + rowExpandable: record => record.message || record.children, + expandedRowRender: record => record.message, // expandRowByClick: true, // expandIconColumnIndex: -1, }, diff --git a/src/client/Components/Calculation/ELT/Content/lib/getData.ts b/src/client/Components/Calculation/ELT/Content/lib/requests.ts similarity index 59% rename from src/client/Components/Calculation/ELT/Content/lib/getData.ts rename to src/client/Components/Calculation/ELT/Content/lib/requests.ts index 45deb9a..c5e3fd9 100644 --- a/src/client/Components/Calculation/ELT/Content/lib/getData.ts +++ b/src/client/Components/Calculation/ELT/Content/lib/requests.ts @@ -1,9 +1,20 @@ +import axios from 'axios'; import ELTService from 'core/services/ELTService'; import { ICalculationStore } from 'core/types/Calculation/Store'; import { IAccount } from 'core/types/Entities/crmEntities'; +import { toJS } from 'mobx'; + +const CancelToken = axios.CancelToken; +export let sources = {}; + +export function cancelRequests(insType: string) { + if (sources[insType]) sources[insType].cancel(); +} + +export const fetchData = (insType: string, composeRequest, convertEltResult) => + function (this: ICalculationStore) { + sources[insType] = CancelToken.source(); -export default (insType: string, composeRequest, convertEltResult) => - function (this: ICalculationStore, callback: () => any) { const { ELTStore } = this.stores; const request = composeRequest.call(this); @@ -11,10 +22,13 @@ export default (insType: string, composeRequest, convertEltResult) => (company: IAccount, i: number) => new Promise((resolve, reject) => { ELTService[insType] - .getCalculation({ - companyIds: [company.evo_id_elt], - ...request, - }) + .getCalculation( + { + companyIds: [company.evo_id_elt], + ...request, + }, + sources[insType].token, + ) .then(res => { if (!company.evo_id_elt || !res[company.evo_id_elt]) { return; @@ -22,6 +36,7 @@ export default (insType: string, composeRequest, convertEltResult) => const converted = convertEltResult( res[company.evo_id_elt], company.accountid, + toJS(this.getValues(['leasingPeriod'])), ); ELTStore.setCompanyRes( insType, @@ -36,5 +51,5 @@ export default (insType: string, composeRequest, convertEltResult) => }), ); - Promise.allSettled(requests).then(() => callback()); + return Promise.race(requests); }; diff --git a/src/client/Components/Calculation/ELT/Content/lib/resetIns.ts b/src/client/Components/Calculation/ELT/Content/lib/resetIns.ts new file mode 100644 index 0000000..62d2cd1 --- /dev/null +++ b/src/client/Components/Calculation/ELT/Content/lib/resetIns.ts @@ -0,0 +1,48 @@ +import { ICalculationStore } from 'core/types/Calculation/Store'; +import { TCRMEntity } from 'core/types/Entities/crmEntities'; +import { pick } from 'lodash'; +import { sources } from './requests'; + +const mapInsType = { + kasko: 100000000, + osago: 100000001, +}; + +export const initFields = ['evo_id_elt', 'name', 'accountid']; + +export function initIns(this: ICalculationStore, insType) { + const insuranceCompanies = this.getTableOptions( + 'tableInsurance', + 'insuranceCompany', + ); + if (insuranceCompanies === undefined) { + return; + } + const { ELTStore } = this.stores; + const list: TCRMEntity[] = []; + insuranceCompanies.forEach(company => { + if ( + company && + company.evo_id_elt && + company.evo_type_ins_policy && + company.evo_type_ins_policy.includes(mapInsType[insType]) + ) { + const companyData = pick(company, initFields, ''); + list.push(companyData); + } + }); + ELTStore[insType].list.replace(list); +} + +export function resetIns(this: ICalculationStore, insType) { + sources[insType] && sources[insType].cancel(); + + const { ELTStore } = this.stores; + + const list: TCRMEntity[] = []; + ELTStore[insType].list.forEach(x => { + const picked = pick(x, initFields, ''); + list.push(picked); + }); + ELTStore[insType].reset(list); +} diff --git a/src/client/Components/Calculation/ELT/Content/lib/validation.ts b/src/client/Components/Calculation/ELT/Content/lib/validation.ts index 0f93f7e..d89b766 100644 --- a/src/client/Components/Calculation/ELT/Content/lib/validation.ts +++ b/src/client/Components/Calculation/ELT/Content/lib/validation.ts @@ -1,19 +1,16 @@ -import { elementsTitles } from 'client/Containers/Calculation/lib/elements/titles'; -import { elementsValues } from 'client/Containers/Calculation/lib/elements/values'; +import { getValueName } from 'client/Containers/Calculation/lib/elements/tools'; import { ICalculationStore } from 'core/types/Calculation/Store'; import { ElementsNames } from 'core/types/Calculation/Store/elements'; +import { isNil } from 'lodash'; -export function validate(this: ICalculationStore, requiredValues) { - const missingValues = requiredValues.filter(x => { - const valueName = elementsValues[x] || ''; - - return ( - this.values[valueName] === undefined || this.values[valueName] === null - ); +export function validate( + this: ICalculationStore, + requiredFields: ElementsNames[], +) { + const missingValues = requiredFields.filter(fieldName => { + const valueName = getValueName(fieldName); + const value = this.getValue(valueName); + return isNil(value); }); return missingValues; } - -export function getFieldsNames(elementsNames: ElementsNames[]): string[] { - return elementsNames.map(x => elementsTitles[x] || ''); -} diff --git a/src/client/Components/Calculation/ELT/index.jsx b/src/client/Components/Calculation/ELT/index.jsx index 28e6c2f..dd03955 100644 --- a/src/client/Components/Calculation/ELT/index.jsx +++ b/src/client/Components/Calculation/ELT/index.jsx @@ -1,51 +1,7 @@ -import { Modal } from 'antd'; -import { Outlined as SpinnerOutlined } from 'client/Components/Spinner'; -import Button from 'client/Elements/Button'; -import { CenterContent } from 'client/Elements/Wrapper'; -import { Box } from 'client/UIKit/grid'; -import { lazy, Suspense, useState } from 'react'; +import { lazy } from 'react'; const Content = lazy(() => import('./Content')); -const ELT = ({ title }) => { - const [isOpenModal, setIsOpenModal] = useState(false); - function closeModal() { - setIsOpenModal(false); - } - return ( - <> - -