import React, { useCallback, useMemo } from 'react'; import { Intent, Button, Popover, Menu, MenuItem, MenuDivider, Position, } from '@blueprintjs/core'; import classNames from 'classnames'; import { FormattedMessage as T, useIntl } from 'react-intl'; import moment from 'moment'; import { CLASSES } from 'common/classes'; import { compose, saveInvoke } from 'utils'; import { useIsValuePassed } from 'hooks'; import LoadingIndicator from 'components/LoadingIndicator'; import { DataTable, Money, Choose, Icon } from 'components'; import EstimatesEmptyStatus from './EstimatesEmptyStatus'; import withEstimates from './withEstimates'; import withEstimateActions from './withEstimateActions'; // Estimates transactions datatable. function EstimatesDataTable({ // #withEstimates estimatesCurrentPage, estimatesLoading, estimatesPageination, estimatesTableQuery, estimatesCurrentViewId, // #withEstimatesActions addEstimatesTableQueries, // #ownProps onEditEstimate, onDeleteEstimate, onSelectedRowsChange, }) { const { formatMessage } = useIntl(); const isLoaded = useIsValuePassed(estimatesLoading, false); const handleEditEstimate = useCallback( (estimate) => () => { saveInvoke(onEditEstimate, estimate); }, [onEditEstimate], ); const handleDeleteEstimate = useCallback( (estimate) => () => { saveInvoke(onDeleteEstimate, estimate); }, [onDeleteEstimate], ); const actionMenuList = useCallback( (estimate) => (
), [handleDeleteEstimate, handleEditEstimate, formatMessage], ); const onRowContextMenu = useCallback( (cell) => { return actionMenuList(cell.row.original); }, [actionMenuList], ); const columns = useMemo( () => [ { id: 'estimate_date', Header: formatMessage({ id: 'estimate_date' }), accessor: (r) => moment(r.estimate_date).format('YYYY MMM DD'), width: 140, className: 'estimate_date', }, { id: 'customer_id', Header: formatMessage({ id: 'customer_name' }), accessor: 'customer.display_name', width: 140, className: 'customer_id', }, { id: 'expiration_date', Header: formatMessage({ id: 'expiration_date' }), accessor: (r) => moment(r.expiration_date).format('YYYY MMM DD'), width: 140, className: 'expiration_date', }, { id: 'estimate_number', Header: formatMessage({ id: 'estimate_number' }), accessor: (row) => (row.estimate_number ? `#${row.estimate_number}` : null), width: 140, className: 'estimate_number', }, { id: 'amount', Header: formatMessage({ id: 'amount' }), accessor: (r) =>