notify-me-wl 1.2.1 → 1.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.
Files changed (4) hide show
  1. package/README.md +170 -161
  2. package/index.html +1 -1
  3. package/index.js +148 -142
  4. package/package.json +1 -1
package/README.md CHANGED
@@ -3,7 +3,7 @@
3
3
  This JavaScript widget allows users to register their interest in a product that is either "coming soon" or "out of stock". Depending on the `data-type` attribute provided, the widget will display appropriate messages and functionality.
4
4
 
5
5
  #### Features:
6
- - Dynamically display a form to collect user information (email, mobile, first name, last name).
6
+ - Dynamically display a form to collect user information (mobile, first name, last name).
7
7
  - Adjust form and button text based on the widget type (`notify-me` or `coming-soon`).
8
8
  - Submit user data to a specified API endpoint with email or mobile as a path parameter and appropriate query parameters.
9
9
 
@@ -21,19 +21,19 @@ Add a button to your HTML where you want the widget to appear. The button should
21
21
 
22
22
  ```html
23
23
  <div id="notification-widget"></div>
24
- <button id="popup-open" data-fields='["email", "mobile", "firstName", "lastName"]' data-type="notify-me">Open Popup</button>
24
+ <button id="popup-open" data-fields='["mobile", "firstName", "lastName"]' data-type="notify-me">Open Popup</button>
25
25
  ```
26
26
 
27
27
  ### Configuration
28
28
 
29
- - `data-fields`: A JSON array specifying the fields to include in the form. Possible values are `"email"`, `"mobile"`, `"firstName"`, and `"lastName"`.
29
+ - `data-fields`: A JSON array specifying the fields to include in the form. Possible values are `"mobile"`, `"firstName"`, and `"lastName"`.
30
30
  - `data-type`: Specifies the type of the widget. Possible values are `"notify-me"` and `"coming-soon"`.
31
31
 
32
32
  ### Example
33
33
 
34
34
  ```html
35
35
  <div id="notification-widget"></div>
36
- <button id="popup-open" data-fields='["email", "mobile"]' data-type="notify-me">Open Popup</button>
36
+ <button id="popup-open" data-fields='["mobile"]' data-type="notify-me">Open Popup</button>
37
37
 
38
38
  <script>
39
39
  // The script provided will be included here
@@ -46,30 +46,27 @@ Add a button to your HTML where you want the widget to appear. The button should
46
46
  2. **Styles Injection**: It injects necessary styles for the modal and form elements.
47
47
  3. **Modal Creation**: Creates the modal structure and appends it to the `notification-widget` div.
48
48
  4. **Dynamic Content**: Based on the `data-type`, it sets the appropriate messages and button text.
49
- 5. **Form Submission**: Collects form data and submits it to the API with the email or mobile number as a path parameter. If a mobile number is provided, it also appends `isMobile=true` to the query string.
49
+ 5. **Form Submission**: Collects form data and submits it to the API with the mandatory email field and other possible fields.
50
50
 
51
- ### API Request Example
51
+ ### API Request Example
52
52
 
53
- For email:
54
53
  ```
55
- https://api.au-aws.thewishlist.io/services/wsservice/api/wishlist/items/customerInterest/{email}
56
- ```
57
-
58
- For mobile:
59
- ```
60
- https://api.au-aws.thewishlist.io/services/wsservice/api/wishlist/items/customerInterest/{mobile}?isMobile=true
54
+ https://api.au-aws.thewishlist.io/services/wsservice/api/wishlist/items/customerInterest
61
55
  ```
62
56
 
63
57
  ### Full Script
64
58
 
65
59
  ```javascript
66
- const ACCESS_TOKEN = "123"; // // Replace `ACCESS_TOKEN` with your actual access token to authenticate API requests.
60
+ // Access token for the API
61
+ const ACCESS_TOKEN = "123"; // Replace `ACCESS_TOKEN` with your actual access token to authenticate API requests.
62
+ const TENANT_ID = "viktoria-woods"; // Replace `TENANT_ID` with your actual tenant ID.
67
63
 
68
64
  document.addEventListener("DOMContentLoaded", function () {
69
- const wrapper = document.getElementById("notification-widget");
70
- if (!wrapper) return;
65
+ const wrapper = document.getElementById("notification-widget");
66
+ if (!wrapper) return;
71
67
 
72
- const styles = `
68
+ // Define and apply styles for the popup and button
69
+ const styles = `
73
70
  .notification-btn {
74
71
  background-color: #fff;
75
72
  border: 1px solid black;
@@ -184,13 +181,14 @@ document.addEventListener("DOMContentLoaded", function () {
184
181
  }
185
182
  `;
186
183
 
187
- const styleSheet = document.createElement("style");
188
- styleSheet.type = "text/css";
189
- styleSheet.innerText = styles;
190
- document.head.appendChild(styleSheet);
184
+ const styleSheet = document.createElement("style");
185
+ styleSheet.type = "text/css";
186
+ styleSheet.innerText = styles;
187
+ document.head.appendChild(styleSheet);
191
188
 
192
- const overlay = document.createElement("div");
193
- overlay.innerHTML = `
189
+ // Create and append the overlay for the popup
190
+ const overlay = document.createElement("div");
191
+ overlay.innerHTML = `
194
192
  <div id="popup-body" class="overlay">
195
193
  <div id="popup-wrapper">
196
194
  <h3 id="popup-title"></h3>
@@ -201,151 +199,162 @@ document.addEventListener("DOMContentLoaded", function () {
201
199
  <select name="select-size" required>
202
200
  </select>
203
201
  </div>
202
+ <input name="email" placeholder="Email" type="email" required />
204
203
  </form>
205
204
  </div>
206
205
  </div>
207
206
  `;
208
207
 
209
- wrapper.appendChild(overlay);
210
-
211
- const popupBody = document.getElementById("popup-body");
212
- const popupClose = document.getElementById("popup-close");
213
- const popupOpenButton = document.getElementById("popup-open");
214
- const popupTitle = document.getElementById("popup-title");
215
- const popupText = document.getElementById("popup-text");
216
- const sizeSelect = document.querySelector("select[name='select-size']");
217
- const form = overlay.querySelector("#popup-form");
218
-
219
- if (!popupBody || !popupClose || !popupOpenButton || !popupTitle || !sizeSelect) return;
220
-
221
- const fields = JSON.parse(popupOpenButton.getAttribute("data-fields") || '["email"]');
222
- const type = popupOpenButton.getAttribute("data-type") || "notify-me";
223
-
224
- const typeConfig = {
225
- "notify-me": {
226
- text: "Register to receive a notification as soon as this item is back in stock",
227
- buttonText: "Notify me",
228
- },
229
- "coming-soon": {
230
- text: "Register your interest to hear more about this item",
231
- buttonText: "Register Interest",
232
- },
233
- };
234
-
235
- // Get product data from Shopify's global variable
236
- const productData = window.Shopify?.product || {
237
- id: 6786188247105,
238
- title: "THE ATG SCULPT FLARES TALL",
239
- product_option_value: {
240
- name: "BUTTER BLACK",
241
- },
242
- variants: [
243
- { id: 1, title: "S" },
244
- { id: 2, title: "M" },
245
- { id: 3, title: "L" },
246
- { id: 4, title: "XL" },
247
- ],
248
- };
249
-
250
- popupTitle.innerHTML = productData.title + "<br/>" + productData.product_option_value.name;
251
- popupText.innerText = typeConfig[type].text;
252
- productData.variants.forEach((variant) => {
253
- const option = document.createElement("option");
254
- option.value = variant.title;
255
- option.textContent = variant.title;
256
- sizeSelect.appendChild(option);
257
- });
258
-
259
- const fieldMap = {
260
- email: `<input name="email" placeholder="Email" type="email" required />`,
261
- mobile: `<input name="mobile" placeholder="Mobile"
262
-
263
- type="tel" required />`,
264
- firstName: `<input name="firstName" placeholder="First name" type="text" required />`,
265
- lastName: `<input name="lastName" placeholder="Last name" type="text" required />`,
266
- };
267
-
268
- fields.forEach((field) => {
269
- if (fieldMap[field]) {
270
- form.insertAdjacentHTML("beforeend", fieldMap[field]);
271
- }
272
- });
273
- form.insertAdjacentHTML("beforeend", `<button type="submit">${typeConfig[type].buttonText}</button>`);
274
-
275
- function showPopup() {
276
- popupBody.style.visibility = "visible";
277
- popupBody.style.opacity = 1;
278
- }
279
-
280
- function hidePopup() {
281
- popupBody.style.visibility = "hidden";
282
- popupBody.style.opacity = 0;
283
- }
284
-
285
- popupOpenButton.addEventListener("click", showPopup);
286
- popupClose.addEventListener("click", hidePopup);
287
-
288
- if (form) {
289
- form.addEventListener("submit", function (event) {
290
- event.preventDefault();
291
-
292
- const selectedSize = sizeSelect.value;
293
- const selectedVariant = productData.variants.find((variant) => variant.title === selectedSize);
294
-
295
- if (selectedVariant) {
296
- const formData = {
297
- productRef: productData.id,
298
- variantRef: selectedVariant.id,
299
- };
300
-
301
- let contactInfo = "";
302
- if (fields.includes("email")) {
303
- formData.email = form.querySelector("input[name='email']").value;
304
- contactInfo = formData.email;
305
- }
306
- if (fields.includes("firstName")) {
307
- formData.firstName = form.querySelector("input[name='firstName']").value;
308
- }
309
- if (fields.includes("lastName")) {
310
- formData.lastName = form.querySelector("input[name='lastName']").value;
311
- }
312
- if (fields.includes("mobile")) {
313
- formData.mobile = form.querySelector("input[name='mobile']").value;
314
- formData.isMobile = true;
315
- contactInfo = formData.mobile;
316
- }
317
-
318
- let url = `https://api.au-aws.thewishlist.io/services/wsservice/api/wishlist/items/customerInterest/${contactInfo}?notifyMe=true`;
319
- if (formData.isMobile) {
320
- url += "&isMobile=true";
321
- }
322
-
323
- fetch(url, {
324
- method: "POST",
325
- headers: {
326
- "Content-Type": "application/json",
327
- Authorization: ACCESS_TOKEN,
328
- },
329
- body: JSON.stringify(formData),
330
- })
331
- .then((response) => {
332
- if (response.ok) {
333
- alert("Form submitted");
334
- hidePopup();
335
- } else {
336
- alert("Form submission failed");
337
- }
338
- })
339
- .catch((error) => {
340
- console.error("Error submitting form:", error);
341
- alert("Form submission failed");
342
- });
208
+ wrapper.appendChild(overlay);
209
+
210
+ const popupBody = document.getElementById("popup-body");
211
+ const popupClose = document.getElementById("popup-close");
212
+ const popupOpenButton = document.getElementById("popup-open");
213
+ const popupTitle = document.getElementById("popup-title");
214
+ const popupText = document.getElementById("popup-text");
215
+ const sizeSelect = document.querySelector("select[name='select-size']");
216
+ const form = overlay.querySelector("#popup-form");
217
+
218
+ if (!popupBody || !popupClose || !popupOpenButton || !popupTitle || !sizeSelect) return;
219
+
220
+ // Parse fields and type to be included in the form from data attribute
221
+ const fields = JSON.parse(popupOpenButton.getAttribute("data-fields") || '["email"]');
222
+ const type = popupOpenButton.getAttribute("data-type") || "notify-me";
223
+ const typeConfig = {
224
+ "notify-me": {
225
+ text: "Register to receive a notification as soon as this item is back in stock",
226
+ buttonText: "Notify me",
227
+ },
228
+ "coming-soon": {
229
+ text: "Register your interest to hear more about this item",
230
+ buttonText: "Register Interest",
231
+ },
232
+ };
233
+
234
+ // Get product data from Shopify's global variable
235
+ const productData = window.Shopify?.product || {
236
+ id: "6786188247105",
237
+ title: "THE ATG SCULPT FLARES TALL",
238
+ product_option_value: {
239
+ name: "BUTTER BLACK",
240
+ },
241
+ variants: [
242
+ { id: 1, title: "S" },
243
+ { id: "40216683806854", title: "M" },
244
+ { id: 3, title: "L" },
245
+ { id: 4, title: "XL" },
246
+ ],
247
+ };
248
+
249
+ // Set the popup title and populate the size dropdown
250
+ popupTitle.innerHTML = productData.title + "<br/>" + productData.product_option_value.name;
251
+ productData.variants.forEach((variant) => {
252
+ const option = document.createElement("option");
253
+ option.value = variant.title;
254
+ option.textContent = variant.title;
255
+ sizeSelect.appendChild(option);
256
+ });
257
+
258
+ // Map for form fields
259
+ popupText.innerText = typeConfig[type].text;
260
+
261
+ const fieldMap = {
262
+ email: `<input name="email" placeholder="Email" type="email" required />`,
263
+ mobile: `<input name="mobile" placeholder="Mobile" type="tel" />`,
264
+ firstName: `<input name="firstName" placeholder="First name" type="text" />`,
265
+ lastName: `<input name="lastName" placeholder="Last name" type="text" />`,
266
+ };
267
+
268
+ // Add fields to the form based on the parsed fields
269
+ fields.forEach((field) => {
270
+ if (fieldMap[field]) {
271
+ form.insertAdjacentHTML("beforeend", fieldMap[field]);
272
+ }
273
+ });
274
+
275
+ form.insertAdjacentHTML("beforeend", `<div id="checkbox-wrapper"></div>`);
276
+ const checkboxWrapper = document.getElementById("checkbox-wrapper");
277
+ checkboxWrapper.insertAdjacentHTML("beforeend", `<input type="checkbox" name="mailList" id="mailList" />`);
278
+ checkboxWrapper.insertAdjacentHTML("beforeend", `<label for="mailList">Subscribe to our mailing list</label>`);
279
+ form.insertAdjacentHTML("beforeend", `<button type="submit">${typeConfig[type].buttonText}</button>`);
280
+
281
+ // Show/hide the popup
282
+ function showPopup() {
283
+ popupBody.style.visibility = "visible";
284
+ popupBody.style.opacity = 1;
285
+ }
286
+
287
+ function hidePopup() {
288
+ popupBody.style.visibility = "hidden";
289
+ popupBody.style.opacity = 0;
290
+ }
291
+
292
+ popupOpenButton.addEventListener("click", showPopup);
293
+ popupClose.addEventListener("click", hidePopup);
294
+
295
+ // Form submission handler
296
+ if (form) {
297
+ form.addEventListener("submit", function (event) {
298
+ event.preventDefault();
299
+
300
+ const selectedSize = sizeSelect.value;
301
+ const selectedVariant = productData.variants.find((variant) => variant.title === selectedSize);
302
+
303
+ if (selectedVariant) {
304
+ const formData = {
305
+ variantRef: selectedVariant.id,
306
+ email: form.querySelector("input[name='email']").value,
307
+ subscribe: form.querySelector("input[name='mailList']").checked,
308
+ };
309
+
310
+ if (type === "coming-soon") {
311
+ formData.comingSoon = true;
312
+ formData.productRef = productData.id;
343
313
  } else {
344
- alert("Selected variant not found");
314
+ formData.notifyMe = true;
315
+ }
316
+ if (fields.includes("firstName")) {
317
+ formData.firstName = form.querySelector("input[name='firstName']").value;
345
318
  }
346
- });
347
- }
319
+ if (fields.includes("lastName")) {
320
+ formData.lastName = form.querySelector("input[name='lastName']").value;
321
+ }
322
+ if (fields.includes("mobile")) {
323
+ formData.mobile = form.querySelector("input[name='mobile']").value;
324
+ formData.phone = form.querySelector("input[name='mobile']").value;
325
+ }
326
+
327
+ let url = `https://api.au-aws.thewishlist.io/services/wsservice/api/wishlist/items/customerInterest`;
328
+
329
+ fetch(url, {
330
+ method: "POST",
331
+ headers: {
332
+ "Content-Type": "application/json",
333
+ Authorization: ACCESS_TOKEN,
334
+ "X-Twc-Tenant": TENANT_ID,
335
+ },
336
+ body: JSON.stringify(formData),
337
+ })
338
+ .then((response) => {
339
+ if (response.ok) {
340
+ alert("Form submitted");
341
+ hidePopup();
342
+ } else {
343
+ alert("Form submission failed");
344
+ }
345
+ })
346
+ .catch((error) => {
347
+ console.error("Error submitting form:", error);
348
+ alert("Form submission failed");
349
+ });
350
+ } else {
351
+ alert("Selected variant not found");
352
+ }
353
+ });
354
+ }
348
355
  });
356
+
349
357
  ```
350
358
 
351
- Replace `ACCESS_TOKEN` with your actual access token to authenticate API requests.
359
+ Replace `ACCESS_TOKEN` with your actual access token to authenticate API requests.
360
+ Replace `TENANT_ID` with your actual tenant to authenticate API requests.
package/index.html CHANGED
@@ -14,7 +14,7 @@
14
14
  </head>
15
15
  <body>
16
16
  <div id="notification-widget">
17
- <button id="popup-open" class="notification-btn" type="button" data-type="notify-me" data-fields='["email", "mobile", "firstName", "lastName"]'>Notify Me - Join Waitlist</button>
17
+ <button id="popup-open" class="notification-btn" type="button" data-type="notify-me" data-fields='["mobile", "firstName", "lastName"]'>Notify Me - Join Waitlist</button>
18
18
  </div>
19
19
  </body>
20
20
  <script src="/index.js"></script>
package/index.js CHANGED
@@ -1,5 +1,6 @@
1
1
  // Access token for the API
2
- const ACCESS_TOKEN = "123"; // Replace `ACCESS_TOKEN` with your actual access token to authenticate API requests.
2
+ const ACCESS_TOKEN = "Bearer eyJhbGciOiJSUzI1NiIsInR5cCIgOiAiSldUIiwia2lkIiA6ICJSUUpQaHRWNmFrSWNXU3ZGekpKMl8yc1NJNkhWLTBEVmExX1F2NWVERzQ4In0.eyJleHAiOjE3MjI1MTkwNjEsImlhdCI6MTcyMjUxNzg2MSwianRpIjoiYzk5NjlkNDQtODY0OC00YjE2LWJjYTktNGVkOTdjMTQyZTVlIiwiaXNzIjoiaHR0cHM6Ly9hdXRoLmF1LXNhbmRib3gudGhld2lzaGxpc3QuaW8vYXV0aC9yZWFsbXMvdHdjTWFpbiIsImF1ZCI6ImFjY291bnQiLCJzdWIiOiJmMzQxZmI5ZS01Y2U2LTRkZjgtYjY1ZC0yNTFjZjgyOTUwNzMiLCJ0eXAiOiJCZWFyZXIiLCJhenAiOiJ0d2MtcG9zLWNsaWVudCIsInNlc3Npb25fc3RhdGUiOiIwOGYzNTBjZS00YjBhLTRiOTctOGM4Yi05Njg2Zjc1YzllMTYiLCJhY3IiOiIxIiwiYWxsb3dlZC1vcmlnaW5zIjpbImh0dHBzOi8vbG9jYWxob3N0Il0sInJlYWxtX2FjY2VzcyI6eyJyb2xlcyI6WyJ0d2MtcG9zLXVzZXIiLCJvZmZsaW5lX2FjY2VzcyIsInR3Yy1zdG9yZS1vd25lciIsInVtYV9hdXRob3JpemF0aW9uIl19LCJyZXNvdXJjZV9hY2Nlc3MiOnsiYWNjb3VudCI6eyJyb2xlcyI6WyJtYW5hZ2UtYWNjb3VudCIsIm1hbmFnZS1hY2NvdW50LWxpbmtzIiwidmlldy1wcm9maWxlIl19fSwic2NvcGUiOiJzdG9yZSBlbWFpbCBwcm9maWxlIHRlbmFudGlkIiwiZW1haWxfdmVyaWZpZWQiOnRydWUsInRlbmFudGlkIjoidHdjZmFzaGlvbnN0YWdpbmciLCJuYW1lIjoiTWF0dCBIYW1wc2hpcmUiLCJwcmVmZXJyZWRfdXNlcm5hbWUiOiJtYXR0QHRoZXdpc2hsaXN0LmlvIiwic3RvcmUiOiI5MjQ4ODMzNTY3NiIsImdpdmVuX25hbWUiOiJNYXR0IiwiZmFtaWx5X25hbWUiOiJIYW1wc2hpcmUiLCJlbWFpbCI6Im1hdHRAdGhld2lzaGxpc3QuaW8ifQ.WbYwyMMFb8BAAPcpUigfUlymtJbAEmQnQCSxy1iUGEVmJe116zL19grxNb-1C7lWhHappiMy69UuLzMEDaqBY4q-Kzo1xTAjIduEUTryMf7GUQMP9YnfWp5ZS1lFCtJPz7UkJaJTHuryVCh34rnkkBnV9KhoITW8GMaheQ5Sp42vY947x-GjOM7uvepxFxykNwR4O1YInwMEvCVmoEUA-T-nQZ7KaLohdCPhLw2kMyIouNPQHoG8ancDWCLFJN0CegFyI7trCjYgjq6h4JxfQiAXGSTJ-DhQrMve3deRZK_ivyEcwy5uWsCOPmsgU_ipheL-ve7h34RkKS0O9Xc1tQ"; // Replace `ACCESS_TOKEN` with your actual access token to authenticate API requests.
3
+ const TENANT_ID = "twcfashionstaging"; // Replace `TENANT_ID` with your actual tenant ID.
3
4
 
4
5
  document.addEventListener("DOMContentLoaded", function () {
5
6
  const wrapper = document.getElementById("notification-widget");
@@ -7,119 +8,119 @@ document.addEventListener("DOMContentLoaded", function () {
7
8
 
8
9
  // Define and apply styles for the popup and button
9
10
  const styles = `
10
- .notification-btn {
11
- background-color: #fff;
12
- border: 1px solid black;
13
- color: black;
14
- padding: 12px 24px;
15
- text-align: center;
16
- width: 100%;
17
- cursor: pointer;
18
- text-transform: uppercase;
19
- }
20
- #popup-body.overlay {
21
- position: fixed;
22
- top: 0;
23
- bottom: 0;
24
- left: 0;
25
- right: 0;
26
- background: rgba(0, 0, 0, 0.7);
27
- transition: opacity 200ms;
28
- visibility: hidden;
29
- opacity: 0;
30
- }
31
- #popup-wrapper {
32
- margin: 70px auto;
33
- padding: 15px;
34
- background: #fff;
35
- border-radius: 5px;
36
- max-width: 360px;
37
- position: relative;
38
- }
39
- #popup-close {
40
- position: absolute;
41
- top: 5px;
42
- right: 15px;
43
- transition: all 200ms;
44
- font-size: 30px;
45
- font-weight: bold;
46
- text-decoration: none;
47
- color: #333;
48
- cursor: pointer;
49
- }
50
- #popup-close:hover {
51
- color: #d80606;
52
- }
53
- #popup-title {
54
- margin: 0;
55
- font-size: 20px;
56
- max-width: 350px;
57
- text-transform: uppercase;
58
- }
59
- #popup-text {
60
- margin: 10px 0;
61
- font-size: 14px;
62
- }
63
- #popup-form {
64
- display: flex;
65
- flex-direction: column;
66
- gap: 10px;
67
- }
68
- #popup-form input {
69
- padding: 0.475em 1em;
70
- border: 1px solid #caced1;
71
- border-radius: 0.25rem;
72
- font-size: 1.15rem;
73
- max-width: 100%;
74
- }
75
- #popup-form input::placeholder {
76
- font-size: 1rem;
77
- }
78
- #popup-form button {
79
- font-size: 0.85rem;
80
- padding: 0.975em 1em;
81
- font-weight: 600;
82
- border: none;
83
- text-transform: uppercase;
84
- background: #aca475;
85
- color: #fff;
86
- cursor: pointer;
87
- }
88
- .custom-select {
89
- position: relative;
90
- }
91
- .custom-select select {
92
- appearance: none;
93
- width: 100%;
94
- font-size: 1.15rem;
95
- padding: 0.475em 1em;
96
- background-color: #fff;
97
- border: 1px solid #caced1;
98
- border-radius: 0.25rem;
99
- color: #000;
100
- cursor: pointer;
101
- }
102
- .custom-select::before,
103
- .custom-select::after {
104
- --size: 0.3rem;
105
- content: "";
106
- position: absolute;
107
- right: 1rem;
108
- pointer-events: none;
109
- }
110
- .custom-select::before {
111
- border-left: var(--size) solid transparent;
112
- border-right: var(--size) solid transparent;
113
- border-bottom: var(--size) solid black;
114
- top: 40%;
115
- }
116
- .custom-select::after {
117
- border-left: var(--size) solid transparent;
118
- border-right: var(--size) solid transparent;
119
- border-top: var(--size) solid black;
120
- top: 55%;
121
- }
122
- `;
11
+ .notification-btn {
12
+ background-color: #fff;
13
+ border: 1px solid black;
14
+ color: black;
15
+ padding: 12px 24px;
16
+ text-align: center;
17
+ width: 100%;
18
+ cursor: pointer;
19
+ text-transform: uppercase;
20
+ }
21
+ #popup-body.overlay {
22
+ position: fixed;
23
+ top: 0;
24
+ bottom: 0;
25
+ left: 0;
26
+ right: 0;
27
+ background: rgba(0, 0, 0, 0.7);
28
+ transition: opacity 200ms;
29
+ visibility: hidden;
30
+ opacity: 0;
31
+ }
32
+ #popup-wrapper {
33
+ margin: 70px auto;
34
+ padding: 15px;
35
+ background: #fff;
36
+ border-radius: 5px;
37
+ max-width: 360px;
38
+ position: relative;
39
+ }
40
+ #popup-close {
41
+ position: absolute;
42
+ top: 5px;
43
+ right: 15px;
44
+ transition: all 200ms;
45
+ font-size: 30px;
46
+ font-weight: bold;
47
+ text-decoration: none;
48
+ color: #333;
49
+ cursor: pointer;
50
+ }
51
+ #popup-close:hover {
52
+ color: #d80606;
53
+ }
54
+ #popup-title {
55
+ margin: 0;
56
+ font-size: 20px;
57
+ max-width: 350px;
58
+ text-transform: uppercase;
59
+ }
60
+ #popup-text {
61
+ margin: 10px 0;
62
+ font-size: 14px;
63
+ }
64
+ #popup-form {
65
+ display: flex;
66
+ flex-direction: column;
67
+ gap: 10px;
68
+ }
69
+ #popup-form input {
70
+ padding: 0.475em 1em;
71
+ border: 1px solid #caced1;
72
+ border-radius: 0.25rem;
73
+ font-size: 1.15rem;
74
+ max-width: 100%;
75
+ }
76
+ #popup-form input::placeholder {
77
+ font-size: 1rem;
78
+ }
79
+ #popup-form button {
80
+ font-size: 0.85rem;
81
+ padding: 0.975em 1em;
82
+ font-weight: 600;
83
+ border: none;
84
+ text-transform: uppercase;
85
+ background: #aca475;
86
+ color: #fff;
87
+ cursor: pointer;
88
+ }
89
+ .custom-select {
90
+ position: relative;
91
+ }
92
+ .custom-select select {
93
+ appearance: none;
94
+ width: 100%;
95
+ font-size: 1.15rem;
96
+ padding: 0.475em 1em;
97
+ background-color: #fff;
98
+ border: 1px solid #caced1;
99
+ border-radius: 0.25rem;
100
+ color: #000;
101
+ cursor: pointer;
102
+ }
103
+ .custom-select::before,
104
+ .custom-select::after {
105
+ --size: 0.3rem;
106
+ content: "";
107
+ position: absolute;
108
+ right: 1rem;
109
+ pointer-events: none;
110
+ }
111
+ .custom-select::before {
112
+ border-left: var(--size) solid transparent;
113
+ border-right: var(--size) solid transparent;
114
+ border-bottom: var(--size) solid black;
115
+ top: 40%;
116
+ }
117
+ .custom-select::after {
118
+ border-left: var(--size) solid transparent;
119
+ border-right: var(--size) solid transparent;
120
+ border-top: var(--size) solid black;
121
+ top: 55%;
122
+ }
123
+ `;
123
124
 
124
125
  const styleSheet = document.createElement("style");
125
126
  styleSheet.type = "text/css";
@@ -129,20 +130,21 @@ document.addEventListener("DOMContentLoaded", function () {
129
130
  // Create and append the overlay for the popup
130
131
  const overlay = document.createElement("div");
131
132
  overlay.innerHTML = `
132
- <div id="popup-body" class="overlay">
133
- <div id="popup-wrapper">
134
- <h3 id="popup-title"></h3>
135
- <span id="popup-close">&times;</span>
136
- <div id="popup-text"></div>
137
- <form id="popup-form">
138
- <div class="custom-select">
139
- <select name="select-size" required>
140
- </select>
141
- </div>
142
- </form>
133
+ <div id="popup-body" class="overlay">
134
+ <div id="popup-wrapper">
135
+ <h3 id="popup-title"></h3>
136
+ <span id="popup-close">&times;</span>
137
+ <div id="popup-text"></div>
138
+ <form id="popup-form">
139
+ <div class="custom-select">
140
+ <select name="select-size" required>
141
+ </select>
143
142
  </div>
144
- </div>
145
- `;
143
+ <input name="email" placeholder="Email" type="email" required />
144
+ </form>
145
+ </div>
146
+ </div>
147
+ `;
146
148
 
147
149
  wrapper.appendChild(overlay);
148
150
 
@@ -172,14 +174,14 @@ document.addEventListener("DOMContentLoaded", function () {
172
174
 
173
175
  // Get product data from Shopify's global variable
174
176
  const productData = window.Shopify?.product || {
175
- id: 6786188247105,
177
+ id: "6786188247105",
176
178
  title: "THE ATG SCULPT FLARES TALL",
177
179
  product_option_value: {
178
180
  name: "BUTTER BLACK",
179
181
  },
180
182
  variants: [
181
183
  { id: 1, title: "S" },
182
- { id: 2, title: "M" },
184
+ { id: "46906570899772", title: "M" },
183
185
  { id: 3, title: "L" },
184
186
  { id: 4, title: "XL" },
185
187
  ],
@@ -195,20 +197,13 @@ document.addEventListener("DOMContentLoaded", function () {
195
197
  });
196
198
 
197
199
  // Map for form fields
198
- popupTitle.innerHTML = productData.title + "<br/>" + productData.product_option_value.name;
199
200
  popupText.innerText = typeConfig[type].text;
200
- productData.variants.forEach((variant) => {
201
- const option = document.createElement("option");
202
- option.value = variant.title;
203
- option.textContent = variant.title;
204
- sizeSelect.appendChild(option);
205
- });
206
201
 
207
202
  const fieldMap = {
208
203
  email: `<input name="email" placeholder="Email" type="email" required />`,
209
- mobile: `<input name="mobile" placeholder="Mobile" type="tel" required />`,
210
- firstName: `<input name="firstName" placeholder="First name" type="text" required />`,
211
- lastName: `<input name="lastName" placeholder="Last name" type="text" required />`,
204
+ mobile: `<input name="mobile" placeholder="Mobile" type="tel" />`,
205
+ firstName: `<input name="firstName" placeholder="First name" type="text" />`,
206
+ lastName: `<input name="lastName" placeholder="Last name" type="text" />`,
212
207
  };
213
208
 
214
209
  // Add fields to the form based on the parsed fields
@@ -217,6 +212,11 @@ document.addEventListener("DOMContentLoaded", function () {
217
212
  form.insertAdjacentHTML("beforeend", fieldMap[field]);
218
213
  }
219
214
  });
215
+
216
+ form.insertAdjacentHTML("beforeend", `<div id="checkbox-wrapper"></div>`);
217
+ const checkboxWrapper = document.getElementById("checkbox-wrapper");
218
+ checkboxWrapper.insertAdjacentHTML("beforeend", `<input type="checkbox" name="mailList" id="mailList" />`);
219
+ checkboxWrapper.insertAdjacentHTML("beforeend", `<label for="mailList">Subscribe to our mailing list</label>`);
220
220
  form.insertAdjacentHTML("beforeend", `<button type="submit">${typeConfig[type].buttonText}</button>`);
221
221
 
222
222
  // Show/hide the popup
@@ -243,12 +243,16 @@ document.addEventListener("DOMContentLoaded", function () {
243
243
 
244
244
  if (selectedVariant) {
245
245
  const formData = {
246
- productRef: productData.id,
247
246
  variantRef: selectedVariant.id,
247
+ email: form.querySelector("input[name='email']").value,
248
+ subscribe: form.querySelector("input[name='mailList']").checked,
248
249
  };
249
250
 
250
- if (fields.includes("email")) {
251
- formData.email = form.querySelector("input[name='email']").value;
251
+ if (type === "coming-soon") {
252
+ formData.comingSoon = true;
253
+ // formData.productRef = productData.id;
254
+ } else {
255
+ formData.notifyMe = true;
252
256
  }
253
257
  if (fields.includes("firstName")) {
254
258
  formData.firstName = form.querySelector("input[name='firstName']").value;
@@ -258,6 +262,7 @@ document.addEventListener("DOMContentLoaded", function () {
258
262
  }
259
263
  if (fields.includes("mobile")) {
260
264
  formData.mobile = form.querySelector("input[name='mobile']").value;
265
+ // formData.phone = form.querySelector("input[name='mobile']").value;
261
266
  }
262
267
 
263
268
  let url = `https://api.au-aws.thewishlist.io/services/wsservice/api/wishlist/items/customerInterest`;
@@ -267,6 +272,7 @@ document.addEventListener("DOMContentLoaded", function () {
267
272
  headers: {
268
273
  "Content-Type": "application/json",
269
274
  Authorization: ACCESS_TOKEN,
275
+ "X-Twc-Tenant": TENANT_ID,
270
276
  },
271
277
  body: JSON.stringify(formData),
272
278
  })
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "notify-me-wl",
3
- "version": "1.2.1",
3
+ "version": "1.3.1",
4
4
  "main": "index.js",
5
5
  "scripts": {
6
6
  "test": "echo \"Error: no test specified\" && exit 1"