@reqdesk/widget 0.2.0 → 0.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/react.js CHANGED
@@ -1,4 +1,4 @@
1
- import { C as setOidcTokenProvider, S as configureWidgetClient, _ as submitReply, a as saveTrackingToken, b as trackTicket, c as getWidgetStyles, d as en, f as closeTicket, g as resolveWidgetUser, h as listMyTickets, i as loadWidgetEmail, l as themeToVars, m as getTicketDetail, n as getTrackingTokens, o as saveWidgetConfig, p as getCategories, r as loadWidgetConfig, s as saveWidgetEmail, t as clearWidgetEmail, u as ar, v as submitTicket, x as uploadAttachment, y as submitTrackingReply } from "./storage-PjDHb5v7.js";
1
+ import { C as configureWidgetClient, S as uploadAttachment, _ as resolveWidgetUser, a as saveTrackingToken, b as submitTrackingReply, c as getWidgetStyles, d as ar, f as en, g as listMyTickets, h as getTicketDetail, i as loadWidgetEmail, l as themeToStyle, m as getCategories, n as getTrackingTokens, o as saveWidgetConfig, p as closeTicket, r as loadWidgetConfig, s as saveWidgetEmail, t as clearWidgetEmail, v as submitReply, w as setOidcTokenProvider, x as trackTicket, y as submitTicket } from "./storage-BG7rsgWE.js";
2
2
  import { createContext, useCallback, useContext, useEffect, useMemo, useRef, useState } from "react";
3
3
  import { QueryClient, QueryClientProvider, keepPreviousData, queryOptions, useMutation, useQuery, useQueryClient } from "@tanstack/react-query";
4
4
  import { Fragment, jsx, jsxs } from "react/jsx-runtime";
@@ -31,7 +31,11 @@ function onAuthStateChange(listener) {
31
31
  listeners = listeners.filter((l) => l !== listener);
32
32
  };
33
33
  }
34
- async function initWidgetAuth(config) {
34
+ function initWidgetAuth(config) {
35
+ initPromise = _initWidgetAuth(config);
36
+ return initPromise;
37
+ }
38
+ async function _initWidgetAuth(config) {
35
39
  setState({ isLoading: true });
36
40
  try {
37
41
  const { createOidc } = await import("oidc-spa/core");
@@ -68,8 +72,13 @@ async function initWidgetAuth(config) {
68
72
  });
69
73
  }
70
74
  }
75
+ let initPromise = null;
71
76
  async function login() {
72
- if (!oidcInstance) return;
77
+ if (!oidcInstance && initPromise) await initPromise;
78
+ if (!oidcInstance) {
79
+ console.warn("[reqdesk-widget] Cannot login: OIDC not initialized. Check auth config.");
80
+ return;
81
+ }
73
82
  await oidcInstance.login({ doesCurrentHrefRequiresAuth: false });
74
83
  }
75
84
  async function logout() {
@@ -297,7 +306,7 @@ function TicketForm({ mode = "inline", onTicketCreated, onError, className, styl
297
306
  onError,
298
307
  t
299
308
  ]);
300
- const cssVars = themeToVars(ctx.theme);
309
+ const cssVars = themeToStyle(ctx.theme);
301
310
  const content = success ? /* @__PURE__ */ jsxs("div", {
302
311
  className: "rqd-success",
303
312
  style: {
@@ -435,7 +444,7 @@ function TicketForm({ mode = "inline", onTicketCreated, onError, className, styl
435
444
  className,
436
445
  style: {
437
446
  ...style,
438
- cssText: cssVars
447
+ ...cssVars
439
448
  },
440
449
  children: /* @__PURE__ */ jsx("div", {
441
450
  className: "rqd-body",
@@ -444,7 +453,7 @@ function TicketForm({ mode = "inline", onTicketCreated, onError, className, styl
444
453
  }) });
445
454
  return /* @__PURE__ */ jsx(ShadowRoot, { children: /* @__PURE__ */ jsx("div", {
446
455
  className: `rqd-inline ${className ?? ""}`,
447
- style: { cssText: cssVars },
456
+ style: cssVars,
448
457
  children: /* @__PURE__ */ jsx("div", {
449
458
  className: "rqd-body",
450
459
  children: content
@@ -456,10 +465,10 @@ function TicketForm({ mode = "inline", onTicketCreated, onError, className, styl
456
465
  function SupportPortal({ className }) {
457
466
  const ctx = useReqdeskContext();
458
467
  const { isLoading } = useReqdesk();
459
- const cssVars = themeToVars(ctx.theme);
468
+ const cssVars = themeToStyle(ctx.theme);
460
469
  return /* @__PURE__ */ jsx(ShadowRoot, { children: /* @__PURE__ */ jsx("div", {
461
470
  className: `rqd-inline ${className ?? ""}`,
462
- style: { cssText: cssVars },
471
+ style: cssVars,
463
472
  children: /* @__PURE__ */ jsx("div", {
464
473
  className: "rqd-body",
465
474
  children: isLoading ? /* @__PURE__ */ jsx("p", {
@@ -1552,7 +1561,7 @@ function FloatingWidget({ position = "bottom-right", contained = false, onTicket
1552
1561
  return (translations[activeLang] ?? translations.en)[key] ?? key;
1553
1562
  }, [activeLang, ctx.translations]);
1554
1563
  const isRtl = activeLang === "ar";
1555
- const cssVars = themeToVars(activeTheme);
1564
+ const cssVars = themeToStyle(activeTheme);
1556
1565
  const posClass = `rqd-${position}`;
1557
1566
  const containedClass = contained ? " rqd-contained" : "";
1558
1567
  const brandName = ctx.theme?.brandName;
@@ -1794,7 +1803,7 @@ function FloatingWidget({ position = "bottom-right", contained = false, onTicket
1794
1803
  const canGoBack = view !== "home";
1795
1804
  const goBackTarget = view === "ticket-detail" ? "my-tickets" : "home";
1796
1805
  return /* @__PURE__ */ jsx(ShadowRoot, { children: /* @__PURE__ */ jsxs("div", {
1797
- style: { cssText: cssVars },
1806
+ style: cssVars,
1798
1807
  ...isRtl ? { dir: "rtl" } : {},
1799
1808
  children: [/* @__PURE__ */ jsx("button", {
1800
1809
  className: `rqd-fab ${posClass}${containedClass}`,