// @ts-nocheck import React, { useMemo } from 'react'; import { Button, NavbarGroup, Classes, NavbarDivider, Alignment, Popover, Menu, MenuItem, PopoverInteractionKind, Position, Intent, Tooltip, MenuDivider, } from '@blueprintjs/core'; import { useHistory } from 'react-router-dom'; import { isEmpty } from 'lodash'; import { Icon, DashboardActionsBar, DashboardRowsHeightButton, FormattedMessage as T, AppToaster, If, } from '@/components'; import { CashFlowMenuItems } from './utils'; import { getAddMoneyOutOptions, getAddMoneyInOptions, } from '@/constants/cashflowOptions'; import { useRefreshCashflowTransactionsInfinity } from '@/hooks/query'; import { useAccountTransactionsContext } from './AccountTransactionsProvider'; import withDialogActions from '@/containers/Dialog/withDialogActions'; import withSettings from '@/containers/Settings/withSettings'; import withSettingsActions from '@/containers/Settings/withSettingsActions'; import { compose } from '@/utils'; import { useUpdateBankAccount, useExcludeUncategorizedTransactions, useUnexcludeUncategorizedTransactions, } from '@/hooks/query/bank-rules'; import { withBanking } from '../withBanking'; import withAlertActions from '@/containers/Alert/withAlertActions'; import { DialogsName } from '@/constants/dialogs'; function AccountTransactionsActionsBar({ // #withDialogActions openDialog, // #withSettings cashflowTansactionsTableSize, // #withSettingsActions addSetting, // #withBanking uncategorizedTransationsIdsSelected, excludedTransactionsIdsSelected, // #withAlerts openAlert, }) { const history = useHistory(); const { accountId, currentAccount } = useAccountTransactionsContext(); // Refresh cashflow infinity transactions hook. const { refresh } = useRefreshCashflowTransactionsInfinity(); const { mutateAsync: updateBankAccount } = useUpdateBankAccount(); // Retrieves the money in/out buttons options. const addMoneyInOptions = useMemo(() => getAddMoneyInOptions(), []); const addMoneyOutOptions = useMemo(() => getAddMoneyOutOptions(), []); const isFeedsActive = !!currentAccount.is_feeds_active; const isFeedsPaused = currentAccount.is_feeds_paused; const isSyncingOwner = currentAccount.is_syncing_owner; // Handle table row size change. const handleTableRowSizeChange = (size) => { addSetting('cashflowTransactions', 'tableSize', size); }; // Handle money in form const handleMoneyInFormTransaction = (account) => { openDialog('money-in', { account_id: accountId, account_type: account.value, account_name: account.name, }); }; // Handle money out form const handlMoneyOutFormTransaction = (account) => { openDialog('money-out', { account_id: accountId, account_type: account.value, account_name: account.name, }); }; // Handle import button click. const handleImportBtnClick = () => { history.push(`/cashflow-accounts/${accountId}/import`); }; // Handle bank rules click. const handleBankRulesClick = () => { history.push(`/bank-rules?accountId=${accountId}`); }; // Handles the bank account disconnect click. const handleDisconnectClick = () => { openDialog(DialogsName.DisconnectBankAccountConfirmation, { bankAccountId: accountId, }); }; // handles the bank update button click. const handleBankUpdateClick = () => { updateBankAccount({ bankAccountId: accountId }) .then(() => { AppToaster.show({ message: 'The transactions of the bank account has been updated.', intent: Intent.SUCCESS, }); }) .catch(() => { AppToaster.show({ message: 'Something went wrong.', intent: Intent.DANGER, }); }); }; // Handle the refresh button click. const handleRefreshBtnClick = () => { refresh(); }; const { mutateAsync: excludeUncategorizedTransactions, isLoading: isExcludingLoading, } = useExcludeUncategorizedTransactions(); const { mutateAsync: unexcludeUncategorizedTransactions, isLoading: isUnexcludingLoading, } = useUnexcludeUncategorizedTransactions(); // Handles the exclude uncategorized transactions in bulk. const handleExcludeUncategorizedBtnClick = () => { excludeUncategorizedTransactions({ ids: uncategorizedTransationsIdsSelected, }) .then(() => { AppToaster.show({ message: 'The selected transactions have been excluded.', intent: Intent.SUCCESS, }); }) .catch(() => { AppToaster.show({ message: 'Something went wrong', intent: Intent.DANGER, }); }); }; // Handles the unexclude categorized button click. const handleUnexcludeUncategorizedBtnClick = () => { unexcludeUncategorizedTransactions({ ids: excludedTransactionsIdsSelected, }) .then(() => { AppToaster.show({ message: 'The selected excluded transactions have been unexcluded.', intent: Intent.SUCCESS, }); }) .catch((error) => { AppToaster.show({ message: 'Something went wrong', intent: Intent.DANGER, }); }); }; // Handle resume bank feeds syncing. const handleResumeFeedsSyncing = () => { openAlert('resume-feeds-syncing-bank-accounnt', { bankAccountId: accountId, }); }; // Handles pause bank feeds syncing. const handlePauseFeedsSyncing = () => { openAlert('pause-feeds-syncing-bank-accounnt', { bankAccountId: accountId, }); }; return ( } buttonProps={{ icon: , }} /> } buttonProps={{ icon: , }} />