Skip to content

armgit / TREK

Public Imported from GitHub
0

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.

fix(notifications): drop a tab the planner lacks from the URL, link booking mails to the reservations tab, open the chat on the phone

Mauricea76a96cccad2
diff --git a/client/src/components/Notifications/useNotificationItemActions.test.ts b/client/src/components/Notifications/useNotificationItemActions.test.ts
index 36d5dc7c4..df27636ad 100644
--- a/client/src/components/Notifications/useNotificationItemActions.test.ts
+++ b/client/src/components/Notifications/useNotificationItemActions.test.ts
@@ -118,6 +118,16 @@ describe('useNotificationItemActions', () => {
expect(navigate).toHaveBeenLastCalledWith('/dashboard');
});
+ it('FE-COMP-NOTIFITEM-ACTIONS-006: an old booking mail link names the reservations tab by its id', async () => {
+ const { result } = renderHook(() =>
+ useNotificationItemActions(
+ notification({ title_key: 'notif.mail_booking_added.title', navigate_target: '/trips/7?tab=bookings' })
+ )
+ );
+ await act(() => result.current.handleNavigate());
+ expect(navigate).toHaveBeenLastCalledWith('/trips/7?tab=buchungen');
+ });
+
it('FE-COMP-NOTIFITEM-ACTIONS-002: navigating marks an unread item read first, then follows and closes', async () => {
const onClose = vi.fn();
const { result } = renderHook(() => useNotificationItemActions(notification(), onClose));
diff --git a/client/src/components/Notifications/useNotificationItemActions.ts b/client/src/components/Notifications/useNotificationItemActions.ts
index 663a054f5..955a691c7 100644
--- a/client/src/components/Notifications/useNotificationItemActions.ts
+++ b/client/src/components/Notifications/useNotificationItemActions.ts
@@ -14,7 +14,8 @@ function notificationTarget(notification: InAppNotification): string | null {
(notification.scope === 'trip' && notification.target > 0 ? String(notification.target) : null);
return tripId ? `/trips/${tripId}?tab=collab` : '/dashboard';
}
- return notification.navigate_target;
+ // Booking mails used to link a tab by its English name, which the planner does not have.
+ return notification.navigate_target?.replace(/([?&]tab=)bookings(?=&|#|$)/, '$1buchungen') ?? null;
}
/** Compact relative timestamp ("5m" / "3h" / "2d"); under a minute it reads `justNow`. */
diff --git a/client/src/mobile/screens/trip/MTripShell.tsx b/client/src/mobile/screens/trip/MTripShell.tsx
index 972b45b0b..79818e30d 100644
--- a/client/src/mobile/screens/trip/MTripShell.tsx
+++ b/client/src/mobile/screens/trip/MTripShell.tsx
@@ -340,6 +340,13 @@ export default function MTripShell({
if (mode === 'browse') setMode('go')
}
+ // A notification link opens its tab the way the dock does, and a message one the chat.
+ useEffect(() => {
+ if (!planner.tabLink) return
+ setMode(m => (m === 'browse' ? 'go' : m))
+ if (planner.tabLink.tab === 'collab') setCollabTab('chat')
+ }, [planner.tabLink])
+
const setTravelMode = (next: MTripMode) => {
setBrowseFromEdit(next === 'browse' && mode === 'edit')
setMode(next)
diff --git a/client/src/pages/tripPlanner/useAssistantDeepLink.test.ts b/client/src/pages/tripPlanner/useAssistantDeepLink.test.ts
index 8e4013b4d..f2d574b9f 100644
--- a/client/src/pages/tripPlanner/useAssistantDeepLink.test.ts
+++ b/client/src/pages/tripPlanner/useAssistantDeepLink.test.ts
@@ -65,10 +65,11 @@ describe('useAssistantTabLink', () => {
const searchParams = new URLSearchParams(query);
const setSearchParams = vi.fn((update: (params: URLSearchParams) => URLSearchParams) => update(searchParams));
const selectTab = vi.fn();
+ const onLinked = vi.fn();
renderHook(() =>
- useAssistantTabLink({ searchParams, setSearchParams: setSearchParams as never, activeTab, selectTab })
+ useAssistantTabLink({ searchParams, setSearchParams: setSearchParams as never, activeTab, selectTab, onLinked })
);
- return { searchParams, setSearchParams, selectTab };
+ return { searchParams, setSearchParams, selectTab, onLinked };
}
it('FE-PLANNER-ASSISTLINK-005: a ?tab= the chat opens while the planner is open switches the tab, once', () => {
@@ -79,13 +80,20 @@ describe('useAssistantTabLink', () => {
expect(searchParams.get('expense')).toBe('7');
});
- it('FE-PLANNER-ASSISTLINK-006: the tab on screen is not switched again; a tab it cannot open is left alone', () => {
+ it('FE-PLANNER-ASSISTLINK-006: the tab on screen is not switched again; a tab it cannot open is dropped from the URL', () => {
const same = setupTab('tab=finanzplan', 'finanzplan');
expect(same.selectTab).not.toHaveBeenCalled();
expect(same.searchParams.has('tab')).toBe(false);
- const unknown = setupTab('tab=nowhere', 'plan');
+ const unknown = setupTab('tab=nowhere&place=3', 'plan');
expect(unknown.selectTab).not.toHaveBeenCalled();
- expect(unknown.setSearchParams).not.toHaveBeenCalled();
+ expect(unknown.onLinked).not.toHaveBeenCalled();
+ expect(unknown.searchParams.has('tab')).toBe(false);
+ expect(unknown.searchParams.get('place')).toBe('3');
+ });
+
+ it('FE-PLANNER-ASSISTLINK-007: every link it takes is reported, also one to the tab already on screen', () => {
+ expect(setupTab('tab=collab', 'plan').onLinked).toHaveBeenCalledWith('collab');
+ expect(setupTab('tab=collab', 'collab').onLinked).toHaveBeenCalledWith('collab');
});
});
diff --git a/client/src/pages/tripPlanner/useAssistantDeepLink.ts b/client/src/pages/tripPlanner/useAssistantDeepLink.ts
index 027329462..1ef0f1011 100644
--- a/client/src/pages/tripPlanner/useAssistantDeepLink.ts
+++ b/client/src/pages/tripPlanner/useAssistantDeepLink.ts
@@ -59,26 +59,33 @@ interface AssistantTabLinkOptions {
activeTab: string;
/** Switches the planner's tab the way its tab bar does. */
selectTab: (tabId: string) => void;
+ /** Told about every link it took, so a shell can open the part of the tab a link means. */
+ onLinked?: (tabId: string) => void;
}
/**
* `?tab=<id>` from a notification or a card in the chat, including while the
* planner is already open. Both desktop and mobile take the requested tab
- * once and then drop it from the URL. What the tab reads beside it stays
- * for that tab to take (`?tab=finanzplan&expense=7`, for example).
+ * once and then drop it from the URL. A tab the planner does not have is
+ * dropped too, so it does not linger in the address bar. What the tab reads
+ * beside it stays for that tab to take (`?tab=finanzplan&expense=7`, for example).
*/
export function useAssistantTabLink({
searchParams,
setSearchParams,
activeTab,
selectTab,
+ onLinked,
}: AssistantTabLinkOptions): void {
const requested = searchParams.get('tab');
const linkable = requested !== null && isDeepLinkableTripTab(requested);
useEffect(() => {
- if (!linkable || requested === null) return;
- if (requested !== activeTab) selectTab(requested);
+ if (requested === null) return;
+ if (linkable) {
+ if (requested !== activeTab) selectTab(requested);
+ onLinked?.(requested);
+ }
setSearchParams(
(params) => {
params.delete('tab');
@@ -86,5 +93,5 @@ export function useAssistantTabLink({
},
{ replace: true }
);
- }, [linkable, requested, activeTab, selectTab, setSearchParams]);
+ }, [linkable, requested, activeTab, selectTab, onLinked, setSearchParams]);
}
diff --git a/client/src/pages/tripPlanner/useTripPlanner.ts b/client/src/pages/tripPlanner/useTripPlanner.ts
index 4cfcc08ea..d9828b12b 100644
--- a/client/src/pages/tripPlanner/useTripPlanner.ts
+++ b/client/src/pages/tripPlanner/useTripPlanner.ts
@@ -290,7 +290,10 @@ export function useTripPlanner() {
}
// Notifications can open a tab while this trip is already mounted, on either layout.
- useAssistantTabLink({ searchParams, setSearchParams, activeTab, selectTab: handleTabChange })
+ // Each link it takes is counted, so the phone shell can open the right part of the tab.
+ const [tabLink, setTabLink] = useState<{ tab: string; seq: number } | null>(null)
+ const onTabLinked = useCallback((tab: string) => setTabLink(prev => ({ tab, seq: (prev?.seq ?? 0) + 1 })), [])
+ useAssistantTabLink({ searchParams, setSearchParams, activeTab, selectTab: handleTabChange, onLinked: onTabLinked })
// handleTabChange is where a tab's lazy load and its session memory happen, and
// the tab we *start* on never goes through it — neither a ?tab= deep link nor a
@@ -741,7 +744,7 @@ export function useTripPlanner() {
dawarichTrailShown, toggleDawarichTrail, dawarichTrail, dawarichHiddenDates, dawarichEnabled: !!enabledAddons.dawarich,
followTrack, roadtripViaCounts,
allowedFileTypes, tripMembers, setTripMembers, refreshMembers, loadAccommodations,
- TRANSPORT_TYPES, TRIP_TABS, activeTab, setActiveTab, handleTabChange,
+ TRANSPORT_TYPES, TRIP_TABS, activeTab, setActiveTab, handleTabChange, tabLink,
leftWidth, rightWidth, leftCollapsed, rightCollapsed, setLeftCollapsed, setRightCollapsed,
leftHidden, rightHidden, toggleLeft, toggleRight, narrowPanels,
startResizeLeft, startResizeRight, nudgeLeft, nudgeRight, resizeMin, resizeMax,
diff --git a/client/tests/unit/mobile/trip/MTripShell.test.tsx b/client/tests/unit/mobile/trip/MTripShell.test.tsx
index 48d242ad9..96fcf7332 100644
--- a/client/tests/unit/mobile/trip/MTripShell.test.tsx
+++ b/client/tests/unit/mobile/trip/MTripShell.test.tsx
@@ -593,6 +593,15 @@ describe('MTripShell', () => {
expect(shellApi.collabTab).toBe('notes')
})
+ it('FE-MOB-SHELL-036b: a message notification opens the chat, not the collab part last open', () => {
+ const { planner, rerenderShell } = renderShell({ activeTab: 'collab' } as Partial<TripPlanner>)
+ fireEvent.click(screen.getByRole('button', { name: 'collab.tabs.notes' }))
+ expect(shellApi.collabTab).toBe('notes')
+ planner.tabLink = { tab: 'collab', seq: 1 }
+ rerenderShell()
+ expect(shellApi.collabTab).toBe('chat')
+ })
+
it('FE-MOB-SHELL-037: setTrTab from a slot routes through the planner and resets browse', () => {
const { planner } = renderShell()
fireEvent.click(screen.getByRole('button', { name: 'trip.mobilePlaces' }))
diff --git a/server/src/nest/notifications/notifications.service.ts b/server/src/nest/notifications/notifications.service.ts
index f15d79b69..cfd9ea16f 100644
--- a/server/src/nest/notifications/notifications.service.ts
+++ b/server/src/nest/notifications/notifications.service.ts
@@ -296,7 +296,7 @@ const EVENT_NOTIFICATION_CONFIG: Record<string, EventNotifConfig> = {
titleKey: 'notif.mail_booking_added.title',
textKey: (p) => (p.role === 'traveller' ? MAIL_BOOKING_TEXT.traveller : MAIL_BOOKING_TEXT.forwarder).textKey,
navigateTextKey: 'notif.action.view_trip',
- navigateTarget: (p) => (p.tripId ? `/trips/${p.tripId}?tab=bookings` : null),
+ navigateTarget: (p) => (p.tripId ? `/trips/${p.tripId}?tab=buchungen` : null),
},
// Bookings from forwarded mails wait in the person's inbox for a decision.
mail_booking_pending: {
diff --git a/server/tests/unit/nest/notifications.service.test.ts b/server/tests/unit/nest/notifications.service.test.ts
index 2e3409760..bd1f2a3b7 100644
--- a/server/tests/unit/nest/notifications.service.test.ts
+++ b/server/tests/unit/nest/notifications.service.test.ts
@@ -682,8 +682,8 @@ describe('send() — in-app notification content', () => {
const notifs = await getInAppNotifications(user.id);
expect(notifs.map((n) => [n.text_key, n.navigate_target])).toEqual(
expect.arrayContaining([
- ['notif.mail_booking_added.text', '/trips/7?tab=bookings'],
- ['notif.mail_booking_added.shared', '/trips/7?tab=bookings'],
+ ['notif.mail_booking_added.text', '/trips/7?tab=buchungen'],
+ ['notif.mail_booking_added.shared', '/trips/7?tab=buchungen'],
['notif.mail_booking_pending.text', '/dashboard?inbox=mail'],
['notif.mail_ingest_paused.text', null],
]),