InsuranceTable: add formatter to insCost field

This commit is contained in:
Chika 2022-07-08 19:13:08 +03:00
parent a670881325
commit c03cba23fd
3 changed files with 19 additions and 8 deletions

View File

@ -3,6 +3,7 @@ import type { ColumnsType } from 'antd/lib/table';
import { MAX_INSURANCE } from 'constants/values';
import InputNumber from 'Elements/InputNumber';
import Select from 'Elements/Select';
import { formatter, parser } from 'tools/number';
import { buildOptionComponent, buildValueComponent } from './builders';
import type * as Insurance from './types';
@ -40,7 +41,17 @@ export const columns: ColumnsType<Insurance.RowValues> = [
render: (_, record) => {
const Component = buildValueComponent(record.key, InputNumber, 'insCost');
return <Component min={0} max={MAX_INSURANCE} step={1000} precision={2} addonAfter="₽" />;
return (
<Component
min={0}
max={MAX_INSURANCE}
step={1000}
precision={2}
parser={parser}
formatter={formatter}
addonAfter="₽"
/>
);
},
},
{

View File

@ -1,15 +1,9 @@
import { MAX_FRANCHISE, MAX_LEASING_PERIOD } from 'constants/values';
import DownloadOutlined from 'Elements/icons/DownloadOutlined';
import date from 'tools/date';
import { formatter, parser } from 'tools/number';
import type { ElementsProps } from './elements-components';
function parser(value?: string) {
const normalized = (value || '0').replace(/\s/g, '').replaceAll(',', '.');
return Number.parseFloat(normalized);
}
const formatter = (value?: number) => Intl.NumberFormat('ru').format(value || 0);
const props: Partial<ElementsProps> = {
tbxLeaseObjectPrice: {
min: 0,

6
tools/number.ts Normal file
View File

@ -0,0 +1,6 @@
export function parser(value?: string) {
const normalized = (value || '0').replace(/\s/g, '').replaceAll(',', '.');
return Number.parseFloat(normalized);
}
export const formatter = (value?: number) => Intl.NumberFormat('ru').format(value || 0);