From a7cabc5395d7a8fe33ffedce3c1baaaa8b25bf40 Mon Sep 17 00:00:00 2001 From: Claude Date: Mon, 1 Jun 2026 07:40:16 +0000 Subject: [PATCH] feat(notifications): deep-link card purchase push to card screen Route notification taps by the `type` the backend sets in the payload. Card transaction notifications now open the card screen instead of always landing on home, completing the existing deep-link TODO in the tap handler. https://claude.ai/code/session_01Wxoh4LSUztzSkDBgb66n67 --- hooks/usePushNotifications.ts | 26 ++++++++++++++++++++------ 1 file changed, 20 insertions(+), 6 deletions(-) diff --git a/hooks/usePushNotifications.ts b/hooks/usePushNotifications.ts index dd2eea30a..3f830989a 100644 --- a/hooks/usePushNotifications.ts +++ b/hooks/usePushNotifications.ts @@ -1,7 +1,7 @@ import { useEffect } from 'react'; import { Platform } from 'react-native'; import * as Notifications from 'expo-notifications'; -import { useRouter } from 'expo-router'; +import { Href, useRouter } from 'expo-router'; import messaging from '@react-native-firebase/messaging'; import { path } from '@/constants/path'; @@ -9,6 +9,19 @@ import { registerPushToken } from '@/lib/api'; import { registerForPushNotificationsAsync } from '@/lib/registerForPushNotifications'; import { useUserStore } from '@/store/useUserStore'; +/** + * Map a push notification's `type` (set by the backend) to an in-app route. + * Card payment notifications open the card screen; anything else goes home. + */ +function getNotificationRoute(type?: string): Href { + switch (type) { + case 'card-transaction': + return path.CARD; + default: + return path.HOME; + } +} + /** * Manages push notification lifecycle: token refresh and notification tap handling. * Must be mounted inside the root layout so listeners are active for the entire session. @@ -39,12 +52,13 @@ export function usePushNotifications() { } }); - // Handle notification taps (user taps a notification from the system tray) + // Handle notification taps (user taps a notification from the system tray). + // Deep-link based on the `type` the backend set in the notification data; + // fall back to home for anything unrecognised. const notificationResponseSubscription = Notifications.addNotificationResponseReceivedListener( - _response => { - // Future: read _response.notification.request.content.data.route for deep linking - // e.g., router.replace(_response.notification.request.content.data.route as any); - router.replace(path.HOME); + response => { + const data = response.notification.request.content.data as { type?: string } | undefined; + router.replace(getNotificationRoute(data?.type)); }, );