mirror of
https://github.com/bigcapitalhq/bigcapital.git
synced 2026-02-20 06:40:31 +00:00
feat(warehouse) add warehouse propover.
This commit is contained in:
@@ -2,6 +2,7 @@ import React, { useState, useEffect } from 'react';
|
|||||||
import { FormGroup, NumericInput, Intent } from '@blueprintjs/core';
|
import { FormGroup, NumericInput, Intent } from '@blueprintjs/core';
|
||||||
import classNames from 'classnames';
|
import classNames from 'classnames';
|
||||||
import { CLASSES } from 'common/classes';
|
import { CLASSES } from 'common/classes';
|
||||||
|
import WarehouseListPopover from '../../containers/WarehouseListPopover';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Numeric input table cell.
|
* Numeric input table cell.
|
||||||
@@ -36,7 +37,8 @@ export default function NumericInputCell({
|
|||||||
onValueChange={handleValueChange}
|
onValueChange={handleValueChange}
|
||||||
onBlur={onBlur}
|
onBlur={onBlur}
|
||||||
fill={true}
|
fill={true}
|
||||||
buttonPosition={"none"}
|
buttonPosition={'none'}
|
||||||
|
rightElement={<WarehouseListPopover />}
|
||||||
/>
|
/>
|
||||||
</FormGroup>
|
</FormGroup>
|
||||||
);
|
);
|
||||||
|
|||||||
44
src/components/DataTableCells/RadioFieldCell.js
Normal file
44
src/components/DataTableCells/RadioFieldCell.js
Normal file
@@ -0,0 +1,44 @@
|
|||||||
|
import React from 'react';
|
||||||
|
import classNames from 'classnames';
|
||||||
|
import { FormGroup, Intent, Classes, Radio } from '@blueprintjs/core';
|
||||||
|
|
||||||
|
const RadioEditableCell = ({
|
||||||
|
row: { index, original },
|
||||||
|
column: { id, radioProps },
|
||||||
|
cell: { value: initialValue },
|
||||||
|
payload,
|
||||||
|
}) => {
|
||||||
|
const [value, setValue] = React.useState(initialValue);
|
||||||
|
|
||||||
|
const onChange = (e) => {
|
||||||
|
const newValue = e.target.checked;
|
||||||
|
debugger;
|
||||||
|
setValue(newValue);
|
||||||
|
payload.updateData(index, id, newValue);
|
||||||
|
};
|
||||||
|
|
||||||
|
React.useEffect(() => {
|
||||||
|
setValue(initialValue);
|
||||||
|
}, [initialValue]);
|
||||||
|
|
||||||
|
const error = payload.errors?.[index]?.[id];
|
||||||
|
|
||||||
|
return (
|
||||||
|
<FormGroup
|
||||||
|
intent={error ? Intent.DANGER : null}
|
||||||
|
className={classNames(Classes.FILL)}
|
||||||
|
>
|
||||||
|
<Radio
|
||||||
|
value={value}
|
||||||
|
label={'Warehouse #1'}
|
||||||
|
onChange={onChange}
|
||||||
|
checked={initialValue}
|
||||||
|
minimal={true}
|
||||||
|
className="ml2"
|
||||||
|
{...radioProps}
|
||||||
|
/>
|
||||||
|
</FormGroup>
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
||||||
|
export default RadioEditableCell;
|
||||||
@@ -9,6 +9,7 @@ import NumericInputCell from './NumericInputCell';
|
|||||||
import CheckBoxFieldCell from './CheckBoxFieldCell';
|
import CheckBoxFieldCell from './CheckBoxFieldCell';
|
||||||
import SwitchFieldCell from './SwitchFieldCell';
|
import SwitchFieldCell from './SwitchFieldCell';
|
||||||
import TextAreaCell from './TextAreaCell';
|
import TextAreaCell from './TextAreaCell';
|
||||||
|
import RadioFieldCell from './RadioFieldCell';
|
||||||
|
|
||||||
export {
|
export {
|
||||||
AccountsListFieldCell,
|
AccountsListFieldCell,
|
||||||
@@ -23,4 +24,5 @@ export {
|
|||||||
CheckBoxFieldCell,
|
CheckBoxFieldCell,
|
||||||
SwitchFieldCell,
|
SwitchFieldCell,
|
||||||
TextAreaCell,
|
TextAreaCell,
|
||||||
|
RadioFieldCell,
|
||||||
};
|
};
|
||||||
|
|||||||
75
src/containers/WarehouseListPopover/WarehousesList.js
Normal file
75
src/containers/WarehouseListPopover/WarehousesList.js
Normal file
@@ -0,0 +1,75 @@
|
|||||||
|
import React from 'react';
|
||||||
|
import styled from 'styled-components';
|
||||||
|
|
||||||
|
import { CLASSES } from 'common/classes';
|
||||||
|
import { TableStyle } from '../../common';
|
||||||
|
import { DataTableEditable, DataTable } from 'components';
|
||||||
|
import { compose, saveInvoke, updateTableCell } from 'utils';
|
||||||
|
import { useWarehouseEntriesColumns } from './components';
|
||||||
|
|
||||||
|
export default function IntegrateWarehousesTable({
|
||||||
|
// #ownProps
|
||||||
|
initialWarehouse,
|
||||||
|
selectedWarehouseId,
|
||||||
|
onUpdateData,
|
||||||
|
entries,
|
||||||
|
errors,
|
||||||
|
}) {
|
||||||
|
const [rows, setRows] = React.useState(initialWarehouse);
|
||||||
|
|
||||||
|
// warehouses entries columns.
|
||||||
|
const columns = useWarehouseEntriesColumns();
|
||||||
|
|
||||||
|
// Handle update data.
|
||||||
|
const handleUpdateData = React.useCallback(
|
||||||
|
(rowIndex, columnId, value) => {
|
||||||
|
const newRows = compose(updateTableCell(rowIndex, columnId, value))(
|
||||||
|
entries,
|
||||||
|
);
|
||||||
|
onUpdateData(newRows);
|
||||||
|
},
|
||||||
|
[onUpdateData, entries],
|
||||||
|
);
|
||||||
|
|
||||||
|
const DATA = [
|
||||||
|
{
|
||||||
|
warehouse_name: true,
|
||||||
|
quantity: '9,444',
|
||||||
|
availiable_for_sale: 0,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
warehouse_name: false,
|
||||||
|
quantity: '19,444',
|
||||||
|
availiable_for_sale: 0,
|
||||||
|
},
|
||||||
|
];
|
||||||
|
|
||||||
|
return (
|
||||||
|
<WarehouseDataTableRoot
|
||||||
|
columns={columns}
|
||||||
|
data={DATA}
|
||||||
|
payload={{
|
||||||
|
errors: errors || [],
|
||||||
|
updateData: handleUpdateData,
|
||||||
|
}}
|
||||||
|
/>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
const WarehouseDataTableRoot = styled(DataTable)`
|
||||||
|
width: 600px;
|
||||||
|
|
||||||
|
.table {
|
||||||
|
border: 1px solid #000000;
|
||||||
|
.thead .th {
|
||||||
|
background: transparent;
|
||||||
|
color: #222222;
|
||||||
|
border-bottom: 1px solid #000000;
|
||||||
|
padding: 0.5rem;
|
||||||
|
}
|
||||||
|
.tbody .tr .td {
|
||||||
|
padding: 0.2rem 0.2rem;
|
||||||
|
border-bottom: 1px solid #cecbcb;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
`;
|
||||||
38
src/containers/WarehouseListPopover/components.js
Normal file
38
src/containers/WarehouseListPopover/components.js
Normal file
@@ -0,0 +1,38 @@
|
|||||||
|
import React from 'react';
|
||||||
|
|
||||||
|
import { RadioFieldCell } from 'components/DataTableCells';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Retrieve warehouse entries columns.
|
||||||
|
*/
|
||||||
|
export function useWarehouseEntriesColumns() {
|
||||||
|
return React.useMemo(
|
||||||
|
() => [
|
||||||
|
{
|
||||||
|
Header: 'Warehouse Name',
|
||||||
|
accessor: 'warehouse_name',
|
||||||
|
Cell: RadioFieldCell,
|
||||||
|
width: 120,
|
||||||
|
disableSortBy: true,
|
||||||
|
className: 'name',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
id: 'quantity',
|
||||||
|
Header: 'Quantity on Hand',
|
||||||
|
accessor: 'quantity',
|
||||||
|
disableSortBy: true,
|
||||||
|
align: 'right',
|
||||||
|
width: '100',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
id: 'availiable_for_sale',
|
||||||
|
Header: 'Availiable for Sale',
|
||||||
|
accessor: 'availiable_for_sale',
|
||||||
|
disableSortBy: true,
|
||||||
|
align: 'right',
|
||||||
|
width: '100',
|
||||||
|
},
|
||||||
|
],
|
||||||
|
[],
|
||||||
|
);
|
||||||
|
}
|
||||||
36
src/containers/WarehouseListPopover/index.js
Normal file
36
src/containers/WarehouseListPopover/index.js
Normal file
@@ -0,0 +1,36 @@
|
|||||||
|
import React from 'react';
|
||||||
|
import styled from 'styled-components';
|
||||||
|
import { PopoverInteractionKind, Position, Button } from '@blueprintjs/core';
|
||||||
|
import { Popover2 } from '@blueprintjs/popover2';
|
||||||
|
import WarehousesList from './WarehousesList';
|
||||||
|
import { Icon, FormattedMessage as T, ButtonLink } from 'components';
|
||||||
|
|
||||||
|
export default function IntegrateWarehouseTable() {
|
||||||
|
return (
|
||||||
|
<Popover2
|
||||||
|
minimal={true}
|
||||||
|
content={<WarehousesList />}
|
||||||
|
interactionKind={PopoverInteractionKind.CLICK}
|
||||||
|
position={Position.BOTTOM_LEFT}
|
||||||
|
modifiers={{
|
||||||
|
offset: { offset: '0, 4' },
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
<PopoverLink>→</PopoverLink>
|
||||||
|
</Popover2>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
const PopoverLink = styled.button`
|
||||||
|
border: 0;
|
||||||
|
cursor: pointer;
|
||||||
|
background: transparent;
|
||||||
|
margin-top: 18px;
|
||||||
|
padding-right: 0px;
|
||||||
|
color: #0052cc;
|
||||||
|
|
||||||
|
&:hover,
|
||||||
|
&:active {
|
||||||
|
text-decoration: underline;
|
||||||
|
}
|
||||||
|
`;
|
||||||
Reference in New Issue
Block a user