import React, {useCallback, useState, useMemo } from 'react'; import { Button, Popover, Menu, MenuItem, MenuDivider, Position, Classes, Tooltip, } from '@blueprintjs/core'; import { FormattedMessage as T, useIntl } from 'react-intl'; import Icon from 'components/Icon'; import { compose } from 'utils'; import DialogConnect from 'connectors/Dialog.connector'; import LoadingIndicator from 'components/LoadingIndicator'; import DataTable from 'components/DataTable'; import Money from 'components/Money'; import { useUpdateEffect } from 'hooks'; import withDashboardActions from 'containers/Dashboard/withDashboardActions'; import withAccountsActions from 'containers/Accounts/withAccountsActions'; import withAccounts from 'containers/Accounts/withAccounts'; import { If } from 'components'; function AccountsDataTable({ // #withDashboardActions accounts, accountsLoading, // #withDialog. openDialog, // own properties loading, onFetchData, onSelectedRowsChange, onDeleteAccount, onInactiveAccount, onActivateAccount, }) { const [initialMount, setInitialMount] = useState(false); const { formatMessage } = useIntl(); useUpdateEffect(() => { if (!accountsLoading) { setInitialMount(true); } }, [accountsLoading, setInitialMount]); const handleEditAccount = useCallback((account) => () => { openDialog('account-form', { action: 'edit', id: account.id }); }, [openDialog]); const handleNewParentAccount = useCallback((account) => { openDialog('account-form', { action: 'new_child', id: account.id }); }, [openDialog]); const actionMenuList = useCallback((account) => ( } /> } onClick={handleEditAccount(account)} /> } onClick={() => handleNewParentAccount(account)} /> } onClick={() => onInactiveAccount(account)} /> } onClick={() => onActivateAccount(account)} /> } onClick={() => onDeleteAccount(account)} /> ), [handleEditAccount, onDeleteAccount, onInactiveAccount,handleNewParentAccount]); const columns = useMemo(() => [ { id: 'name', Header: formatMessage({id:'account_name'}), accessor: row => { return (row.description) ? ( { row.name } ) : row.name; }, className: 'account_name', width: 300, }, { id: 'code', Header: formatMessage({id:'code'}), accessor: 'code', className: 'code', width: 100, }, { id: 'type', Header: formatMessage({id:'type'}), accessor: 'type.name', className: 'type', width: 120, }, { id: 'normal', Header: formatMessage({id:'normal'}), Cell: ({ cell }) => { const account = cell.row.original; const normal = account.type ? account.type.normal : ''; const arrowDirection = normal === 'credit' ? 'down' : 'up'; return ( ); }, className: 'normal', width: 75, }, { id: 'balance', Header: formatMessage({id:'balance'}), Cell: ({ cell }) => { const account = cell.row.original; const {balance = null} = account; return (balance) ? ( ) : (--); }, width: 150, }, { id: 'actions', Header: '', Cell: ({ cell }) => (