|
|
@@ -8,7 +8,15 @@ import {
|
|
|
useCallback,
|
|
|
type ReactNode,
|
|
|
} from "react";
|
|
|
-import { LiveChat, type LiveChatVisibilityType } from "@/components/common/CustomerService/LiveChat/LiveChat";
|
|
|
+import {
|
|
|
+ LiveChatWidget,
|
|
|
+ type EventHandlerPayload,
|
|
|
+ type WidgetState
|
|
|
+} from "@livechat/widget-react";
|
|
|
+
|
|
|
+type LiveChatVisibilityType = WidgetState['visibility'];
|
|
|
+type LiveChatReadyEventHandlerPayload = EventHandlerPayload<"onReady">;
|
|
|
+
|
|
|
|
|
|
type LiveChatContextType = {
|
|
|
visibility: LiveChatVisibilityType;
|
|
|
@@ -27,7 +35,7 @@ export function LiveChatProvider({
|
|
|
children:ReactNode;
|
|
|
}){
|
|
|
|
|
|
- const [visibility, setVisibility]=useState<LiveChatVisibilityType>('hidden');
|
|
|
+ const [visibility, setVisibility]=useState<LiveChatVisibilityType>('minimized');
|
|
|
const isUseMiniRef = useRef(false);
|
|
|
|
|
|
const openMiniMode = useCallback(() => {
|
|
|
@@ -50,13 +58,20 @@ export function LiveChatProvider({
|
|
|
|
|
|
},[]);
|
|
|
|
|
|
- const visibilityChanged = (str: LiveChatVisibilityType) => {
|
|
|
+ const visibilityChanged = useCallback((event: EventHandlerPayload<"onVisibilityChanged">) => {
|
|
|
+ const str = event.visibility;
|
|
|
if(str === 'minimized' && !isUseMiniRef.current) {
|
|
|
- hide();
|
|
|
+ setVisibility('hidden');
|
|
|
}
|
|
|
- };
|
|
|
+ },[]);
|
|
|
|
|
|
- const ready = () => {};
|
|
|
+ const ready = useCallback((e:LiveChatReadyEventHandlerPayload) => {
|
|
|
+ console.log(e);
|
|
|
+ if(!isUseMiniRef.current) {
|
|
|
+ setVisibility('hidden');
|
|
|
+ }
|
|
|
+ },[]);
|
|
|
+ console.log("[LiveChatProvider render]", visibility);
|
|
|
return (
|
|
|
<LiveChatContext.Provider
|
|
|
value={{
|
|
|
@@ -68,11 +83,13 @@ export function LiveChatProvider({
|
|
|
}}
|
|
|
>
|
|
|
{children}
|
|
|
- <LiveChat
|
|
|
+ <LiveChatWidget
|
|
|
+ license="8982890"
|
|
|
visibility={visibility}
|
|
|
- readyHandler={ready}
|
|
|
- visibilityChangeHandler={visibilityChanged}
|
|
|
+ onReady={ready}
|
|
|
+ onVisibilityChanged={visibilityChanged}
|
|
|
/>
|
|
|
+
|
|
|
</LiveChatContext.Provider>
|
|
|
|
|
|
|