A local-first personal finance app
Allow marking transactions as Transfers on mobile devices (#4511)
Luke98e4ece50adc
diff --git a/packages/desktop-client/src/components/accounts/Account.tsx b/packages/desktop-client/src/components/accounts/Account.tsxindex 4a66bb1d05..cb291091ac 100644--- a/packages/desktop-client/src/components/accounts/Account.tsx+++ b/packages/desktop-client/src/components/accounts/Account.tsx@@ -45,7 +45,6 @@ import {type PagedQuery,} from 'loot-core/client/query-helpers';import { type AppDispatch } from 'loot-core/client/store';-import { validForTransfer } from 'loot-core/client/transfer';import { send, listen } from 'loot-core/platform/client/fetch';import * as undo from 'loot-core/platform/client/undo';import { type UndoState } from 'loot-core/server/undo';@@ -308,6 +307,7 @@ type AccountInternalProps = {hideFraction: boolean;accountsSyncing: string[];dispatch: AppDispatch;+ onSetTransfer: ReturnType<typeof useTransactionBatchActions>['onSetTransfer'];};type AccountInternalState = {search: string;@@ -1350,49 +1350,11 @@ class AccountInternal extends PureComponent<};onSetTransfer = async (ids: string[]) => {- const onConfirmTransfer = async (ids: string[]) => {- this.setState({ workingHard: true });-- const payees = this.props.payees;-- const { data: transactions } = await runQuery(- q('transactions')- .filter({ id: { $oneof: ids } })- .select('*'),- );- const [fromTrans, toTrans] = transactions;-- if (transactions.length === 2 && validForTransfer(fromTrans, toTrans)) {- const fromPayee = payees.find(- p => p.transfer_acct === fromTrans.account,- );- const toPayee = payees.find(p => p.transfer_acct === toTrans.account);-- const changes = {- updated: [- {- ...fromTrans,- payee: toPayee?.id,- transfer_id: toTrans.id,- },- {- ...toTrans,- payee: fromPayee?.id,- transfer_id: fromTrans.id,- },- ],- };-- await send('transactions-batch-update', changes);- }-- await this.refetchTransactions();- };-- await this.checkForReconciledTransactions(+ this.setState({ workingHard: true });+ await this.props.onSetTransfer(ids,- 'batchEditWithReconciled',- onConfirmTransfer,+ this.props.payees,+ this.refetchTransactions,);};@@ -1937,6 +1899,7 @@ type AccountHackProps = Omit<| 'onBatchLinkSchedule'| 'onBatchUnlinkSchedule'| 'onBatchDelete'+ | 'onSetTransfer'>;function AccountHack(props: AccountHackProps) {@@ -1948,6 +1911,7 @@ function AccountHack(props: AccountHackProps) {onBatchLinkSchedule,onBatchUnlinkSchedule,onBatchDelete,+ onSetTransfer,} = useTransactionBatchActions();return (@@ -1959,6 +1923,7 @@ function AccountHack(props: AccountHackProps) {onBatchLinkSchedule={onBatchLinkSchedule}onBatchUnlinkSchedule={onBatchUnlinkSchedule}onBatchDelete={onBatchDelete}+ onSetTransfer={onSetTransfer}{...props}/>);diff --git a/packages/desktop-client/src/components/mobile/accounts/AccountTransactions.tsx b/packages/desktop-client/src/components/mobile/accounts/AccountTransactions.tsxindex 9dfd826afb..c28ebc0032 100644--- a/packages/desktop-client/src/components/mobile/accounts/AccountTransactions.tsx+++ b/packages/desktop-client/src/components/mobile/accounts/AccountTransactions.tsx@@ -347,6 +347,7 @@ function TransactionListWithPreviews({onSearch={onSearch}onOpenTransaction={onOpenTransaction}onRefresh={onRefresh}+ account={account}/>);}diff --git a/packages/desktop-client/src/components/mobile/budget/CategoryTransactions.tsx b/packages/desktop-client/src/components/mobile/budget/CategoryTransactions.tsxindex 9427fd9fd8..dac9bb132a 100644--- a/packages/desktop-client/src/components/mobile/budget/CategoryTransactions.tsx+++ b/packages/desktop-client/src/components/mobile/budget/CategoryTransactions.tsx@@ -128,6 +128,7 @@ export function CategoryTransactions({onLoadMore={loadMoreTransactions}onOpenTransaction={onOpenTransaction}onRefresh={undefined}+ account={undefined}/></SchedulesProvider></Page>diff --git a/packages/desktop-client/src/components/mobile/transactions/TransactionList.tsx b/packages/desktop-client/src/components/mobile/transactions/TransactionList.tsxindex 2fe59e36af..28ee59a84b 100644--- a/packages/desktop-client/src/components/mobile/transactions/TransactionList.tsx+++ b/packages/desktop-client/src/components/mobile/transactions/TransactionList.tsx@@ -10,16 +10,22 @@ import { ListBox, Section, Header, Collection } from 'react-aria-components';import { Trans, useTranslation } from 'react-i18next';import { Button } from '@actual-app/components/button';-import { Menu, type MenuItemObject } from '@actual-app/components/menu';+import {+ Menu,+ type MenuItem,+ type MenuItemObject,+} from '@actual-app/components/menu';import { Popover } from '@actual-app/components/popover';import { styles } from '@actual-app/components/styles';import { Text } from '@actual-app/components/text';import { View } from '@actual-app/components/view';import { setNotificationInset } from 'loot-core/client/actions';+import { validForTransfer } from 'loot-core/client/transfer';import * as monthUtils from 'loot-core/shared/months';import { isPreviewId } from 'loot-core/shared/transactions';import { groupById, integerToCurrency } from 'loot-core/shared/util';+import { type AccountEntity } from 'loot-core/types/models';import { type TransactionEntity } from 'loot-core/types/models/transaction';import { useAccounts } from '../../../hooks/useAccounts';@@ -72,6 +78,7 @@ type TransactionListProps = {onOpenTransaction?: (transaction: TransactionEntity) => void;isLoadingMore: boolean;onLoadMore: () => void;+ account?: AccountEntity;};export function TransactionList({@@ -80,6 +87,7 @@ export function TransactionList({onOpenTransaction,isLoadingMore,onLoadMore,+ account,}: TransactionListProps) {const { t } = useTranslation();const sections = useMemo(() => {@@ -205,7 +213,10 @@ export function TransactionList({)}{selectedTransactions.size > 0 && (- <SelectedTransactionsFloatingActionBar transactions={transactions} />+ <SelectedTransactionsFloatingActionBar+ transactions={transactions}+ showMakeTransfer={!account}+ />)}</>);@@ -214,12 +225,15 @@ export function TransactionList({type SelectedTransactionsFloatingActionBarProps = {transactions: readonly TransactionEntity[];style?: CSSProperties;+ showMakeTransfer: boolean;};function SelectedTransactionsFloatingActionBar({transactions,style = {},+ showMakeTransfer,}: SelectedTransactionsFloatingActionBarProps) {+ const { t } = useTranslation();const editMenuTriggerRef = useRef(null);const [isEditMenuOpen, setIsEditMenuOpen] = useState(false);const moreOptionsMenuTriggerRef = useRef(null);@@ -228,6 +242,7 @@ function SelectedTransactionsFloatingActionBar({<T extends string>(item: MenuItemObject<T>) => ({...styles.mobileMenuItem,color: theme.mobileHeaderText,+ ...(item.disabled === true && { color: theme.buttonBareDisabledText }),...(item.name === 'delete' && { color: theme.errorTextMenu }),}),[],@@ -268,6 +283,7 @@ function SelectedTransactionsFloatingActionBar({onBatchDelete,onBatchLinkSchedule,onBatchUnlinkSchedule,+ onSetTransfer,} = useTransactionBatchActions();const navigate = useNavigate();@@ -288,6 +304,51 @@ function SelectedTransactionsFloatingActionBar({};}, [dispatch]);+ const canBeTransfer = useMemo(() => {+ // only two selected+ if (selectedTransactionsArray.length !== 2) {+ return false;+ }+ const fromTrans = transactions.find(+ t => t.id === selectedTransactionsArray[0],+ );+ const toTrans = transactions.find(+ t => t.id === selectedTransactionsArray[1],+ );++ // previously selected transactions aren't always present in current transaction list+ if (!fromTrans || !toTrans) {+ return false;+ }++ return validForTransfer(fromTrans, toTrans);+ }, [selectedTransactionsArray, transactions]);++ const moreOptionsMenuItems: MenuItem<string>[] = [+ {+ name: 'duplicate',+ text: t('Duplicate'),+ },+ {+ name: allTransactionsAreLinked ? 'unlink-schedule' : 'link-schedule',+ text: allTransactionsAreLinked+ ? t('Unlink schedule')+ : t('Link schedule'),+ },+ {+ name: 'delete',+ text: t('Delete'),+ },+ ];++ if (showMakeTransfer) {+ moreOptionsMenuItems.splice(2, 0, {+ name: 'transfer',+ text: t('Make transfer'),+ disabled: !canBeTransfer,+ });+ }+return (<FloatingActionBar style={style}><View@@ -334,13 +395,13 @@ function SelectedTransactionsFloatingActionBar({<Buttonvariant="bare"ref={editMenuTriggerRef}- aria-label="Edit fields"+ aria-label={t('Edit fields')}onPress={() => {setIsEditMenuOpen(true);}}{...buttonProps}>- Edit+ <Trans>Edit</Trans></Button><Popover@@ -357,7 +418,7 @@ function SelectedTransactionsFloatingActionBar({name,ids: selectedTransactionsArray,onSuccess: (ids, name, value, mode) => {- let displayValue = value;+ let displayValue;switch (name) {case 'account':displayValue =@@ -417,19 +478,19 @@ function SelectedTransactionsFloatingActionBar({// },{name: 'account',- text: 'Account',+ text: t('Account'),},{name: 'payee',- text: 'Payee',+ text: t('Payee'),},{name: 'notes',- text: 'Notes',+ text: t('Notes'),},{name: 'category',- text: 'Category',+ text: t('Category'),},// Add support later on until we have more user friendly amount input modal.// {@@ -438,7 +499,7 @@ function SelectedTransactionsFloatingActionBar({// },{name: 'cleared',- text: 'Cleared',+ text: t('Cleared'),},]}/>@@ -447,7 +508,7 @@ function SelectedTransactionsFloatingActionBar({<Buttonvariant="bare"ref={moreOptionsMenuTriggerRef}- aria-label="More options"+ aria-label={t('More options')}onPress={() => {setIsMoreOptionsMenuOpen(true);}}@@ -475,7 +536,10 @@ function SelectedTransactionsFloatingActionBar({ids: selectedTransactionsArray,onSuccess: ids => {showUndoNotification({- message: `Successfully duplicated ${ids.length} transaction${ids.length > 1 ? 's' : ''}.`,+ message: t(+ 'Successfully duplicated {{count}} transactions.',+ { count: ids.length },+ ),});},});@@ -486,7 +550,10 @@ function SelectedTransactionsFloatingActionBar({// TODO: When schedule becomes available in mobile, update undo notification message// with `messageActions` to open the schedule when the schedule name is clicked.showUndoNotification({- message: `Successfully linked ${ids.length} transaction${ids.length > 1 ? 's' : ''} to ${schedule.name}.`,+ message: t(+ 'Successfully linked {{count}} transactions to {{schedule}}.',+ { count: ids.length, schedule: schedule.name },+ ),});},});@@ -495,7 +562,10 @@ function SelectedTransactionsFloatingActionBar({ids: selectedTransactionsArray,onSuccess: ids => {showUndoNotification({- message: `Successfully unlinked ${ids.length} transaction${ids.length > 1 ? 's' : ''} from their respective schedules.`,+ message: t(+ 'Successfully unlinked {{count}} transactions from their respective schedules.',+ { count: ids.length },+ ),});},});@@ -505,36 +575,28 @@ function SelectedTransactionsFloatingActionBar({onSuccess: ids => {showUndoNotification({type: 'warning',- message: `Successfully deleted ${ids.length} transaction${ids.length > 1 ? 's' : ''}.`,+ message: t(+ 'Successfully deleted {{count}} transactions.',+ { count: ids.length },+ ),});},});+ } else if (type === 'transfer') {+ onSetTransfer?.(selectedTransactionsArray, payees, ids =>+ showUndoNotification({+ message: t(+ 'Successfully marked {{count}} transactions as transfer.',+ {+ count: ids.length,+ },+ ),+ }),+ );}setIsMoreOptionsMenuOpen(false);}}- items={[- {- name: 'duplicate',- text: 'Duplicate',- },- ...(allTransactionsAreLinked- ? [- {- name: 'unlink-schedule',- text: 'Unlink schedule',- },- ]- : [- {- name: 'link-schedule',- text: 'Link schedule',- },- ]),- {- name: 'delete',- text: 'Delete',- },- ]}+ items={moreOptionsMenuItems}/></Popover></View>diff --git a/packages/desktop-client/src/components/mobile/transactions/TransactionListWithBalances.tsx b/packages/desktop-client/src/components/mobile/transactions/TransactionListWithBalances.tsxindex a8da911d1d..4dde239df0 100644--- a/packages/desktop-client/src/components/mobile/transactions/TransactionListWithBalances.tsx+++ b/packages/desktop-client/src/components/mobile/transactions/TransactionListWithBalances.tsx@@ -5,6 +5,7 @@ import { Label } from '@actual-app/components/label';import { styles } from '@actual-app/components/styles';import { View } from '@actual-app/components/view';+import { type AccountEntity } from 'loot-core/types/models';import { type TransactionEntity } from 'loot-core/types/models/transaction';import { SelectedProvider, useSelected } from '../../../hooks/useSelected';@@ -91,6 +92,7 @@ type TransactionListWithBalancesProps = {onLoadMore: () => void;onOpenTransaction: (transaction: TransactionEntity) => void;onRefresh?: () => void;+ account?: AccountEntity;};export function TransactionListWithBalances({@@ -105,6 +107,7 @@ export function TransactionListWithBalances({onLoadMore,onOpenTransaction,onRefresh,+ account,}: TransactionListWithBalancesProps) {const selectedInst = useSelected('transactions', [...transactions], []);@@ -148,6 +151,7 @@ export function TransactionListWithBalances({isLoadingMore={isLoadingMore}onLoadMore={onLoadMore}onOpenTransaction={onOpenTransaction}+ account={account}/></PullToRefresh></>diff --git a/packages/desktop-client/src/components/reports/reports/Calendar.tsx b/packages/desktop-client/src/components/reports/reports/Calendar.tsxindex a5bcc5d2e2..ea5483fe15 100644--- a/packages/desktop-client/src/components/reports/reports/Calendar.tsx+++ b/packages/desktop-client/src/components/reports/reports/Calendar.tsx@@ -695,6 +695,7 @@ function CalendarInner({ widget, parameters }: CalendarInnerProps) {transactions={allTransactions}onOpenTransaction={onOpenTransaction}isLoadingMore={false}+ account={undefined}/></View></animated.div>diff --git a/packages/desktop-client/src/hooks/useTransactionBatchActions.ts b/packages/desktop-client/src/hooks/useTransactionBatchActions.tsindex ff4f366751..e78a12a4f4 100644--- a/packages/desktop-client/src/hooks/useTransactionBatchActions.ts+++ b/packages/desktop-client/src/hooks/useTransactionBatchActions.ts@@ -1,5 +1,6 @@import { pushModal } from 'loot-core/client/actions';import { runQuery } from 'loot-core/client/query-helpers';+import { validForTransfer } from 'loot-core/client/transfer';import { send } from 'loot-core/platform/client/fetch';import * as monthUtils from 'loot-core/shared/months';import { q } from 'loot-core/shared/query';@@ -12,6 +13,7 @@ import {} from 'loot-core/shared/transactions';import { applyChanges, type Diff } from 'loot-core/shared/util';import {+ type PayeeEntity,type AccountEntity,type ScheduleEntity,type TransactionEntity,@@ -408,11 +410,59 @@ export function useTransactionBatchActions() {}};+ const onSetTransfer = async (+ ids: string[],+ payees: PayeeEntity[],+ onSuccess: (ids: string[]) => void,+ ) => {+ const onConfirmTransfer = async (ids: string[]) => {+ const { data: transactions } = await runQuery(+ q('transactions')+ .filter({ id: { $oneof: ids } })+ .select('*'),+ );+ const [fromTrans, toTrans] = transactions;++ if (transactions.length === 2 && validForTransfer(fromTrans, toTrans)) {+ const fromPayee = payees.find(+ p => p.transfer_acct === fromTrans.account,+ );+ const toPayee = payees.find(p => p.transfer_acct === toTrans.account);++ const changes = {+ updated: [+ {+ ...fromTrans,+ payee: toPayee?.id,+ transfer_id: toTrans.id,+ },+ {+ ...toTrans,+ payee: fromPayee?.id,+ transfer_id: fromTrans.id,+ },+ ],+ };++ await send('transactions-batch-update', changes);+ }++ onSuccess?.(ids);+ };++ await checkForReconciledTransactions(+ ids,+ 'batchEditWithReconciled',+ onConfirmTransfer,+ );+ };+return {onBatchEdit,onBatchDuplicate,onBatchDelete,onBatchLinkSchedule,onBatchUnlinkSchedule,+ onSetTransfer,};}diff --git a/upcoming-release-notes/4511.md b/upcoming-release-notes/4511.mdnew file mode 100644index 0000000000..ae3ce9f8d1--- /dev/null+++ b/upcoming-release-notes/4511.md@@ -0,0 +1,6 @@+---+category: Enhancements+authors: [rugulous, tempiz]+---++Allow marking transactions as Transfers on mobile/small screen devices