add elt components
This commit is contained in:
parent
4c9e107c54
commit
baf4f3fad0
@ -0,0 +1,20 @@
|
||||
import { useStore } from '@/stores/hooks';
|
||||
import { observer } from 'mobx-react-lite';
|
||||
import { Table } from 'ui/antd';
|
||||
|
||||
export const PolicyTable = observer(({ getter, ...props }) => {
|
||||
const { $tables } = useStore();
|
||||
const { getValues } = getter($tables.elt);
|
||||
|
||||
return (
|
||||
<Table
|
||||
size="small"
|
||||
pagination={false}
|
||||
dataSource={getValues}
|
||||
scroll={{
|
||||
x: true,
|
||||
}}
|
||||
{...props}
|
||||
/>
|
||||
);
|
||||
});
|
||||
@ -0,0 +1,15 @@
|
||||
import { useStore } from '@/stores/hooks';
|
||||
import { observer } from 'mobx-react-lite';
|
||||
import { Button } from 'ui/antd';
|
||||
import { ReloadOutlined } from 'ui/elements/icons';
|
||||
|
||||
export const ReloadButton = observer(({ getter }) => {
|
||||
const { $tables } = useStore();
|
||||
const { validation } = getter($tables.elt);
|
||||
|
||||
const hasErrors = validation.hasErrors;
|
||||
|
||||
return (
|
||||
<Button onClick={() => {}} disabled={hasErrors} shape="circle" icon={<ReloadOutlined />} />
|
||||
);
|
||||
});
|
||||
@ -0,0 +1,22 @@
|
||||
import { useStore } from '@/stores/hooks';
|
||||
import { observer } from 'mobx-react-lite';
|
||||
import { Alert } from 'ui/antd';
|
||||
|
||||
export const Validation = observer(({ getter }) => {
|
||||
const { $tables, $process } = useStore();
|
||||
const { validation } = getter($tables.elt);
|
||||
|
||||
const errors = validation.getErrors();
|
||||
|
||||
if (errors?.length) {
|
||||
return (
|
||||
<Alert
|
||||
type={$process.has('Unlimited') ? 'warning' : 'error'}
|
||||
banner
|
||||
message={errors[0].message}
|
||||
/>
|
||||
);
|
||||
}
|
||||
|
||||
return false;
|
||||
});
|
||||
@ -0,0 +1,3 @@
|
||||
export * from './PolicyTable';
|
||||
export * from './ReloadButton';
|
||||
export * from './Validation';
|
||||
20
apps/web/Components/Calculation/Form/ELT/Kasko.jsx
Normal file
20
apps/web/Components/Calculation/Form/ELT/Kasko.jsx
Normal file
@ -0,0 +1,20 @@
|
||||
import { PolicyTable, ReloadButton, Validation } from './Components';
|
||||
import { columns } from './lib/config';
|
||||
import { Flex } from 'ui/grid';
|
||||
|
||||
function getter(eltStore) {
|
||||
return eltStore.kasko;
|
||||
}
|
||||
|
||||
const kaskoColumns = [...columns];
|
||||
kaskoColumns[0].title = 'Страховая компания КАСКО';
|
||||
kaskoColumns[3].title = <ReloadButton getter={getter} />;
|
||||
|
||||
export function Kasko() {
|
||||
return (
|
||||
<Flex flexDirection="column">
|
||||
<Validation getter={getter} />
|
||||
<PolicyTable getter={getter} columns={kaskoColumns} />
|
||||
</Flex>
|
||||
);
|
||||
}
|
||||
20
apps/web/Components/Calculation/Form/ELT/Osago.jsx
Normal file
20
apps/web/Components/Calculation/Form/ELT/Osago.jsx
Normal file
@ -0,0 +1,20 @@
|
||||
import { PolicyTable, ReloadButton, Validation } from './Components';
|
||||
import { columns } from './lib/config';
|
||||
import { Flex } from 'ui/grid';
|
||||
|
||||
function getter(eltStore) {
|
||||
return eltStore.osago;
|
||||
}
|
||||
|
||||
const osagoColumns = [...columns];
|
||||
osagoColumns[0].title = 'Страховая компания ОСАГО';
|
||||
osagoColumns[3].title = <ReloadButton getter={getter} />;
|
||||
|
||||
export function Osago() {
|
||||
return (
|
||||
<Flex flexDirection="column">
|
||||
<Validation getter={getter} />
|
||||
<PolicyTable getter={getter} columns={osagoColumns} />
|
||||
</Flex>
|
||||
);
|
||||
}
|
||||
20
apps/web/Components/Calculation/Form/ELT/index.jsx
Normal file
20
apps/web/Components/Calculation/Form/ELT/index.jsx
Normal file
@ -0,0 +1,20 @@
|
||||
import { Kasko } from './Kasko';
|
||||
import { Osago } from './Osago';
|
||||
|
||||
const id = 'elt';
|
||||
const title = 'ЭЛТ';
|
||||
|
||||
function ELT() {
|
||||
return (
|
||||
<>
|
||||
<Osago />
|
||||
<Kasko />
|
||||
</>
|
||||
);
|
||||
}
|
||||
|
||||
export default {
|
||||
Component: ELT,
|
||||
id,
|
||||
title,
|
||||
};
|
||||
35
apps/web/Components/Calculation/Form/ELT/lib/config.tsx
Normal file
35
apps/web/Components/Calculation/Form/ELT/lib/config.tsx
Normal file
@ -0,0 +1,35 @@
|
||||
import type { RowSchema } from '@/config/schema/elt';
|
||||
import { LoadingOutlined } from 'ui/elements/icons';
|
||||
import type { ColumnsType } from 'ui/elements/table';
|
||||
import type { z } from 'zod';
|
||||
|
||||
type Row = z.infer<typeof RowSchema>;
|
||||
|
||||
const formatter = Intl.NumberFormat('ru', {
|
||||
currency: 'RUB',
|
||||
style: 'currency',
|
||||
}).format;
|
||||
|
||||
export const columns: ColumnsType<Row> = [
|
||||
{
|
||||
dataIndex: 'name',
|
||||
title: 'Страховая компания',
|
||||
},
|
||||
{
|
||||
dataIndex: 'sum',
|
||||
render: formatter,
|
||||
sortDirections: ['descend', 'ascend'],
|
||||
sorter: (a, b) => a.sum - b.sum,
|
||||
title: 'Сумма',
|
||||
},
|
||||
{
|
||||
dataIndex: 'totalFranchise',
|
||||
render: formatter,
|
||||
title: 'Франшиза',
|
||||
},
|
||||
{
|
||||
dataIndex: 'isFetching',
|
||||
render: (value) => value && <LoadingOutlined spin />,
|
||||
title: undefined,
|
||||
},
|
||||
];
|
||||
4
apps/web/Components/Calculation/Form/ELT/types.ts
Normal file
4
apps/web/Components/Calculation/Form/ELT/types.ts
Normal file
@ -0,0 +1,4 @@
|
||||
import type { RowSchema } from '@/config/schema/elt';
|
||||
import type { z } from 'zod';
|
||||
|
||||
export type Row = z.infer<typeof RowSchema>;
|
||||
@ -5,6 +5,7 @@ import { MAX_INSURANCE } from '@/constants/values';
|
||||
import { parser } from 'tools/number';
|
||||
import { InputNumber, Select } from 'ui/elements';
|
||||
import { createFormatter } from 'ui/elements/InputNumber';
|
||||
import type { ColumnsType } from 'ui/elements/Table';
|
||||
|
||||
export const columns: ColumnsType<Insurance.RowValues> = [
|
||||
{
|
||||
|
||||
@ -1,5 +1,6 @@
|
||||
import AddProduct from './AddProduct';
|
||||
import CreateKP from './CreateKP';
|
||||
import ELT from './ELT';
|
||||
import Insurance from './Insurance';
|
||||
import Leasing from './Leasing';
|
||||
import LeasingObject from './LeasingObject';
|
||||
@ -17,6 +18,7 @@ const formTabs = [
|
||||
LeasingObject,
|
||||
SupplierAgent,
|
||||
Insurance,
|
||||
ELT,
|
||||
AddProduct,
|
||||
CreateKP,
|
||||
Unlimited,
|
||||
|
||||
9
apps/web/config/schema/elt.ts
Normal file
9
apps/web/config/schema/elt.ts
Normal file
@ -0,0 +1,9 @@
|
||||
import { z } from 'zod';
|
||||
|
||||
export const RowSchema = z.object({
|
||||
isFetching: z.boolean(),
|
||||
sum: z.number(),
|
||||
key: z.string(),
|
||||
name: z.string(),
|
||||
totalFranchise: z.number(),
|
||||
});
|
||||
29
apps/web/stores/tables/elt/index.ts
Normal file
29
apps/web/stores/tables/elt/index.ts
Normal file
@ -0,0 +1,29 @@
|
||||
import PolicyStore from './policy';
|
||||
import type RootStore from '@/stores/root';
|
||||
|
||||
export default class ELTStore {
|
||||
public kasko: PolicyStore;
|
||||
public osago: PolicyStore;
|
||||
|
||||
constructor(rootStore: RootStore) {
|
||||
this.kasko = new PolicyStore({
|
||||
rootStore,
|
||||
validationConfig: {
|
||||
err_key: 'ERR_ELT_KASKO',
|
||||
err_title: 'ЭЛТ КАСКО',
|
||||
},
|
||||
});
|
||||
this.osago = new PolicyStore({
|
||||
rootStore,
|
||||
validationConfig: {
|
||||
err_key: 'ERR_ELT_OSAGO',
|
||||
err_title: 'ЭЛТ ОСАГО',
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
public reset = () => {
|
||||
this.kasko.reset();
|
||||
this.osago.reset();
|
||||
};
|
||||
}
|
||||
45
apps/web/stores/tables/elt/policy.ts
Normal file
45
apps/web/stores/tables/elt/policy.ts
Normal file
@ -0,0 +1,45 @@
|
||||
import type RootStore from '../../root';
|
||||
import Validation from '../../validation';
|
||||
import type { ValidationConfig } from '../../validation/types';
|
||||
import type * as ELT from '@/Components/Calculation/Form/ELT/types';
|
||||
import type { IObservableArray } from 'mobx';
|
||||
import { makeAutoObservable, observable } from 'mobx';
|
||||
|
||||
type ConstructorInput = {
|
||||
rootStore: RootStore;
|
||||
validationConfig: ValidationConfig;
|
||||
};
|
||||
|
||||
export default class PolicyStore {
|
||||
private root: RootStore;
|
||||
public validation: Validation;
|
||||
private rows: IObservableArray<ELT.Row>;
|
||||
private selectedKey: string | null = null;
|
||||
|
||||
constructor({ rootStore, validationConfig }: ConstructorInput) {
|
||||
this.rows = observable<ELT.Row>([]);
|
||||
makeAutoObservable(this);
|
||||
this.validation = new Validation(validationConfig, rootStore);
|
||||
this.root = rootStore;
|
||||
}
|
||||
|
||||
public get getValues() {
|
||||
return this.rows;
|
||||
}
|
||||
|
||||
public get hasErrors() {
|
||||
return this.validation.hasErrors;
|
||||
}
|
||||
|
||||
public setSelectedKey = (key: string) => {
|
||||
this.selectedKey = key;
|
||||
};
|
||||
|
||||
public get getSelectedRow() {
|
||||
return this.rows.find((x) => x.key === this.selectedKey);
|
||||
}
|
||||
|
||||
public reset = () => {
|
||||
this.rows.clear();
|
||||
};
|
||||
}
|
||||
@ -1,3 +1,4 @@
|
||||
import ELTStore from './elt';
|
||||
import FinGAPTable from './fingap';
|
||||
import InsuranceTable from './insurance';
|
||||
import PaymentsTable from './payments';
|
||||
@ -7,10 +8,12 @@ export default class TablesStore {
|
||||
public payments: PaymentsTable;
|
||||
public insurance: InsuranceTable;
|
||||
public fingap: FinGAPTable;
|
||||
public elt: ELTStore;
|
||||
|
||||
constructor(rootStore: RootStore) {
|
||||
this.payments = new PaymentsTable(rootStore);
|
||||
this.insurance = new InsuranceTable(rootStore);
|
||||
this.fingap = new FinGAPTable(rootStore);
|
||||
this.elt = new ELTStore(rootStore);
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user