From 754e8c6c39bc4dfd5fdae64780aa50c7e1bc94f5 Mon Sep 17 00:00:00 2001 From: Chika Date: Thu, 15 Apr 2021 14:08:00 +0300 Subject: [PATCH] eslint fixes: pt.1 --- .eslintrc.json | 4 +- .../Calculation/lib/elements/elementsProps.ts | 16 +- .../Calculation/lib/elements/tables.ts | 2 +- src/client/UIKit/colors.js | 1 + src/client/UIKit/lib/createColorProxy.js | 1 + src/client/hooks/Calculation/useValidation.ts | 7 +- src/client/hooks/Calculation/useValue.js | 1 - .../Effects/actions/calculate/prepareData.ts | 1 - .../Effects/actions/calculate/validate.ts | 7 +- .../Effects/reactions/loadKpReaction/index.ts | 137 +++++++++++------- src/core/types/Entities/crmEntities.ts | 4 +- 11 files changed, 101 insertions(+), 80 deletions(-) diff --git a/.eslintrc.json b/.eslintrc.json index 63e9daf..701e7ae 100644 --- a/.eslintrc.json +++ b/.eslintrc.json @@ -20,6 +20,8 @@ "rules": { "no-console": "warn", "react/display-name": "off", - "@typescript-eslint/explicit-module-boundary-types": "off" + "@typescript-eslint/explicit-module-boundary-types": "off", + "react/prop-types": "off", + "no-unused-vars": "warn" } } diff --git a/src/client/Containers/Calculation/lib/elements/elementsProps.ts b/src/client/Containers/Calculation/lib/elements/elementsProps.ts index 1322cd4..3305b30 100644 --- a/src/client/Containers/Calculation/lib/elements/elementsProps.ts +++ b/src/client/Containers/Calculation/lib/elements/elementsProps.ts @@ -1,18 +1,13 @@ -import { ElementProps } from 'core/types/Calculation/components'; -import { - TElements, - ResultElementsNames, -} from 'core/types/Calculation/Store/elements'; -import { round } from 'lodash'; - +import { DownloadOutlined } from '@ant-design/icons'; import { validateEmail, validateInn, validateKpp, validatePhone, } from 'core/tools/validate'; - -import { DownloadOutlined } from '@ant-design/icons'; +import { ElementProps } from 'core/types/Calculation/components'; +import { TElements } from 'core/types/Calculation/Store/elements'; +import { round } from 'lodash'; const elementsProps: TElements = { selectChannel: { @@ -135,8 +130,7 @@ const elementsProps: TElements = { min: '50', max: '99', }, - selectSeasonType: { - }, + selectSeasonType: {}, tbxComissionPerc: { min: '0', max: '100', diff --git a/src/client/Containers/Calculation/lib/elements/tables.ts b/src/client/Containers/Calculation/lib/elements/tables.ts index 1d4c48f..544ae1f 100644 --- a/src/client/Containers/Calculation/lib/elements/tables.ts +++ b/src/client/Containers/Calculation/lib/elements/tables.ts @@ -45,7 +45,7 @@ const elementsTables: StoreTables = { Component: Select, props: { nameMiddleware: name => { - const targetName = name.match(/\"(.+)\"/); + const targetName = name.match(/"(.+)"/); if (targetName) { return targetName[1] .replaceAll('"', String.fromCharCode(160)) diff --git a/src/client/UIKit/colors.js b/src/client/UIKit/colors.js index db2bac9..367b4f3 100644 --- a/src/client/UIKit/colors.js +++ b/src/client/UIKit/colors.js @@ -1,3 +1,4 @@ +/* eslint-disable @typescript-eslint/no-var-requires */ /* eslint-disable no-undef */ const createColorProxy = require('./lib/createColorProxy'); diff --git a/src/client/UIKit/lib/createColorProxy.js b/src/client/UIKit/lib/createColorProxy.js index 17f8752..d6d5b4f 100644 --- a/src/client/UIKit/lib/createColorProxy.js +++ b/src/client/UIKit/lib/createColorProxy.js @@ -1,3 +1,4 @@ +/* eslint-disable no-undef */ /* eslint-disable indent */ const createColorProxy = process.env.NODE_ENV === 'development' && typeof Proxy !== 'undefined' diff --git a/src/client/hooks/Calculation/useValidation.ts b/src/client/hooks/Calculation/useValidation.ts index b0fe468..f13f444 100644 --- a/src/client/hooks/Calculation/useValidation.ts +++ b/src/client/hooks/Calculation/useValidation.ts @@ -1,5 +1,3 @@ -/* eslint-disable react-hooks/exhaustive-deps */ - import { ValidateStatus } from 'antd/lib/form/FormItem'; import { INVALID_INPUT as INVALID_INPUT_MESSAGE } from 'core/constants/errorMessages'; import { ElementsNames } from 'core/types/Calculation/Store/elements'; @@ -10,7 +8,10 @@ import { import { useEffect, useState } from 'react'; import { useStores } from '../useStores'; -type TValidation = { errorMessage: string; validator: Function }; +type TValidation = { + errorMessage: string; + validator: ((_: any) => boolean) | undefined; +}; interface IUseValidationArgs { elementName: ElementsNames; value: any; diff --git a/src/client/hooks/Calculation/useValue.js b/src/client/hooks/Calculation/useValue.js index cdcdad3..a488695 100644 --- a/src/client/hooks/Calculation/useValue.js +++ b/src/client/hooks/Calculation/useValue.js @@ -1,4 +1,3 @@ -/* eslint-disable react-hooks/exhaustive-deps */ import { DEFAULT_DEBOUNCE_DELAY } from 'core/constants/debounce'; import { Process } from 'core/types/Calculation/Store/process'; import { useEffect, useState } from 'react'; diff --git a/src/client/stores/CalculationStore/Effects/actions/calculate/prepareData.ts b/src/client/stores/CalculationStore/Effects/actions/calculate/prepareData.ts index 015fb78..d80c941 100644 --- a/src/client/stores/CalculationStore/Effects/actions/calculate/prepareData.ts +++ b/src/client/stores/CalculationStore/Effects/actions/calculate/prepareData.ts @@ -15,7 +15,6 @@ export default ({ const { values, options, tables } = calculationStore; - //@ts-ignore const preparedPaymentsRows: PaymentRow[] = Array.from( { length: values.leasingPeriod }, () => ({ diff --git a/src/client/stores/CalculationStore/Effects/actions/calculate/validate.ts b/src/client/stores/CalculationStore/Effects/actions/calculate/validate.ts index 7e77822..078b635 100644 --- a/src/client/stores/CalculationStore/Effects/actions/calculate/validate.ts +++ b/src/client/stores/CalculationStore/Effects/actions/calculate/validate.ts @@ -126,8 +126,8 @@ const validatePaymentsTable = () => { if (isValidRows()) { const target_payments = payments.slice(1, 4); - const min = Math.min.apply(Math, target_payments); - const max = Math.max.apply(Math, target_payments); + const min = Math.min(...target_payments); + const max = Math.max(...target_payments); const areInvalidRows = max - min > 10; CalculationStore.setTableRows( @@ -207,10 +207,9 @@ const validatePaymentsTable = () => { const startPositions = seasonTypeOptions && seasonTypeOptions.startPositions; - const stepsValues = []; + const stepsValues: any[] = []; for (let i = 0; i < startPositions.length; i++) { const targetIndex = startPositions[i]; - //@ts-ignore stepsValues.push(unshiftedMiddleRows[targetIndex]); } diff --git a/src/client/stores/CalculationStore/Effects/reactions/loadKpReaction/index.ts b/src/client/stores/CalculationStore/Effects/reactions/loadKpReaction/index.ts index cabd745..7a8d101 100644 --- a/src/client/stores/CalculationStore/Effects/reactions/loadKpReaction/index.ts +++ b/src/client/stores/CalculationStore/Effects/reactions/loadKpReaction/index.ts @@ -1,5 +1,7 @@ -//@ts-nocheck - +import { IEvoGraph } from './../../../../../../core/types/Entities/crmEntities'; +/* eslint-disable @typescript-eslint/ban-ts-comment */ +import { IGetCRMEntitiesResponse } from 'core/types/Calculation/Responses'; +import { TElements } from 'core/types/Calculation/Store/elements'; import { message } from 'antd'; import { elementsValues } from 'client/Containers/Calculation/lib/elements/values'; import { openNotification } from 'client/Elements/Notification'; @@ -76,6 +78,7 @@ const loadKpReaction: IReactionEffect = calculationStore => ({ const newValues = Object.assign( {}, ...Object.values(elementsValues).map(valueName => ({ + //@ts-ignore [valueName]: quote[mapKPtoValues[valueName]], })), ); @@ -85,9 +88,10 @@ const loadKpReaction: IReactionEffect = calculationStore => ({ let accountidData; if (lead) { - const selected_lead = calculationStore.getOptions('selectLead', { + const selected_lead = calculationStore.getOption('selectLead', { value: lead, }); + if (selected_lead && selected_lead.accountidData) { accountidData = selected_lead.accountidData; } @@ -124,7 +128,11 @@ const loadKpReaction: IReactionEffect = calculationStore => ({ } } - const { entities: options } = await CrmService.crmgqlquery({ + const { + entities: options, + }: IGetCRMEntitiesResponse & { + entities: TElements; + } = await CrmService.crmgqlquery({ query: optionsQuery, variables: { statecode: 0, @@ -210,38 +218,44 @@ const loadKpReaction: IReactionEffect = calculationStore => ({ } } - const evo_graph = quote.evo_graphs.sort( - (a, b) => b.createdon - a.createdon, - )[0]; - const payments = evo_graph.evo_planpayments - .slice(1, evo_graph.evo_planpayments.length - 1) - .map((evo_planpayment, i) => ({ - paymentRelation: { - validation: undefined, - value: evo_planpayment.evo_payment_ratio, - status: tablePaymentsStatuses( - quote.evo_graph_type, - quote.evo_period, - )?.includes(i + 1) - ? ElementStatus.Default - : ElementStatus.Disabled, - }, - })); - calculationStore.replaceTableRows('tablePayments')([ - { - paymentRelation: { - value: quote.evo_first_payment_perc, - status: ElementStatus.Disabled, - }, - }, - ...payments, - { - paymentRelation: { - value: quote.evo_last_payment_perc, - status: ElementStatus.Disabled, - }, - }, - ]); + let evo_graph: IEvoGraph = {}; + if (quote.evo_graphs) { + evo_graph = quote.evo_graphs.sort( + //@ts-ignore + (a, b) => b.createdon - a.createdon, + )[0]; + if (evo_graph.evo_planpayments) { + const payments = evo_graph.evo_planpayments + .slice(1, evo_graph.evo_planpayments.length - 1) + .map((evo_planpayment, i) => ({ + paymentRelation: { + validation: undefined, + value: evo_planpayment.evo_payment_ratio, + status: tablePaymentsStatuses( + quote.evo_graph_type, + quote.evo_period, + )?.includes(i + 1) + ? ElementStatus.Default + : ElementStatus.Disabled, + }, + })); + calculationStore.replaceTableRows('tablePayments')([ + { + paymentRelation: { + value: quote.evo_first_payment_perc, + status: ElementStatus.Disabled, + }, + }, + ...payments, + { + paymentRelation: { + value: quote.evo_last_payment_perc, + status: ElementStatus.Disabled, + }, + }, + ]); + } + } const base_product = calculationStore.getOption('selectProduct', { evo_baseproductid: newValues.product, @@ -264,30 +278,41 @@ const loadKpReaction: IReactionEffect = calculationStore => ({ }), ); - const rate = calculationStore.getOptions('selectRate'); - const target_rate = rate.find(x => x.evo_rateid === quote.evo_rateid); + const rate = calculationStore.getOption('selectRate', { + evo_rateid: quote.evo_rateid, + }); let clientRisk = quote.evo_client_riskid; if (opportunity) { - const { - evo_programsolution, - evo_client_riskid, - } = calculationStore.getOption('selectOpportunity', { - value: opportunity, - }); + const current_opportunity = calculationStore.getOption( + 'selectOpportunity', + { + value: opportunity, + }, + ); - if (evo_programsolution === 100000000) { - const midClientRisk = calculationStore.getOption( - 'selectClientRisk', - { - evo_id: '2', - }, - ); - if (midClientRisk) { - clientRisk = midClientRisk.evo_client_riskid; + if (current_opportunity) { + const { + evo_programsolution, + evo_client_riskid, + } = current_opportunity; + + if (evo_programsolution === 100000000) { + const midClientRisk = calculationStore.getOption( + 'selectClientRisk', + { + evo_id: '2', + }, + ); + if (midClientRisk) { + clientRisk = midClientRisk.evo_client_riskid; + } + } else if ( + evo_programsolution !== 100000000 && + evo_client_riskid + ) { + clientRisk = evo_client_riskid; } - } else if (evo_programsolution !== 100000000 && evo_client_riskid) { - clientRisk = evo_client_riskid; } } @@ -298,7 +323,7 @@ const loadKpReaction: IReactionEffect = calculationStore => ({ ...newValues, product: base_product?.evo_id, ...addProducts, - rate: target_rate?.evo_id, + rate: rate?.evo_id, lead, opportunity, quote: quoteId, diff --git a/src/core/types/Entities/crmEntities.ts b/src/core/types/Entities/crmEntities.ts index b1511e9..b8f46e5 100644 --- a/src/core/types/Entities/crmEntities.ts +++ b/src/core/types/Entities/crmEntities.ts @@ -86,10 +86,10 @@ export interface IQuote { evo_townid?: string; } -interface IEvoGraph { +export interface IEvoGraph { createdon?: Date; evo_sumpay_withnds?: number; - evo_planpayment?: IEvoPlanPayment[]; + evo_planpayments?: IEvoPlanPayment[]; } export interface ITransactionCurrency {