Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

🐛 Bug Report: useUpdateUserGlobalPreferences - Cannot read properties of undefined (reading 'preference') #6372

Open
2 tasks done
thomasJourdin opened this issue Aug 21, 2024 · 1 comment
Labels

Comments

@thomasJourdin
Copy link

📜 Description

I work on a React/Typescript app and i'm currently implementing a custom notification interface based on all the hooks available through the package (@novu/notification-center).

I'm facing an error using the following hook : "useUpdateUserGlobalPreferences" and more precisely the "updateUserGlobalPreferences" method available throught this hook

👟 Reproduction steps

  1. Setup a React environment

  2. Install @novu/notification-center package (2.0.0-canary.0)

  3. Create a component using the hook "useUpdateUserGlobalPreferences", for example :

import { ReactElement, useEffect } from 'react';
import { useFetchUserGlobalPreferences, useUpdateUserGlobalPreferences } from '@novu/notification-center';

function UserNotificationsSettingsForm(): ReactElement {
  const { refetch, data } = useFetchUserGlobalPreferences();
  const { updateUserGlobalPreferences } = useUpdateUserGlobalPreferences();

  useEffect(() => {
    refetch();
  }, []);

  const handleUpdateUserGlobalPreferences = () => {
    updateUserGlobalPreferences({
      preferences: [
        {
          channelType: 'email',
          enabled: false,
        },
      ],
      enabled: true,
    });
  };

  return (
    <div>
      <button type="button" onClick={() => handleUpdateUserGlobalPreferences()}>
        Update Preferences
      </button>
    </div>
  );
}

export default UserNotificationsSettingsForm;
  1. Call the "updateUserGlobalPreferences" method (in the example, with a simple button click)

👍 Expected behavior

It should update user global preferences and return success (or nothing)

👎 Actual Behavior with Screenshots

It actually encounter an error in the "useUpdateUserGlobalPreferences.js" file as mentionned in this error message :
image

It seems that the function tries to reach a key in the "object" named "old" but this is impossible because of the type of "old" wich seems to be an array :
image

Novu version

2.0.0-canary.0

npm version

No response

node version

No response

📃 Provide any additional context for the Bug.

The value of "data" object given by the hook "useFetchUserGlobalConfiguration" is the following :
[ { "preference": { "enabled": true, "channels": { "email": true, "sms": true, "in_app": true, "chat": true, "push": true } } } ]

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

  • I checked and didn't find a similar issue

🏢 Have you read the Contributing Guidelines?

Are you willing to submit PR?

None

Copy link

linear bot commented Aug 21, 2024

NV-4231 🐛 Bug Report:

@thomasJourdin thomasJourdin changed the title 🐛 Bug Report: 🐛 Bug Report: useUpdateUserGlobalPreferences - Cannot read properties of undefined (reading 'preference') Aug 26, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant