Skip to content

Add NotificationDeepLinkHandler and related tests for handling deep l…#268

Open
Chrisbankz0 wants to merge 3 commits intoamina69:mainfrom
Chrisbankz0:feat/notification-deeplink-handler
Open

Add NotificationDeepLinkHandler and related tests for handling deep l…#268
Chrisbankz0 wants to merge 3 commits intoamina69:mainfrom
Chrisbankz0:feat/notification-deeplink-handler

Conversation

@Chrisbankz0
Copy link
Copy Markdown

#closes #234

PR Summary

Adds a notification deep-link handler for the PetAd frontend application. On app startup, the handler checks for a notificationId query parameter, fetches the associated notification, marks it as read, navigates to the correct route using notificationRouter(), and removes the query parameter from the URL.

What changed

  • Added src/lib/NotificationDeepLinkHandler.tsx

    • Reads ?notificationId= from the current URL on app mount.
    • Fetches /api/notifications/:id to retrieve the notification payload.
    • Marks the notification as read with PATCH /api/notifications/:id/read.
    • Uses notificationRouter() to determine the destination route.
    • Removes notificationId from the URL after handling.
    • Handles 404 by logging a warning and continuing without navigation.
  • Updated src/App.tsx

    • Mounted <NotificationDeepLinkHandler /> globally so deep links are processed as soon as the app renders.
  • Updated src/mocks/handlers/notify.ts

    • Added mock support for GET /api/notifications/:id in the development/test mock server.
  • Added tests

    • src/lib/__tests__/NotificationDeepLinkHandler.test.tsx
    • Covered handling for valid notification IDs and 404 cases.
    • Existing router behavior continues to be validated by src/lib/__tests__/notificationRouter.test.ts.

Why this matters

This change enables notification deep-linking for the app, allowing users to open a URL with ?notificationId= and be routed directly to the relevant page while still marking the notification as read. It also removes the query parameter after processing so the URL remains clean.

Testing instructions

  1. Install dependencies if needed:

    • npm install
  2. Run the focused tests:

    • node_modules/.bin/vitest run src/lib/__tests__/NotificationDeepLinkHandler.test.tsx src/lib/__tests__/notificationRouter.test.ts
  3. Run the app:

    • npm run dev
  4. Validate deep-link behavior in the browser:

    • Open http://localhost:5173/?notificationId=notif-001
    • Confirm the app navigates to /adoption/adoption-001/settlement
    • Confirm the URL no longer contains notificationId
  5. Validate 404 handling:

    • Open http://localhost:5173/?notificationId=missing-id
    • Confirm no navigation occurs and the query parameter is removed

Notes

  • The implementation uses existing app infrastructure and the centralized apiClient for API calls.
  • The deep-link handler runs once on initial mount and does not render UI itself.
  • If the notification fetch fails with a non-404 error, the error is re-thrown so the normal app error handling can take over.

#closes

@drips-wave
Copy link
Copy Markdown

drips-wave bot commented Mar 28, 2026

@Chrisbankz0 Great news! 🎉 Based on an automated assessment of this PR, the linked Wave issue(s) no longer count against your application limits.

You can now already apply to more issues while waiting for a review of this PR. Keep up the great work! 🚀

Learn more about application limits

@amina69
Copy link
Copy Markdown
Owner

amina69 commented Mar 28, 2026

@Chrisbankz0 you have lint error

@amina69
Copy link
Copy Markdown
Owner

amina69 commented Mar 28, 2026

@Chrisbankz0 lint erorrs
Screenshot from 2026-03-28 16-10-29

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Frontend · Notification UI] Create NotificationDeepLinkHandler

2 participants