@heycater/qualification-funnel 1.19.33 → 1.19.35

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/index.esm.js CHANGED
@@ -30597,7 +30597,7 @@ const EVENT_TYPE_TO_ICON = {
30597
30597
  party: "drinks",
30598
30598
  meeting: "fingerfood",
30599
30599
  conference: "buffet",
30600
- workshop: "street_food",
30600
+ workshop: "fine_dining",
30601
30601
  other: null
30602
30602
  };
30603
30603
  const EventTypeTiles = ({
@@ -33242,33 +33242,83 @@ function useAbandonmentTracking(funnelContextRef, state) {
33242
33242
  ]);
33243
33243
  }
33244
33244
  const FEATURE_FLAG_NAME = "qf_redesign_v1";
33245
- function useFunnelVariant() {
33246
- const forceRedesign = typeof window !== "undefined" && window.location.search.includes("variant=redesign");
33247
- const [variant, setVariant] = useState(forceRedesign ? "redesign" : "control");
33245
+ const POSTHOG_POLL_INTERVAL_MS = 100;
33246
+ const POSTHOG_MAX_WAIT_MS = 5e3;
33247
+ function checkPostHogFlag() {
33248
+ if (typeof window === "undefined") return null;
33249
+ const posthog = window.posthog;
33250
+ if (!(posthog == null ? void 0 : posthog.getFeatureFlag)) return null;
33251
+ const flagValue = posthog.getFeatureFlag(FEATURE_FLAG_NAME);
33252
+ if (flagValue === "redesign") return "redesign";
33253
+ if (flagValue === "control") return "control";
33254
+ return null;
33255
+ }
33256
+ function getUrlVariantOverride() {
33257
+ if (typeof window === "undefined") return null;
33258
+ const search = window.location.search;
33259
+ if (search.includes("variant=redesign")) return "redesign";
33260
+ if (search.includes("variant=control")) return "control";
33261
+ return null;
33262
+ }
33263
+ function useFunnelVariantWithLoading() {
33264
+ const urlOverride = getUrlVariantOverride();
33265
+ const [result, setResult] = useState(() => {
33266
+ if (urlOverride) {
33267
+ return { variant: urlOverride, isLoading: false };
33268
+ }
33269
+ const initialFlag = checkPostHogFlag();
33270
+ if (initialFlag !== null) {
33271
+ return { variant: initialFlag, isLoading: false };
33272
+ }
33273
+ return { variant: "control", isLoading: true };
33274
+ });
33248
33275
  useEffect(() => {
33249
- if (forceRedesign) {
33250
- setVariant("redesign");
33276
+ if (urlOverride) {
33277
+ setResult({ variant: urlOverride, isLoading: false });
33251
33278
  return;
33252
33279
  }
33253
- if (typeof window === "undefined" || !window.posthog) {
33280
+ const flagValue = checkPostHogFlag();
33281
+ if (flagValue !== null) {
33282
+ setResult({ variant: flagValue, isLoading: false });
33254
33283
  return;
33255
33284
  }
33256
- const posthog = window.posthog;
33257
- const checkFlag = () => {
33258
- var _a2;
33259
- const flagValue = (_a2 = posthog.getFeatureFlag) == null ? void 0 : _a2.call(posthog, FEATURE_FLAG_NAME);
33260
- if (flagValue === "redesign") {
33261
- setVariant("redesign");
33262
- } else {
33263
- setVariant("control");
33285
+ let resolved = false;
33286
+ let timeoutId = null;
33287
+ const startTime = Date.now();
33288
+ const resolve = (variant) => {
33289
+ if (resolved) return;
33290
+ resolved = true;
33291
+ if (timeoutId) clearTimeout(timeoutId);
33292
+ setResult({ variant, isLoading: false });
33293
+ };
33294
+ const pollForPostHog = () => {
33295
+ if (resolved) return;
33296
+ const posthog = window.posthog;
33297
+ const immediateFlag = checkPostHogFlag();
33298
+ if (immediateFlag !== null) {
33299
+ resolve(immediateFlag);
33300
+ return;
33301
+ }
33302
+ if (posthog == null ? void 0 : posthog.onFeatureFlags) {
33303
+ posthog.onFeatureFlags(() => {
33304
+ const flag = checkPostHogFlag();
33305
+ resolve(flag ?? "control");
33306
+ });
33307
+ return;
33308
+ }
33309
+ if (Date.now() - startTime >= POSTHOG_MAX_WAIT_MS) {
33310
+ resolve("control");
33311
+ return;
33264
33312
  }
33313
+ timeoutId = setTimeout(pollForPostHog, POSTHOG_POLL_INTERVAL_MS);
33265
33314
  };
33266
- checkFlag();
33267
- if (posthog.onFeatureFlags) {
33268
- posthog.onFeatureFlags(checkFlag);
33269
- }
33270
- }, [forceRedesign]);
33271
- return variant;
33315
+ pollForPostHog();
33316
+ return () => {
33317
+ resolved = true;
33318
+ if (timeoutId) clearTimeout(timeoutId);
33319
+ };
33320
+ }, [urlOverride]);
33321
+ return result;
33272
33322
  }
33273
33323
  const EmbeddedFunnel = React__default.forwardRef(
33274
33324
  ({
@@ -33284,7 +33334,7 @@ const EmbeddedFunnel = React__default.forwardRef(
33284
33334
  }, ref2) => {
33285
33335
  var _a2, _b, _c, _d, _e, _f, _g, _h, _i, _j;
33286
33336
  const scrollHelperRef = useRef(null);
33287
- const funnelVariant = useFunnelVariant();
33337
+ const { variant: funnelVariant, isLoading: variantLoading } = useFunnelVariantWithLoading();
33288
33338
  const { state, actions, canContinue } = useQualification({});
33289
33339
  const funnelContext = useRef({
33290
33340
  session_id: "",
@@ -33385,6 +33435,9 @@ const EmbeddedFunnel = React__default.forwardRef(
33385
33435
  return null;
33386
33436
  }
33387
33437
  const isFullscreen = mode === "fullscreen";
33438
+ if (isFullscreen && variantLoading) {
33439
+ return /* @__PURE__ */ jsx(VariantLoadingWrapper, { children: /* @__PURE__ */ jsx(SmallSpinner, {}) });
33440
+ }
33388
33441
  const shouldUseRedesign = isFullscreen && funnelVariant === "redesign";
33389
33442
  if (shouldUseRedesign) {
33390
33443
  return /* @__PURE__ */ jsx(
@@ -33531,6 +33584,26 @@ const FormWrapper = styled.form`
33531
33584
  outline: none;
33532
33585
  }
33533
33586
  `;
33587
+ const VariantLoadingWrapper = styled.div`
33588
+ min-height: 100vh;
33589
+ display: flex;
33590
+ align-items: center;
33591
+ justify-content: center;
33592
+ background: #fff;
33593
+ `;
33594
+ const SmallSpinner = styled.div`
33595
+ width: 40px;
33596
+ height: 40px;
33597
+ border: 3px solid #f3f3f3;
33598
+ border-top: 3px solid #F95524;
33599
+ border-radius: 50%;
33600
+ animation: spin 1s linear infinite;
33601
+
33602
+ @keyframes spin {
33603
+ 0% { transform: rotate(0deg); }
33604
+ 100% { transform: rotate(360deg); }
33605
+ }
33606
+ `;
33534
33607
  var createBreakpoints$1 = {};
33535
33608
  var interopRequireDefault = { exports: {} };
33536
33609
  (function(module) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@heycater/qualification-funnel",
3
- "version": "1.19.33",
3
+ "version": "1.19.35",
4
4
  "type": "module",
5
5
  "description": "Heycater embedded qualification funnel widget",
6
6
  "main": "dist/index.cjs.js",