import React, { useEffect, useCallback, useState, useMemo } from 'react'; import { Button, Popover, Menu, MenuItem, MenuDivider, Position, Classes, Tooltip, } from '@blueprintjs/core'; import { useParams } from 'react-router-dom'; import Icon from 'components/Icon'; import { compose } from 'utils'; import AccountsConnect from 'connectors/Accounts.connector'; import DialogConnect from 'connectors/Dialog.connector'; import DashboardConnect from 'connectors/Dashboard.connector'; import ViewConnect from 'connectors/View.connector'; import LoadingIndicator from 'components/LoadingIndicator'; import DataTable from 'components/DataTable'; import Money from 'components/Money'; import { useUpdateEffect } from 'hooks'; function AccountsDataTable({ loading, accounts, onDeleteAccount, onInactiveAccount, openDialog, changeCurrentView, changePageSubtitle, getViewItem, setTopbarEditView, accountsLoading, onFetchData, onSelectedRowsChange }) { const [initialMount, setInitialMount] = useState(false); 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) => ( handleNewParentAccount(account)} /> onInactiveAccount(account)} /> onDeleteAccount(account)} /> ), [handleEditAccount, onDeleteAccount, onInactiveAccount]); const columns = useMemo(() => [ { id: 'name', Header: 'Account Name', accessor: row => { return (row.description) ? ( { row.name } ) : row.name; }, className: 'account_name', width: 300, }, { id: 'code', Header: 'Code', accessor: 'code', className: 'code', width: 100, }, { id: 'type', Header: 'Type', accessor: 'type.name', className: 'type', width: 120, }, { id: 'normal', Header: 'Normal', Cell: ({ cell }) => { const account = cell.row.original; const type = account.type ? account.type.normal : ''; const arrowDirection = type === 'credit' ? 'down' : 'up'; return (); }, className: 'normal', width: 75, }, { id: 'balance', Header: 'Balance', Cell: ({ cell }) => { const account = cell.row.original; const {balance = null} = account; return (balance) ? ( ) : (--); }, width: 150, }, { id: 'actions', Header: '', Cell: ({ cell }) => (