@heycater/qualification-funnel 1.19.34 → 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
@@ -13325,7 +13325,14 @@ function requireFunctionBind() {
13325
13325
  functionBind = Function.prototype.bind || implementation2;
13326
13326
  return functionBind;
13327
13327
  }
13328
- var functionCall = Function.prototype.call;
13328
+ var functionCall;
13329
+ var hasRequiredFunctionCall;
13330
+ function requireFunctionCall() {
13331
+ if (hasRequiredFunctionCall) return functionCall;
13332
+ hasRequiredFunctionCall = 1;
13333
+ functionCall = Function.prototype.call;
13334
+ return functionCall;
13335
+ }
13329
13336
  var functionApply;
13330
13337
  var hasRequiredFunctionApply;
13331
13338
  function requireFunctionApply() {
@@ -13337,12 +13344,12 @@ function requireFunctionApply() {
13337
13344
  var reflectApply = typeof Reflect !== "undefined" && Reflect && Reflect.apply;
13338
13345
  var bind$2 = requireFunctionBind();
13339
13346
  var $apply$1 = requireFunctionApply();
13340
- var $call$2 = functionCall;
13347
+ var $call$2 = requireFunctionCall();
13341
13348
  var $reflectApply = reflectApply;
13342
13349
  var actualApply = $reflectApply || bind$2.call($call$2, $apply$1);
13343
13350
  var bind$1 = requireFunctionBind();
13344
13351
  var $TypeError$4 = type;
13345
- var $call$1 = functionCall;
13352
+ var $call$1 = requireFunctionCall();
13346
13353
  var $actualApply = actualApply;
13347
13354
  var callBindApplyHelpers = function callBindBasic(args) {
13348
13355
  if (args.length < 1 || typeof args[0] !== "function") {
@@ -13457,7 +13464,7 @@ var getProto = requireGetProto();
13457
13464
  var $ObjectGPO = requireObject_getPrototypeOf();
13458
13465
  var $ReflectGPO = requireReflect_getPrototypeOf();
13459
13466
  var $apply = requireFunctionApply();
13460
- var $call = functionCall;
13467
+ var $call = requireFunctionCall();
13461
13468
  var needsEval = {};
13462
13469
  var TypedArray = typeof Uint8Array === "undefined" || !getProto ? undefined$1 : getProto(Uint8Array);
13463
13470
  var INTRINSICS = {
@@ -33235,33 +33242,83 @@ function useAbandonmentTracking(funnelContextRef, state) {
33235
33242
  ]);
33236
33243
  }
33237
33244
  const FEATURE_FLAG_NAME = "qf_redesign_v1";
33238
- function useFunnelVariant() {
33239
- const forceRedesign = typeof window !== "undefined" && window.location.search.includes("variant=redesign");
33240
- 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
+ });
33241
33275
  useEffect(() => {
33242
- if (forceRedesign) {
33243
- setVariant("redesign");
33276
+ if (urlOverride) {
33277
+ setResult({ variant: urlOverride, isLoading: false });
33244
33278
  return;
33245
33279
  }
33246
- if (typeof window === "undefined" || !window.posthog) {
33280
+ const flagValue = checkPostHogFlag();
33281
+ if (flagValue !== null) {
33282
+ setResult({ variant: flagValue, isLoading: false });
33247
33283
  return;
33248
33284
  }
33249
- const posthog = window.posthog;
33250
- const checkFlag = () => {
33251
- var _a2;
33252
- const flagValue = (_a2 = posthog.getFeatureFlag) == null ? void 0 : _a2.call(posthog, FEATURE_FLAG_NAME);
33253
- if (flagValue === "redesign") {
33254
- setVariant("redesign");
33255
- } else {
33256
- 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;
33257
33312
  }
33313
+ timeoutId = setTimeout(pollForPostHog, POSTHOG_POLL_INTERVAL_MS);
33258
33314
  };
33259
- checkFlag();
33260
- if (posthog.onFeatureFlags) {
33261
- posthog.onFeatureFlags(checkFlag);
33262
- }
33263
- }, [forceRedesign]);
33264
- return variant;
33315
+ pollForPostHog();
33316
+ return () => {
33317
+ resolved = true;
33318
+ if (timeoutId) clearTimeout(timeoutId);
33319
+ };
33320
+ }, [urlOverride]);
33321
+ return result;
33265
33322
  }
33266
33323
  const EmbeddedFunnel = React__default.forwardRef(
33267
33324
  ({
@@ -33277,7 +33334,7 @@ const EmbeddedFunnel = React__default.forwardRef(
33277
33334
  }, ref2) => {
33278
33335
  var _a2, _b, _c, _d, _e, _f, _g, _h, _i, _j;
33279
33336
  const scrollHelperRef = useRef(null);
33280
- const funnelVariant = useFunnelVariant();
33337
+ const { variant: funnelVariant, isLoading: variantLoading } = useFunnelVariantWithLoading();
33281
33338
  const { state, actions, canContinue } = useQualification({});
33282
33339
  const funnelContext = useRef({
33283
33340
  session_id: "",
@@ -33378,6 +33435,9 @@ const EmbeddedFunnel = React__default.forwardRef(
33378
33435
  return null;
33379
33436
  }
33380
33437
  const isFullscreen = mode === "fullscreen";
33438
+ if (isFullscreen && variantLoading) {
33439
+ return /* @__PURE__ */ jsx(VariantLoadingWrapper, { children: /* @__PURE__ */ jsx(SmallSpinner, {}) });
33440
+ }
33381
33441
  const shouldUseRedesign = isFullscreen && funnelVariant === "redesign";
33382
33442
  if (shouldUseRedesign) {
33383
33443
  return /* @__PURE__ */ jsx(
@@ -33524,6 +33584,26 @@ const FormWrapper = styled.form`
33524
33584
  outline: none;
33525
33585
  }
33526
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
+ `;
33527
33607
  var createBreakpoints$1 = {};
33528
33608
  var interopRequireDefault = { exports: {} };
33529
33609
  (function(module) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@heycater/qualification-funnel",
3
- "version": "1.19.34",
3
+ "version": "1.19.35",
4
4
  "type": "module",
5
5
  "description": "Heycater embedded qualification funnel widget",
6
6
  "main": "dist/index.cjs.js",