mirror of
https://github.com/bigcapitalhq/bigcapital.git
synced 2026-02-14 11:50:31 +00:00
49 lines
1.2 KiB
JavaScript
49 lines
1.2 KiB
JavaScript
import React from 'react';
|
|
import classNames from 'classnames';
|
|
import { get } from 'lodash';
|
|
import { Classes, Checkbox, FormGroup, Intent } from '@blueprintjs/core';
|
|
|
|
const CheckboxEditableCell = ({
|
|
row: { index, original },
|
|
column: { id, disabledAccessor, checkboxProps },
|
|
cell: { value: initialValue },
|
|
payload,
|
|
}) => {
|
|
const [value, setValue] = React.useState(initialValue);
|
|
|
|
const onChange = (e) => {
|
|
const newValue = e.target.checked;
|
|
|
|
setValue(newValue);
|
|
payload.updateData(index, id, newValue);
|
|
};
|
|
|
|
React.useEffect(() => {
|
|
setValue(initialValue);
|
|
}, [initialValue]);
|
|
|
|
const error = payload.errors?.[index]?.[id];
|
|
|
|
// Detarmines whether the checkbox is disabled.
|
|
const disabled = disabledAccessor ? get(original, disabledAccessor) : false;
|
|
|
|
return (
|
|
<FormGroup
|
|
intent={error ? Intent.DANGER : null}
|
|
className={classNames(Classes.FILL)}
|
|
>
|
|
<Checkbox
|
|
value={value}
|
|
onChange={onChange}
|
|
checked={initialValue}
|
|
disabled={disabled}
|
|
minimal={true}
|
|
className="ml2"
|
|
{...checkboxProps}
|
|
/>
|
|
</FormGroup>
|
|
);
|
|
};
|
|
|
|
export default CheckboxEditableCell;
|