From 2b383695faeb8be4abef1df240cf36aeba7ead2d Mon Sep 17 00:00:00 2001 From: Chika Date: Wed, 29 Jun 2022 13:30:06 +0300 Subject: [PATCH] Calculation/Insurance: add FinGAP table --- .../Form/Insurance/FinGAPTable/config.ts | 25 +++++++++++++ .../Form/Insurance/FinGAPTable/index.jsx | 33 +++++++++++++++++ .../Form/Insurance/FinGAPTable/types.ts | 10 +++++ .../Calculation/Form/Insurance/index.jsx | 3 +- pages/_app.tsx | 15 +++++--- stores/tables/fingap/index.ts | 37 +++++++++++++++++++ stores/tables/index.ts | 3 ++ 7 files changed, 120 insertions(+), 6 deletions(-) create mode 100644 Components/Calculation/Form/Insurance/FinGAPTable/config.ts create mode 100644 Components/Calculation/Form/Insurance/FinGAPTable/index.jsx create mode 100644 Components/Calculation/Form/Insurance/FinGAPTable/types.ts create mode 100644 stores/tables/fingap/index.ts diff --git a/Components/Calculation/Form/Insurance/FinGAPTable/config.ts b/Components/Calculation/Form/Insurance/FinGAPTable/config.ts new file mode 100644 index 0000000..8451361 --- /dev/null +++ b/Components/Calculation/Form/Insurance/FinGAPTable/config.ts @@ -0,0 +1,25 @@ +/* eslint-disable import/prefer-default-export */ +import type { ColumnsType } from 'antd/lib/table'; +import { formatMoney } from 'tools/format'; +import type { Risk } from './types'; + +export const columns: ColumnsType = [ + { + key: 'riskName', + dataIndex: 'riskName', + title: 'Риск', + width: '55%', + }, + { + key: 'sum', + title: 'Страховая сумма', + dataIndex: 'sum', + render: (value: number) => formatMoney(value, 'RUB'), + }, + { + key: 'premium', + title: 'Страховая премия по риску', + dataIndex: 'premium', + render: (value: number) => formatMoney(value, 'RUB'), + }, +]; diff --git a/Components/Calculation/Form/Insurance/FinGAPTable/index.jsx b/Components/Calculation/Form/Insurance/FinGAPTable/index.jsx new file mode 100644 index 0000000..e4e053d --- /dev/null +++ b/Components/Calculation/Form/Insurance/FinGAPTable/index.jsx @@ -0,0 +1,33 @@ +import Table from 'Elements/Table'; +import { useStore } from 'stores/hooks'; +import { columns } from './config'; + +export default function FinGAPTable() { + const { $tables } = useStore(); + const { finGAP } = $tables; + + return ( + { + const selectedKeys = selectedRows.reduce((acc, row) => { + acc.push(row.key); + if (row.keys) return [...acc, ...row.keys]; + + return acc; + }, []); + + finGAP.setSelectedKeys(selectedKeys); + }, + }} + pagination={false} + size="small" + scroll={{ + x: true, + }} + /> + ); +} diff --git a/Components/Calculation/Form/Insurance/FinGAPTable/types.ts b/Components/Calculation/Form/Insurance/FinGAPTable/types.ts new file mode 100644 index 0000000..b7c2efd --- /dev/null +++ b/Components/Calculation/Form/Insurance/FinGAPTable/types.ts @@ -0,0 +1,10 @@ +export type Risk = { + key: string; + riskId: string; + riskName: string; + calcType: number; + premiumPerc: number; + sum: number; + premium: number; + keys?: string[]; +}; diff --git a/Components/Calculation/Form/Insurance/index.jsx b/Components/Calculation/Form/Insurance/index.jsx index 2e93cf7..830515d 100644 --- a/Components/Calculation/Form/Insurance/index.jsx +++ b/Components/Calculation/Form/Insurance/index.jsx @@ -1,6 +1,7 @@ import { Flex } from 'UIKit/grid'; import renderFormRows from '../../lib/render-rows'; import { id, rows, title } from './config'; +import FinGAPTable from './FinGAPTable'; import InsuranceTable from './InsuranceTable'; function Insurance() { @@ -10,7 +11,7 @@ function Insurance() { {renderedRows} - {/* TODO: add FinGAP Table */} + ); } diff --git a/pages/_app.tsx b/pages/_app.tsx index 85c7711..12be3d2 100644 --- a/pages/_app.tsx +++ b/pages/_app.tsx @@ -1,5 +1,6 @@ /* eslint-disable global-require */ import { ApolloProvider } from '@apollo/client'; +import { ConfigProvider } from 'antd'; import 'antd/dist/antd.less'; import { useApollo } from 'apollo/hooks'; import Layout from 'Components/Layout'; @@ -11,6 +12,8 @@ import { GlobalStyle } from 'UIKit/colors'; import theme from 'UIKit/theme'; import '../styles/globals.css'; +import ruRU from 'antd/lib/locale/ru_RU'; + if (process.env.NODE_ENV === 'development') { require('../mocks'); } @@ -28,11 +31,13 @@ function App({ Component, pageProps }: AppProps) { - - - - - + + + + + + + ); diff --git a/stores/tables/fingap/index.ts b/stores/tables/fingap/index.ts new file mode 100644 index 0000000..8910a79 --- /dev/null +++ b/stores/tables/fingap/index.ts @@ -0,0 +1,37 @@ +import type * as FinGAP from 'Components/Calculation/Form/Insurance/FinGAPTable/types'; +import type { IObservableArray } from 'mobx'; +import { makeAutoObservable, observable } from 'mobx'; +import type RootStore from 'stores/root'; + +export default class FinGAPTable { + root: RootStore; + risks: IObservableArray; + selectedKeys: Set; + + constructor(rootStore: RootStore) { + this.selectedKeys = new Set(); + this.risks = observable([]); + makeAutoObservable(this); + + this.root = rootStore; + } + + setRisks = (risks: FinGAP.Risk[]) => { + this.risks.replace(risks); + }; + + setSelectedKeys = (keys: string[]) => { + this.selectedKeys = new Set(keys); + }; + + get totalSum() { + return this.risks + .filter((risk) => this.selectedKeys.has(risk.key)) + .reduce((sum, risk) => sum + risk.premium, 0); + } + + clear = () => { + this.risks.clear(); + this.selectedKeys.clear(); + }; +} diff --git a/stores/tables/index.ts b/stores/tables/index.ts index b01bcd8..29d7b9a 100644 --- a/stores/tables/index.ts +++ b/stores/tables/index.ts @@ -1,10 +1,13 @@ import type RootStore from 'stores/root'; +import FinGAPTable from './fingap'; import InsuranceTable from './insurance'; export default class TablesStore { insurance: InsuranceTable; + finGAP: FinGAPTable; constructor(rootStore: RootStore) { this.insurance = new InsuranceTable(rootStore); + this.finGAP = new FinGAPTable(rootStore); } }