@logaflow/react
Version:
Streamline user feedback collection with Logaflow. Efficiently collect feedback from your users to accelerate bug fixes and increase product impact.
72 lines (71 loc) • 1.82 kB
JavaScript
import { jsx as p } from "react/jsx-runtime";
import { useState as d, useCallback as i, useEffect as u } from "react";
const m = "logaflow-webcomponent-js";
function b({
projectKey: e,
useCustomTrigger: n,
userId: o,
name: a,
email: s,
avatar: r,
triggerText: w
}) {
const [g, l] = d(!1), c = i(() => {
if (document.querySelector("#" + m)) {
l(!0);
return;
}
const t = document.createElement("script"), f = window._is_logaflow_debug ? "http://localhost:4001" : "https://widget.logaflow.com";
t.crossOrigin = "true", t.async = !0, t.type = "module", t.src = `${f}/addons/logaflow-widget.es.js?version=3.0.0`, t.onload = function() {
l(!0);
}, document.head.appendChild(t);
}, []);
return u(() => {
e && c();
}, [c, e]), g ? /* @__PURE__ */ p(
"logaflow-widget",
{
"project-key": e,
"use-custom-trigger": n,
avatar: r,
email: s,
name: a,
"user-id": o,
"trigger-text": w
}
) : null;
}
function h() {
const [e, n] = d(!1), o = i((s) => {
const { data: r } = s;
r.from === "logaflowwidget" && r.state && n(r.state.open);
}, []), a = i(() => {
const s = {
from: "logaflowlib",
action: "open"
};
window.postMessage(s, window.location.origin);
}, []);
return u(() => (window.removeEventListener("message", o), window.addEventListener("message", o), () => {
window.removeEventListener("message", o);
}), [o]), { isOpen: e, open: a };
}
function v() {
return { setUser: i((n) => {
window.postMessage(
{
from: "logaflowlib",
action: "setuser",
payload: {
user: n
}
},
window.location.origin
);
}, []) };
}
export {
b as LogaflowWidget,
h as useLogaflowPopup,
v as useLogaflowUser
};