novuhq / novu

Open-Source Notification Platform. Embeddable Notification Center, E-mail, Push and Slack Integrations.
https://novu.co
Other
34.76k stars 3.56k forks source link

[NV-1842] 🐛 Bug Report: useFetchNotifications doesn't allow to use useMarkNotificationsAs #3016

Open antoniodinovi opened 1 year ago

antoniodinovi commented 1 year ago

📜 Description

When i try to use the function markNotificationAs exposed by useMarkNotificationsAs the application return an error but the notification state is update

client.js?5139:1 TypeError: Cannot read properties of undefined (reading 'pages')
    at eval (index.js?600e:1:17571)
    at functionalUpdate (utils.mjs?c391:8:1)
    at QueryClient.setQueryData (queryClient.mjs?10f3:91:34)
    at eval (queryClient.mjs?10f3:107:6)
    at Array.map (<anonymous>)
    at eval (queryClient.mjs?10f3:105:31)
    at Object.batch (notifyManager.mjs?41b3:20:1)
    at QueryClient.setQueriesData (queryClient.mjs?10f3:105:12)
    at Object.onSuccess (index.js?600e:1:17518)
    at Mutation.execute (mutation.mjs?9f7c:141:1)

👟 Reproduction steps

  const {
    data: notifications,
    hasNextPage,
    isFetching,
    refetch,
    fetchNextPage
  } = useFetchNotifications({ query: { feedIdentifier: 'app' } });

......

const { markNotificationsAs } = useMarkNotificationsAs();

const onClick = async () => {
  if (!notification?.seen) {
    markNotificationsAs({
      seen: true,
      read: false,
      messageId: notification?._id
    });
  }
};

Invoking onClick starts the api call and the state of the notification is updated on refresh but the function return an error

👍 Expected behavior

Call the function shoud not throw errors

👎 Actual Behavior with Screenshots

Click on the unseen notification to mark as seen throw the console error

image

📃 Provide any additional context for the Bug.

No response

👀 Have you spent some time to check if this bug has been raised before?

🏢 Have you read the Contributing Guidelines?

Are you willing to submit PR?

None

NV-1842

antoniodinovi commented 1 year ago

[Update], after reading the source code i found that this appens only when notifications are fetched using useFetchNotifications, using useNotifications solve the problem. But i need to mark as read also notification filtered by feed.

Abobos commented 6 months ago

Can I work on this issue? @scopsy

scopsy commented 6 months ago

@Abobos we are currently working on a completely reimaged headless and react component suite. So this will be handled by the new SDK :)