diff --git a/.storybook/main.js b/.storybook/main.js index 6283b05..f6261ce 100644 --- a/.storybook/main.js +++ b/.storybook/main.js @@ -1,16 +1,14 @@ module.exports = { stories: ['../src/**/*.stories.mdx', '../src/**/*.stories.@(js|jsx|ts|tsx)'], - addons: [ - '@storybook/addon-links', - '@storybook/addon-essentials', - { - name: '@storybook/preset-create-react-app', - options: { - craOverrides: { - fileLoaderExcludes: ['less'], - }, - }, - }, - '@storybook/preset-ant-design', - ], -}; + addons: ['@storybook/addon-links', '@storybook/addon-essentials', { + name: '@storybook/preset-create-react-app', + options: { + craOverrides: { + fileLoaderExcludes: ['less'] + } + } + }, '@storybook/preset-ant-design'], + core: { + builder: "webpack5" + } +}; \ No newline at end of file diff --git a/package.json b/package.json index 6055d41..c1fba4d 100644 --- a/package.json +++ b/package.json @@ -29,13 +29,15 @@ "use-debounce": "^6.0.1" }, "devDependencies": { - "@storybook/addon-actions": "^6.2.9", - "@storybook/addon-essentials": "^6.2.9", - "@storybook/addon-links": "^6.2.9", - "@storybook/node-logger": "^6.2.9", + "@storybook/addon-actions": "^6.4.18", + "@storybook/addon-essentials": "^6.4.18", + "@storybook/addon-links": "^6.4.18", + "@storybook/builder-webpack5": "^6.4.18", + "@storybook/manager-webpack5": "^6.4.18", + "@storybook/node-logger": "^6.4.18", "@storybook/preset-ant-design": "^0.0.2", - "@storybook/preset-create-react-app": "^3.1.7", - "@storybook/react": "^6.2.9", + "@storybook/preset-create-react-app": "^4.0.0", + "@storybook/react": "^6.4.18", "@testing-library/jest-dom": "^5.11.4", "@testing-library/react": "^11.1.0", "@testing-library/user-event": "^12.1.10", @@ -53,7 +55,8 @@ "cz-conventional-changelog": "^3.3.0", "dotenv-cli": "^4.1.1", "rimraf": "^3.0.2", - "source-map-explorer": "^2.5.2" + "source-map-explorer": "^2.5.2", + "webpack": "5" }, "resolutions": { "mini-css-extract-plugin": "2.4.5" diff --git a/src/client/Containers/Calculation/Components/ELT/Components/Controls/BottomControls.jsx b/src/client/Containers/Calculation/Components/ELT/Components/Controls/BottomControls.jsx index 0a5efe3..e639bd1 100644 --- a/src/client/Containers/Calculation/Components/ELT/Components/Controls/BottomControls.jsx +++ b/src/client/Containers/Calculation/Components/ELT/Components/Controls/BottomControls.jsx @@ -13,12 +13,12 @@ const BottomControls = ({ insType, onSelectRow, selectedKey }) => { calculationProcess.addProcess(Process.ELT); const selectRes = onSelectRow.call(calculationStore, insType, selectedKey); - if (selectRes && selectRes.message) { + if (selectRes?.message) { openNotification({ type: 'warning', - title: 'Внимание', + message: 'Внимание', description: selectRes.message, - })(); + }); } else { ELTStore[insType].setKey(selectedKey); message.success({ content: 'Выбранный расчет ЭЛТ применен' }); diff --git a/src/client/Containers/Calculation/Components/ELT/lib/validation.ts b/src/client/Containers/Calculation/Components/ELT/lib/validation.ts index 1db38d2..5b8d358 100644 --- a/src/client/Containers/Calculation/Components/ELT/lib/validation.ts +++ b/src/client/Containers/Calculation/Components/ELT/lib/validation.ts @@ -46,12 +46,12 @@ export default function (this: ICalculationStore, validation: ELTValidation) { if (missingElementsNames.length > 0) { openNotification({ type: 'error', - title: 'Ошибка во время расчета ЭЛТ', + message: 'Ошибка во время расчета ЭЛТ', description: String.prototype.concat( 'Не заполнены поля: ', missingElementsNames.join(', '), ), - })(); + }); return false; } diff --git a/src/client/Containers/Calculation/Components/Sections/sectionsList.ts b/src/client/Containers/Calculation/Components/Sections/sectionsList.ts index 402f4ab..8284e9d 100644 --- a/src/client/Containers/Calculation/Components/Sections/sectionsList.ts +++ b/src/client/Containers/Calculation/Components/Sections/sectionsList.ts @@ -328,7 +328,7 @@ const sections: ISection[] = [ { elements: [ 'selectTechnicalCard', - // 'selectFuelCard', + 'selectFuelCard', 'selectInsNSIB', 'radioRequirementTelematic', 'selectTracker', diff --git a/src/client/Containers/Calculation/Elements/tables/insurance.ts b/src/client/Containers/Calculation/Elements/tables/insurance.ts index 402a135..415ce89 100644 --- a/src/client/Containers/Calculation/Elements/tables/insurance.ts +++ b/src/client/Containers/Calculation/Elements/tables/insurance.ts @@ -157,9 +157,9 @@ const callbacks: Table['callbacks'] = { }); openNotification({ type: 'error', - title: 'Ошибка', + message: 'Ошибка', description: 'Не указана страховая компания по полису', - })(); + }); } else { calculationStore.setTableRow( 'tableInsurance', @@ -187,9 +187,9 @@ const callbacks: Table['callbacks'] = { }); openNotification({ type: 'error', - title: 'Ошибка', + message: 'Ошибка', description: 'Не указан срок страхования', - })(); + }); } else { calculationStore.setTableRow( 'tableInsurance', @@ -217,9 +217,9 @@ const callbacks: Table['callbacks'] = { }); openNotification({ type: 'error', - title: 'Ошибка', + message: 'Ошибка', description: 'Не указан плательщик', - })(); + }); } else { calculationStore.setTableRow( 'tableInsurance', @@ -249,9 +249,9 @@ const callbacks: Table['callbacks'] = { }); openNotification({ type: 'error', - title: 'Ошибка', + message: 'Ошибка', description: 'Не указан плательщик', - })(); + }); } else { calculationStore.setTableRow( 'tableInsurance', @@ -281,9 +281,9 @@ const callbacks: Table['callbacks'] = { }); openNotification({ type: 'error', - title: 'Ошибка', + message: 'Ошибка', description: 'Не указан срок страхования', - })(); + }); } else { calculationStore.setTableRow( 'tableInsurance', @@ -314,9 +314,9 @@ const callbacks: Table['callbacks'] = { }); openNotification({ type: 'error', - title: 'Ошибка', + message: 'Ошибка', description: 'Не указана страховая компания по полису', - })(); + }); } else { calculationStore.setTableRow( 'tableInsurance', diff --git a/src/client/Elements/Notification.stories.jsx b/src/client/Elements/Notification.stories.jsx new file mode 100644 index 0000000..c13f101 --- /dev/null +++ b/src/client/Elements/Notification.stories.jsx @@ -0,0 +1,30 @@ +import { openNotification } from './Notification'; + +export default { + title: 'Notification', +}; + +export const Notification = () => ( + <> + + + +); diff --git a/src/client/Elements/Notification.ts b/src/client/Elements/Notification.ts index 137a0e3..c40f1bb 100644 --- a/src/client/Elements/Notification.ts +++ b/src/client/Elements/Notification.ts @@ -1,27 +1,17 @@ import { notification } from 'antd'; +import { ArgsProps, NotificationInstance } from 'antd/lib/notification'; import { NOTIFICATION_DEBOUNCE } from 'core/constants/debounce'; import { debounce } from 'lodash'; -type TNotification = 'success' | 'info' | 'warning' | 'error'; +const defaultOptions: Partial = { + placement: 'bottomRight', +}; -export const openNotification = ({ - type, - title, - description, -}: { - type: TNotification; - title: string; - description?: string; -}) => - debounce( - () => - notification[type]({ - message: title, - description, - placement: 'bottomRight', - style: { - zIndex: 9999999999, - }, - }), - NOTIFICATION_DEBOUNCE, - ); +type NotificationOptions = ArgsProps & { + type: keyof NotificationInstance; +}; + +export const openNotification = debounce((options: NotificationOptions) => { + if (!options.key) options.key = JSON.stringify(options); + notification[options.type]({ ...defaultOptions, ...options }); +}, NOTIFICATION_DEBOUNCE); diff --git a/src/client/stores/CalculationStore/Data/values.js b/src/client/stores/CalculationStore/Data/values.js index 6d4cd52..166a4c6 100644 --- a/src/client/stores/CalculationStore/Data/values.js +++ b/src/client/stores/CalculationStore/Data/values.js @@ -1,6 +1,7 @@ import { getValueName } from 'client/Containers/Calculation/Elements/tools'; import initialFilters, { - noResetValueElements + autoSetValuesElements, + noResetValueElements, } from 'client/stores/CalculationStore/config/initialFilters'; import initialStatuses from 'client/stores/CalculationStore/config/initialStatuses'; import { isNil, mergeWith, pick } from 'lodash'; @@ -112,13 +113,23 @@ const valuesActions = { setFilter(elementName, filter) { const valueName = getValueName(elementName); const value = this.getValue(valueName); + + const filteredOptions = filter && filter(this.getOptions(elementName)); + // После установки фильтра проверяем, что значение есть в отфильтрованном списке, иначе сбрасываем значение if ( - filter && - !filter(this.getOptions(elementName)).some(x => x.value === value) && + !filteredOptions?.some(x => x.value === value) && !noResetValueElements.includes(elementName) ) { this.setValue(valueName, null); } + + // После установки фильтра если остается одна запись указываем ее в значение + if ( + autoSetValuesElements.includes(elementName) && + filteredOptions?.length === 1 + ) { + this.setValue(valueName, filteredOptions[0].value); + } this.filters[elementName] = filter; }, // applyFilters(filters) { diff --git a/src/client/stores/CalculationStore/Effects/actions/calculate/index.ts b/src/client/stores/CalculationStore/Effects/actions/calculate/index.ts index 6f5930f..c961457 100644 --- a/src/client/stores/CalculationStore/Effects/actions/calculate/index.ts +++ b/src/client/stores/CalculationStore/Effects/actions/calculate/index.ts @@ -60,18 +60,18 @@ export default function (this: ICalculationStore) { if (invalidElements.length > 0) openNotification({ type: 'error', - title: 'Ошибка во время расчета графика', + message: 'Ошибка во время расчета графика', description: 'Некорректно заполнены поля: ' + invalidElements.join(', '), - })(); + }); if (invalidTables.length > 0) openNotification({ type: 'error', - title: 'Ошибка во время расчета графика', + message: 'Ошибка во время расчета графика', description: 'Некорректно заполнены таблицы: ' + invalidTables.join(', '), - })(); + }); return; } @@ -115,14 +115,14 @@ export default function (this: ICalculationStore) { .catch(err => { openNotification({ type: 'error', - title: 'Ошибка во время расчета!', + message: 'Ошибка во время расчета!', description: err.response && err.response.data && (err.response.data.errors ? err.response.data.errors.join(', ') : err.response.data), - })(); + }); throw err; }) diff --git a/src/client/stores/CalculationStore/Effects/actions/calculate/validate/elements.ts b/src/client/stores/CalculationStore/Effects/actions/calculate/validate/elements.ts index 4bfff21..2a54268 100644 --- a/src/client/stores/CalculationStore/Effects/actions/calculate/validate/elements.ts +++ b/src/client/stores/CalculationStore/Effects/actions/calculate/validate/elements.ts @@ -150,7 +150,7 @@ const elementsValidations: Partial< selectTarif: CONDITIONS.IS_NULL, // selectRate: VALIDATIONS.IS_NULL, selectRegistration: CONDITIONS.IS_NULL, - tbxLeaseObjectPrice: CONDITIONS.LESS_OR_EQUALS_ZERO, + // tbxLeaseObjectPrice: CONDITIONS.LESS_OR_EQUALS_ZERO, // tbxLastPaymentPerc: VALIDATIONS.IS_NULL, // tbxLastPaymentRub: VALIDATIONS.IS_NULL, // tbxFirstPaymentPerc: VALIDATIONS.IS_NULL, diff --git a/src/client/stores/CalculationStore/Effects/actions/createKP.ts b/src/client/stores/CalculationStore/Effects/actions/createKP.ts index 3613db1..f86a29c 100644 --- a/src/client/stores/CalculationStore/Effects/actions/createKP.ts +++ b/src/client/stores/CalculationStore/Effects/actions/createKP.ts @@ -82,8 +82,8 @@ export default async function (this: ICalculationStore) { } catch (err) { openNotification({ type: 'error', - title: 'Ошибка во время создания КП!', - })(); + message: 'Ошибка во время создания КП!', + }); const { response } = err as AxiosError; const error = response?.data || err; diff --git a/src/client/stores/CalculationStore/Effects/autorun.ts b/src/client/stores/CalculationStore/Effects/autorun.ts index 60cbe60..00c48c8 100644 --- a/src/client/stores/CalculationStore/Effects/autorun.ts +++ b/src/client/stores/CalculationStore/Effects/autorun.ts @@ -63,9 +63,9 @@ const autorunEffects: IAutorunEffect[] = [ calculationStore.setValidation('tbxEngineVolume', false); openNotification({ type: 'error', - title: 'Ошибка', + message: 'Ошибка', description: 'Объем двигателя должен быть больше 0', - })(); + }); } else { calculationStore.setValidation('tbxEngineVolume', undefined); } @@ -74,9 +74,9 @@ const autorunEffects: IAutorunEffect[] = [ calculationStore.setValidation('selectEngineType', false); openNotification({ type: 'error', - title: 'Ошибка', + message: 'Ошибка', description: 'Тип двигателя должен содержать данные', - })(); + }); } else { calculationStore.setValidation('selectEngineType', undefined); } @@ -85,9 +85,9 @@ const autorunEffects: IAutorunEffect[] = [ calculationStore.setValidation('tbxLeaseObjectMotorPower', false); openNotification({ type: 'error', - title: 'Ошибка', + message: 'Ошибка', description: 'Мощность двигателя должна быть больше 0', - })(); + }); } else { calculationStore.setValidation('tbxLeaseObjectMotorPower', undefined); } diff --git a/src/client/stores/CalculationStore/Effects/reactions/gibddReactions.ts b/src/client/stores/CalculationStore/Effects/reactions/gibddReactions.ts index 481f4f6..5a0c5dc 100644 --- a/src/client/stores/CalculationStore/Effects/reactions/gibddReactions.ts +++ b/src/client/stores/CalculationStore/Effects/reactions/gibddReactions.ts @@ -139,10 +139,10 @@ const gibddReactions: IReactionEffect[] = [ calculationStore.setValidation('tbxMaxMass', false); openNotification({ type: 'error', - title: 'Ошибка', + message: 'Ошибка', description: 'При категории ТС = В Разерешенная макс.масс не может быть больше 3500кг', - })(); + }); } break; } @@ -151,9 +151,9 @@ const gibddReactions: IReactionEffect[] = [ calculationStore.setValidation('tbxMaxMass', false); openNotification({ type: 'error', - title: 'Ошибка', + message: 'Ошибка', description: 'Разерешенная макс.масс не может быть меньше 3500кг', - })(); + }); } break; } @@ -243,10 +243,10 @@ const gibddReactions: IReactionEffect[] = [ calculationStore.setValidation('selectObjectCategoryTax', false); openNotification({ type: 'error', - title: 'Ошибка', + message: 'Ошибка', description: 'Необходимо из ЭПТС указать Категорию в соответствии с ТР ТС 018/2011', - })(); + }); } else { calculationStore.setValidation('selectObjectCategoryTax', undefined); } @@ -268,9 +268,9 @@ const gibddReactions: IReactionEffect[] = [ calculationStore.setValidation('selectInsNSIB', false); openNotification({ type: 'error', - title: 'Ошибка', + message: 'Ошибка', description: 'Страхование НСИБ обязательно для мотоциклистов', - })(); + }); } else { calculationStore.setValidation('selectInsNSIB', undefined); } diff --git a/src/client/stores/CalculationStore/Effects/reactions/loadKpReaction/index.ts b/src/client/stores/CalculationStore/Effects/reactions/loadKpReaction/index.ts index 37dab16..13eeb73 100644 --- a/src/client/stores/CalculationStore/Effects/reactions/loadKpReaction/index.ts +++ b/src/client/stores/CalculationStore/Effects/reactions/loadKpReaction/index.ts @@ -1,7 +1,10 @@ import { message } from 'antd'; import { resetIns } from 'client/Containers/Calculation/Components/ELT/lib/resetIns'; import { numberElementsProps } from 'client/Containers/Calculation/Elements/props/common'; -import { getTitle, getValueName } from 'client/Containers/Calculation/Elements/tools'; +import { + getTitle, + getValueName, +} from 'client/Containers/Calculation/Elements/tools'; import { ElementsNames } from 'client/Containers/Calculation/types/elements'; import { openNotification } from 'client/Elements/Notification'; import initialValues from 'client/stores/CalculationStore/config/initialValues'; @@ -10,7 +13,7 @@ import { mainOptionsForQuoteQuery, quoteQuery, secondaryOptionsForQuoteQuery, - singleOptionsForQuoteQuery + singleOptionsForQuoteQuery, } from 'core/services/CrmService/graphql/query/quote'; import { TOptionizedEntity } from 'core/services/CrmService/types/common'; import { @@ -18,7 +21,7 @@ import { IAccount, IEvoGraph, IEvoTown, - IQuote + IQuote, } from 'core/services/CrmService/types/entities'; import { currentISODate } from 'core/tools/date'; import { NIL } from 'core/tools/uuid'; @@ -28,7 +31,6 @@ import { get, invert, isEqual, isNil } from 'lodash'; import { ElementStatus } from 'types/elements'; import { getValuesFromKP } from './mapKpToValues'; - const map_add_product_types_to_values = { technicalCard: 100000000, registration: 100000001, @@ -578,9 +580,9 @@ const loadKpReaction: IReactionEffect = calculationStore => ({ .join(', '); openNotification({ type: 'warning', - title: 'Внимание', + message: 'Внимание', description: 'При подгрузке КП были сброшены поля: ' + fieldsTitles, - })(); + }); } // check min max number values @@ -658,9 +660,9 @@ const loadKpReaction: IReactionEffect = calculationStore => ({ .catch(err => { openNotification({ type: 'error', - title: `Ошибка во время загрузки КП `, + message: `Ошибка во время загрузки КП `, description: `${err}`, - })(); + }); throw err; }) .finally(() => { diff --git a/src/client/stores/CalculationStore/Effects/reactions/otherReactions.ts b/src/client/stores/CalculationStore/Effects/reactions/otherReactions.ts index 58709b9..7e8613f 100644 --- a/src/client/stores/CalculationStore/Effects/reactions/otherReactions.ts +++ b/src/client/stores/CalculationStore/Effects/reactions/otherReactions.ts @@ -238,10 +238,10 @@ const reactionEffects: IReactionEffect[] = [ calculationStore.setValidation('tbxIndAgentRewardSumm', false); openNotification({ type: 'error', - title: 'Ошибка', + message: 'Ошибка', description: 'Вознаграждение агента ФЛ указано больше условия по агентскому договору! \nЗначение установлено по условию договора.', - })(); + }); return; } else if ( !indAgentRewardCondition.evo_reduce_reward && @@ -254,10 +254,10 @@ const reactionEffects: IReactionEffect[] = [ calculationStore.setValidation('tbxIndAgentRewardSumm', false); openNotification({ type: 'error', - title: 'Ошибка', + message: 'Ошибка', description: 'Вознаграждение агента ФЛ указано меньше условия по агентскому договору! \nЗначение установлено по условию договора.', - })(); + }); return; } } @@ -288,10 +288,10 @@ const reactionEffects: IReactionEffect[] = [ ); openNotification({ type: 'error', - title: 'Ошибка', + message: 'Ошибка', description: 'Вознаграждение двойного агента указано больше условия по агентскому договору! \nЗначение установлено по условию договора.', - })(); + }); return; } else if ( !selectCalcDoubleAgentRewardCondition.evo_reduce_reward && @@ -307,10 +307,10 @@ const reactionEffects: IReactionEffect[] = [ ); openNotification({ type: 'error', - title: 'Ошибка', + message: 'Ошибка', description: 'Вознаграждение двойного агента указано меньше условия по агентскому договору! \nЗначение установлено по условию договора.', - })(); + }); return; } } @@ -338,10 +338,10 @@ const reactionEffects: IReactionEffect[] = [ calculationStore.setValidation('tbxCalcBrokerRewardSum', false); openNotification({ type: 'error', - title: 'Ошибка', + message: 'Ошибка', description: 'Вознаграждение брокера указано больше условия по агентскому договору! \nЗначение установлено по условию договора.', - })(); + }); return; } else if ( !selectCalcBrokerRewardCondition.evo_reduce_reward && @@ -354,10 +354,10 @@ const reactionEffects: IReactionEffect[] = [ calculationStore.setValidation('tbxCalcBrokerRewardSum', false); openNotification({ type: 'error', - title: 'Ошибка', + message: 'Ошибка', description: 'Вознаграждение брокера указано меньше условия по агентскому договору! \nЗначение установлено по условию договора.', - })(); + }); return; } } @@ -387,10 +387,10 @@ const reactionEffects: IReactionEffect[] = [ calculationStore.setValidation('tbxFinDepartmentRewardSumm', false); openNotification({ type: 'error', - title: 'Ошибка', + message: 'Ошибка', description: 'Вознаграждение финотдела указано больше условия по агентскому договору! \nЗначение установлено по условию договора.', - })(); + }); return; } else if ( !selectFinDepartmentRewardCondtion.evo_reduce_reward && @@ -403,10 +403,10 @@ const reactionEffects: IReactionEffect[] = [ calculationStore.setValidation('tbxFinDepartmentRewardSumm', false); openNotification({ type: 'error', - title: 'Ошибка', + message: 'Ошибка', description: 'Вознаграждение финотдела указано меньше условия по агентскому договору! \nЗначение установлено по условию договора.', - })(); + }); return; } } @@ -494,10 +494,10 @@ const reactionEffects: IReactionEffect[] = [ calculationStore.setValidation('tbxLastPaymentRub', false); openNotification({ type: 'error', - title: 'Ошибка', + message: 'Ошибка', description: 'Последний платеж меньше 3500 руб. не может быть при наличии НСИБ, укажите большее значение', - })(); + }); } else { calculationStore.setValidation('tbxLastPaymentRub', true); } @@ -808,10 +808,10 @@ const reactionEffects: IReactionEffect[] = [ calculationStore.setValidation('tbxDealerRewardSumm', false); openNotification({ type: 'error', - title: 'Ошибка', + message: 'Ошибка', description: 'Вознаграждение ЮЛ поставщика указано больше условия по агентскому договору! \nЗначение установлено по условию договора.', - })(); + }); return; } else if ( !dealerRewardCondition.evo_reduce_reward && @@ -823,10 +823,10 @@ const reactionEffects: IReactionEffect[] = [ calculationStore.setValidation('tbxDealerRewardSumm', false); openNotification({ type: 'error', - title: 'Ошибка', + message: 'Ошибка', description: 'Вознаграждение ЮЛ поставщика указано меньше условия по агентскому договору! \nЗначение установлено по условию договора.', - })(); + }); return; } } @@ -853,10 +853,10 @@ const reactionEffects: IReactionEffect[] = [ calculationStore.setValidation('tbxDealerBrokerRewardSumm', false); openNotification({ type: 'error', - title: 'Ошибка', + message: 'Ошибка', description: 'Вознаграждение брокера поставщика указано больше условия по агентскому договору! \nЗначение установлено по условию договора.', - })(); + }); return; } } @@ -871,10 +871,10 @@ const reactionEffects: IReactionEffect[] = [ calculationStore.setValidation('tbxDealerBrokerRewardSumm', false); openNotification({ type: 'error', - title: 'Ошибка', + message: 'Ошибка', description: 'Вознаграждение брокера поставщика указано меньше условия по агентскому договору! \nЗначение установлено по условию договора.', - })(); + }); return; } } @@ -914,10 +914,10 @@ const reactionEffects: IReactionEffect[] = [ calculationStore.setValidation('tbxSaleBonus', false); openNotification({ type: 'error', - title: 'Ошибка', + message: 'Ошибка', description: 'Размер бонуса МПЛ не может быть выше установленного по СОТ', - })(); + }); return; } else { calculationStore.setValidation('tbxSaleBonus', undefined); @@ -1107,10 +1107,10 @@ const reactionEffects: IReactionEffect[] = [ }, 0); openNotification({ type: 'warning', - title: 'Внимание', + message: 'Внимание!', description: 'При сезонном графике срок лизинга должен быть больше 14 месяцев', - })(); + }); } }, }), @@ -1322,9 +1322,9 @@ const reactionEffects: IReactionEffect[] = [ calculationStore.setValidation('tbxCountSeats', false); openNotification({ type: 'error', - title: 'Ошибка', + message: 'Ошибка', description: 'Количество мест должно быть меньше 9', - })(); + }); } break; } @@ -1335,10 +1335,10 @@ const reactionEffects: IReactionEffect[] = [ calculationStore.setValidation('tbxMaxMass', false); openNotification({ type: 'error', - title: 'Ошибка', + message: 'Ошибка', description: 'Разрешенная максимальная масса должна быть больше 0', - })(); + }); } break; } @@ -1350,9 +1350,9 @@ const reactionEffects: IReactionEffect[] = [ calculationStore.setValidation('tbxCountSeats', false); openNotification({ type: 'error', - title: 'Ошибка', + message: 'Ошибка', description: 'Кол-во мест должно быть больше 8', - })(); + }); } break; } @@ -1411,9 +1411,9 @@ const reactionEffects: IReactionEffect[] = [ calculationStore.setValidation('tbxMileage', false); openNotification({ type: 'error', - title: 'Ошибка', + message: 'Ошибка', description: 'Не указан пробег', - })(); + }); } else { calculationStore.setValidation('tbxMileage', undefined); } @@ -1475,6 +1475,13 @@ const reactionEffects: IReactionEffect[] = [ }, }), + calculationStore => ({ + expression: () => calculationStore.getValue('leaseObjectType'), + effect: leaseObjectType => { + !leaseObjectType && calculationStore.setValue('brand', null); + }, + }), + calculationStore => ({ expression: () => { return { diff --git a/src/client/stores/CalculationStore/Effects/reactions/priceReactions/index.ts b/src/client/stores/CalculationStore/Effects/reactions/priceReactions/index.ts index 89c71af..7cf10f5 100644 --- a/src/client/stores/CalculationStore/Effects/reactions/priceReactions/index.ts +++ b/src/client/stores/CalculationStore/Effects/reactions/priceReactions/index.ts @@ -26,10 +26,8 @@ export default [ (calculationStore, calculationProcess) => ({ expression: () => { - const { - leaseObjectPrice, - supplierDiscountPerc, - } = calculationStore.values; + const { leaseObjectPrice, supplierDiscountPerc } = + calculationStore.values; return [leaseObjectPrice, supplierDiscountPerc]; }, effect: ([leaseObjectPrice = 0, supplierDiscountPerc = 0]) => { @@ -74,11 +72,8 @@ export default [ calculationStore => ({ expression: () => { - const { - supplierCurrency, - leaseObjectPrice, - firstPaymentPerc, - } = calculationStore.values; + const { supplierCurrency, leaseObjectPrice, firstPaymentPerc } = + calculationStore.values; return [supplierCurrency, leaseObjectPrice, firstPaymentPerc]; }, effect: ([ @@ -102,11 +97,8 @@ export default [ (calculationStore, calculationProcess) => ({ expression: () => { - const { - supplierCurrency, - leaseObjectPrice, - comissionPerc, - } = calculationStore.values; + const { supplierCurrency, leaseObjectPrice, comissionPerc } = + calculationStore.values; return [supplierCurrency, leaseObjectPrice, comissionPerc]; }, effect: ([supplierCurrencyId, leaseObjectPrice = 0, comissionPerc = 0]) => { @@ -252,10 +244,10 @@ export default [ calculationStore.setValidation('tbxSupplierDiscountRub', false); openNotification({ type: 'error', - title: 'Ошибка', + message: 'Ошибка', description: 'Скидка от поставщика не может быть больше или равна стоимости ПЛ.', - })(); + }); } else { calculationStore.setValidation('tbxSupplierDiscountRub', undefined); } @@ -288,10 +280,10 @@ export default [ calculationStore.setValidation('tbxFirstPaymentRub', false); openNotification({ type: 'error', - title: 'Ошибка', + message: 'Ошибка', description: 'Первый платеж не может быть больше или равен стоимости ПЛ.', - })(); + }); } else { calculationStore.setValidation('tbxFirstPaymentRub', undefined); } diff --git a/src/client/stores/CalculationStore/Effects/reactions/recalcWoRevisionReactions.ts b/src/client/stores/CalculationStore/Effects/reactions/recalcWoRevisionReactions.ts index 76f2b8d..95cfa05 100644 --- a/src/client/stores/CalculationStore/Effects/reactions/recalcWoRevisionReactions.ts +++ b/src/client/stores/CalculationStore/Effects/reactions/recalcWoRevisionReactions.ts @@ -127,34 +127,34 @@ const reactionEffects: IReactionEffect[] = [ ); const quote = calculationStore.getOption('selectQuote'); - if (quote?.evo_max_price_change) { - if (price - supplierDiscountRub > quote.evo_max_price_change) { - calculationStore.setValidation('tbxLeaseObjectPrice', false); - openNotification({ - type: 'error', - title: 'Ошибка', - description: - 'Указанная стоимость предмета лизинга больше возмножного изменения стоимости предмета лизинга при пересчете без пересмотра. ' + - 'Уменьшите стоимость предмета лизинга', - })(); - } else { - calculationStore.setValidation('tbxLeaseObjectPrice', undefined); - } + if ( + quote?.evo_max_price_change && + price - supplierDiscountRub > quote.evo_max_price_change + ) { + calculationStore.setValidation('tbxLeaseObjectPrice', false); + openNotification({ + type: 'error', + message: 'Ошибка', + description: + 'Указанная стоимость предмета лизинга больше возмножного изменения стоимости предмета лизинга при пересчете без пересмотра. ' + + 'Уменьшите стоимость предмета лизинга', + }); } - if (quote?.evo_min_change_price) { - if (price - supplierDiscountRub < quote.evo_min_change_price) { - calculationStore.setValidation('tbxLeaseObjectPrice', false); - openNotification({ - type: 'error', - title: 'Ошибка', - description: - 'Указанная стоимость предмета лизинга меньше возмножного изменения стоимости предмета лизинга при пересчете без пересмотра. ' + - 'Увеличьте стоимость предмета лизинга', - })(); - } else { - calculationStore.setValidation('tbxLeaseObjectPrice', undefined); - } + if ( + quote?.evo_min_change_price && + price - supplierDiscountRub < quote.evo_min_change_price + ) { + calculationStore.setValidation('tbxLeaseObjectPrice', false); + openNotification({ + type: 'error', + message: 'Ошибка', + description: + 'Указанная стоимость предмета лизинга меньше возмножного изменения стоимости предмета лизинга при пересчете без пересмотра. ' + + 'Увеличьте стоимость предмета лизинга', + }); + } else { + calculationStore.setValidation('tbxLeaseObjectPrice', undefined); } }, }), @@ -176,10 +176,10 @@ const reactionEffects: IReactionEffect[] = [ calculationStore.setValidation('tbxFirstPaymentPerc', false); openNotification({ type: 'error', - title: 'Ошибка', + message: 'Ошибка', description: 'Указанный первый платеж меньше одобренного. При пересчете без пересмотра изменение первого платежа возможно только в большую сторону от одобренного значения', - })(); + }); } else { calculationStore.setValidation('tbxFirstPaymentPerc', undefined); } @@ -204,10 +204,10 @@ const reactionEffects: IReactionEffect[] = [ calculationStore.setValidation('tbxLeaseObjectCount', false); openNotification({ type: 'error', - title: 'Ошибка', + message: 'Ошибка', description: 'Количество ПЛ превышает лимит пересчета без пересмотра', - })(); + }); } else { calculationStore.setValidation('tbxLeaseObjectCount', undefined); } @@ -253,10 +253,10 @@ const reactionEffects: IReactionEffect[] = [ } else { openNotification({ type: 'error', - title: 'Ошибка', + message: 'Ошибка', description: 'Указанная разрешенная макс. масса выходит из утвержденного диапазона. Для изменения параметра требуется пересмотр сделки', - })(); + }); calculationStore.setValidation('tbxMaxMass', false); } } @@ -288,10 +288,10 @@ const reactionEffects: IReactionEffect[] = [ } else { openNotification({ type: 'error', - title: 'Ошибка', + message: 'Ошибка', description: 'Указанное кол-во мест выходит из утвержденного диапазона. Для изменения параметра требуется пересмотр сделки', - })(); + }); calculationStore.setValidation('tbxCountSeats', false); } } else { @@ -492,17 +492,6 @@ const reactionEffects: IReactionEffect[] = [ ), ), ); - - if (!calculationProcess.hasProcess(Process.LoadKp)) { - const elementOptions = calculationStore.getOptions( - elementName, - undefined, - true, - ); - //TODO: удалить после рефактора CalculationStore - if (elementOptions?.length === 1) - calculationStore.setValue(valueName, elementOptions[0].value); - } }); }, options: { @@ -527,10 +516,10 @@ const reactionEffects: IReactionEffect[] = [ ) { openNotification({ type: 'error', - title: 'Ошибка', + message: 'Ошибка', description: 'При пересчете без пересмотра последний платеж можно уменьшать или увеличивать до 1%', - })(); + }); calculationStore.setValidation('tbxLastPaymentPerc', false); } else { calculationStore.setValidation('tbxLastPaymentPerc', undefined); @@ -551,10 +540,10 @@ const reactionEffects: IReactionEffect[] = [ calculationStore.setValidation('tbxLastPaymentPerc', false); openNotification({ type: 'error', - title: 'Ошибка', + message: 'Ошибка', description: 'При балансе лизингодатель последний платеж не может быть меньше 1%! Увеличьте значение.', - })(); + }); return; } } else { @@ -562,10 +551,10 @@ const reactionEffects: IReactionEffect[] = [ calculationStore.setValidation('tbxLastPaymentPerc', false); openNotification({ type: 'error', - title: 'Ошибка', + message: 'Ошибка', description: 'Последний платеж не может быть равен 0. Увеличьте значение', - })(); + }); return; } } diff --git a/src/client/stores/CalculationStore/Effects/reactions/tablesReactions.ts b/src/client/stores/CalculationStore/Effects/reactions/tablesReactions.ts index c046633..e23d999 100644 --- a/src/client/stores/CalculationStore/Effects/reactions/tablesReactions.ts +++ b/src/client/stores/CalculationStore/Effects/reactions/tablesReactions.ts @@ -141,10 +141,10 @@ export default [ }); openNotification({ type: 'info', - title: 'Внимание!', + message: 'Внимание!', description: 'Срок страхования КАСКО изменен на 12 месяцев, т.к. оформляется Однолетний полис', - })(); + }); } }, }), @@ -277,9 +277,9 @@ export default [ openNotification({ type: 'error', - title: 'Ошибка во время расчета графика', + message: 'Ошибка во время расчета графика', description: 'Укажите стоимость КАСКО', - })(); + }); } else { calculationStore.setTableRow('tableInsurance', rows => rows.findIndex(x => x.policyType?.value === 'КАСКО'), @@ -322,9 +322,9 @@ export default [ }); openNotification({ type: 'error', - title: 'Ошибка во время расчета графика', + message: 'Ошибка во время расчета графика', description: 'Укажите стоимость КАСКО, включаемую в график', - })(); + }); } else { calculationStore.setTableRow('tableInsurance', rows => rows.findIndex(x => x.policyType?.value === 'КАСКО'), @@ -371,9 +371,9 @@ export default [ }); openNotification({ type: 'error', - title: 'Ошибка во время расчета графика', + message: 'Ошибка во время расчета графика', description: 'Укажите стоимость ОСАГО, включаемую в график', - })(); + }); } else { calculationStore.setTableRow('tableInsurance', rows => rows.findIndex(x => x.policyType?.value === 'ОСАГО'), diff --git a/src/client/stores/CalculationStore/config/initialFilters.ts b/src/client/stores/CalculationStore/config/initialFilters.ts index 2f0fdc4..b7e04c8 100644 --- a/src/client/stores/CalculationStore/config/initialFilters.ts +++ b/src/client/stores/CalculationStore/config/initialFilters.ts @@ -4,5 +4,18 @@ import { TElementFilter } from 'core/types/Calculation/Store/filters'; const initialFilters: Partial> = {}; export const noResetValueElements: ElementsNames[] = ['selectTechnicalCard']; +export const autoSetValuesElements: ElementsNames[] = [ + 'selectProduct', + 'selectLeaseObjectType', + 'selectBrand', + 'selectModel', + 'selectConfiguration', + 'selectTracker', + 'selectTelematic', + 'selectTechnicalCard', + 'selectFuelCard', + 'selectRegistration', + 'selectTownRegistration', +]; export default initialFilters; diff --git a/src/core/validation/validate.ts b/src/core/validation/validate.ts index 7fe7e81..035546b 100644 --- a/src/core/validation/validate.ts +++ b/src/core/validation/validate.ts @@ -1,4 +1,3 @@ - import { getValueName } from 'client/Containers/Calculation/Elements/tools'; import { ElementsNames } from 'client/Containers/Calculation/types/elements'; import { openNotification } from 'client/Elements/Notification'; @@ -60,9 +59,9 @@ export function showValidationMessages( if (message) openNotification({ type: 'error', - title, + message: title, description: message, - })(); + }); }); } return { hasMessages };