@saasquatch/squatch-js 2.3.1-3 → 2.3.1-7

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,
@@ -15,6 +16,10 @@ import {
15
16
  } from "./sandbox";
16
17
  import { getVersions } from "./versions";
17
18
  import { delay } from "./util";
19
+ import { widgets, worker } from "./generate";
20
+ import { rest } from "msw";
21
+
22
+ // 2. Define request handlers and response resolvers.
18
23
 
19
24
  const modes = ["POPUP", "EMBED"];
20
25
  const widgetTypes = [
@@ -22,14 +27,29 @@ const widgetTypes = [
22
27
  "CONVERSION_WIDGET",
23
28
  "p/tuesday-test/w/referrerWidget",
24
29
  ];
25
- const staticVersions = ["HEAD", "latest", "alpha"];
30
+ const staticVersions = ["HEAD", "latest", "alpha", "next", "local"];
26
31
 
27
32
  /**
28
33
  * Use the addUrlProps higher-order component to hook-in react-url-query.
29
34
  */
30
35
  class App extends Component {
36
+ constructor(props) {
37
+ super(props);
38
+ worker.start({
39
+ findWorker: (scriptURL, _mockServiceWorkerUrl) =>
40
+ scriptURL.includes("mockServiceWorker"),
41
+ onUnhandledRequest(req) {
42
+ console.error(
43
+ "Found an unhandled %s request to %s",
44
+ req.method,
45
+ req.url.href
46
+ );
47
+ },
48
+ });
49
+ }
31
50
  state = {
32
51
  versions: staticVersions,
52
+ toolbarOpen: true,
33
53
  };
34
54
  async componentWillMount() {
35
55
  const apiVersions = await getVersions();
@@ -39,31 +59,61 @@ class App extends Component {
39
59
  render() {
40
60
  return (
41
61
  <div>
42
- <hr />
43
- <div>
44
- <ParamArea />
62
+ <button
63
+ onClick={() =>
64
+ this.setState({ toolbarOpen: !this.state.toolbarOpen })
65
+ }
66
+ style={{ float: "right" }}
67
+ >
68
+ {this.state.toolbarOpen ? `<` : `>`}
69
+ </button>
70
+ <div style={{ display: this.state.toolbarOpen ? "block" : "none" }}>
71
+ <hr />
72
+ <div>
73
+ <ParamArea />
74
+ <hr />
75
+ <h2>Quick pick variables</h2>
76
+ <details>
77
+ <summary>Tenant / Program</summary>
78
+ <ul>
79
+ <li>
80
+ <a href={href(popup)}>Popup (classic)</a>
81
+ </li>
82
+ <li>
83
+ <a href={href(embed)}>Embed (classic)</a>
84
+ </li>
85
+ <li>
86
+ <a href={href(popupNew)}>Popup (new program)</a>
87
+ </li>
88
+ <li>
89
+ <a href={href(embedNew)}>Embed (new program)</a>
90
+ </li>
91
+ <li>
92
+ <a href={href(popupReferred)}>
93
+ Popup (classic referred widget)
94
+ </a>
95
+ </li>
96
+ <li>
97
+ <a href={href(embedReferred)}>
98
+ Embed (classic referred widget)
99
+ </a>
100
+ </li>
101
+ </ul>
102
+ </details>
103
+ <WidgetType />
104
+ <ModeList />
105
+ <UserList />
106
+ <VersionList {...this.state} />
107
+ <MockedWidgets />
108
+ <CustomMockedWidget />
109
+ </div>
45
110
  <hr />
46
- <h2>Quick pick variables</h2>
47
- <details>
48
- <summary>Tenant / Program</summary>
49
- <a href={href(popup)}>Popup (classic)</a>
50
- <a href={href(embed)}>Embed (classic)</a>
51
- <a href={href(popupNew)}>Popup (new program)</a>
52
- <a href={href(embedNew)}>Embed (new program)</a>
53
- <a href={href(popupReferred)}>Popup (classic referred widget)</a>
54
- <a href={href(embedReferred)}>Embed (classic referred widget)</a>
55
- </details>
56
- <WidgetType />
57
- <ModeList />
58
- <UserList />
59
- <VersionList {...this.state} />
60
- </div>
61
- <hr />
62
111
 
63
- <button onClick={() => recordPurchase()}>Record Purchase</button>
64
- <hr />
112
+ <button onClick={() => recordPurchase()}>Record Purchase</button>
113
+ <hr />
65
114
 
66
- <button onClick={() => runEventBomb()}>Event Bomb</button>
115
+ <button onClick={() => runEventBomb()}>Event Bomb</button>
116
+ </div>
67
117
  </div>
68
118
  );
69
119
  }
@@ -74,7 +124,7 @@ function ParamArea() {
74
124
  <div>
75
125
  <h2>Squatch.js Config</h2>
76
126
  <div>
77
- <textarea id="area1" rows={15} cols={80}>
127
+ <textarea id="area1" rows={15} cols={70} style={{ maxWidth: "100%" }}>
78
128
  {JSON.stringify(window["sandbox"], null, 2)}
79
129
  </textarea>
80
130
  </div>
@@ -219,6 +269,7 @@ function UserList(props) {
219
269
  }
220
270
  function VersionList(props) {
221
271
  const { versions } = props;
272
+
222
273
  return (
223
274
  <details
224
275
  title={"Version: " + window["sandbox"].version || "Head"}
@@ -235,15 +286,165 @@ function VersionList(props) {
235
286
  script:
236
287
  v.toLocaleLowerCase() == "head"
237
288
  ? script
289
+ : v == "local"
290
+ ? `./squatchjs.min.js`
238
291
  : `https://unpkg.com/@saasquatch/squatch-js@${v}`,
239
292
  })}
240
293
  >
241
- {v}
294
+ <button>{v}</button>
242
295
  </a>
243
296
  ))}
244
297
  </details>
245
298
  );
246
299
  }
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
+ // window.location.href = `/?widgetType=${widget}`;
323
+ }
324
+
325
+ async function getCustomWidget() {
326
+ window["sandbox"].initObj = {
327
+ ...window["sandbox"].initObj,
328
+ engagementMedium: "EMBED",
329
+ };
330
+
331
+ const value = document.getElementById("custom-widget")?.value;
332
+ worker.use(
333
+ rest.put(
334
+ "https://staging.referralsaasquatch.com/api/*",
335
+ (req, res, ctx) => {
336
+ return res(
337
+ ctx.delay(500),
338
+ ctx.status(202, "Mocked status"),
339
+ ctx.json({ jsOptions: {}, user: {}, template: value })
340
+ );
341
+ }
342
+ )
343
+ );
344
+ document.getElementById("squatchembed").innerHTML = "";
345
+ window["squatch"].widgets().upsertUser(window["sandbox"].initObj);
346
+ // window.location.href = `/?widgetType=${widget}`;
347
+ }
348
+
349
+ function MockedWidgets(props) {
350
+ const { versions } = props;
351
+
352
+ const [engagementMedium, setEngagementMedium] = useState("EMBED");
353
+ return (
354
+ <details
355
+ title={"Version: " + window["sandbox"].version || "Head"}
356
+ key={0}
357
+ id={`dropdown-basic-1`}
358
+ >
359
+ <summary>Mocked Widgets</summary>
360
+ <label>Embed</label>
361
+ <input
362
+ type="radio"
363
+ name="embed"
364
+ checked={engagementMedium === "EMBED"}
365
+ onClick={() => setEngagementMedium("EMBED")}
366
+ ></input>
367
+
368
+ <label>Popup</label>
369
+ <input
370
+ type="radio"
371
+ name="popup"
372
+ checked={engagementMedium === "POPUP"}
373
+ onClick={() => setEngagementMedium("POPUP")}
374
+ ></input>
375
+ <br />
376
+ <button
377
+ onClick={() => getMockWidget("QuirksVanillaGA", engagementMedium)}
378
+ >
379
+ Quirks mode - Vanilla
380
+ </button>
381
+ <button onClick={() => getMockWidget("QuirksMintGA", engagementMedium)}>
382
+ Quirks mode - Mint
383
+ </button>
384
+ <button onClick={() => getMockWidget("classic", engagementMedium)}>
385
+ Classic
386
+ </button>
387
+ <button onClick={() => getMockWidget("MintGA", engagementMedium)}>
388
+ GA - Mint
389
+ </button>
390
+ <button onClick={() => getMockWidget("VanillaGA", engagementMedium)}>
391
+ GA - Vanilla
392
+ </button>
393
+ <button
394
+ onClick={() => getMockWidget("MintGAContainer", engagementMedium)}
395
+ >
396
+ Mint - With Container
397
+ </button>
398
+ <button
399
+ onClick={() => getMockWidget("QuirksMintGAContainer", engagementMedium)}
400
+ >
401
+ Quirks mode - Mint - With Container
402
+ </button>
403
+ <button
404
+ onClick={() =>
405
+ getMockWidget("MintGAContainerDisplayBlock", engagementMedium)
406
+ }
407
+ >
408
+ Mint - With Container + Display Block
409
+ </button>
410
+ <button
411
+ onClick={() =>
412
+ getMockWidget("QuirksMintGAContainerDisplayBlock", engagementMedium)
413
+ }
414
+ >
415
+ Quirks mode - Mint - With Container + Display Block
416
+ </button>
417
+ <button
418
+ onClick={() => getMockWidget("VanillaGANoContainer", engagementMedium)}
419
+ >
420
+ Vanilla - No Container
421
+ </button>
422
+ </details>
423
+ );
424
+ }
425
+
426
+ function CustomMockedWidget(props) {
427
+ const { versions } = props;
428
+
429
+ return (
430
+ <details
431
+ title={"Version: " + window["sandbox"].version || "Head"}
432
+ key={0}
433
+ id={`dropdown-basic-1`}
434
+ >
435
+ <summary>Custom Mocked Widget</summary>
436
+ <textarea
437
+ id="custom-widget"
438
+ rows={15}
439
+ cols={70}
440
+ style={{ maxWidth: "100%" }}
441
+ ></textarea>
442
+ <div>
443
+ <button onClick={() => getCustomWidget()}>Load Widget</button>
444
+ </div>
445
+ </details>
446
+ );
447
+ }
247
448
  const root = document.getElementById("app");
248
- console.log("mount to", root);
449
+
249
450
  render(<App />, root);