InsuranceTable: add formatter to insCost field
This commit is contained in:
parent
a670881325
commit
c03cba23fd
@ -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="₽"
|
||||
/>
|
||||
);
|
||||
},
|
||||
},
|
||||
{
|
||||
|
||||
@ -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
6
tools/number.ts
Normal 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);
|
||||
Loading…
x
Reference in New Issue
Block a user