import React from 'react';
import {
Menu,
MenuDivider,
MenuItem,
Intent,
Tag,
Position,
Button,
Popover,
} from '@blueprintjs/core';
import intl from 'react-intl-universal';
import { isNumber } from 'lodash';
import { FormattedMessage as T, Icon, Money, If, Can } from 'components';
import { isBlank, safeCallback } from 'utils';
import {
AbilitySubject,
Item_Abilities,
Inventory_Adjustment_Abilities,
} from '../../common/abilityOption';
/**
* Publish accessor
*/
export const PublishAccessor = (r) => {
return r.is_published ? (
) : (
);
};
export const TypeAccessor = (row) => {
return row.type ? (
{intl.get(row.type)}
) : (
''
);
};
export const ItemCodeAccessor = (row) =>
row.type ? (
{intl.get(row.type)}
) : (
''
);
export const QuantityOnHandCell = ({ cell: { value } }) => {
return isNumber(value) ? (
{value}
) : null;
};
export const CostPriceCell = ({ cell: { value } }) => {
return !isBlank(value) ? : null;
};
export const SellPriceCell = ({ cell: { value } }) => {
return !isBlank(value) ? : null;
};
export const ItemTypeAccessor = (row) => {
return row.type ? (
{intl.get(row.type)}
) : null;
};
export function ItemsActionMenuList({
row: { original },
payload: {
onEditItem,
onInactivateItem,
onActivateItem,
onMakeAdjustment,
onDeleteItem,
onDuplicate,
onViewDetails,
},
}) {
return (
);
}
export const ItemsActionsTableCell = (props) => {
return (
}
>
} />
);
};
/**
* Retrieve all items table columns.
*/
export const useItemsTableColumns = () => {
return React.useMemo(
() => [
{
id: 'name',
Header: intl.get('item_name'),
accessor: 'name',
className: 'name',
width: 180,
clickable: true,
textOverview: true,
},
{
id: 'code',
Header: intl.get('item_code'),
accessor: 'code',
className: 'code',
width: 120,
clickable: true,
},
{
id: 'type',
Header: intl.get('item_type'),
accessor: ItemTypeAccessor,
className: 'item_type',
width: 120,
clickable: true,
},
{
id: 'category',
Header: intl.get('category'),
accessor: 'category.name',
className: 'category',
width: 150,
clickable: true,
textOverview: true,
},
{
id: 'sell_price',
Header: intl.get('sell_price'),
accessor: 'sell_price_formatted',
align: 'right',
width: 150,
clickable: true,
},
{
id: 'cost_price',
Header: intl.get('cost_price'),
accessor: 'cost_price_formatted',
align: 'right',
width: 150,
clickable: true,
},
{
id: 'quantity_on_hand',
Header: intl.get('quantity_on_hand'),
accessor: 'quantity_on_hand',
Cell: QuantityOnHandCell,
align: 'right',
width: 140,
clickable: true,
},
],
[],
);
};