The most complete open-source travel planner: real-time collaboration, bookings, budgets, packing lists, journals, offline PWA, SSO and an AI-ready MCP server, with planet-wide place search and routing built in.
TypeScript budget-trackercollaborativedockeritinerarymcp-serveroffline-firstopen-sourceopenstreetmappacking-listpwareal-timeself-hostedselfhostedtraveltravel-apptravel-journaltravel-plannertripitwanderlog
fix(mail-ingest): open the prefilled form again for an entry asked for twice in the same trip
Maurice755ca865a4a9
diff --git a/client/src/components/MailIngest/useMailPrefillLink.test.ts b/client/src/components/MailIngest/useMailPrefillLink.test.tsnew file mode 100644index 000000000..0d0213463--- /dev/null+++ b/client/src/components/MailIngest/useMailPrefillLink.test.ts@@ -0,0 +1,59 @@+// FE-MAIL-PREFILL-001 to FE-MAIL-PREFILL-002: "Fill in yourself" opens the booking form in the trip.+import { act, renderHook, waitFor } from '@testing-library/react';+import type { BookingImportPreviewItem } from '@trek/shared';+import { createElement, type ReactNode } from 'react';+import { MemoryRouter, useSearchParams } from 'react-router';+import { beforeEach, describe, expect, it, vi } from 'vitest';+import { TranslationProvider } from '../../i18n/TranslationContext';++const repo = vi.hoisted(() => ({ prefill: vi.fn() }));+const toast = vi.hoisted(() => ({ success: vi.fn(), error: vi.fn() }));+vi.mock('../../repo/mailIngestRepo', () => ({ mailIngestRepo: repo }));+vi.mock('../shared/Toast', () => ({ useToast: () => toast }));++const { useMailPrefillLink } = await import('./useMailPrefillLink');++const ITEM = { type: 'hotel', title: 'Hotel Roma' } as BookingImportPreviewItem;++const wrapper = ({ children }: { children: ReactNode }) =>+ createElement(+ MemoryRouter,+ { initialEntries: ['/trips/5?mailPrefill=12'] },+ createElement(TranslationProvider, null, children)+ );++function setup() {+ const startImportReview = vi.fn();+ const view = renderHook(+ () => {+ const [searchParams, setSearchParams] = useSearchParams();+ useMailPrefillLink({ searchParams, setSearchParams, loaded: true, startImportReview });+ return { searchParams, setSearchParams };+ },+ { wrapper }+ );+ return { ...view, startImportReview };+}++beforeEach(() => {+ vi.clearAllMocks();+ repo.prefill.mockResolvedValue({ trip_id: 5, item: ITEM });+});++describe('useMailPrefillLink', () => {+ it('FE-MAIL-PREFILL-001: opens the form once and takes the parameter out of the address', async () => {+ const { result, startImportReview } = setup();+ await waitFor(() => expect(startImportReview).toHaveBeenCalledTimes(1));+ expect(startImportReview.mock.calls[0].slice(0, 3)).toEqual([[ITEM], [], 'bookings']);+ expect(repo.prefill).toHaveBeenCalledWith(12);+ expect(result.current.searchParams.get('mailPrefill')).toBeNull();+ });++ it('FE-MAIL-PREFILL-002: the same entry asked for again in the open trip opens the form again', async () => {+ const { result, startImportReview } = setup();+ await waitFor(() => expect(startImportReview).toHaveBeenCalledTimes(1));+ act(() => result.current.setSearchParams({ mailPrefill: '12' }));+ await waitFor(() => expect(startImportReview).toHaveBeenCalledTimes(2));+ expect(result.current.searchParams.get('mailPrefill')).toBeNull();+ });+});diff --git a/client/src/components/MailIngest/useMailPrefillLink.ts b/client/src/components/MailIngest/useMailPrefillLink.tsindex ac89c0586..11d4d3d25 100644--- a/client/src/components/MailIngest/useMailPrefillLink.ts+++ b/client/src/components/MailIngest/useMailPrefillLink.ts@@ -29,7 +29,11 @@ export function useMailPrefillLink({const handled = useRef<string | null>(null);useEffect(() => {- if (!requested || !loaded || handled.current === requested) return;+ if (!requested) {+ handled.current = null;+ return;+ }+ if (!loaded || handled.current === requested) return;handled.current = requested;setSearchParams((prev) => {