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

How to Detect Modal Close or Preferences Update? #13

Open
cristinaITdeveloper opened this issue Nov 21, 2024 · 5 comments
Open

How to Detect Modal Close or Preferences Update? #13

cristinaITdeveloper opened this issue Nov 21, 2024 · 5 comments
Labels
question Further information is requested

Comments

@cristinaITdeveloper
Copy link

I’m using this library in my Next.js application, and I’ve implemented a button in the footer that opens the preferences modal using the openPreferences method.

Now, I’d like to detect when the modal is closed or when the user updates their preferences. I’ve tried listening for events such as preferences_updated or iubenda_preferences_updated, but they don’t seem to be triggered.

Additionally, I see there’s a dispatchUserPreferences method in the library, but I’m not sure how to use it effectively in this context. Could you please clarify:

  • What is the correct way to detect when the modal is closed or the preferences are updated?
  • How should dispatchUserPreferences be used in this case?

Any guidance or examples would be greatly appreciated.

@liarco
Copy link
Member

liarco commented Nov 21, 2024

Hi @cristinaITdeveloper,
Thanks for reaching out.

Can you please provide me with a minimal reproducer to show me what you are trying to achieve? A basic NextJS project with minimal dependencies and a sample page with some comments about the expected behavior might help.
Unfortunately, I can't provide you with direct support for this kind of stuff (custom needs, code examples, etc.). Here is our support policy. However, I'll do my best to review your repo and try to help you as much as I can.

@liarco liarco added the question Further information is requested label Nov 21, 2024
@cristinaITdeveloper
Copy link
Author

cristinaITdeveloper commented Nov 22, 2024

Hi @liarco, thanks for reply.

I need to know when the user changes consents by opening the modal with the openPreferences method.
I saw the code and there is no way to do it.

Probably the insertion of callbacks (of the open PR) can help in this case by implementing the onConsentGiven and onConsentRejected callbacks.

Also because I noticed that the first time accepting or rejecting from the banner, the dispatchUserPreferences method is invoked to update the context, while when opening the modal with openPreferences there is nothing that notifies the change of preferences.

@liarco
Copy link
Member

liarco commented Nov 22, 2024

Thanks for the additional information. Callbacks are not supported because we have always been able to implement everything without them. Adding callbacks could lead to misuse, so I want to find a real purpose for them before considering adding them.

May I ask what is the use case for this need? Why do you see the need to use callbacks in a React environment?
Understanding the context would help me find the best solution to implement what you need in a way that makes sense for this project, not just your specific use case.

Have you had a chance to look at the source code? The is an example of a custom component that reacts to consent changes. It might be a good place to start.

That said, if you really need this feature, then providing us with a repo is not an option, it's the only way for me to understand what you want to do and help you here. 🙏

Thanks for your understanding.

@cristinaITdeveloper
Copy link
Author

cristinaITdeveloper commented Nov 22, 2024

I have already written previously what I would need.
I need to know when the user opens the modal with openPreferences and changes the consents.
I ask this because by debugging with logs, I have not seen the updated context data.

@liarco
Copy link
Member

liarco commented Nov 22, 2024

I have already written previously what I would need.
I need to know when the user opens the modal with openPreferences and changes the consents.

Ok, this is "what you need" and I get it, but I asked the "use case for this need", which is what you need it for.

For instance: "I want to be able to update a css class on an element whenever a user enables the marketing features". Of course this specific result can be obtained without the callbacks, but this is exactly my point: I can't think of a use case that requires this feature.

I ask this because by debugging with logs, I have not seen the updated context data.

What do you mean? Is this a bug? It's hard to understand what's not working without a sample project to review an run on my machine. Can't you really create one that shows this issue?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Further information is requested
Projects
None yet
Development

No branches or pull requests

2 participants