mirror of
https://github.com/bigcapitalhq/bigcapital.git
synced 2026-02-18 13:50:31 +00:00
47 lines
1.0 KiB
JavaScript
47 lines
1.0 KiB
JavaScript
import React, { useState, useEffect } from 'react';
|
|
import { FormGroup, NumericInput, Intent } from '@blueprintjs/core';
|
|
import classNames from 'classnames';
|
|
|
|
import { CellType } from 'common';
|
|
import { CLASSES } from 'common/classes';
|
|
|
|
/**
|
|
* Numeric input table cell.
|
|
*/
|
|
export default function NumericInputCell({
|
|
row: { index },
|
|
column: { id },
|
|
cell: { value: initialValue },
|
|
payload,
|
|
}) {
|
|
const [value, setValue] = useState(initialValue);
|
|
|
|
const handleValueChange = (newValue) => {
|
|
setValue(newValue);
|
|
};
|
|
const onBlur = () => {
|
|
payload.updateData(index, id, value);
|
|
};
|
|
useEffect(() => {
|
|
setValue(initialValue);
|
|
}, [initialValue]);
|
|
|
|
const error = payload.errors?.[index]?.[id];
|
|
|
|
return (
|
|
<FormGroup
|
|
intent={error ? Intent.DANGER : null}
|
|
className={classNames(CLASSES.FILL)}
|
|
>
|
|
<NumericInput
|
|
value={value}
|
|
onValueChange={handleValueChange}
|
|
onBlur={onBlur}
|
|
fill={true}
|
|
buttonPosition={'none'}
|
|
/>
|
|
</FormGroup>
|
|
);
|
|
}
|
|
|
|
NumericInputCell.cellType = CellType.Field; |