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

Customer profile is not loaded on page load #19

Open
furiousteabag opened this issue May 19, 2023 · 10 comments
Open

Customer profile is not loaded on page load #19

furiousteabag opened this issue May 19, 2023 · 10 comments

Comments

@furiousteabag
Copy link

Hey guys!

I am using an example of agent-app-sdk with the latest version of SDK (1.6.4) for retrieving the currently opened chat. It works when I change the current chat, but it does not load the current chat when I've just opened an app. So in order to set a customer profile agent have to click on some chat even when he has a chat opened.

To be precise, I have the following component:

import React, { Component, useEffect } from "react"
import { createDetailsWidget } from "@livechat/agent-app-sdk"

const MainForm = () => {
    useEffect(() => {
        createDetailsWidget().then((widget) => {
            widget.on("customer_profile", (profile) => {
                console.log("Customer profile: ", profile)
            })
        })
    }, [])
    return (
        <div>
            <h1>hello</h1>
        </div>
    )
}

I expect it to print customer profiles in 2 situations:

  1. When the agent changes the selected chat: it works perfectly
  2. When component loads and chat is already selected: this does not work

Here is the screencast of this in action:

agent-app-sdk-bug-showcase.mov

If you need some other info let me know!
Thanks.

@furiousteabag
Copy link
Author

@jakubsikora sorry for pinging you, because the repo does not seem very active!

@wojciechdudek-livechat
Copy link
Collaborator

wojciechdudek-livechat commented May 22, 2023

Hi,

thanks for letting us know. We'll definitely look at it, but in the meantime - Developer Console supports new application blocks which can make the process of bootstrapping app much faster and easier. Can you have a look at video below and try to reproduce your problem with that approach? You can look at the results and tell us if it matches your expectation.

On the video I've created new sample app based on our fullstack-app template (NextJS), with authorization block and Agent App chat widget. Instead of hosting sample app locally I've used deployment block - it's currently in beta version hidden under "experimental features", but you can turn them on in your Console's profile settings easily.

On the video it seems to work as you expected.
https://github.com/livechat/products-sdk/assets/117641044/4b008992-e356-48db-a473-f36bd29c4145


Link to template:
https://github.com/livechat/developer-app-template-nextjs

Implementation of hook dedicated for chat widget:
https://github.com/livechat/developer-app-template-nextjs/blob/main/hooks/products/livechat/useDetailsWidget.ts

Usage of page:
https://github.com/livechat/developer-app-template-nextjs/blob/main/pages/livechat/chat-details.tsx

@furiousteabag
Copy link
Author

Thank you for your answer!

I've tried to deploy with the new feature, but I could not link the repository (no repositories show up) although I've authenticated via Github.
image

But I don't think it is a deployment issue because it will execute the same code.

I've changed my React code so it looks the same as in your working example:

const MainForm = () => {
    const [widget, setWidget] = useState(null)
    const [customerProfile, setCustomerProfile] = useState(null)

    const widgetButtonHandler = useCallback(() => {
        // Handler for widget buttons
    }, [])

    useEffect(() => {
        createDetailsWidget().then(setWidget)
    }, [])

    useEffect(() => {
        if (widget) {
            setCustomerProfile(widget.getCustomerProfile())

            widget.on("customer_profile", (customerProfile) => {
                setCustomerProfile(customerProfile)
                console.log("Customer profile: ", customerProfile)
            })
            widget.on("customer_details_section_button_click", widgetButtonHandler)

            return () => {
                widget.off("customer_profile", setCustomerProfile)
                widget.off("customer_details_section_button_click", widgetButtonHandler)
            }
        }
        // eslint-disable-next-line react-hooks/exhaustive-deps
    }, [widget, widgetButtonHandler])

    return (
        <div>
            <h1>{customerProfile?.name}</h1>
        </div>
    )
}

But it still works only on selection chat but not on load.
I am wondering if it is a problem with React overall because I have a lot of code already and it would be great not to rewrite everything via NextJS.

Thank you once again!

@furiousteabag
Copy link
Author

Hey guys!
Any updates on the issue?
Thank you!

@furiousteabag
Copy link
Author

Hi @wojciechdudek-livechat!
Do you have any updates on that by any chance?

@danishs360
Copy link

Any Updates on this ?? @wojciechdudek-livechat

@wojciechdudek-livechat
Copy link
Collaborator

wojciechdudek-livechat commented Aug 31, 2023

Hi guys, still working on the solution.

@SmirnovAlexander , @danishs360 - do you guys both use authorization block with redirection strategy in your app?

@furiousteabag
Copy link
Author

@wojciechdudek-livechat Yes

@wojciechdudek-livechat
Copy link
Collaborator

wojciechdudek-livechat commented Sep 28, 2023

@SmirnovAlexander, as livechat/accounts-sdk#13 is already resolved - can you confirm that upgrading accounts-sdk to v2.0.8 resolves your problem?

@furiousteabag
Copy link
Author

@wojciechdudek-livechat thanks! It works now.

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

No branches or pull requests

3 participants