Skip to content

A local-first personal finance app

Add mobile schedules pages (#6158)

Matiss Janis Aboltinsb7fa1df20cfc
diff --git a/packages/desktop-client/e2e/page-models/mobile-navigation.ts b/packages/desktop-client/e2e/page-models/mobile-navigation.ts
index dcda9d9d73..d6c5c9a83c 100644
--- a/packages/desktop-client/e2e/page-models/mobile-navigation.ts
+++ b/packages/desktop-client/e2e/page-models/mobile-navigation.ts
@@ -7,6 +7,7 @@ import { MobileBudgetPage } from './mobile-budget-page';
import { MobilePayeesPage } from './mobile-payees-page';
import { MobileReportsPage } from './mobile-reports-page';
import { MobileRulesPage } from './mobile-rules-page';
+import { MobileSchedulesPage } from './mobile-schedules-page';
import { MobileTransactionEntryPage } from './mobile-transaction-entry-page';
import { SettingsPage } from './settings-page';
@@ -24,6 +25,7 @@ const ROUTES_BY_PAGE = {
Accounts: '/accounts',
Transaction: '/transactions/new',
Reports: '/reports',
+ Schedules: '/schedules',
Payees: '/payees',
Rules: '/rules',
'Bank Sync': '/bank-sync',
@@ -178,6 +180,13 @@ export class MobileNavigation {
);
}
+ async goToSchedulesPage() {
+ return this.navigateToPage(
+ 'Schedules',
+ () => new MobileSchedulesPage(this.page),
+ );
+ }
+
async goToRulesPage() {
return await this.navigateToPage(
'Rules',
diff --git a/packages/desktop-client/e2e/page-models/mobile-schedules-page.ts b/packages/desktop-client/e2e/page-models/mobile-schedules-page.ts
new file mode 100644
index 0000000000..200e378bcb
--- /dev/null
+++ b/packages/desktop-client/e2e/page-models/mobile-schedules-page.ts
@@ -0,0 +1,86 @@
+import { type Locator, type Page } from '@playwright/test';
+
+export class MobileSchedulesPage {
+ readonly page: Page;
+ readonly searchBox: Locator;
+ readonly addButton: Locator;
+ readonly schedulesList: Locator;
+ readonly emptyMessage: Locator;
+ readonly loadingIndicator: Locator;
+
+ constructor(page: Page) {
+ this.page = page;
+ this.searchBox = page.getByPlaceholder('Filter schedules…');
+ this.addButton = page.getByRole('button', { name: 'Add new schedule' });
+ this.schedulesList = page.getByRole('grid', { name: 'Schedules' });
+ this.emptyMessage = page.getByText(
+ 'No schedules found. Create your first schedule to get started!',
+ );
+ this.loadingIndicator = page.getByTestId('animated-loading');
+ }
+
+ async waitFor(options?: {
+ state?: 'attached' | 'detached' | 'visible' | 'hidden';
+ timeout?: number;
+ }) {
+ await this.schedulesList.waitFor(options);
+ }
+
+ /**
+ * Search for schedules using the search box
+ */
+ async searchFor(text: string) {
+ await this.searchBox.fill(text);
+ }
+
+ /**
+ * Clear the search box
+ */
+ async clearSearch() {
+ await this.searchBox.fill('');
+ }
+
+ /**
+ * Get the nth schedule item (0-based index)
+ */
+ getNthSchedule(index: number) {
+ return this.getAllSchedules().nth(index);
+ }
+
+ /**
+ * Get all visible schedule items
+ */
+ getAllSchedules() {
+ return this.schedulesList.getByRole('gridcell');
+ }
+
+ /**
+ * Click on a schedule to open the edit page
+ */
+ async clickSchedule(index: number) {
+ const schedule = this.getNthSchedule(index);
+ await schedule.click();
+ }
+
+ /**
+ * Click the add button to create a new schedule
+ */
+ async clickAddSchedule() {
+ await this.addButton.click();
+ }
+
+ /**
+ * Get the number of visible schedules
+ */
+ async getScheduleCount() {
+ const schedules = this.getAllSchedules();
+ return await schedules.count();
+ }
+
+ /**
+ * Wait for loading to complete
+ */
+ async waitForLoadingToComplete(timeout: number = 10000) {
+ await this.loadingIndicator.waitFor({ state: 'hidden', timeout });
+ }
+}
diff --git a/packages/desktop-client/e2e/schedules.mobile.test.ts b/packages/desktop-client/e2e/schedules.mobile.test.ts
new file mode 100644
index 0000000000..0b88a92b00
--- /dev/null
+++ b/packages/desktop-client/e2e/schedules.mobile.test.ts
@@ -0,0 +1,140 @@
+import { type Page } from '@playwright/test';
+
+import { expect, test } from './fixtures';
+import { ConfigurationPage } from './page-models/configuration-page';
+import { MobileNavigation } from './page-models/mobile-navigation';
+import { type MobileSchedulesPage } from './page-models/mobile-schedules-page';
+
+test.describe('Mobile Schedules', () => {
+ let page: Page;
+ let navigation: MobileNavigation;
+ let schedulesPage: MobileSchedulesPage;
+ let configurationPage: ConfigurationPage;
+
+ test.beforeEach(async ({ browser }) => {
+ page = await browser.newPage();
+ navigation = new MobileNavigation(page);
+ configurationPage = new ConfigurationPage(page);
+
+ // Set mobile viewport
+ await page.setViewportSize({
+ width: 350,
+ height: 600,
+ });
+
+ await page.goto('/');
+ await configurationPage.createTestFile();
+
+ // Navigate to schedules page and wait for it to load
+ schedulesPage = await navigation.goToSchedulesPage();
+ });
+
+ test.afterEach(async () => {
+ await page.close();
+ });
+
+ test('checks the page visuals', async () => {
+ await schedulesPage.waitForLoadingToComplete();
+
+ // Check that the header is present
+ await expect(
+ page.getByRole('heading', { name: 'Schedules' }),
+ ).toBeVisible();
+
+ // Check that the add button is present
+ await expect(schedulesPage.addButton).toBeVisible();
+
+ // Check that the search box is present with proper placeholder
+ await expect(schedulesPage.searchBox).toBeVisible();
+ await expect(schedulesPage.searchBox).toHaveAttribute(
+ 'placeholder',
+ 'Filter schedules…',
+ );
+
+ await expect(page).toMatchThemeScreenshots();
+ });
+
+ test('page handles empty state gracefully', async () => {
+ // Search for something that won't match to get empty state
+ await schedulesPage.searchFor('NonExistentSchedule123456789');
+ await page.waitForTimeout(500);
+
+ // Check that empty message is shown
+ await expect(schedulesPage.emptyMessage).toBeVisible();
+
+ await expect(page).toMatchThemeScreenshots();
+ });
+
+ test('clicking on a schedule opens edit form', async () => {
+ await schedulesPage.waitForLoadingToComplete();
+
+ // Wait for at least one schedule to be present
+ await expect(async () => {
+ const scheduleCount = await schedulesPage.getScheduleCount();
+ expect(scheduleCount).toBeGreaterThan(0);
+ }).toPass();
+
+ // Click on the first schedule
+ await schedulesPage.clickSchedule(0);
+
+ // Wait for the edit page to load
+ await expect(
+ page.getByRole('heading', { name: 'Edit Schedule' }),
+ ).toBeVisible();
+
+ // Check that the save button is present
+ await expect(page.getByRole('button', { name: 'Save' })).toBeVisible();
+
+ await expect(page).toMatchThemeScreenshots();
+ });
+
+ test('searches and filters schedules', async () => {
+ await schedulesPage.waitForLoadingToComplete();
+
+ // Wait for schedules to load
+ await expect(async () => {
+ const scheduleCount = await schedulesPage.getScheduleCount();
+ expect(scheduleCount).toBeGreaterThan(0);
+ }).toPass();
+
+ // Search for a specific schedule
+ await schedulesPage.searchFor('Dominion Power');
+ await page.waitForTimeout(500);
+
+ // Verify search box has the value
+ await expect(schedulesPage.searchBox).toHaveValue('Dominion Power');
+ expect(await schedulesPage.getScheduleCount()).toBe(1);
+
+ await expect(page).toMatchThemeScreenshots();
+
+ // Clear search
+ await schedulesPage.clearSearch();
+ await page.waitForTimeout(500);
+
+ // Verify all schedules are visible again
+ expect(await schedulesPage.getScheduleCount()).toBeGreaterThan(1);
+
+ await expect(page).toMatchThemeScreenshots();
+ });
+
+ test('displays schedule details correctly in list', async () => {
+ await schedulesPage.waitForLoadingToComplete();
+
+ // Wait for schedules to load
+ await expect(async () => {
+ const scheduleCount = await schedulesPage.getScheduleCount();
+ expect(scheduleCount).toBeGreaterThan(0);
+ }).toPass();
+
+ // Get the first schedule and verify it has content
+ const firstSchedule = schedulesPage.getNthSchedule(0);
+ await expect(firstSchedule).toBeVisible();
+
+ // Verify schedule contains expected text elements
+ const scheduleText = await firstSchedule.textContent();
+ expect(scheduleText).toBeTruthy();
+ expect(scheduleText?.length).toBeGreaterThan(0);
+
+ await expect(page).toMatchThemeScreenshots();
+ });
+});
diff --git a/packages/desktop-client/e2e/schedules.mobile.test.ts-snapshots/Mobile-Schedules-checks-the-page-visuals-1-chromium-linux.png b/packages/desktop-client/e2e/schedules.mobile.test.ts-snapshots/Mobile-Schedules-checks-the-page-visuals-1-chromium-linux.png
new file mode 100644
index 0000000000..a1e99ca45e
Binary files /dev/null and b/packages/desktop-client/e2e/schedules.mobile.test.ts-snapshots/Mobile-Schedules-checks-the-page-visuals-1-chromium-linux.png differ
diff --git a/packages/desktop-client/e2e/schedules.mobile.test.ts-snapshots/Mobile-Schedules-checks-the-page-visuals-2-chromium-linux.png b/packages/desktop-client/e2e/schedules.mobile.test.ts-snapshots/Mobile-Schedules-checks-the-page-visuals-2-chromium-linux.png
new file mode 100644
index 0000000000..3b0bfa6f12
Binary files /dev/null and b/packages/desktop-client/e2e/schedules.mobile.test.ts-snapshots/Mobile-Schedules-checks-the-page-visuals-2-chromium-linux.png differ
diff --git a/packages/desktop-client/e2e/schedules.mobile.test.ts-snapshots/Mobile-Schedules-checks-the-page-visuals-3-chromium-linux.png b/packages/desktop-client/e2e/schedules.mobile.test.ts-snapshots/Mobile-Schedules-checks-the-page-visuals-3-chromium-linux.png
new file mode 100644
index 0000000000..6585b4b33a
Binary files /dev/null and b/packages/desktop-client/e2e/schedules.mobile.test.ts-snapshots/Mobile-Schedules-checks-the-page-visuals-3-chromium-linux.png differ
diff --git a/packages/desktop-client/e2e/schedules.mobile.test.ts-snapshots/Mobile-Schedules-clicking-on-a-schedule-opens-edit-form-1-chromium-linux.png b/packages/desktop-client/e2e/schedules.mobile.test.ts-snapshots/Mobile-Schedules-clicking-on-a-schedule-opens-edit-form-1-chromium-linux.png
new file mode 100644
index 0000000000..845cf8f9f1
Binary files /dev/null and b/packages/desktop-client/e2e/schedules.mobile.test.ts-snapshots/Mobile-Schedules-clicking-on-a-schedule-opens-edit-form-1-chromium-linux.png differ
diff --git a/packages/desktop-client/e2e/schedules.mobile.test.ts-snapshots/Mobile-Schedules-clicking-on-a-schedule-opens-edit-form-2-chromium-linux.png b/packages/desktop-client/e2e/schedules.mobile.test.ts-snapshots/Mobile-Schedules-clicking-on-a-schedule-opens-edit-form-2-chromium-linux.png
new file mode 100644
index 0000000000..34c967515e
Binary files /dev/null and b/packages/desktop-client/e2e/schedules.mobile.test.ts-snapshots/Mobile-Schedules-clicking-on-a-schedule-opens-edit-form-2-chromium-linux.png differ
diff --git a/packages/desktop-client/e2e/schedules.mobile.test.ts-snapshots/Mobile-Schedules-clicking-on-a-schedule-opens-edit-form-3-chromium-linux.png b/packages/desktop-client/e2e/schedules.mobile.test.ts-snapshots/Mobile-Schedules-clicking-on-a-schedule-opens-edit-form-3-chromium-linux.png
new file mode 100644
index 0000000000..acb916d583
Binary files /dev/null and b/packages/desktop-client/e2e/schedules.mobile.test.ts-snapshots/Mobile-Schedules-clicking-on-a-schedule-opens-edit-form-3-chromium-linux.png differ
diff --git a/packages/desktop-client/e2e/schedules.mobile.test.ts-snapshots/Mobile-Schedules-displays-schedule-details-correctly-in-list-1-chromium-linux.png b/packages/desktop-client/e2e/schedules.mobile.test.ts-snapshots/Mobile-Schedules-displays-schedule-details-correctly-in-list-1-chromium-linux.png
new file mode 100644
index 0000000000..a1e99ca45e
Binary files /dev/null and b/packages/desktop-client/e2e/schedules.mobile.test.ts-snapshots/Mobile-Schedules-displays-schedule-details-correctly-in-list-1-chromium-linux.png differ
diff --git a/packages/desktop-client/e2e/schedules.mobile.test.ts-snapshots/Mobile-Schedules-displays-schedule-details-correctly-in-list-2-chromium-linux.png b/packages/desktop-client/e2e/schedules.mobile.test.ts-snapshots/Mobile-Schedules-displays-schedule-details-correctly-in-list-2-chromium-linux.png
new file mode 100644
index 0000000000..3b0bfa6f12
Binary files /dev/null and b/packages/desktop-client/e2e/schedules.mobile.test.ts-snapshots/Mobile-Schedules-displays-schedule-details-correctly-in-list-2-chromium-linux.png differ
diff --git a/packages/desktop-client/e2e/schedules.mobile.test.ts-snapshots/Mobile-Schedules-displays-schedule-details-correctly-in-list-3-chromium-linux.png b/packages/desktop-client/e2e/schedules.mobile.test.ts-snapshots/Mobile-Schedules-displays-schedule-details-correctly-in-list-3-chromium-linux.png
new file mode 100644
index 0000000000..6585b4b33a
Binary files /dev/null and b/packages/desktop-client/e2e/schedules.mobile.test.ts-snapshots/Mobile-Schedules-displays-schedule-details-correctly-in-list-3-chromium-linux.png differ
diff --git a/packages/desktop-client/e2e/schedules.mobile.test.ts-snapshots/Mobile-Schedules-page-handles-empty-state-gracefully-1-chromium-linux.png b/packages/desktop-client/e2e/schedules.mobile.test.ts-snapshots/Mobile-Schedules-page-handles-empty-state-gracefully-1-chromium-linux.png
new file mode 100644
index 0000000000..ef054f9748
Binary files /dev/null and b/packages/desktop-client/e2e/schedules.mobile.test.ts-snapshots/Mobile-Schedules-page-handles-empty-state-gracefully-1-chromium-linux.png differ
diff --git a/packages/desktop-client/e2e/schedules.mobile.test.ts-snapshots/Mobile-Schedules-page-handles-empty-state-gracefully-2-chromium-linux.png b/packages/desktop-client/e2e/schedules.mobile.test.ts-snapshots/Mobile-Schedules-page-handles-empty-state-gracefully-2-chromium-linux.png
new file mode 100644
index 0000000000..861ef76366
Binary files /dev/null and b/packages/desktop-client/e2e/schedules.mobile.test.ts-snapshots/Mobile-Schedules-page-handles-empty-state-gracefully-2-chromium-linux.png differ
diff --git a/packages/desktop-client/e2e/schedules.mobile.test.ts-snapshots/Mobile-Schedules-page-handles-empty-state-gracefully-3-chromium-linux.png b/packages/desktop-client/e2e/schedules.mobile.test.ts-snapshots/Mobile-Schedules-page-handles-empty-state-gracefully-3-chromium-linux.png
new file mode 100644
index 0000000000..283b8c0a60
Binary files /dev/null and b/packages/desktop-client/e2e/schedules.mobile.test.ts-snapshots/Mobile-Schedules-page-handles-empty-state-gracefully-3-chromium-linux.png differ
diff --git a/packages/desktop-client/e2e/schedules.mobile.test.ts-snapshots/Mobile-Schedules-searches-and-filters-schedules-1-chromium-linux.png b/packages/desktop-client/e2e/schedules.mobile.test.ts-snapshots/Mobile-Schedules-searches-and-filters-schedules-1-chromium-linux.png
new file mode 100644
index 0000000000..719e487c48
Binary files /dev/null and b/packages/desktop-client/e2e/schedules.mobile.test.ts-snapshots/Mobile-Schedules-searches-and-filters-schedules-1-chromium-linux.png differ
diff --git a/packages/desktop-client/e2e/schedules.mobile.test.ts-snapshots/Mobile-Schedules-searches-and-filters-schedules-2-chromium-linux.png b/packages/desktop-client/e2e/schedules.mobile.test.ts-snapshots/Mobile-Schedules-searches-and-filters-schedules-2-chromium-linux.png
new file mode 100644
index 0000000000..dac8c6a531
Binary files /dev/null and b/packages/desktop-client/e2e/schedules.mobile.test.ts-snapshots/Mobile-Schedules-searches-and-filters-schedules-2-chromium-linux.png differ
diff --git a/packages/desktop-client/e2e/schedules.mobile.test.ts-snapshots/Mobile-Schedules-searches-and-filters-schedules-3-chromium-linux.png b/packages/desktop-client/e2e/schedules.mobile.test.ts-snapshots/Mobile-Schedules-searches-and-filters-schedules-3-chromium-linux.png
new file mode 100644
index 0000000000..f2509d00e5
Binary files /dev/null and b/packages/desktop-client/e2e/schedules.mobile.test.ts-snapshots/Mobile-Schedules-searches-and-filters-schedules-3-chromium-linux.png differ
diff --git a/packages/desktop-client/e2e/schedules.mobile.test.ts-snapshots/Mobile-Schedules-searches-and-filters-schedules-4-chromium-linux.png b/packages/desktop-client/e2e/schedules.mobile.test.ts-snapshots/Mobile-Schedules-searches-and-filters-schedules-4-chromium-linux.png
new file mode 100644
index 0000000000..2ee42b3721
Binary files /dev/null and b/packages/desktop-client/e2e/schedules.mobile.test.ts-snapshots/Mobile-Schedules-searches-and-filters-schedules-4-chromium-linux.png differ
diff --git a/packages/desktop-client/e2e/schedules.mobile.test.ts-snapshots/Mobile-Schedules-searches-and-filters-schedules-5-chromium-linux.png b/packages/desktop-client/e2e/schedules.mobile.test.ts-snapshots/Mobile-Schedules-searches-and-filters-schedules-5-chromium-linux.png
new file mode 100644
index 0000000000..9b1f8948cd
Binary files /dev/null and b/packages/desktop-client/e2e/schedules.mobile.test.ts-snapshots/Mobile-Schedules-searches-and-filters-schedules-5-chromium-linux.png differ
diff --git a/packages/desktop-client/e2e/schedules.mobile.test.ts-snapshots/Mobile-Schedules-searches-and-filters-schedules-6-chromium-linux.png b/packages/desktop-client/e2e/schedules.mobile.test.ts-snapshots/Mobile-Schedules-searches-and-filters-schedules-6-chromium-linux.png
new file mode 100644
index 0000000000..2bf190a1a4
Binary files /dev/null and b/packages/desktop-client/e2e/schedules.mobile.test.ts-snapshots/Mobile-Schedules-searches-and-filters-schedules-6-chromium-linux.png differ
diff --git a/packages/desktop-client/e2e/schedules.test.ts-snapshots/Schedules-creates-a-full-list-of-schedules-3-chromium-linux.png b/packages/desktop-client/e2e/schedules.test.ts-snapshots/Schedules-creates-a-full-list-of-schedules-3-chromium-linux.png
index 370dbf3ac2..3bc485c95d 100644
Binary files a/packages/desktop-client/e2e/schedules.test.ts-snapshots/Schedules-creates-a-full-list-of-schedules-3-chromium-linux.png and b/packages/desktop-client/e2e/schedules.test.ts-snapshots/Schedules-creates-a-full-list-of-schedules-3-chromium-linux.png differ
diff --git a/packages/desktop-client/src/components/FinancesApp.tsx b/packages/desktop-client/src/components/FinancesApp.tsx
index 547887baea..d024d07eb0 100644
--- a/packages/desktop-client/src/components/FinancesApp.tsx
+++ b/packages/desktop-client/src/components/FinancesApp.tsx
@@ -259,10 +259,14 @@ export function FinancesApp() {
<Route
path="/schedules"
+ element={<NarrowAlternate name="Schedules" />}
+ />
+ <Route
+ path="/schedules/:id"
element={
- <NarrowNotSupported>
- <WideComponent name="Schedules" />
- </NarrowNotSupported>
+ <WideNotSupported>
+ <NarrowAlternate name="ScheduleEdit" />
+ </WideNotSupported>
}
/>
@@ -369,6 +373,7 @@ export function FinancesApp() {
<Route path="/bank-sync" element={<MobileNavTabs />} />
<Route path="/rules" element={<MobileNavTabs />} />
<Route path="/payees" element={<MobileNavTabs />} />
+ <Route path="/schedules" element={<MobileNavTabs />} />
<Route path="*" element={null} />
</Routes>
</ScrollProvider>
diff --git a/packages/desktop-client/src/components/Modals.tsx b/packages/desktop-client/src/components/Modals.tsx
index 9a12048c16..379d68ac31 100644
--- a/packages/desktop-client/src/components/Modals.tsx
+++ b/packages/desktop-client/src/components/Modals.tsx
@@ -61,6 +61,7 @@ import { PasswordEnableModal } from './modals/PasswordEnableModal';
import { PayeeAutocompleteModal } from './modals/PayeeAutocompleteModal';
import { PluggyAiInitialiseModal } from './modals/PluggyAiInitialiseModal';
import { ScheduledTransactionMenuModal } from './modals/ScheduledTransactionMenuModal';
+import { SchedulesPageMenuModal } from './modals/SchedulesPageMenuModal';
import { SelectLinkedAccountsModal } from './modals/SelectLinkedAccountsModal';
import { SimpleFinInitialiseModal } from './modals/SimpleFinInitialiseModal';
import { TrackingBalanceMenuModal } from './modals/TrackingBalanceMenuModal';
@@ -339,6 +340,9 @@ export function Modals() {
case 'budget-page-menu':
return <BudgetPageMenuModal key={key} {...modal.options} />;
+ case 'schedules-page-menu':
+ return <SchedulesPageMenuModal key={key} />;
+
case 'envelope-budget-month-menu':
return (
<SheetNameProvider
diff --git a/packages/desktop-client/src/components/mobile/MobileNavTabs.tsx b/packages/desktop-client/src/components/mobile/MobileNavTabs.tsx
index 236f83a61c..56ce3066e9 100644
--- a/packages/desktop-client/src/components/mobile/MobileNavTabs.tsx
+++ b/packages/desktop-client/src/components/mobile/MobileNavTabs.tsx
@@ -123,8 +123,8 @@ export function MobileNavTabs() {
Icon: SvgReports,
},
{
- name: t('Schedules (Soon)'),
- path: '/schedules/soon',
+ name: t('Schedules'),
+ path: '/schedules',
style: navTabStyle,
Icon: SvgCalendar3,
},
diff --git a/packages/desktop-client/src/components/mobile/schedules/AddScheduleButton.tsx b/packages/desktop-client/src/components/mobile/schedules/AddScheduleButton.tsx
new file mode 100644
index 0000000000..37d55fe4be
--- /dev/null
+++ b/packages/desktop-client/src/components/mobile/schedules/AddScheduleButton.tsx
@@ -0,0 +1,27 @@
+import React, { useCallback } from 'react';
+import { useTranslation } from 'react-i18next';
+
+import { Button } from '@actual-app/components/button';
+import { SvgAdd } from '@actual-app/components/icons/v1';
+
+import { useNavigate } from '@desktop-client/hooks/useNavigate';
+
+export function AddScheduleButton() {
+ const { t } = useTranslation();
+ const navigate = useNavigate();
+
+ const handleAddSchedule = useCallback(() => {
+ navigate('/schedules/new');
+ }, [navigate]);
+
+ return (
+ <Button
+ variant="bare"
+ aria-label={t('Add new schedule')}
+ style={{ margin: 10 }}
+ onPress={handleAddSchedule}
+ >
+ <SvgAdd width={20} height={20} />
+ </Button>
+ );
+}
diff --git a/packages/desktop-client/src/components/mobile/schedules/MobileScheduleEditPage.tsx b/packages/desktop-client/src/components/mobile/schedules/MobileScheduleEditPage.tsx
new file mode 100644
index 0000000000..e29d8a517b
--- /dev/null
+++ b/packages/desktop-client/src/components/mobile/schedules/MobileScheduleEditPage.tsx
@@ -0,0 +1,275 @@
+// @ts-strict-ignore
+import React from 'react';
+import { useTranslation, Trans } from 'react-i18next';
+import { useParams } from 'react-router';
+
+import { Button } from '@actual-app/components/button';
+import { styles } from '@actual-app/components/styles';
+import { Text } from '@actual-app/components/text';
+import { theme } from '@actual-app/components/theme';
+import { View } from '@actual-app/components/view';
+
+import { send, sendCatch } from 'loot-core/platform/client/fetch';
+import * as monthUtils from 'loot-core/shared/months';
+import { q } from 'loot-core/shared/query';
+import { type RecurConfig, type ScheduleEntity } from 'loot-core/types/models';
+
+import { MobileBackButton } from '@desktop-client/components/mobile/MobileBackButton';
+import { MobilePageHeader, Page } from '@desktop-client/components/Page';
+import { updateScheduleConditions } from '@desktop-client/components/schedules/schedule-edit-utils';
+import { ScheduleEditForm } from '@desktop-client/components/schedules/ScheduleEditForm';
+import { useNavigate } from '@desktop-client/hooks/useNavigate';
+import { useScheduleEdit } from '@desktop-client/hooks/useScheduleEdit';
+import { useSelected } from '@desktop-client/hooks/useSelected';
+import { useUndo } from '@desktop-client/hooks/useUndo';
+import { aqlQuery } from '@desktop-client/queries/aqlQuery';
+
+export function MobileScheduleEditPage() {
+ const { t } = useTranslation();
+ const navigate = useNavigate();
+ const { id } = useParams<{ id?: string }>();
+ const { showUndoNotification } = useUndo();
+
+ const adding = !id || id === 'new';
+
+ // Create initial schedule if adding
+ const initialSchedule = adding
+ ? (() => {
+ const date = {
+ start: monthUtils.currentDay(),
+ frequency: 'monthly',
+ patterns: [],
+ skipWeekend: false,
+ weekendSolveMode: 'after',
+ endMode: 'never',
+ endOccurrences: 1,
+ endDate: monthUtils.currentDay(),
+ } satisfies RecurConfig;
+
+ return {
+ posts_transaction: false,
+ _date: date,
+ _conditions: [{ op: 'isapprox', field: 'date', value: date }],
+ _actions: [],
+ } satisfies Partial<ScheduleEntity>;
+ })()
+ : undefined;
+
+ const { state, dispatch, isLoading } = useScheduleEdit({
+ scheduleId: id,
+ adding,
+ initialSchedule,
+ useGetScheduledAmount: true,
+ });
+
+ const selectedInst = useSelected('transactions', state.transactions, []);
+
+ async function onSave() {
+ dispatch({ type: 'form-error', error: null });
+ if (!state.schedule) {
+ return;
+ }
+
+ if (state.fields.name) {
+ const { data: sameName } = await aqlQuery(
+ q('schedules').filter({ name: state.fields.name }).select('id'),
+ );
+ if (sameName.length > 0 && sameName[0].id !== state.schedule.id) {
+ dispatch({
+ type: 'form-error',
+ error: t('There is already a schedule with this name'),
+ });
+ return;
+ }
+ }
+
+ const { error, conditions } = updateScheduleConditions(
+ state.schedule,
+ state.fields,
+ );
+
+ if (error) {
+ dispatch({ type: 'form-error', error });
+ return;
+ }
+
+ const res = await sendCatch(
+ adding ? 'schedule/create' : 'schedule/update',
+ {
+ schedule: {
+ id: state.schedule.id,
+ posts_transaction: state.fields.posts_transaction,
+ name: state.fields.name,
+ },
+ conditions,
+ },
+ );
+
+ if (res.error) {
+ dispatch({
+ type: 'form-error',
+ error: t(
+ 'An error occurred while saving. Please visit https://actualbudget.org/contact/ for support.',
+ ),
+ });
+ return;
+ }
+
+ if (adding) {
+ await onLinkTransactions([...selectedInst.items], res.data);
+ }
+
+ showUndoNotification({
+ message: adding
+ ? t('Schedule created successfully')
+ : t('Schedule saved successfully'),
+ });
+
+ // Navigate back to schedules list
+ navigate('/schedules');
+ }
+
+ async function onEditRule(ruleId: string) {
+ navigate(`/rules/${ruleId}`);
+ }
+
+ async function onLinkTransactions(ids: string[], scheduleId?: string) {
+ await send('transactions-batch-update', {
+ updated: ids.map(id => ({
+ id,
+ schedule: scheduleId,
+ })),
+ });
+ selectedInst.dispatch({ type: 'select-none' });
+ }
+
+ async function onUnlinkTransactions(ids: string[]) {
+ await send('transactions-batch-update', {
+ updated: ids.map(id => ({ id, schedule: null })),
+ });
+ selectedInst.dispatch({ type: 'select-none' });
+ }
+
+ const { schedule } = state;
+
+ function onSwitchTransactions(mode: 'linked' | 'matched') {
+ dispatch({ type: 'switch-transactions', mode });
+ selectedInst.dispatch({ type: 'select-none' });
+ }
+
+ // This is derived from the date
+ const repeats =
+ state.fields.date && typeof state.fields.date !== 'string'
+ ? !!state.fields.date.frequency
+ : false;
+
+ const pageTitle = adding ? t('Create Schedule') : t('Edit Schedule');
+
+ // Show loading state while fetching schedule
+ if (isLoading) {
+ return (
+ <Page
+ header={
+ <MobilePageHeader
+ title={t('Loading...')}
+ leftContent={<MobileBackButton onPress={() => navigate(-1)} />}
+ />
+ }
+ padding={0}
+ >
+ <View
+ style={{
+ flex: 1,
+ backgroundColor: theme.mobilePageBackground,
+ justifyContent: 'center',
+ alignItems: 'center',
+ }}
+ >
+ <Text>
+ <Trans>Loading schedule...</Trans>
+ </Text>
+ </View>
+ </Page>
+ );
+ }
+
+ if (!schedule) {
+ return (
+ <Page
+ header={
+ <MobilePageHeader
+ title={t('Schedule not found')}
+ leftContent={
+ <MobileBackButton onPress={() => navigate('/schedules')} />
+ }
+ />
+ }
+ padding={0}
+ >
+ <View
+ style={{
+ flex: 1,
+ backgroundColor: theme.mobilePageBackground,
+ justifyContent: 'center',
+ alignItems: 'center',
+ }}
+ >
+ <Text>
+ <Trans>Schedule not found</Trans>
+ </Text>
+ </View>
+ </Page>
+ );
+ }
+
+ return (
+ <Page
+ header={
+ <MobilePageHeader
+ title={pageTitle}
+ leftContent={<MobileBackButton onPress={() => navigate(-1)} />}
+ />
+ }
+ footer={
+ <View
+ style={{
+ paddingLeft: styles.mobileEditingPadding,
+ paddingRight: styles.mobileEditingPadding,
+ paddingTop: 10,
+ paddingBottom: 'calc(10px + env(safe-area-inset-bottom))',
+ backgroundColor: theme.tableHeaderBackground,
+ borderTopWidth: 1,
+ borderColor: theme.tableBorder,
+ }}
+ >
+ <Button
+ variant="primary"
+ onPress={onSave}
+ style={{ height: styles.mobileMinHeight }}
+ >
+ <Trans>Save</Trans>
+ </Button>
+ </View>
+ }
+ padding={0}
+ >
+ <ScheduleEditForm
+ fields={state.fields}
+ dispatch={dispatch}
+ upcomingDates={state.upcomingDates}
+ repeats={repeats}
+ schedule={schedule}
+ adding={adding}
+ isCustom={state.isCustom ?? false}
+ onEditRule={onEditRule}
+ transactions={state.transactions}
+ transactionsMode={state.transactionsMode}
+ error={state.error}
+ selectedInst={selectedInst}
+ onSwitchTransactions={onSwitchTransactions}
+ onLinkTransactions={onLinkTransactions}
+ onUnlinkTransactions={onUnlinkTransactions}
+ />
+ </Page>
+ );
+}
diff --git a/packages/desktop-client/src/components/mobile/schedules/MobileSchedulesPage.tsx b/packages/desktop-client/src/components/mobile/schedules/MobileSchedulesPage.tsx
new file mode 100644
index 0000000000..b141ecff14
--- /dev/null
+++ b/packages/desktop-client/src/components/mobile/schedules/MobileSchedulesPage.tsx
@@ -0,0 +1,194 @@
+import React, { useState, useCallback, useMemo } from 'react';
+import { Trans, useTranslation } from 'react-i18next';
+
+import { Button } from '@actual-app/components/button';
+import { styles } from '@actual-app/components/styles';
+import { Text } from '@actual-app/components/text';
+import { theme } from '@actual-app/components/theme';
+import { View } from '@actual-app/components/view';
+
+import { send } from 'loot-core/platform/client/fetch';
+import { format as monthUtilFormat } from 'loot-core/shared/months';
+import { getNormalisedString } from 'loot-core/shared/normalisation';
+import { q } from 'loot-core/shared/query';
+import { getScheduledAmount } from 'loot-core/shared/schedules';
+import { type ScheduleEntity } from 'loot-core/types/models';
+
+import { AddScheduleButton } from './AddScheduleButton';
+import { SchedulesList } from './SchedulesList';
+
+import { Search } from '@desktop-client/components/common/Search';
+import { MobilePageHeader, Page } from '@desktop-client/components/Page';
+import { useAccounts } from '@desktop-client/hooks/useAccounts';
+import { useDateFormat } from '@desktop-client/hooks/useDateFormat';
+import { useFormat } from '@desktop-client/hooks/useFormat';
+import { useLocalPref } from '@desktop-client/hooks/useLocalPref';
+import { useNavigate } from '@desktop-client/hooks/useNavigate';
+import { usePayees } from '@desktop-client/hooks/usePayees';
+import { useSchedules } from '@desktop-client/hooks/useSchedules';
+import { useUndo } from '@desktop-client/hooks/useUndo';
+import { pushModal } from '@desktop-client/modals/modalsSlice';
+import { addNotification } from '@desktop-client/notifications/notificationsSlice';
+import { useDispatch } from '@desktop-client/redux';
+
+export function MobileSchedulesPage() {
+ const { t } = useTranslation();
+ const navigate = useNavigate();
+ const dispatch = useDispatch();
+ const { showUndoNotification } = useUndo();
+ const [filter, setFilter] = useState('');
+ const [showCompleted = false] = useLocalPref('schedules.showCompleted');
+ const format = useFormat();
+ const dateFormat = useDateFormat() || 'MM/dd/yyyy';
+
+ const onOpenSchedulesPageMenu = useCallback(() => {
+ dispatch(pushModal({ modal: { name: 'schedules-page-menu' } }));
+ }, [dispatch]);
+
+ const schedulesQuery = useMemo(() => q('schedules').select('*'), []);
+ const {
+ isLoading: isSchedulesLoading,
+ schedules,
+ statuses,
+ } = useSchedules({ query: schedulesQuery });
+
+ const payees = usePayees();
+ const accounts = useAccounts();
+
+ const filteredSchedules = useMemo(() => {
+ const filterIncludes = (str: string | null | undefined) =>
+ str
+ ? getNormalisedString(str).includes(getNormalisedString(filter)) ||
+ getNormalisedString(filter).includes(getNormalisedString(str))
+ : false;
+
+ const baseSchedules = filter
+ ? schedules.filter(schedule => {
+ const payee = payees.find(p => schedule._payee === p.id);
+ const account = accounts.find(a => schedule._account === a.id);
+ const amount = getScheduledAmount(schedule._amount);
+ const amountStr =
+ (schedule._amountOp === 'isapprox' ||
+ schedule._amountOp === 'isbetween'
+ ? '~'
+ : '') +
+ (amount > 0 ? '+' : '') +
+ format(Math.abs(amount || 0), 'financial');
+ const dateStr = schedule.next_date
+ ? monthUtilFormat(schedule.next_date, dateFormat)
+ : null;
+ const statusLabel = statuses.get(schedule.id);
+
+ return (
+ filterIncludes(schedule.name) ||
+ filterIncludes(payee?.name) ||
+ filterIncludes(account?.name) ||
+ filterIncludes(amountStr) ||
+ filterIncludes(statusLabel) ||
+ filterIncludes(dateStr)
+ );
+ })
+ : schedules;
+
+ if (showCompleted) {
+ return baseSchedules;
+ }
+
+ return baseSchedules.filter(s => !s.completed);
+ }, [
+ schedules,
+ filter,
+ payees,
+ accounts,
+ format,
+ dateFormat,
+ statuses,
+ showCompleted,
+ ]);
+
+ const handleSchedulePress = useCallback(
+ (schedule: ScheduleEntity) => {
+ navigate(`/schedules/${schedule.id}`);
+ },
+ [navigate],
+ );
+
+ const handleScheduleDelete = useCallback(
+ async (schedule: ScheduleEntity) => {
+ try {
+ await send('schedule/delete', { id: schedule.id });
+ showUndoNotification({
+ message: t('Schedule deleted successfully'),
+ });
+ } catch (error) {
+ console.error('Failed to delete schedule:', error);
+ dispatch(
+ addNotification({
+ notification: {
+ type: 'error',
+ message: t('Failed to delete schedule. Please try again.'),
+ },
+ }),
+ );
+ }
+ },
+ [dispatch, showUndoNotification, t],
+ );
+
+ return (
+ <Page
+ header={
+ <MobilePageHeader
+ title={
+ <Button
+ variant="bare"
+ onPress={onOpenSchedulesPageMenu}
+ style={{
+ fontSize: 16,
+ fontWeight: 500,
+ }}
+ >
+ <Text style={styles.underlinedText}>
+ <Trans>Schedules</Trans>
+ </Text>
+ </Button>
+ }
+ rightContent={<AddScheduleButton />}
+ />
+ }
+ padding={0}
+ >
+ <View
+ style={{
+ flexDirection: 'row',
+ alignItems: 'center',
+ backgroundColor: theme.mobilePageBackground,
+ padding: 10,
+ width: '100%',
+ borderBottomWidth: 2,
+ borderBottomStyle: 'solid',
+ borderBottomColor: theme.tableBorder,
+ }}
+ >
+ <Search
+ placeholder={t('Filter schedules…')}
+ value={filter}
+ onChange={setFilter}
+ width="100%"
+ height={styles.mobileMinHeight}
+ style={{
+ backgroundColor: theme.tableBackground,
+ borderColor: theme.formInputBorder,
+ }}
+ />
+ </View>
+ <SchedulesList
+ schedules={filteredSchedules}
+ isLoading={isSchedulesLoading}
+ statuses={statuses}
+ onSchedulePress={handleSchedulePress}
+ onScheduleDelete={handleScheduleDelete}
+ />
+ </Page>
+ );
+}
diff --git a/packages/desktop-client/src/components/mobile/schedules/SchedulesList.tsx b/packages/desktop-client/src/components/mobile/schedules/SchedulesList.tsx
new file mode 100644
index 0000000000..7294023241
--- /dev/null
+++ b/packages/desktop-client/src/components/mobile/schedules/SchedulesList.tsx
@@ -0,0 +1,112 @@
+import { Virtualizer, GridList, ListLayout } from 'react-aria-components';
+import { useTranslation } from 'react-i18next';
+
+import { AnimatedLoading } from '@actual-app/components/icons/AnimatedLoading';
+import { Text } from '@actual-app/components/text';
+import { theme } from '@actual-app/components/theme';
+import { View } from '@actual-app/components/view';
+
+import { type ScheduleEntity } from 'loot-core/types/models';
+
+import { SchedulesListItem } from './SchedulesListItem';
+
+import { MOBILE_NAV_HEIGHT } from '@desktop-client/components/mobile/MobileNavTabs';
+import { type ScheduleStatusType } from '@desktop-client/hooks/useSchedules';
+
+type SchedulesListProps = {
+ schedules: readonly ScheduleEntity[];
+ isLoading: boolean;
+ statuses: Map<ScheduleEntity['id'], ScheduleStatusType>;
+ onSchedulePress: (schedule: ScheduleEntity) => void;
+ onScheduleDelete: (schedule: ScheduleEntity) => void;
+};
+
+export function SchedulesList({
+ schedules,
+ isLoading,
+ statuses,
+ onSchedulePress,
+ onScheduleDelete,
+}: SchedulesListProps) {
+ const { t } = useTranslation();
+
+ if (isLoading && schedules.length === 0) {
+ return (
+ <View
+ style={{
+ flex: 1,
+ alignItems: 'center',
+ justifyContent: 'center',
+ paddingTop: 100,
+ }}
+ >
+ <AnimatedLoading style={{ width: 25, height: 25 }} />
+ </View>
+ );
+ }
+
+ if (schedules.length === 0) {
+ return (
+ <View
+ style={{
+ flex: 1,
+ alignItems: 'center',
+ justifyContent: 'center',
+ paddingHorizontal: 20,
+ }}
+ >
+ <Text
+ style={{
+ fontSize: 16,
+ color: theme.pageTextSubdued,
+ textAlign: 'center',
+ paddingLeft: 10,
+ paddingRight: 10,
+ }}
+ >
+ {t('No schedules found. Create your first schedule to get started!')}
+ </Text>
+ </View>
+ );
+ }
+
+ return (
+ <View style={{ flex: 1, overflow: 'auto' }}>
+ <Virtualizer
+ layout={ListLayout}
+ layoutOptions={{
+ estimatedRowHeight: 140,
+ padding: 0,
+ }}
+ >
+ <GridList
+ aria-label={t('Schedules')}
+ aria-busy={isLoading || undefined}
+ items={schedules}
+ style={{
+ paddingBottom: MOBILE_NAV_HEIGHT,
+ }}
+ >
+ {schedule => (
+ <SchedulesListItem
+ value={schedule}
+ status={statuses.get(schedule.id) || 'scheduled'}
+ onAction={() => onSchedulePress(schedule)}
+ onDelete={() => onScheduleDelete(schedule)}
+ />
+ )}
+ </GridList>
+ </Virtualizer>
+ {isLoading && (
+ <View
+ style={{
+ alignItems: 'center',
+ paddingTop: 20,
+ }}
+ >
+ <AnimatedLoading style={{ width: 20, height: 20 }} />
+ </View>
+ )}
+ </View>
+ );
+}
diff --git a/packages/desktop-client/src/components/mobile/schedules/SchedulesListItem.tsx b/packages/desktop-client/src/components/mobile/schedules/SchedulesListItem.tsx
new file mode 100644
index 0000000000..42a821ada5
--- /dev/null
+++ b/packages/desktop-client/src/components/mobile/schedules/SchedulesListItem.tsx
@@ -0,0 +1,136 @@
+import React from 'react';
+import { type GridListItemProps } from 'react-aria-components';
+import { Trans, useTranslation } from 'react-i18next';
+
+import { Button } from '@actual-app/components/button';
+import { SpaceBetween } from '@actual-app/components/space-between';
+import { styles } from '@actual-app/components/styles';
+import { Text } from '@actual-app/components/text';
+import { theme } from '@actual-app/components/theme';
+import { View } from '@actual-app/components/view';
+
+import { format as monthUtilFormat } from 'loot-core/shared/months';
+import { getScheduledAmount } from 'loot-core/shared/schedules';
+import { type ScheduleEntity } from 'loot-core/types/models';
+import { type WithRequired } from 'loot-core/types/util';
+
+import { ActionableGridListItem } from '@desktop-client/components/mobile/ActionableGridListItem';
+import { StatusBadge } from '@desktop-client/components/schedules/StatusBadge';
+import { DisplayId } from '@desktop-client/components/util/DisplayId';
+import { useDateFormat } from '@desktop-client/hooks/useDateFormat';
+import { useFormat } from '@desktop-client/hooks/useFormat';
+import { type ScheduleStatusType } from '@desktop-client/hooks/useSchedules';
+
+type SchedulesListItemProps = {
+ onDelete: () => void;
+ status: ScheduleStatusType;
+} & WithRequired<GridListItemProps<ScheduleEntity>, 'value'>;
+
+export function SchedulesListItem({
+ value: schedule,
+ onDelete,
+ status,
+ style,
+ ...props
+}: SchedulesListItemProps) {
+ const { t } = useTranslation();
+ const format = useFormat();
+ const dateFormat = useDateFormat() || 'MM/dd/yyyy';
+
+ const amount = getScheduledAmount(schedule._amount);
+ const amountStr =
+ (schedule._amountOp === 'isapprox' || schedule._amountOp === 'isbetween'
+ ? '~'
+ : '') +
+ (amount > 0 ? '+' : '') +
+ format(Math.abs(amount || 0), 'financial');
+
+ return (
+ <ActionableGridListItem
+ id={schedule.id}
+ value={schedule}
+ textValue={schedule.name || t('Unnamed schedule')}
+ style={{ ...styles.mobileListItem, padding: '8px 16px', ...style }}
+ actions={
+ <Button
+ variant="bare"
+ onPress={onDelete}
+ style={{
+ color: theme.errorText,
+ width: '100%',
+ }}
+ >
+ <Trans>Delete</Trans>
+ </Button>
+ }
+ {...props}
+ >
+ <SpaceBetween
+ gap={12}
+ style={{ alignItems: 'flex-start', width: '100%' }}
+ >
+ <View
+ style={{
+ flex: 1,
+ flexDirection: 'column',
+ gap: 4,
+ }}
+ >
+ {/* Schedule name */}
+ <Text
+ style={{
+ fontSize: 15,
+ fontWeight: 600,
+ color: schedule.name
+ ? theme.pageText
+ : theme.buttonNormalDisabledText,
+ }}
+ >
+ {schedule.name || t('Unnamed schedule')}
+ </Text>
+
+ {/* Payee and Account */}
+ <SpaceBetween gap={4} style={{ flexWrap: 'wrap' }}>
+ <SpaceBetween gap={4} direction="horizontal">
+ <Text style={{ color: theme.pageTextSubdued }}>
+ <Trans>Payee:</Trans>
+ </Text>
+ <DisplayId type="payees" id={schedule._payee} />
+ </SpaceBetween>
+ <SpaceBetween gap={4} direction="horizontal">
+ <Text style={{ color: theme.pageTextSubdued }}>
+ <Trans>Account:</Trans>
+ </Text>
+ <DisplayId type="accounts" id={schedule._account} />
+ </SpaceBetween>
+ </SpaceBetween>
+
+ {/* Amount and Date */}
+ <SpaceBetween gap={8} style={{ flexWrap: 'wrap' }}>
+ <SpaceBetween gap={4} direction="horizontal">
+ <Text style={{ color: theme.pageTextSubdued }}>
+ <Trans>Amount:</Trans>
+ </Text>
+ <Text style={{ color: theme.pageText }}>{amountStr}</Text>
+ </SpaceBetween>
+ {schedule.next_date && (
+ <SpaceBetween gap={4} direction="horizontal">
+ <Text style={{ color: theme.pageTextSubdued }}>
+ <Trans>Next:</Trans>
+ </Text>
+ <Text style={{ color: theme.pageText }}>
+ {monthUtilFormat(schedule.next_date, dateFormat)}
+ </Text>
+ </SpaceBetween>
+ )}
+ </SpaceBetween>
+ </View>
+
+ {/* Status badge */}
+ <View style={{ flexShrink: 0, paddingTop: 2 }}>
+ <StatusBadge status={status} />
+ </View>
+ </SpaceBetween>
+ </ActionableGridListItem>
+ );
+}
diff --git a/packages/desktop-client/src/components/modals/SchedulesPageMenuModal.tsx b/packages/desktop-client/src/components/modals/SchedulesPageMenuModal.tsx
new file mode 100644
index 0000000000..a9ce1e5154
--- /dev/null
+++ b/packages/desktop-client/src/components/modals/SchedulesPageMenuModal.tsx
@@ -0,0 +1,78 @@
+import { type CSSProperties } from 'react';
+import { useTranslation } from 'react-i18next';
+
+import { Menu } from '@actual-app/components/menu';
+import { styles } from '@actual-app/components/styles';
+import { theme } from '@actual-app/components/theme';
+
+import {
+ Modal,
+ ModalCloseButton,
+ ModalHeader,
+} from '@desktop-client/components/common/Modal';
+import { useLocalPref } from '@desktop-client/hooks/useLocalPref';
+
+export function SchedulesPageMenuModal() {
+ const { t } = useTranslation();
+ const defaultMenuItemStyle: CSSProperties = {
+ ...styles.mobileMenuItem,
+ color: theme.menuItemText,
+ borderRadius: 0,
+ borderTop: `1px solid ${theme.pillBorder}`,
+ };
+
+ return (
+ <Modal name="schedules-page-menu">
+ {({ state: { close } }) => (
+ <>
+ <ModalHeader
+ title={t('Schedules')}
+ rightContent={<ModalCloseButton onPress={close} />}
+ />
+ <SchedulesPageMenu
+ getItemStyle={() => defaultMenuItemStyle}
+ onClose={close}
+ />
+ </>
+ )}
+ </Modal>
+ );
+}
+
+type SchedulesPageMenuProps = {
+ getItemStyle?: () => CSSProperties;
+ onClose: () => void;
+};
+
+function SchedulesPageMenu({ getItemStyle, onClose }: SchedulesPageMenuProps) {
+ const { t } = useTranslation();
+ const [showCompleted, setShowCompletedPref] = useLocalPref(
+ 'schedules.showCompleted',
+ );
+
+ const onMenuSelect = (name: string) => {
+ switch (name) {
+ case 'toggle-completed-schedules':
+ setShowCompletedPref(!showCompleted);
+ break;
+ default:
+ throw new Error(`Unrecognized menu item: ${name}`);
+ }
+ onClose();
+ };
+
+ return (
+ <Menu
+ getItemStyle={getItemStyle}
+ onMenuSelect={onMenuSelect}
+ items={[
+ {
+ name: 'toggle-completed-schedules',
+ text: showCompleted
+ ? t('Hide completed schedules')
+ : t('Show completed schedules'),
+ },
+ ]}
+ />
+ );
+}
diff --git a/packages/desktop-client/src/components/responsive/narrow.ts b/packages/desktop-client/src/components/responsive/narrow.ts
index 99f0e2a2d9..9ca5e6b14a 100644
--- a/packages/desktop-client/src/components/responsive/narrow.ts
+++ b/packages/desktop-client/src/components/responsive/narrow.ts
@@ -6,6 +6,9 @@ export { AccountPage as Account } from '../mobile/accounts/AccountPage';
export { MobileRulesPage as Rules } from '../mobile/rules/MobileRulesPage';
export { MobileRuleEditPage as RuleEdit } from '../mobile/rules/MobileRuleEditPage';
+export { MobileSchedulesPage as Schedules } from '../mobile/schedules/MobileSchedulesPage';
+export { MobileScheduleEditPage as ScheduleEdit } from '../mobile/schedules/MobileScheduleEditPage';
+
export { CategoryPage as Category } from '../mobile/budget/CategoryPage';
export { MobilePayeesPage as Payees } from '../mobile/payees/MobilePayeesPage';
export { MobilePayeeEditPage as PayeeEdit } from '../mobile/payees/MobilePayeeEditPage';
diff --git a/packages/desktop-client/src/components/responsive/wide.ts b/packages/desktop-client/src/components/responsive/wide.ts
index 2dcd844bb9..0dd07f5c02 100644
--- a/packages/desktop-client/src/components/responsive/wide.ts
+++ b/packages/desktop-client/src/components/responsive/wide.ts
@@ -1,6 +1,7 @@
export { Budget } from '../budget';
export { Schedules } from '../schedules';
+export { Schedules as ScheduleEdit } from '../schedules';
export { GoCardlessLink } from '../gocardless/GoCardlessLink';
diff --git a/packages/desktop-client/src/components/schedules/ScheduleEditForm.tsx b/packages/desktop-client/src/components/schedules/ScheduleEditForm.tsx
index 09aae945aa..a76b22dad8 100644
--- a/packages/desktop-client/src/components/schedules/ScheduleEditForm.tsx
+++ b/packages/desktop-client/src/components/schedules/ScheduleEditForm.tsx
@@ -5,6 +5,7 @@ import { Trans, useTranslation } from 'react-i18next';
import { Button } from '@actual-app/components/button';
import { useResponsive } from '@actual-app/components/hooks/useResponsive';
import { InitialFocus } from '@actual-app/components/initial-focus';
+import { Input } from '@actual-app/components/input';
import { SpaceBetween } from '@actual-app/components/space-between';
import { Text } from '@actual-app/components/text';
import { theme } from '@actual-app/components/theme';
@@ -127,10 +128,11 @@ export function ScheduleEditForm({
<FormField style={{ flex: 1 }}>
<FormLabel title={t('Schedule Name')} htmlFor="name-field" />
<InitialFocus>
- <GenericInput
- type="string"
+ <Input
+ id="name-field"
value={fields.name}
- onChange={e => {
+ placeholder={t('nothing')}
+ onChangeValue={e => {
dispatch({ type: 'set-field', field: 'name', value: e });
}}
/>
@@ -314,84 +316,83 @@ export function ScheduleEditForm({
<Trans>Repeats</Trans>
</label>
</View>
+ </SpaceBetween>
- <SpaceBetween
- gap={5}
- direction="vertical"
- style={{ alignItems: 'flex-end' }}
+ <SpaceBetween
+ gap={5}
+ direction="vertical"
+ align="end"
+ style={{ marginTop: 10 }}
+ >
+ <View
+ style={{
+ marginTop: 5,
+ flexDirection: 'row',
+ alignItems: 'center',
+ userSelect: 'none',
+ justifyContent: 'flex-end',
+ }}
>
- <View
- style={{
- marginTop: 5,
- flexDirection: 'row',
- alignItems: 'center',
- userSelect: 'none',
- justifyContent: 'flex-end',
+ <Checkbox
+ id="form_posts_transaction"
+ checked={fields.posts_transaction}
+ onChange={e => {
+ dispatch({
+ type: 'set-field',
+ field: 'posts_transaction',
+ value: e.target.checked,
+ });
}}
+ />
+ <label
+ htmlFor="form_posts_transaction"
+ style={{ userSelect: 'none' }}
>
- <Checkbox
- id="form_posts_transaction"
- checked={fields.posts_transaction}
- onChange={e => {
- dispatch({
- type: 'set-field',
- field: 'posts_transaction',
- value: e.target.checked,
- });
- }}
- />
- <label
- htmlFor="form_posts_transaction"
- style={{ userSelect: 'none' }}
- >
- <Trans>Automatically add transaction</Trans>
- </label>
- </View>
+ <Trans>Automatically add transaction</Trans>
+ </label>
+ </View>
- <Text
- style={{
- width: 350,
- textAlign: 'right',
- color: theme.pageTextLight,
- fontSize: 13,
- lineHeight: '1.4em',
- }}
- >
- <Trans>
- If checked, the schedule will automatically create transactions
- for you in the specified account
- </Trans>
- </Text>
+ <Text
+ style={{
+ maxWidth: 350,
+ textAlign: 'right',
+ color: theme.pageTextLight,
+ fontSize: 13,
+ lineHeight: '1.4em',
+ }}
+ >
+ <Trans>
+ If checked, the schedule will automatically create transactions
+ for you in the specified account
+ </Trans>
+ </Text>
- {!adding && schedule.rule && (
- <SpaceBetween style={{ marginTop: 20, alignItems: 'center' }}>
- {isCustom && (
- <Text
- style={{
- color: theme.pageTextLight,
- fontSize: 13,
- textAlign: 'right',
- width: 350,
- }}
- >
- <Trans>
- This schedule has custom conditions and actions
- </Trans>
- </Text>
- )}
- <Button onPress={() => onEditRule(schedule.rule)}>
- <Trans>Edit as rule</Trans>
- </Button>
- </SpaceBetween>
- )}
- </SpaceBetween>
+ {!adding && schedule.rule && (
+ <SpaceBetween style={{ marginTop: 20, alignItems: 'center' }}>
+ {isCustom && (
+ <Text
+ style={{
+ color: theme.pageTextLight,
+ fontSize: 13,
+ textAlign: 'right',
+ width: 350,
+ }}
+ >
+ <Trans>This schedule has custom conditions and actions</Trans>
+ </Text>
+ )}
+ <Button onPress={() => onEditRule(schedule.rule)}>
+ <Trans>Edit as rule</Trans>
+ </Button>
+ </SpaceBetween>
+ )}
</SpaceBetween>
</View>
<View
style={{
padding: 10,
- minHeight: 150,
+ minHeight: '30vh',
borderTop: `1px solid ${theme.tableBorder}`,
}}
>
diff --git a/packages/desktop-client/src/components/schedules/ScheduleEditModal.tsx b/packages/desktop-client/src/components/schedules/ScheduleEditModal.tsx
index 9d02dd305b..8245a8b4fa 100644
--- a/packages/desktop-client/src/components/schedules/ScheduleEditModal.tsx
+++ b/packages/desktop-client/src/components/schedules/ScheduleEditModal.tsx
@@ -1,23 +1,17 @@
// @ts-strict-ignore
-import React, { useEffect, useReducer } from 'react';
+import React, { useMemo } from 'react';
import { useTranslation, Trans } from 'react-i18next';
import { Button } from '@actual-app/components/button';
import { SpaceBetween } from '@actual-app/components/space-between';
-import { t } from 'i18next';
import { send, sendCatch } from 'loot-core/platform/client/fetch';
import * as monthUtils from 'loot-core/shared/months';
import { q } from 'loot-core/shared/query';
-import { extractScheduleConds } from 'loot-core/shared/schedules';
-import {
- type TransactionEntity,
- type ScheduleEntity,
- type RuleConditionOp,
- type RecurConfig,
-} from 'loot-core/types/models';
+import { type ScheduleEntity, type RecurConfig } from 'loot-core/types/models';
-import { ScheduleEditForm, type ScheduleFormFields } from './ScheduleEditForm';
+import { updateScheduleConditions } from './schedule-edit-utils';
+import { ScheduleEditForm } from './ScheduleEditForm';
import {
Modal,
@@ -25,6 +19,7 @@ import {
ModalHeader,
} from '@desktop-client/components/common/Modal';
import { usePayees } from '@desktop-client/hooks/usePayees';
+import { useScheduleEdit } from '@desktop-client/hooks/useScheduleEdit';
import { useSelected } from '@desktop-client/hooks/useSelected';
import {
type Modal as ModalType,
@@ -32,61 +27,8 @@ import {
} from '@desktop-client/modals/modalsSlice';
import { getPayeesById } from '@desktop-client/payees/payeesSlice';
import { aqlQuery } from '@desktop-client/queries/aqlQuery';
-import { liveQuery } from '@desktop-client/queries/liveQuery';
import { useDispatch } from '@desktop-client/redux';
-type Fields = ScheduleFormFields;
-
-function updateScheduleConditions(
- schedule: Partial<ScheduleEntity>,
- fields: Fields,
-) {
- const conds = extractScheduleConds(schedule._conditions);
-
- const updateCond = (
- cond: ReturnType<typeof extractScheduleConds>[keyof ReturnType<
- typeof extractScheduleConds
- >],
- op: RuleConditionOp,
- field: string,
- value: (typeof fields)[keyof typeof fields],
- ) => {
- if (cond) {
- return { ...cond, value };
- }
-
- if (value != null || field === 'payee') {
- return { op, field, value };
- }
-
- return null;
- };
-
- // Validate
- if (fields.date == null) {
- return { error: t('Date is required') };
- }
-
- if (fields.amount == null) {
- return { error: t('A valid amount is required') };
- }
-
- return {
- conditions: [
- updateCond(conds.payee, 'is', 'payee', fields.payee),
- updateCond(conds.account, 'is', 'account', fields.account),
- updateCond(conds.date, 'isapprox', 'date', fields.date),
- // We don't use `updateCond` for amount because we want to
- // overwrite it completely
- {
- op: fields.amountOp,
- field: 'amount',
- value: fields.amount,
- },
- ].filter(val => !!val),
- };
-}
-
type ScheduleEditModalProps = Extract<
ModalType,
{ name: 'schedule-edit' }
@@ -100,356 +42,54 @@ export function ScheduleEditModal({ id, transaction }: ScheduleEditModalProps) {
const payees = getPayeesById(usePayees());
const globalDispatch = useDispatch();
- const [state, dispatch] = useReducer(
- (
- state: {
- isCustom?: boolean;
- schedule: null | Partial<ScheduleEntity>;
- upcomingDates: null | string[];
- error: null | string;
- fields: Fields;
- transactions: TransactionEntity[];
- transactionsMode: 'matched' | 'linked';
- },
- action:
- | {
- type: 'set-schedule';
- schedule: Partial<ScheduleEntity>;
- }
- | {
- type: 'set-field';
- field: 'name' | 'account' | 'payee';
- value: string;
- }
- | {
- type: 'set-field';
- field: 'amountOp';
- value: 'is' | 'isbetween' | 'isapprox';
- }
- | {
- type: 'set-field';
- field: 'amount';
- value: number | { num1: number; num2: number };
- }
- | {
- type: 'set-field';
- field: 'date';
- value: string | RecurConfig;
- }
- | {
- type: 'set-field';
- field: 'posts_transaction';
- value: boolean;
- }
- | {
- type: 'set-transactions';
- transactions: TransactionEntity[];
- }
- | {
- type: 'set-repeats';
- repeats: boolean;
- }
- | {
- type: 'set-upcoming-dates';
- dates: null | string[];
- }
- | {
- type: 'form-error';
- error: null | string;
- }
- | {
- type: 'switch-transactions';
- mode: 'matched' | 'linked';
- },
- ) => {
- switch (action.type) {
- case 'set-schedule': {
- const schedule = action.schedule;
-
- // See if there are custom rules
- const conds = extractScheduleConds(schedule._conditions);
- const condsSet = new Set(Object.values(conds));
- const isCustom = !!(
- schedule._conditions?.find(c => !condsSet.has(c)) ||
- schedule._actions?.find(a => a.op !== 'link-schedule')
- );
-
- return {
- ...state,
- schedule: action.schedule,
- isCustom,
- fields: {
- payee: schedule._payee ?? null,
- account: schedule._account ?? null,
- amount: schedule._amount || 0,
- amountOp: schedule._amountOp || 'isapprox',
- date: schedule._date ?? null,
- posts_transaction: action.schedule.posts_transaction ?? false,
- name: schedule.name ?? null,
- },
- };
- }
- case 'set-field': {
- if (!(action.field in state.fields)) {
- throw new Error('Unknown field: ' + action.field);
- }
-
- const fields: { [key: string]: typeof action.value | undefined } = {
- [action.field]: action.value,
- };
-
- // If we are changing the amount operator either to or
- // away from the `isbetween` operator, the amount value is
- // different and we need to convert it
- if (
- action.field === 'amountOp' &&
- action.value !== state.fields.amountOp
- ) {
- if (action.value === 'isbetween') {
- // We need a range if switching to `isbetween`. The
- // amount field should be a number since we are
- // switching away from the other ops, but check just in
- // case
- fields.amount =
- typeof state.fields.amount === 'number'
- ? { num1: state.fields.amount, num2: state.fields.amount }
- : { num1: 0, num2: 0 };
- } else if (state.fields.amountOp === 'isbetween') {
- // We need just a number if switching away from
- // `isbetween`. The amount field should be a range, but
- // also check just in case. We grab just the first
- // number and use it
- fields.amount =
- typeof state.fields.amount === 'number'
- ? state.fields.amount
- : state.fields.amount?.num1;
- }
- }
-
- return {
- ...state,
- fields: { ...state.fields, ...fields },
- };
- }
-
- case 'set-transactions': {
- if (fromTrans && action.transactions) {
- action.transactions.sort(a => {
- return transaction.id === a.id ? -1 : 1;
- });
- }
- return { ...state, transactions: action.transactions };
- }
-
- case 'set-repeats': {
- return {
- ...state,
- fields: {
- ...state.fields,
- date: action.repeats
- ? ({
- frequency: 'monthly',
- endMode: 'never',
- start: monthUtils.currentDay(),
- patterns: [],
- } satisfies RecurConfig)
- : monthUtils.currentDay(),
- },
- };
- }
-
- case 'set-upcoming-dates': {
- return {
- ...state,
- upcomingDates: action.dates,
- };
- }
-
- case 'form-error': {
- return { ...state, error: action.error };
- }
-
- case 'switch-transactions': {
- return { ...state, transactionsMode: action.mode };
- }
-
- default: {
- throw new Error('Unknown action');
- }
- }
- },
- {
- schedule: null,
- upcomingDates: null,
- error: null,
- fields: {
- payee: null,
- account: null,
- amount: null,
- amountOp: null,
- date: null,
- posts_transaction: false,
- name: null,
- },
- transactions: [],
- transactionsMode: adding ? 'matched' : 'linked',
- },
- );
-
- async function loadSchedule() {
- const { data } = await aqlQuery(q('schedules').filter({ id }).select('*'));
- return data[0];
- }
-
- useEffect(() => {
- async function run() {
- if (adding) {
- const date = {
- start: monthUtils.currentDay(),
- frequency: 'monthly',
- patterns: [],
- skipWeekend: false,
- weekendSolveMode: 'after',
- endMode: 'never',
- endOccurrences: 1,
- endDate: monthUtils.currentDay(),
- } satisfies RecurConfig;
-
- const schedule: Partial<ScheduleEntity> = fromTrans
- ? {
- posts_transaction: false,
- _conditions: [{ op: 'isapprox', field: 'date', value: date }],
- _actions: [],
- _account: transaction.account,
- _amount: transaction.amount,
- _amountOp: 'is',
- name: transaction.payee ? payees[transaction.payee].name : '',
- _payee: transaction.payee ? transaction.payee : '',
- _date: {
- ...date,
- frequency: 'monthly',
- start: transaction.date,
- patterns: [],
- },
- }
- : {
- posts_transaction: false,
- _date: date,
- _conditions: [{ op: 'isapprox', field: 'date', value: date }],
- _actions: [],
- };
-
- dispatch({ type: 'set-schedule', schedule });
- } else {
- const schedule = await loadSchedule();
-
- if (schedule && state.schedule == null) {
- dispatch({ type: 'set-schedule', schedule });
- }
- }
+ // Create initial schedule if adding from transaction
+ const initialSchedule = useMemo(() => {
+ if (!adding) {
+ return undefined;
}
- run();
- }, []);
-
- useEffect(() => {
- async function run() {
- const date = state.fields.date;
-
- if (date === null) {
- dispatch({ type: 'set-upcoming-dates', dates: null });
- return;
- }
-
- if (typeof date === 'string') {
- const today = monthUtils.currentDay();
- if (date === today || monthUtils.isAfter(date, today)) {
- dispatch({ type: 'set-upcoming-dates', dates: [date] });
- } else {
- dispatch({ type: 'set-upcoming-dates', dates: null });
- }
- return;
- }
-
- const { data } = await sendCatch('schedule/get-upcoming-dates', {
- config: date,
- count: 3,
- });
- dispatch({ type: 'set-upcoming-dates', dates: data });
- }
- run();
- }, [state.fields.date]);
-
- useEffect(() => {
- if (
- state.schedule &&
- state.schedule.id &&
- state.transactionsMode === 'linked'
- ) {
- const live = liveQuery<TransactionEntity>(
- q('transactions')
- .filter({ schedule: state.schedule.id })
- .select('*')
- .options({ splits: 'all' }),
- {
- onData: data =>
- dispatch({ type: 'set-transactions', transactions: data }),
- },
- );
- return live.unsubscribe;
- }
- }, [state.schedule, state.transactionsMode]);
-
- useEffect(() => {
- let current = true;
- let unsubscribe: (() => void) | undefined;
-
- if (state.schedule && state.transactionsMode === 'matched') {
- const updated = updateScheduleConditions(state.schedule, state.fields);
-
- if ('error' in updated) {
- dispatch({ type: 'form-error', error: updated.error });
- return;
- }
-
- // *Extremely* gross hack because the rules are not mapped to
- // public names automatically. We really should be doing that
- // at the database layer
- const conditions = updated.conditions.map(cond => {
- if (cond.field === 'description') {
- return { ...cond, field: 'payee' };
- } else if (cond.field === 'acct') {
- return { ...cond, field: 'account' };
- }
- return cond;
- });
-
- send('make-filters-from-conditions', {
- conditions,
- }).then(({ filters }) => {
- if (current) {
- const live = liveQuery<TransactionEntity>(
- q('transactions')
- .filter({ $and: filters })
- .select('*')
- .options({ splits: 'all' }),
- {
- onData: data =>
- dispatch({ type: 'set-transactions', transactions: data }),
- },
- );
- unsubscribe = live.unsubscribe;
- }
- });
- }
-
- return () => {
- current = false;
- if (unsubscribe) {
- unsubscribe();
- }
- };
- }, [state.schedule, state.transactionsMode, state.fields]);
+ const date = {
+ start: monthUtils.currentDay(),
+ frequency: 'monthly',
+ patterns: [],
+ skipWeekend: false,
+ weekendSolveMode: 'after',
+ endMode: 'never',
+ endOccurrences: 1,
+ endDate: monthUtils.currentDay(),
+ } satisfies RecurConfig;
+
+ const transFields = fromTrans
+ ? ({
+ _account: transaction.account,
+ _amount: transaction.amount,
+ _amountOp: 'is',
+ name: transaction.payee ? payees[transaction.payee].name : '',
+ _payee: transaction.payee ? transaction.payee : '',
+ _date: {
+ ...date,
+ frequency: 'monthly',
+ start: transaction.date,
+ patterns: [],
+ },
+ } satisfies Partial<ScheduleEntity>)
+ : {};
+
+ return {
+ posts_transaction: false,
+ _date: date,
+ _conditions: [{ op: 'isapprox', field: 'date', value: date }],
+ _actions: [],
+ ...transFields,
+ } satisfies Partial<ScheduleEntity>;
+ }, [adding, fromTrans, payees, transaction]);
+
+ const { state, dispatch, loadSchedule } = useScheduleEdit({
+ scheduleId: id,
+ adding,
+ initialSchedule,
+ transactionId: transaction?.id,
+ });
const selectedInst = useSelected(
'transactions',
@@ -530,6 +170,10 @@ export function ScheduleEditModal({ id, transaction }: ScheduleEditModalProps) {
rule,
onSave: async () => {
const schedule = await loadSchedule();
+ if (schedule) {
+ throw new Error('Schedule found');
+ }
+
dispatch({ type: 'set-schedule', schedule });
},
},
diff --git a/packages/desktop-client/src/components/schedules/SchedulesTable.tsx b/packages/desktop-client/src/components/schedules/SchedulesTable.tsx
index 10afa3235e..7d4c3ad2f8 100644
--- a/packages/desktop-client/src/components/schedules/SchedulesTable.tsx
+++ b/packages/desktop-client/src/components/schedules/SchedulesTable.tsx
@@ -1,5 +1,5 @@
// @ts-strict-ignore
-import React, { useRef, useState, useMemo, type CSSProperties } from 'react';
+import React, { useRef, useMemo, type CSSProperties } from 'react';
import { Trans, useTranslation } from 'react-i18next';
import { Button } from '@actual-app/components/button';
@@ -31,6 +31,7 @@ import { useAccounts } from '@desktop-client/hooks/useAccounts';
import { useContextMenu } from '@desktop-client/hooks/useContextMenu';
import { useDateFormat } from '@desktop-client/hooks/useDateFormat';
import { useFormat } from '@desktop-client/hooks/useFormat';
+import { useLocalPref } from '@desktop-client/hooks/useLocalPref';
import { usePayees } from '@desktop-client/hooks/usePayees';
import {
type ScheduleStatusType,
@@ -325,7 +326,9 @@ export function SchedulesTable({
const format = useFormat();
const dateFormat = useDateFormat() || 'MM/dd/yyyy';
- const [showCompleted, setShowCompleted] = useState(false);
+ const [showCompleted = false, setShowCompleted] = useLocalPref(
+ 'schedules.showCompleted',
+ );
const payees = usePayees();
const accounts = useAccounts();
diff --git a/packages/desktop-client/src/components/schedules/schedule-edit-utils.ts b/packages/desktop-client/src/components/schedules/schedule-edit-utils.ts
new file mode 100644
index 0000000000..9f9ebdb4f5
--- /dev/null
+++ b/packages/desktop-client/src/components/schedules/schedule-edit-utils.ts
@@ -0,0 +1,59 @@
+import { t } from 'i18next';
+
+import { extractScheduleConds } from 'loot-core/shared/schedules';
+import {
+ type ScheduleEntity,
+ type RuleConditionOp,
+} from 'loot-core/types/models';
+
+import { type ScheduleFormFields } from './ScheduleEditForm';
+
+export function updateScheduleConditions(
+ schedule: Partial<ScheduleEntity>,
+ fields: ScheduleFormFields,
+): { error?: string; conditions?: unknown[] } {
+ const conds = extractScheduleConds(schedule._conditions);
+
+ const updateCond = (
+ cond: ReturnType<typeof extractScheduleConds>[keyof ReturnType<
+ typeof extractScheduleConds
+ >],
+ op: RuleConditionOp,
+ field: string,
+ value: (typeof fields)[keyof typeof fields],
+ ) => {
+ if (cond) {
+ return { ...cond, value };
+ }
+
+ if (value != null || field === 'payee') {
+ return { op, field, value };
+ }
+
+ return null;
+ };
+
+ // Validate
+ if (fields.date == null) {
+ return { error: t('Date is required'), conditions: [] };
+ }
+
+ if (fields.amount == null) {
+ return { error: t('A valid amount is required'), conditions: [] };
+ }
+
+ return {
+ conditions: [
+ updateCond(conds.payee, 'is', 'payee', fields.payee),
+ updateCond(conds.account, 'is', 'account', fields.account),
+ updateCond(conds.date, 'isapprox', 'date', fields.date),
+ // We don't use `updateCond` for amount because we want to
+ // overwrite it completely
+ {
+ op: (fields.amountOp || 'isapprox') as RuleConditionOp,
+ field: 'amount',
+ value: fields.amount,
+ },
+ ].filter(val => !!val),
+ };
+}
diff --git a/packages/desktop-client/src/hooks/useScheduleEdit.ts b/packages/desktop-client/src/hooks/useScheduleEdit.ts
new file mode 100644
index 0000000000..4fe2577213
--- /dev/null
+++ b/packages/desktop-client/src/hooks/useScheduleEdit.ts
@@ -0,0 +1,412 @@
+// @ts-strict-ignore
+import { useEffect, useEffectEvent, useReducer, useState } from 'react';
+
+import { send, sendCatch } from 'loot-core/platform/client/fetch';
+import * as monthUtils from 'loot-core/shared/months';
+import { q } from 'loot-core/shared/query';
+import {
+ extractScheduleConds,
+ getScheduledAmount,
+} from 'loot-core/shared/schedules';
+import {
+ type TransactionEntity,
+ type ScheduleEntity,
+ type RecurConfig,
+} from 'loot-core/types/models';
+
+import { updateScheduleConditions } from '@desktop-client/components/schedules/schedule-edit-utils';
+import { type ScheduleFormFields } from '@desktop-client/components/schedules/ScheduleEditForm';
+import { aqlQuery } from '@desktop-client/queries/aqlQuery';
+import { liveQuery } from '@desktop-client/queries/liveQuery';
+
+export type ScheduleEditState = {
+ isCustom?: boolean;
+ schedule: null | Partial<ScheduleEntity>;
+ upcomingDates: null | string[];
+ error: null | string;
+ fields: ScheduleFormFields;
+ transactions: TransactionEntity[];
+ transactionsMode: 'matched' | 'linked';
+};
+
+type ScheduleEditAction =
+ | {
+ type: 'set-schedule';
+ schedule: Partial<ScheduleEntity>;
+ }
+ | {
+ type: 'set-field';
+ field: 'name' | 'account' | 'payee';
+ value: string;
+ }
+ | {
+ type: 'set-field';
+ field: 'amountOp';
+ value: 'is' | 'isbetween' | 'isapprox';
+ }
+ | {
+ type: 'set-field';
+ field: 'amount';
+ value: number | { num1: number; num2: number };
+ }
+ | {
+ type: 'set-field';
+ field: 'date';
+ value: string | RecurConfig;
+ }
+ | {
+ type: 'set-field';
+ field: 'posts_transaction';
+ value: boolean;
+ }
+ | {
+ type: 'set-transactions';
+ transactions: TransactionEntity[];
+ transactionId?: string;
+ }
+ | {
+ type: 'set-repeats';
+ repeats: boolean;
+ }
+ | {
+ type: 'set-upcoming-dates';
+ dates: null | string[];
+ }
+ | {
+ type: 'form-error';
+ error: null | string;
+ }
+ | {
+ type: 'switch-transactions';
+ mode: 'matched' | 'linked';
+ };
+
+function createScheduleEditReducer(useGetScheduledAmount: boolean = false) {
+ return (
+ state: ScheduleEditState,
+ action: ScheduleEditAction,
+ ): ScheduleEditState => {
+ switch (action.type) {
+ case 'set-schedule': {
+ const schedule = action.schedule;
+
+ // See if there are custom rules
+ const conds = extractScheduleConds(schedule._conditions);
+ const condsSet = new Set(Object.values(conds));
+ const isCustom = !!(
+ schedule._conditions?.find(c => !condsSet.has(c)) ||
+ schedule._actions?.find(a => a.op !== 'link-schedule')
+ );
+
+ return {
+ ...state,
+ schedule: action.schedule,
+ isCustom,
+ fields: {
+ payee: schedule._payee ?? null,
+ account: schedule._account ?? null,
+ amount: schedule._amount || 0,
+ amountOp: schedule._amountOp || 'isapprox',
+ date: schedule._date ?? null,
+ posts_transaction: action.schedule.posts_transaction ?? false,
+ name: schedule.name ?? null,
+ },
+ };
+ }
+ case 'set-field': {
+ if (!(action.field in state.fields)) {
+ throw new Error('Unknown field: ' + action.field);
+ }
+
+ const fields: { [key: string]: typeof action.value | undefined } = {
+ [action.field]: action.value,
+ };
+
+ // If we are changing the amount operator either to or
+ // away from the `isbetween` operator, the amount value is
+ // different and we need to convert it
+ if (
+ action.field === 'amountOp' &&
+ action.value !== state.fields.amountOp
+ ) {
+ if (action.value === 'isbetween') {
+ // We need a range if switching to `isbetween`
+ if (useGetScheduledAmount) {
+ const num = getScheduledAmount(state.fields.amount);
+ fields.amount = { num1: num, num2: num };
+ } else {
+ fields.amount =
+ typeof state.fields.amount === 'number'
+ ? { num1: state.fields.amount, num2: state.fields.amount }
+ : { num1: 0, num2: 0 };
+ }
+ } else if (state.fields.amountOp === 'isbetween') {
+ // We need just a number if switching away from `isbetween`
+ if (useGetScheduledAmount) {
+ const num = getScheduledAmount(state.fields.amount);
+ fields.amount = num;
+ } else {
+ fields.amount =
+ typeof state.fields.amount === 'number'
+ ? state.fields.amount
+ : state.fields.amount?.num1;
+ }
+ }
+ }
+
+ return {
+ ...state,
+ fields: { ...state.fields, ...fields },
+ };
+ }
+
+ case 'set-transactions': {
+ const transactions = action.transactions;
+ // Sort transactions if we have a transactionId to prioritize
+ if (action.transactionId && transactions) {
+ transactions.sort(a => {
+ return action.transactionId === a.id ? -1 : 1;
+ });
+ }
+ return { ...state, transactions };
+ }
+
+ case 'set-repeats': {
+ if (!action.repeats) {
+ return {
+ ...state,
+ fields: {
+ ...state.fields,
+ date: monthUtils.currentDay(),
+ },
+ };
+ }
+
+ const date = {
+ start: monthUtils.currentDay(),
+ frequency: 'monthly',
+ patterns: [],
+ skipWeekend: false,
+ weekendSolveMode: 'after',
+ endMode: 'never',
+ endOccurrences: 1,
+ endDate: monthUtils.currentDay(),
+ } satisfies RecurConfig;
+
+ return {
+ ...state,
+ fields: {
+ ...state.fields,
+ date,
+ },
+ };
+ }
+
+ case 'set-upcoming-dates': {
+ return {
+ ...state,
+ upcomingDates: action.dates,
+ };
+ }
+
+ case 'form-error': {
+ return { ...state, error: action.error };
+ }
+
+ case 'switch-transactions': {
+ return { ...state, transactionsMode: action.mode };
+ }
+
+ default: {
+ throw new Error('Unknown action');
+ }
+ }
+ };
+}
+
+type UseScheduleEditOptions = {
+ scheduleId: string | null | undefined;
+ adding: boolean;
+ initialSchedule?: Partial<ScheduleEntity>;
+ transactionId?: string;
+ useGetScheduledAmount?: boolean;
+};
+
+export function useScheduleEdit({
+ scheduleId,
+ adding,
+ initialSchedule,
+ transactionId,
+ useGetScheduledAmount = false,
+}: UseScheduleEditOptions) {
+ const reducer = createScheduleEditReducer(useGetScheduledAmount);
+
+ const [isLoading, setIsLoading] = useState(false);
+ const [state, dispatch] = useReducer(reducer, {
+ schedule: null,
+ upcomingDates: null,
+ error: null,
+ fields: {
+ payee: null,
+ account: null,
+ amount: null,
+ amountOp: null,
+ date: null,
+ posts_transaction: false,
+ name: null,
+ },
+ transactions: [],
+ transactionsMode: adding ? 'matched' : 'linked',
+ });
+
+ async function loadSchedule() {
+ if (!scheduleId) {
+ return null;
+ }
+
+ setIsLoading(true);
+ const { data } = await aqlQuery(
+ q('schedules').filter({ id: scheduleId }).select('*'),
+ );
+ setIsLoading(false);
+
+ return data[0];
+ }
+
+ const setSchedule = useEffectEvent(async () => {
+ if (adding) {
+ if (initialSchedule) {
+ dispatch({ type: 'set-schedule', schedule: initialSchedule });
+ }
+ return;
+ }
+
+ const schedule = await loadSchedule();
+ if (schedule && state.schedule == null) {
+ dispatch({ type: 'set-schedule', schedule });
+ }
+ });
+
+ // Load schedule on mount
+ useEffect(() => {
+ setSchedule();
+ }, []);
+
+ // Update upcoming dates when date changes
+ useEffect(() => {
+ async function run() {
+ const date = state.fields.date;
+
+ if (date === null) {
+ dispatch({ type: 'set-upcoming-dates', dates: null });
+ return;
+ }
+
+ if (typeof date === 'string') {
+ const today = monthUtils.currentDay();
+ if (date === today || monthUtils.isAfter(date, today)) {
+ dispatch({ type: 'set-upcoming-dates', dates: [date] });
+ } else {
+ dispatch({ type: 'set-upcoming-dates', dates: null });
+ }
+ return;
+ }
+
+ const { data } = await sendCatch('schedule/get-upcoming-dates', {
+ config: date,
+ count: 3,
+ });
+ dispatch({ type: 'set-upcoming-dates', dates: data });
+ }
+ run();
+ }, [state.fields.date]);
+
+ // Load linked transactions
+ useEffect(() => {
+ if (
+ state.schedule &&
+ state.schedule.id &&
+ state.transactionsMode === 'linked'
+ ) {
+ const live = liveQuery<TransactionEntity>(
+ q('transactions')
+ .filter({ schedule: state.schedule.id })
+ .select('*')
+ .options({ splits: 'all' }),
+ {
+ onData: data =>
+ dispatch({
+ type: 'set-transactions',
+ transactions: data,
+ transactionId,
+ }),
+ },
+ );
+ return live.unsubscribe;
+ }
+ }, [state.schedule, state.transactionsMode, transactionId]);
+
+ // Load matched transactions
+ useEffect(() => {
+ let current = true;
+ let unsubscribe: (() => void) | undefined;
+
+ if (state.schedule && state.transactionsMode === 'matched') {
+ const updated = updateScheduleConditions(state.schedule, state.fields);
+
+ if ('error' in updated) {
+ dispatch({ type: 'form-error', error: updated.error });
+ return;
+ }
+
+ // *Extremely* gross hack because the rules are not mapped to
+ // public names automatically. We really should be doing that
+ // at the database layer
+ const conditions = (updated.conditions || []).map(cond => {
+ const typedCond = cond as { field: string; op: string; value: unknown };
+ if (typedCond.field === 'description') {
+ return { ...typedCond, field: 'payee' };
+ } else if (typedCond.field === 'acct') {
+ return { ...typedCond, field: 'account' };
+ }
+ return typedCond;
+ });
+
+ send('make-filters-from-conditions', {
+ conditions,
+ }).then(({ filters }) => {
+ if (current) {
+ const live = liveQuery<TransactionEntity>(
+ q('transactions')
+ .filter({ $and: filters })
+ .select('*')
+ .options({ splits: 'all' }),
+ {
+ onData: data =>
+ dispatch({
+ type: 'set-transactions',
+ transactions: data,
+ transactionId,
+ }),
+ },
+ );
+ unsubscribe = live.unsubscribe;
+ }
+ });
+ }
+
+ return () => {
+ current = false;
+ if (unsubscribe) {
+ unsubscribe();
+ }
+ };
+ }, [state.schedule, state.transactionsMode, state.fields, transactionId]);
+
+ return {
+ state,
+ dispatch,
+ loadSchedule,
+ isLoading,
+ };
+}
diff --git a/packages/desktop-client/src/modals/modalsSlice.ts b/packages/desktop-client/src/modals/modalsSlice.ts
index b7d266ee22..24bef911cf 100644
--- a/packages/desktop-client/src/modals/modalsSlice.ts
+++ b/packages/desktop-client/src/modals/modalsSlice.ts
@@ -464,6 +464,9 @@ export type Modal =
onSwitchBudgetFile: () => void;
};
}
+ | {
+ name: 'schedules-page-menu';
+ }
| {
name: 'envelope-budget-month-menu';
options: {
diff --git a/packages/loot-core/src/types/prefs.ts b/packages/loot-core/src/types/prefs.ts
index f00e239bf1..31ed54dfe7 100644
--- a/packages/loot-core/src/types/prefs.ts
+++ b/packages/loot-core/src/types/prefs.ts
@@ -80,6 +80,7 @@ export type LocalPrefs = Partial<{
'budget.showHiddenCategories': boolean;
'budget.startMonth': string;
'flags.updateNotificationShownForVersion': string;
+ 'schedules.showCompleted': boolean;
reportsViewLegend: boolean;
reportsViewSummary: boolean;
reportsViewLabel: boolean;
diff --git a/upcoming-release-notes/6158.md b/upcoming-release-notes/6158.md
new file mode 100644
index 0000000000..18a0d063be
--- /dev/null
+++ b/upcoming-release-notes/6158.md
@@ -0,0 +1,6 @@
+---
+category: Features
+authors: [MatissJanis]
+---
+
+Mobile schedules page