// @ts-nocheck import React, { useMemo } from 'react'; import { Button, NavbarGroup, Classes, NavbarDivider, Alignment, Popover, Menu, MenuItem, PopoverInteractionKind, Position, Intent, Switch, 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 { useRefreshCashflowTransactions } from '@/hooks/query'; import { useAccountTransactionsContext } from './AccountTransactionsProvider'; import { useMediaQuery } from '@/hooks/useMediaQuery'; import { useAppShellContext } from '@/components/AppShell/AppContentShell/AppContentShellProvider'; import withDialogActions from '@/containers/Dialog/withDialogActions'; import withSettings from '@/containers/Settings/withSettings'; import withSettingsActions from '@/containers/Settings/withSettingsActions'; import { withBankingActions } from '../withBankingActions'; import { withBanking } from '../withBanking'; import withAlertActions from '@/containers/Alert/withAlertActions'; import { useUpdateBankAccount, useExcludeUncategorizedTransactions, useUnexcludeUncategorizedTransactions, } from '@/hooks/query/bank-rules'; import { DialogsName } from '@/constants/dialogs'; import { compose } from '@/utils'; function AccountTransactionsActionsBar({ // #withDialogActions openDialog, // #withSettings cashflowTansactionsTableSize, // #withSettingsActions addSetting, // #withBanking uncategorizedTransationsIdsSelected, excludedTransactionsIdsSelected, openMatchingTransactionAside, categorizedTransactionsSelected, // #withBankingActions enableMultipleCategorization, // #withAlerts openAlert, }) { const history = useHistory(); const { accountId, currentAccount } = useAccountTransactionsContext(); // Refresh cashflow infinity transactions hook. const { refresh } = useRefreshCashflowTransactions(); 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(accountId); }; 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 multi select transactions for categorization or matching. const handleMultipleCategorizingSwitch = (event) => { enableMultipleCategorization(event.currentTarget.checked); }; // 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, }); }; // Handles uncategorize the categorized transactions in bulk. const handleUncategorizeCategorizedBulkBtnClick = () => { openAlert('uncategorize-transactions-bulk', { uncategorizeTransactionsIds: categorizedTransactionsSelected, }); }; // Handles the delete account button click. const handleDeleteAccountClick = () => { openAlert('account-delete', { accountId, }); }; const { hideAside } = useAppShellContext(); const isMin1350Query = useMediaQuery('(min-width: 1350px)'); // Shrink actions to dropdown if the aside is open and matched the media query, // To avoid actions overflow in small screens. const shrinkActions = !hideAside && !isMin1350Query; return ( } buttonProps={{ icon: , }} /> } buttonProps={{ icon: , }} />