@saasquatch/squatch-js 2.3.1-4 → 2.3.1

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/demo/toolbar.tsx CHANGED
@@ -1,5 +1,6 @@
1
- import React, { Component, version } from "react";
1
+ import React, { Component, useState, version } from "react";
2
2
  import { render } from "react-dom";
3
+ import squatch from "../dist/squatch";
3
4
 
4
5
  import {
5
6
  popup,
@@ -17,13 +18,6 @@ import { getVersions } from "./versions";
17
18
  import { delay } from "./util";
18
19
  import { widgets, worker } from "./generate";
19
20
  import { rest } from "msw";
20
- import classic from "./templates/classic";
21
- import MintGA from "./templates/MintGA";
22
- import VanillaGA from "./templates/VanillaGA";
23
-
24
- console.log("me old sandbox", window["sandbox"]);
25
-
26
- console.log("my worker", { worker });
27
21
 
28
22
  // 2. Define request handlers and response resolvers.
29
23
 
@@ -33,7 +27,7 @@ const widgetTypes = [
33
27
  "CONVERSION_WIDGET",
34
28
  "p/tuesday-test/w/referrerWidget",
35
29
  ];
36
- const staticVersions = ["HEAD", "latest", "alpha", "next"];
30
+ const staticVersions = ["HEAD", "latest", "alpha", "next", "local"];
37
31
 
38
32
  /**
39
33
  * Use the addUrlProps higher-order component to hook-in react-url-query.
@@ -111,6 +105,7 @@ class App extends Component {
111
105
  <UserList />
112
106
  <VersionList {...this.state} />
113
107
  <MockedWidgets />
108
+ <CustomMockedWidget />
114
109
  </div>
115
110
  <hr />
116
111
 
@@ -274,6 +269,7 @@ function UserList(props) {
274
269
  }
275
270
  function VersionList(props) {
276
271
  const { versions } = props;
272
+
277
273
  return (
278
274
  <details
279
275
  title={"Version: " + window["sandbox"].version || "Head"}
@@ -290,44 +286,68 @@ function VersionList(props) {
290
286
  script:
291
287
  v.toLocaleLowerCase() == "head"
292
288
  ? script
289
+ : v == "local"
290
+ ? `./squatchjs.min.js`
293
291
  : `https://unpkg.com/@saasquatch/squatch-js@${v}`,
294
292
  })}
295
293
  >
296
- {v}
294
+ <button>{v}</button>
297
295
  </a>
298
296
  ))}
299
297
  </details>
300
298
  );
301
299
  }
302
300
 
301
+ async function getMockWidget(widget, engagementMedium) {
302
+ window["mockWidget"] = widget;
303
+ window["sandbox"].initObj = {
304
+ ...window["sandbox"].initObj,
305
+ engagementMedium,
306
+ };
307
+
308
+ worker.use(
309
+ rest.put(
310
+ "https://staging.referralsaasquatch.com/api/*",
311
+ (req, res, ctx) => {
312
+ return res(
313
+ ctx.delay(500),
314
+ ctx.status(202, "Mocked status"),
315
+ ctx.json(widgets[window["mockWidget"]])
316
+ );
317
+ }
318
+ )
319
+ );
320
+ document.getElementById("squatchembed").innerHTML = "";
321
+ window["squatch"].widgets().upsertUser(window["sandbox"].initObj);
322
+ }
323
+
324
+ async function getCustomWidget(engagementMedium) {
325
+ window["sandbox"].initObj = {
326
+ ...window["sandbox"].initObj,
327
+ engagementMedium,
328
+ };
329
+
330
+ const value = document.getElementById("custom-widget")?.value;
331
+ worker.use(
332
+ rest.put(
333
+ "https://staging.referralsaasquatch.com/api/*",
334
+ (req, res, ctx) => {
335
+ return res(
336
+ ctx.delay(500),
337
+ ctx.status(202, "Mocked status"),
338
+ ctx.json({ jsOptions: {}, user: {}, template: value })
339
+ );
340
+ }
341
+ )
342
+ );
343
+ document.getElementById("squatchembed").innerHTML = "";
344
+ window["squatch"].widgets().upsertUser(window["sandbox"].initObj);
345
+ }
346
+
303
347
  function MockedWidgets(props) {
304
348
  const { versions } = props;
305
349
 
306
- async function getMockWidget(widget) {
307
- console.log("fetch");
308
- // window["squatch"].render()
309
- window["mockWidget"] = widget;
310
- window["sandbox"].initObj = {
311
- ...window["sandbox"].initObj,
312
- engagementMedium: "EMBED",
313
- };
314
-
315
- worker.use(
316
- rest.put(
317
- "https://staging.referralsaasquatch.com/api/*",
318
- (req, res, ctx) => {
319
- return res(
320
- ctx.delay(500),
321
- ctx.status(202, "Mocked status"),
322
- ctx.json(widgets[window["mockWidget"]])
323
- );
324
- }
325
- )
326
- );
327
- document.getElementById("squatchembed").innerHTML = "";
328
- window["squatch"].widgets().upsertUser(window["sandbox"].initObj);
329
- // window.location.href = `/?widgetType=${widget}`;
330
- }
350
+ const [engagementMedium, setEngagementMedium] = useState("EMBED");
331
351
  return (
332
352
  <details
333
353
  title={"Version: " + window["sandbox"].version || "Head"}
@@ -335,24 +355,112 @@ function MockedWidgets(props) {
335
355
  id={`dropdown-basic-1`}
336
356
  >
337
357
  <summary>Mocked Widgets</summary>
338
- <button onClick={() => getMockWidget("QuirksVanillaGA")}>
358
+ <label>Embed</label>
359
+ <input
360
+ type="radio"
361
+ name="embed"
362
+ checked={engagementMedium === "EMBED"}
363
+ onClick={() => setEngagementMedium("EMBED")}
364
+ ></input>
365
+
366
+ <label>Popup</label>
367
+ <input
368
+ type="radio"
369
+ name="popup"
370
+ checked={engagementMedium === "POPUP"}
371
+ onClick={() => setEngagementMedium("POPUP")}
372
+ ></input>
373
+ <br />
374
+ <button
375
+ onClick={() => getMockWidget("QuirksVanillaGA", engagementMedium)}
376
+ >
339
377
  Quirks mode - Vanilla
340
378
  </button>
341
- <button onClick={() => getMockWidget("QuirksMintGA")}>
379
+ <button onClick={() => getMockWidget("QuirksMintGA", engagementMedium)}>
342
380
  Quirks mode - Mint
343
381
  </button>
344
- <button onClick={() => getMockWidget("classic")}>Classic</button>
345
- <button onClick={() => getMockWidget("MintGA")}>GA - Mint</button>
346
- <button onClick={() => getMockWidget("VanillaGA")}>GA - Vanilla</button>
347
- <button onClick={() => getMockWidget("MintGAContainer")}>
382
+ <button onClick={() => getMockWidget("classic", engagementMedium)}>
383
+ Classic
384
+ </button>
385
+ <button onClick={() => getMockWidget("MintGA", engagementMedium)}>
386
+ GA - Mint
387
+ </button>
388
+ <button onClick={() => getMockWidget("VanillaGA", engagementMedium)}>
389
+ GA - Vanilla
390
+ </button>
391
+ <button
392
+ onClick={() => getMockWidget("MintGAContainer", engagementMedium)}
393
+ >
348
394
  Mint - With Container
349
395
  </button>
350
- <button onClick={() => getMockWidget("VanillaGANoContainer")}>
396
+ <button
397
+ onClick={() => getMockWidget("QuirksMintGAContainer", engagementMedium)}
398
+ >
399
+ Quirks mode - Mint - With Container
400
+ </button>
401
+ <button
402
+ onClick={() =>
403
+ getMockWidget("MintGAContainerDisplayBlock", engagementMedium)
404
+ }
405
+ >
406
+ Mint - With Container + Display Block
407
+ </button>
408
+ <button
409
+ onClick={() =>
410
+ getMockWidget("QuirksMintGAContainerDisplayBlock", engagementMedium)
411
+ }
412
+ >
413
+ Quirks mode - Mint - With Container + Display Block
414
+ </button>
415
+ <button
416
+ onClick={() => getMockWidget("VanillaGANoContainer", engagementMedium)}
417
+ >
351
418
  Vanilla - No Container
352
419
  </button>
353
420
  </details>
354
421
  );
355
422
  }
423
+
424
+ function CustomMockedWidget(props) {
425
+ const { versions } = props;
426
+ const [engagementMedium, setEngagementMedium] = useState("EMBED");
427
+ return (
428
+ <details
429
+ title={"Version: " + window["sandbox"].version || "Head"}
430
+ key={0}
431
+ id={`dropdown-basic-1`}
432
+ >
433
+ <summary>Custom Mocked Widget</summary>
434
+ <label>Embed</label>
435
+ <input
436
+ type="radio"
437
+ name="embed"
438
+ checked={engagementMedium === "EMBED"}
439
+ onClick={() => setEngagementMedium("EMBED")}
440
+ ></input>
441
+
442
+ <label>Popup</label>
443
+ <input
444
+ type="radio"
445
+ name="popup"
446
+ checked={engagementMedium === "POPUP"}
447
+ onClick={() => setEngagementMedium("POPUP")}
448
+ ></input>
449
+ <br />
450
+ <textarea
451
+ id="custom-widget"
452
+ rows={15}
453
+ cols={70}
454
+ style={{ maxWidth: "100%" }}
455
+ ></textarea>
456
+ <div>
457
+ <button onClick={() => getCustomWidget(engagementMedium)}>
458
+ Load Widget
459
+ </button>
460
+ </div>
461
+ </details>
462
+ );
463
+ }
356
464
  const root = document.getElementById("app");
357
465
 
358
466
  render(<App />, root);