diff --git a/craco.config.js b/craco.config.js index adc592d..2fdf2da 100644 --- a/craco.config.js +++ b/craco.config.js @@ -1,20 +1,31 @@ -/* eslint-disable no-undef */ -/* eslint-disable @typescript-eslint/no-var-requires */ -const CracoLessPlugin = require('craco-less'); +const CracoAntDesignPlugin = require('craco-antd'); const colors = require('./src/client/UIKit/colors'); module.exports = { plugins: [ { - plugin: CracoLessPlugin, + plugin: CracoAntDesignPlugin, options: { - lessLoaderOptions: { - lessOptions: { - modifyVars: { '@primary-color': colors.primary }, - javascriptEnabled: true, - }, + customizeTheme: { + '@primary-color': colors.primary, + }, + babelPluginImportOptions: { + libraryDirectory: 'es', }, }, }, ], + babel: { + plugins: [ + [ + 'transform-imports', + { + lodash: { + transform: 'lodash/${member}', + preventFullImport: true, + }, + }, + ], + ], + }, }; diff --git a/package.json b/package.json index 7c08b12..50428f8 100644 --- a/package.json +++ b/package.json @@ -12,10 +12,11 @@ "@testing-library/user-event": "^7.1.2", "antd": "^4.15.0", "axios": "^0.21.1", - "craco-less": "^1.17.1", + "babel-plugin-transform-imports": "^2.0.0", + "craco-antd": "^1.19.0", + "dayjs": "^1.10.4", "graphql": "^15.5.0", "lodash": "^4.17.21", - "luxon": "^1.26.0", "mobx": "^6.1.8", "mobx-react-lite": "^3.2.0", "pluralize": "^8.0.0", @@ -34,7 +35,6 @@ "devDependencies": { "@types/jest": "^26.0.15", "@types/lodash": "^4.14.168", - "@types/luxon": "^1.26.3", "@types/pluralize": "^0.0.29", "@types/react": "^17.0.3", "@types/react-dom": "^17.0.3", @@ -42,7 +42,8 @@ "@types/rebass": "^4.0.8", "@types/styled-components": "^5.1.9", "commitizen": "^4.2.3", - "cz-conventional-changelog": "^3.3.0" + "cz-conventional-changelog": "^3.3.0", + "source-map-explorer": "^2.5.2" }, "scripts": { "test": "craco test", @@ -51,7 +52,8 @@ "build": "craco build", "eslint": "eslint ./src", "eslint:fix": "eslint ./src --fix", - "commit": "git-cz" + "commit": "git-cz", + "analyze": "source-map-explorer 'build/static/js/*.js'" }, "eslintConfig": { "extends": "react-app" diff --git a/src/client/Components/Spinner.jsx b/src/client/Components/Spinner.jsx index 99b50c6..e6c7e31 100644 --- a/src/client/Components/Spinner.jsx +++ b/src/client/Components/Spinner.jsx @@ -1,5 +1,5 @@ import { Spin } from 'antd'; -import { Box, Flex } from 'rebass/styled-components'; +import { Box, Flex } from 'client/UIKit/grid'; export default () => ( diff --git a/src/client/Containers/Calculation/lib/elements/elementsProps.ts b/src/client/Containers/Calculation/lib/elements/elementsProps.ts index 3305b30..7edab06 100644 --- a/src/client/Containers/Calculation/lib/elements/elementsProps.ts +++ b/src/client/Containers/Calculation/lib/elements/elementsProps.ts @@ -1,4 +1,5 @@ -import { DownloadOutlined } from '@ant-design/icons'; +import DownloadOutlined from '@ant-design/icons/lib/icons/DownloadOutlined'; +import { currentYear } from 'core/tools/date'; import { validateEmail, validateInn, @@ -165,7 +166,7 @@ const elementsProps: TElements = { }, tbxLeaseObjectYear: { min: '1994', - max: new Date().getUTCFullYear() + 1, + max: currentYear + 1, }, selectLeaseObjectCategory: { showSearch: false, diff --git a/src/client/Containers/Calculation/lib/fetchData/queries/optionsQuery.ts b/src/client/Containers/Calculation/lib/fetchData/queries/optionsQuery.ts index 92cb6ec..6815031 100644 --- a/src/client/Containers/Calculation/lib/fetchData/queries/optionsQuery.ts +++ b/src/client/Containers/Calculation/lib/fetchData/queries/optionsQuery.ts @@ -1,6 +1,6 @@ -import { currentDate } from 'core/tools/date'; -import { IQueryToCRMGQL } from 'core/types/Calculation/Requests'; import { gql } from '@apollo/client'; +import { currentISODate } from 'core/tools/date'; +import { IQueryToCRMGQL } from 'core/types/Calculation/Requests'; const query = gql` query( @@ -262,7 +262,7 @@ const query = gql` `; const variables = { - currentDate, + currentDate: currentISODate, statecode: 0, supplier_account_type: [100000001], supplier_legal_form: 100000001, diff --git a/src/client/Containers/Calculation/lib/fetchData/queries/staticDataQuery.ts b/src/client/Containers/Calculation/lib/fetchData/queries/staticDataQuery.ts index cb9a614..19b5dfb 100644 --- a/src/client/Containers/Calculation/lib/fetchData/queries/staticDataQuery.ts +++ b/src/client/Containers/Calculation/lib/fetchData/queries/staticDataQuery.ts @@ -1,6 +1,6 @@ -import { IQueryToCRMGQL } from 'core/types/Calculation/Requests'; -import { currentDate } from 'core/tools/date'; import { gql } from '@apollo/client'; +import { currentISODate } from 'core/tools/date'; +import { IQueryToCRMGQL } from 'core/types/Calculation/Requests'; const query = gql` query($statecode: Int, $currentDate: DateTime) { @@ -61,7 +61,7 @@ const query = gql` const variables = { statecode: 0, - currentDate, + currentDate: currentISODate, }; export default { diff --git a/src/client/stores/CalculationStore/Effects/actions/calculate/prepareData.ts b/src/client/stores/CalculationStore/Effects/actions/calculate/prepareData.ts index 419bc58..440527f 100644 --- a/src/client/stores/CalculationStore/Effects/actions/calculate/prepareData.ts +++ b/src/client/stores/CalculationStore/Effects/actions/calculate/prepareData.ts @@ -1,9 +1,9 @@ import valuesConstants from 'core/constants/values'; +import { currentDate } from 'core/tools/date'; import { PaymentRow, PreparedValues } from 'core/types/Calculation/Prepare'; import { IPreparedData } from 'core/types/Calculation/Requests'; import { ICalculationStore } from 'core/types/Calculation/Store'; -import { DateTime } from 'luxon'; -import { NIL } from 'uuid'; +import NIL from 'uuid/dist/esm-browser/nil'; import { convertPrice } from '../../lib/tools'; export default ({ @@ -11,8 +11,6 @@ export default ({ }: { calculationStore: ICalculationStore; }): IPreparedData => { - const currentDate = DateTime.local().toUTC().toJSDate(); - const { values, options, tables } = calculationStore; const preparedPaymentsRows: PaymentRow[] = Array.from( diff --git a/src/client/stores/CalculationStore/Effects/reactions/loadKpReaction/index.ts b/src/client/stores/CalculationStore/Effects/reactions/loadKpReaction/index.ts index f611aad..9a7aa88 100644 --- a/src/client/stores/CalculationStore/Effects/reactions/loadKpReaction/index.ts +++ b/src/client/stores/CalculationStore/Effects/reactions/loadKpReaction/index.ts @@ -1,11 +1,11 @@ +/* eslint-disable @typescript-eslint/ban-ts-comment */ import { message } from 'antd'; import { elementsValues } from 'client/Containers/Calculation/lib/elements/values'; import { openNotification } from 'client/Elements/Notification'; import { calculationProcess } from 'client/stores/CalculationStore'; import initialValues from 'client/stores/CalculationStore/config/initialValues'; import CrmService from 'core/services/CrmService'; -import { currentDate } from 'core/tools/date'; -/* eslint-disable @typescript-eslint/ban-ts-comment */ +import { currentISODate } from 'core/tools/date'; import { IGetCRMEntitiesResponse } from 'core/types/Calculation/Responses'; import { IReactionEffect } from 'core/types/Calculation/Store/effect'; import { TElements } from 'core/types/Calculation/Store/elements'; @@ -139,7 +139,7 @@ const loadKpReaction: IReactionEffect = calculationStore => ({ evo_brandid: quote.evo_brandid || NIL, evo_modelid: quote.evo_modelid || NIL, salonaccountid: quote.evo_supplier_accountid || NIL, - currentDate, + currentDate: currentISODate, dealer_person_accountid: quote.evo_dealer_person_accountid || NIL, dealer_broker_accountid: quote.evo_dealer_broker_accountid || NIL, hasDealerBroker: quote.evo_dealer_broker_accountid ? true : false, diff --git a/src/client/stores/CalculationStore/Effects/reactions/requestReactions.ts b/src/client/stores/CalculationStore/Effects/reactions/requestReactions.ts index a634bb7..41c61f9 100644 --- a/src/client/stores/CalculationStore/Effects/reactions/requestReactions.ts +++ b/src/client/stores/CalculationStore/Effects/reactions/requestReactions.ts @@ -1,9 +1,9 @@ import { gql } from '@apollo/client'; import CrmService from 'core/services/CrmService'; -import { currentDate } from 'core/tools/date'; +import { currentISODate } from 'core/tools/date'; import { IReactionEffect } from 'core/types/Calculation/Store/effect'; -import { ElementStatus } from 'core/types/statuses'; import { Process } from 'core/types/Calculation/Store/process'; +import { ElementStatus } from 'core/types/statuses'; import { quoteFields } from '../lib/queries'; export default [ @@ -350,7 +350,7 @@ export default [ `, variables: { evo_agent_accountid: indAgentId, - currentDate, + currentDate: currentISODate, statecode: 0, }, toOptions: ['evo_reward_condition'], @@ -410,7 +410,7 @@ export default [ `, variables: { evo_agent_accountid: doubleAgentId, - currentDate, + currentDate: currentISODate, statecode: 0, }, toOptions: ['evo_reward_condition'], @@ -472,7 +472,7 @@ export default [ `, variables: { evo_agent_accountid: calcFinDepartmentId, - currentDate, + currentDate: currentISODate, statecode: 0, }, toOptions: ['evo_reward_condition'], @@ -532,7 +532,7 @@ export default [ `, variables: { evo_agent_accountid: calcBrokerId, - currentDate, + currentDate: currentISODate, statecode: 0, }, toOptions: ['evo_reward_condition'], @@ -708,7 +708,7 @@ export default [ `, variables: { evo_agent_accountid: dealerBrokerId, - currentDate, + currentDate: currentISODate, statecode: 0, }, toOptions: ['evo_reward_condition'], @@ -767,7 +767,7 @@ export default [ `, variables: { evo_agent_accountid: dealerPersonId, - currentDate, + currentDate: currentISODate, statecode: 0, }, toOptions: ['evo_reward_condition'], diff --git a/src/client/stores/CalculationStore/config/initialValues.ts b/src/client/stores/CalculationStore/config/initialValues.ts index ff30f1a..cd352cc 100644 --- a/src/client/stores/CalculationStore/config/initialValues.ts +++ b/src/client/stores/CalculationStore/config/initialValues.ts @@ -1,4 +1,5 @@ -import { TValues, TValue } from 'core/types/Calculation/Store/values'; +import { currentYear } from 'core/tools/date'; +import { TValue, TValues } from 'core/types/Calculation/Store/values'; const initialValues: TValues = { lead: null, @@ -37,7 +38,7 @@ const initialValues: TValues = { maxMass: 0, countSeats: 0, maxSpeed: 0, - leaseObjectYear: new Date().getUTCFullYear(), + leaseObjectYear: currentYear, engineType: 100000000, leaseObjectCategory: 100000001, leaseObjectMotorPower: 0, diff --git a/src/core/tools/assignProps.js b/src/core/tools/assignProps.js deleted file mode 100644 index d0def4c..0000000 --- a/src/core/tools/assignProps.js +++ /dev/null @@ -1,14 +0,0 @@ -function assignProperties(target, ...sources) { - sources.forEach(source => { - Object.defineProperties( - target, - Object.keys(source).reduce((descriptors, key) => { - descriptors[key] = Object.getOwnPropertyDescriptor(source, key); - return descriptors; - }, {}) - ); - }); - return target; -} - -export default assignProperties; diff --git a/src/core/tools/date.js b/src/core/tools/date.js index bfe52ff..83afb92 100644 --- a/src/core/tools/date.js +++ b/src/core/tools/date.js @@ -1,3 +1,7 @@ -import { DateTime } from 'luxon'; +import dayjs from 'dayjs'; +import utc from 'dayjs/plugin/utc'; +dayjs.extend(utc); -export const currentDate = DateTime.local().toUTC().toISO(); +export const currentISODate = dayjs().utc().toISOString(); +export const currentDate = dayjs().toDate(); +export const currentYear = dayjs().year(); diff --git a/src/core/tools/string.ts b/src/core/tools/string.ts deleted file mode 100644 index 37719dc..0000000 --- a/src/core/tools/string.ts +++ /dev/null @@ -1,9 +0,0 @@ -export function stringifyObject(obj_from_json: any): string { - if (typeof obj_from_json !== 'object' || Array.isArray(obj_from_json)) { - return JSON.stringify(obj_from_json); - } - const props = Object.keys(obj_from_json) - .map(key => `${key}:${stringifyObject(obj_from_json[key])}`) - .join(','); - return `${props}`; -} diff --git a/src/core/tools/validate.js b/src/core/tools/validate.js index 6a935e8..42f2ccd 100644 --- a/src/core/tools/validate.js +++ b/src/core/tools/validate.js @@ -1,4 +1,5 @@ -import validator from 'validator'; +import isEmail from 'validator/es/lib/isEmail'; +import isMobilePhone from 'validator/es/lib/isMobilePhone'; const isINNIndividual = value => { const valueToString = value ? value.toString() : ''; @@ -81,10 +82,10 @@ export function validateKpp(value) { export function validatePhone(value) { const stringValue = value ? value.toString() : ''; - return validator.isMobilePhone(stringValue, ['ru-RU']); + return isMobilePhone(stringValue, ['ru-RU']); } export function validateEmail(value) { const stringValue = value ? value.toString() : ''; - return validator.isEmail(stringValue); + return isEmail(stringValue); }