Calculation/Result: add PaymentsTable

This commit is contained in:
Chika 2022-06-29 14:41:30 +03:00
parent 33677c504f
commit ed011d2f69
6 changed files with 102 additions and 1 deletions

View File

@ -0,0 +1,34 @@
/* eslint-disable import/prefer-default-export */
import type { ColumnsType } from 'antd/lib/table';
import { formatMoney } from 'tools/format';
import { pipe } from 'tools/function';
import { round } from 'tools/number';
import type { Payment } from './types';
export const columns: ColumnsType<Payment> = [
{
key: 'num',
dataIndex: 'num',
title: '#',
width: '10%',
},
{
key: 'paymentSum',
dataIndex: 'paymentSum',
title: 'Сумма платежа',
render: (value) => pipe(round, formatMoney)(value),
},
{
key: 'ndsCompensation',
dataIndex: 'ndsCompensation',
title: 'НДС к возмещению',
render: (value) => pipe(round, formatMoney)(value),
},
{
key: 'redemptionAmount',
dataIndex: 'redemptionAmount',
title: 'Сумма досрочного выкупа',
render: (value) => pipe(round, formatMoney)(value),
},
];

View File

@ -0,0 +1,31 @@
import Table from 'Elements/Table';
import { toJS } from 'mobx';
import { observer } from 'mobx-react-lite';
import { useStore } from 'stores/hooks';
import { columns } from './config';
const PaymentsTable = observer(() => {
const { $results } = useStore();
return (
<Table
columns={columns}
dataSource={toJS($results.payments)}
size="small"
pagination={{
defaultPageSize: 12,
pageSizeOptions: [12, 60],
responsive: true,
}}
scroll={{
x: true,
}}
/>
);
});
export default {
id: 'payments-table',
title: 'Таблица платежей',
Component: PaymentsTable,
};

View File

@ -0,0 +1,7 @@
export type Payment = {
key: string;
num: number;
paymentSum: string;
ndsCompensation: string;
redemptionAmount: string;
};

View File

@ -3,9 +3,10 @@ import Tabs from 'Elements/layout/Tabs';
import styled from 'styled-components';
import { min } from 'UIKit/mq';
import Output from './Output';
import PaymentsTable from './PaymentsTable';
import Validation from './Validation';
const resultsTabs = [Output, Validation];
const resultsTabs = [PaymentsTable, Output, Validation];
const Wrapper = styled(Background)`
padding: 4px 10px;

25
stores/results/index.ts Normal file
View File

@ -0,0 +1,25 @@
import type { Payment } from 'Components/Calculation/Results/PaymentsTable/types';
import type { IObservableArray } from 'mobx';
import { makeAutoObservable, observable } from 'mobx';
import type RootStore from 'stores/root';
export default class Results {
root: RootStore;
payments: IObservableArray<Payment>;
constructor(rootStore: RootStore) {
this.payments = observable<Payment>([]);
makeAutoObservable(this);
this.root = rootStore;
}
setPayments = (payments: Payment[]) => {
this.payments.replace(payments);
};
clear = () => {
this.payments.clear();
};
}

View File

@ -1,6 +1,7 @@
/* eslint-disable import/no-cycle */
import { enableStaticRendering } from 'mobx-react-lite';
import CalculationStore from './calculation';
import ResultsStore from './results';
import TablesStore from './tables';
import UserStore from './user';
@ -9,11 +10,13 @@ enableStaticRendering(typeof window === 'undefined');
export default class RootStore {
$user: UserStore;
$calculation: CalculationStore;
$results: ResultsStore;
$tables: TablesStore;
constructor() {
this.$user = new UserStore(this);
this.$calculation = new CalculationStore(this);
this.$results = new ResultsStore(this);
this.$tables = new TablesStore(this);
}
}