A local-first personal finance app
Recognize HTTP GET parameters to prefill new transaction on mobile (#6050)
Benedikt Müller3be66e76834c
diff --git a/packages/desktop-client/e2e/transactions.mobile.test.ts b/packages/desktop-client/e2e/transactions.mobile.test.tsindex 376eea5644..cf64a55be9 100644--- a/packages/desktop-client/e2e/transactions.mobile.test.ts+++ b/packages/desktop-client/e2e/transactions.mobile.test.ts@@ -54,6 +54,31 @@ test.describe('Mobile Transactions', () => {await expect(page).toMatchThemeScreenshots();});+ test('prefills a new transaction with URL search params', async () => {+ const transactionEntryPage = await navigation.goToTransactionEntryPage();+ await page.goto(+ transactionEntryPage.page.url() ++ '?category=Food&amount=23.42&account=HSBC&date=2025-10-31&cleared=true&payee=Kroger¬es=just+a+note',+ );+ // Note: no easy way to test cleared checkbox+ await expect(page.getByTestId('transaction-form'))+ .toMatchAriaSnapshot(`- text: Amount+- textbox+- text: 23.42 Payee+- button "Kroger" [disabled]+- text: Category+- button "Food" [disabled]+- button "Split" [disabled]:+ - img+ - text: Split+- text: Account+- button "HSBC" [disabled]+- text: Date+- textbox [disabled]: 2025-10-31+- text: Cleared Notes+- textbox [disabled]: just a note`);+ });+test('creates a transaction from `/accounts/:id` page', async () => {const accountsPage = await navigation.goToAccountsPage();const accountPage = await accountsPage.openNthAccount(2);diff --git a/packages/desktop-client/src/components/mobile/transactions/TransactionEdit.tsx b/packages/desktop-client/src/components/mobile/transactions/TransactionEdit.tsxindex 627da2f59e..b8e80f0672 100644--- a/packages/desktop-client/src/components/mobile/transactions/TransactionEdit.tsx+++ b/packages/desktop-client/src/components/mobile/transactions/TransactionEdit.tsx@@ -8,7 +8,7 @@ import React, {useCallback,} from 'react';import { Trans, useTranslation } from 'react-i18next';-import { useLocation, useParams } from 'react-router';+import { useLocation, useParams, useSearchParams } from 'react-router';import { Button } from '@actual-app/components/button';import { SvgSplit } from '@actual-app/components/icons/v0';@@ -1271,23 +1271,6 @@ function isTemporary(transaction: TransactionEntity) {return transaction.id.indexOf('temp') === 0;}-function makeTemporaryTransactions(- accountId: AccountEntity['id'],- categoryId: CategoryEntity['id'],- lastDate?: string,-) {- return [- {- id: 'temp',- date: lastDate || monthUtils.currentDay(),- account: accountId,- category: categoryId,- amount: 0,- cleared: false,- },- ];-}-type TransactionEditUnconnectedProps = {categories: CategoryEntity[];accounts: AccountEntity[];@@ -1305,6 +1288,7 @@ function TransactionEditUnconnected({}: TransactionEditUnconnectedProps) {const { transactionId } = useParams();const { state: locationState } = useLocation();+ const [searchParams] = useSearchParams();const dispatch = useDispatch();const [transactions, setTransactions] = useState<TransactionEntity[]>([]);const [fetchedTransactions, setFetchedTransactions] = useState<@@ -1313,6 +1297,19 @@ function TransactionEditUnconnected({const isAdding = useRef(false);const isDeleted = useRef(false);+ const searchParamCategory = useMemo(+ () => categories.find(c => c.name === searchParams.get('category'))?.id,+ [categories, searchParams],+ );+ const searchParamAccount = useMemo(+ () => accounts.find(a => a.name === searchParams.get('account'))?.id,+ [accounts, searchParams],+ );+ const searchParamPayee = useMemo(+ () => payees.find(p => p.name === searchParams.get('payee'))?.id,+ [payees, searchParams],+ );+useEffect(() => {let unmounted = false;@@ -1352,15 +1349,40 @@ function TransactionEditUnconnected({useEffect(() => {if (isAdding.current) {- setTransactions(- makeTemporaryTransactions(- locationState?.accountId || lastTransaction?.account || null,- locationState?.categoryId || null,- lastTransaction?.date,- ),- );+ setTransactions([+ {+ id: 'temp',+ date: (() => {+ const dateParam = searchParams.get('date') || '';+ if (!isNaN(Date.parse(dateParam))) {+ return dateParam;+ }+ return lastTransaction?.date || monthUtils.currentDay();+ })(),+ payee: searchParamPayee,+ account:+ searchParamAccount ||+ locationState?.accountId ||+ lastTransaction?.account ||+ null,+ category: searchParamCategory || locationState?.categoryId || null,+ amount: -amountToInteger(+ parseFloat(searchParams.get('amount') || '') || 0,+ ),+ cleared: searchParams.get('cleared') === 'true',+ notes: searchParams.get('notes') || '',+ },+ ]);}- }, [locationState?.accountId, locationState?.categoryId, lastTransaction]);+ }, [+ locationState?.accountId,+ locationState?.categoryId,+ lastTransaction,+ searchParamAccount,+ searchParamCategory,+ searchParamPayee,+ searchParams,+ ]);const onUpdate = useCallback(async (diff --git a/upcoming-release-notes/6050.md b/upcoming-release-notes/6050.mdnew file mode 100644index 0000000000..bc3b956ae8--- /dev/null+++ b/upcoming-release-notes/6050.md@@ -0,0 +1,6 @@+---+category: Features+authors: [diktomat]+---++Allow prefilling input fields on mobile new transaction page via HTTP GET parameters