import React from 'react';
import {
Menu,
MenuDivider,
MenuItem,
Intent,
Tag,
Position,
Button,
Popover,
} from '@blueprintjs/core';
import { useIntl, FormattedMessage as T } from 'react-intl';
import { formatMessage } from 'services/intl';
import { isNumber } from 'lodash';
import { Icon, Money, If } from 'components';
import { isBlank, safeCallback } from 'utils';
/**
* Publish accessor
*/
export const PublishAccessor = (r) => {
return r.is_published ? (
) : (
);
};
export const TypeAccessor = (row) => {
return row.type ? (
{formatMessage({ id: row.type })}
) : (
''
);
};
export const ItemCodeAccessor = (row) =>
row.type ? (
{formatMessage({ id: 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 ? (
{formatMessage({ id: row.type })}
) : null;
};
export function ItemsActionMenuList({
row: { original },
payload: {
onEditItem,
onInactivateItem,
onActivateItem,
onMakeAdjustment,
onDeleteItem,
onDuplicate,
},
}) {
const { formatMessage } = useIntl();
return (
);
}
export const ItemsActionsTableCell = (props) => {
return (
}
>
} />
);
};
/**
* Retrieve all items table columns.
*/
export const useItemsTableColumns = () => {
const { formatMessage } = useIntl();
return React.useMemo(
() => [
{
id: 'name',
Header: formatMessage({ id: 'item_name' }),
accessor: 'name',
className: 'name',
width: 180,
},
{
id: 'code',
Header: formatMessage({ id: 'item_code' }),
accessor: 'code',
className: 'code',
width: 120,
},
{
id: 'type',
Header: formatMessage({ id: 'item_type' }),
accessor: ItemTypeAccessor,
className: 'item_type',
width: 120,
},
{
id: 'category',
Header: formatMessage({ id: 'category' }),
accessor: 'category.name',
className: 'category',
width: 150,
},
{
id: 'sell_price',
Header: formatMessage({ id: 'sell_price' }),
// Cell: SellPriceCell,
accessor: 'sell_price_formatted',
className: 'sell-price',
width: 150,
},
{
id: 'cost_price',
Header: formatMessage({ id: 'cost_price' }),
// Cell: CostPriceCell,
accessor: 'cost_price_formatted',
className: 'cost-price',
width: 150,
},
{
id: 'quantity_on_hand',
Header: formatMessage({ id: 'quantity_on_hand' }),
accessor: 'quantity_on_hand',
Cell: QuantityOnHandCell,
width: 140,
},
{
id: 'actions',
Cell: ItemsActionsTableCell,
width: 60,
skeletonWidthMin: 100,
},
],
[formatMessage],
);
};