notify-me-wl 1.3.1 → 1.4.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 +360 -360
  2. package/index.html +21 -21
  3. package/index.js +324 -296
  4. package/package.json +1 -1
package/README.md CHANGED
@@ -1,360 +1,360 @@
1
- ### Coming Soon/Notify Me Widget
2
-
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
-
5
- #### Features:
6
- - Dynamically display a form to collect user information (mobile, first name, last name).
7
- - Adjust form and button text based on the widget type (`notify-me` or `coming-soon`).
8
- - Submit user data to a specified API endpoint with email or mobile as a path parameter and appropriate query parameters.
9
-
10
- ### Installation
11
-
12
- Add the following script to your HTML to include the widget:
13
-
14
- ```html
15
- <script src="https://cdn.jsdelivr.net/npm/notify-me-wl/index.js"></script>
16
- ```
17
-
18
- ### Usage
19
-
20
- Add a button to your HTML where you want the widget to appear. The button should have an `id` of `popup-open`, a `data-fields` attribute with the fields you want to include in the form (as a JSON string), and a `data-type` attribute to specify the widget type (`notify-me` or `coming-soon`).
21
-
22
- ```html
23
- <div id="notification-widget"></div>
24
- <button id="popup-open" data-fields='["mobile", "firstName", "lastName"]' data-type="notify-me">Open Popup</button>
25
- ```
26
-
27
- ### Configuration
28
-
29
- - `data-fields`: A JSON array specifying the fields to include in the form. Possible values are `"mobile"`, `"firstName"`, and `"lastName"`.
30
- - `data-type`: Specifies the type of the widget. Possible values are `"notify-me"` and `"coming-soon"`.
31
-
32
- ### Example
33
-
34
- ```html
35
- <div id="notification-widget"></div>
36
- <button id="popup-open" data-fields='["mobile"]' data-type="notify-me">Open Popup</button>
37
-
38
- <script>
39
- // The script provided will be included here
40
- </script>
41
- ```
42
-
43
- ### How It Works
44
-
45
- 1. **Initialization**: The script listens for the `DOMContentLoaded` event to initialize the widget.
46
- 2. **Styles Injection**: It injects necessary styles for the modal and form elements.
47
- 3. **Modal Creation**: Creates the modal structure and appends it to the `notification-widget` div.
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 mandatory email field and other possible fields.
50
-
51
- ### API Request Example
52
-
53
- ```
54
- https://api.au-aws.thewishlist.io/services/wsservice/api/wishlist/items/customerInterest
55
- ```
56
-
57
- ### Full Script
58
-
59
- ```javascript
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.
63
-
64
- document.addEventListener("DOMContentLoaded", function () {
65
- const wrapper = document.getElementById("notification-widget");
66
- if (!wrapper) return;
67
-
68
- // Define and apply styles for the popup and button
69
- const styles = `
70
- .notification-btn {
71
- background-color: #fff;
72
- border: 1px solid black;
73
- color: black;
74
- padding: 12px 24px;
75
- text-align: center;
76
- width: 100%;
77
- cursor: pointer;
78
- text-transform: uppercase;
79
- }
80
- #popup-body.overlay {
81
- position: fixed;
82
- top: 0;
83
- bottom: 0;
84
- left: 0;
85
- right: 0;
86
- background: rgba(0, 0, 0, 0.7);
87
- transition: opacity 200ms;
88
- visibility: hidden;
89
- opacity: 0;
90
- }
91
- #popup-wrapper {
92
- margin: 70px auto;
93
- padding: 15px;
94
- background: #fff;
95
- border-radius: 5px;
96
- max-width: 360px;
97
- position: relative;
98
- }
99
- #popup-close {
100
- position: absolute;
101
- top: 5px;
102
- right: 15px;
103
- transition: all 200ms;
104
- font-size: 30px;
105
- font-weight: bold;
106
- text-decoration: none;
107
- color: #333;
108
- cursor: pointer;
109
- }
110
- #popup-close:hover {
111
- color: #d80606;
112
- }
113
- #popup-title {
114
- margin: 0;
115
- font-size: 20px;
116
- max-width: 350px;
117
- text-transform: uppercase;
118
- }
119
- #popup-text {
120
- margin: 10px 0;
121
- font-size: 14px;
122
- }
123
- #popup-form {
124
- display: flex;
125
- flex-direction: column;
126
- gap: 10px;
127
- }
128
- #popup-form input {
129
- padding: 0.475em 1em;
130
- border: 1px solid #caced1;
131
- border-radius: 0.25rem;
132
- font-size: 1.15rem;
133
- max-width: 100%;
134
- }
135
- #popup-form input::placeholder {
136
- font-size: 1rem;
137
- }
138
- #popup-form button {
139
- font-size: 0.85rem;
140
- padding: 0.975em 1em;
141
- font-weight: 600;
142
- border: none;
143
- text-transform: uppercase;
144
- background: #aca475;
145
- color: #fff;
146
- cursor: pointer;
147
- }
148
- .custom-select {
149
- position: relative;
150
- }
151
- .custom-select select {
152
- appearance: none;
153
- width: 100%;
154
- font-size: 1.15rem;
155
- padding: 0.475em 1em;
156
- background-color: #fff;
157
- border: 1px solid #caced1;
158
- border-radius: 0.25rem;
159
- color: #000;
160
- cursor: pointer;
161
- }
162
- .custom-select::before,
163
- .custom-select::after {
164
- --size: 0.3rem;
165
- content: "";
166
- position: absolute;
167
- right: 1rem;
168
- pointer-events: none;
169
- }
170
- .custom-select::before {
171
- border-left: var(--size) solid transparent;
172
- border-right: var(--size) solid transparent;
173
- border-bottom: var(--size) solid black;
174
- top: 40%;
175
- }
176
- .custom-select::after {
177
- border-left: var(--size) solid transparent;
178
- border-right: var(--size) solid transparent;
179
- border-top: var(--size) solid black;
180
- top: 55%;
181
- }
182
- `;
183
-
184
- const styleSheet = document.createElement("style");
185
- styleSheet.type = "text/css";
186
- styleSheet.innerText = styles;
187
- document.head.appendChild(styleSheet);
188
-
189
- // Create and append the overlay for the popup
190
- const overlay = document.createElement("div");
191
- overlay.innerHTML = `
192
- <div id="popup-body" class="overlay">
193
- <div id="popup-wrapper">
194
- <h3 id="popup-title"></h3>
195
- <span id="popup-close">&times;</span>
196
- <div id="popup-text"></div>
197
- <form id="popup-form">
198
- <div class="custom-select">
199
- <select name="select-size" required>
200
- </select>
201
- </div>
202
- <input name="email" placeholder="Email" type="email" required />
203
- </form>
204
- </div>
205
- </div>
206
- `;
207
-
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;
313
- } else {
314
- formData.notifyMe = true;
315
- }
316
- if (fields.includes("firstName")) {
317
- formData.firstName = form.querySelector("input[name='firstName']").value;
318
- }
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
- }
355
- });
356
-
357
- ```
358
-
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.
1
+ ### Coming Soon/Notify Me Widget
2
+
3
+ This JavaScript widget allows users to register their interest in a product that is either "coming soon" or "out of stock" (aka "notify me"). Depending on the `data-type` attribute provided, the widget will display appropriate messages and functionality.
4
+
5
+ #### Features:
6
+ - Dynamically display a form to collect user information (mobile, first name, last name).
7
+ - Adjust form and button text based on the widget type (`notify-me` or `coming-soon`).
8
+ - Submit user data to a specified API endpoint with email or mobile as a path parameter and appropriate query parameters.
9
+ - An option for the user to subscribe to the database (opt-in)
10
+
11
+ ### Installation
12
+
13
+ Add the following script to your HTML to include the widget:
14
+
15
+ ```html
16
+ <script src="https://cdn.jsdelivr.net/npm/notify-me-wl/index.js"></script>
17
+ ```
18
+
19
+ ### Usage
20
+
21
+ Add a button to your HTML where you want the widget to appear. The button should have an `id` of `popup-open`, a `data-fields` attribute with the fields you want to include in the form (as a JSON string), and a `data-type` attribute to specify the widget type (`notify-me` or `coming-soon`).
22
+
23
+ ```html
24
+ <div id="notification-widget"></div>
25
+ <button id="popup-open" data-fields='["mobile", "firstName", "lastName"]' data-type="notify-me">Open Popup</button>
26
+ ```
27
+
28
+ ### Configuration
29
+
30
+ - `data-fields`: A JSON array specifying the fields to include in the form. Possible values are `"mobile"`, `"firstName"`, and `"lastName"`.
31
+ - `data-type`: Specifies the type of the widget. Possible values are `"notify-me"` and `"coming-soon"`.
32
+
33
+ ### Example
34
+
35
+ ```html
36
+ <div id="notification-widget"></div>
37
+ <button id="popup-open" data-fields='["mobile"]' data-type="notify-me">Open Popup</button>
38
+
39
+ <script>
40
+ // The script provided will be included here
41
+ </script>
42
+ ```
43
+
44
+ ### How It Works
45
+
46
+ 1. **Initialization**: The script listens for the `DOMContentLoaded` event to initialize the widget.
47
+ 2. **Styles Injection**: It injects necessary styles for the modal and form elements.
48
+ 3. **Modal Creation**: Creates the modal structure and appends it to the `notification-widget` div.
49
+ 4. **Dynamic Content**: Based on the `data-type`, it sets the appropriate messages and button text.
50
+ 5. **Form Submission**: Collects form data and submits it to the API with the mandatory email field and other possible fields.
51
+
52
+ ### API Request Example
53
+
54
+ # For sandbox environment
55
+ ```
56
+ https://api.au-sandbox.thewishlist.io/services/wsservice/api/wishlist/items/customerInterest
57
+ ```
58
+ # For production environment
59
+ ```
60
+ https://api.au-aws.thewishlist.io/services/wsservice/api/wishlist/items/customerInterest
61
+ ```
62
+
63
+
64
+ ### Full Script
65
+
66
+ ```javascript
67
+ // Access token for the API
68
+ const ACCESS_TOKEN = "123"; // Replace `ACCESS_TOKEN` with your actual access token to authenticate API requests.
69
+ const TENANT_ID = "victoria-woods"; // Replace `TENANT_ID` with your actual tenant ID.
70
+
71
+ document.addEventListener("DOMContentLoaded", function () {
72
+ const wrapper = document.getElementById("notification-widget");
73
+ if (!wrapper) return;
74
+
75
+ // Define and apply styles for the popup and button
76
+ const styles = `
77
+ .notification-btn {
78
+ background-color: #fff;
79
+ border: 1px solid black;
80
+ color: black;
81
+ padding: 12px 24px;
82
+ text-align: center;
83
+ width: 100%;
84
+ cursor: pointer;
85
+ text-transform: uppercase;
86
+ }
87
+ #popup-body.overlay {
88
+ position: fixed;
89
+ z-index: 9998;
90
+ top: 0;
91
+ bottom: 0;
92
+ left: 0;
93
+ right: 0;
94
+ background: rgba(0, 0, 0, 0.7);
95
+ transition: opacity 200ms;
96
+ visibility: hidden;
97
+ opacity: 0;
98
+ }
99
+ #popup-wrapper {
100
+ margin: 70px auto;
101
+ z-index: 9999;
102
+ padding: 15px;
103
+ background: #fff;
104
+ border-radius: 5px;
105
+ max-width: 360px;
106
+ position: relative;
107
+ }
108
+ #popup-close {
109
+ position: absolute;
110
+ top: 5px;
111
+ right: 15px;
112
+ transition: all 200ms;
113
+ font-size: 30px;
114
+ font-weight: bold;
115
+ text-decoration: none;
116
+ color: #333;
117
+ cursor: pointer;
118
+ }
119
+ #popup-close:hover {
120
+ color: #d80606;
121
+ }
122
+ #popup-title {
123
+ margin: 0;
124
+ font-size: 20px;
125
+ max-width: 350px;
126
+ text-transform: uppercase;
127
+ }
128
+ #popup-text {
129
+ margin: 10px 0;
130
+ font-size: 14px;
131
+ }
132
+ #popup-form {
133
+ display: flex;
134
+ flex-direction: column;
135
+ gap: 10px;
136
+ }
137
+ #popup-form input {
138
+ padding: 0.475em 1em;
139
+ border: 1px solid #caced1;
140
+ border-radius: 0.25rem;
141
+ font-size: 1.15rem;
142
+ max-width: 100%;
143
+ }
144
+ #popup-form input::placeholder {
145
+ font-size: 1rem;
146
+ }
147
+ #popup-form button {
148
+ font-size: 0.85rem;
149
+ padding: 0.975em 1em;
150
+ font-weight: 600;
151
+ border: none;
152
+ text-transform: uppercase;
153
+ background: #aca475;
154
+ color: #fff;
155
+ cursor: pointer;
156
+ }
157
+ .custom-select {
158
+ position: relative;
159
+ }
160
+ .custom-select select {
161
+ appearance: none;
162
+ width: 100%;
163
+ font-size: 1.15rem;
164
+ padding: 0.475em 1em;
165
+ background-color: #fff;
166
+ border: 1px solid #caced1;
167
+ border-radius: 0.25rem;
168
+ color: #000;
169
+ cursor: pointer;
170
+ }
171
+ .custom-select::before,
172
+ .custom-select::after {
173
+ --size: 0.3rem;
174
+ content: "";
175
+ position: absolute;
176
+ right: 1rem;
177
+ pointer-events: none;
178
+ }
179
+ .custom-select::before {
180
+ border-left: var(--size) solid transparent;
181
+ border-right: var(--size) solid transparent;
182
+ border-bottom: var(--size) solid black;
183
+ top: 40%;
184
+ }
185
+ .custom-select::after {
186
+ border-left: var(--size) solid transparent;
187
+ border-right: var(--size) solid transparent;
188
+ border-top: var(--size) solid black;
189
+ top: 55%;
190
+ }
191
+ `;
192
+
193
+ const styleSheet = document.createElement("style");
194
+ styleSheet.type = "text/css";
195
+ styleSheet.innerText = styles;
196
+ document.head.appendChild(styleSheet);
197
+
198
+ // Create and append the overlay for the popup
199
+ const overlay = document.createElement("div");
200
+ overlay.innerHTML = `
201
+ <div id="popup-body" class="overlay">
202
+ <div id="popup-wrapper">
203
+ <h3 id="popup-title"></h3>
204
+ <span id="popup-close">&times;</span>
205
+ <div id="popup-text"></div>
206
+ <form id="popup-form">
207
+ <div class="custom-select">
208
+ <select name="select-size" required>
209
+ </select>
210
+ </div>
211
+ <input name="email" placeholder="Email" type="email" required />
212
+ </form>
213
+ </div>
214
+ </div>
215
+ `;
216
+
217
+ wrapper.appendChild(overlay);
218
+
219
+ const popupBody = document.getElementById("popup-body");
220
+ const popupClose = document.getElementById("popup-close");
221
+ const popupOpenButton = document.getElementById("popup-open");
222
+ const popupTitle = document.getElementById("popup-title");
223
+ const popupText = document.getElementById("popup-text");
224
+ const sizeSelect = document.querySelector("select[name='select-size']");
225
+ const form = overlay.querySelector("#popup-form");
226
+
227
+ if (!popupBody || !popupClose || !popupOpenButton || !popupTitle || !sizeSelect) return;
228
+
229
+ // Parse fields and type to be included in the form from data attribute
230
+ const fields = JSON.parse(popupOpenButton.getAttribute("data-fields") || '["email"]');
231
+ const type = popupOpenButton.getAttribute("data-type") || "notify-me";
232
+ const typeConfig = {
233
+ "notify-me": {
234
+ text: "Register to receive a notification as soon as this item is back in stock",
235
+ buttonText: "Notify me",
236
+ },
237
+ "coming-soon": {
238
+ text: "Register your interest to hear more about this item",
239
+ buttonText: "Register Interest",
240
+ },
241
+ };
242
+
243
+ // Get product data from Shopify's global variable
244
+ const productData = window?.currentProduct;
245
+
246
+ // Map for form fields
247
+ popupText.innerText = typeConfig[type].text;
248
+
249
+ const fieldMap = {
250
+ email: `<input name="email" placeholder="Email" type="email" required />`,
251
+ mobile: `<input name="mobile" placeholder="Mobile" type="tel" required />`,
252
+ firstName: `<input name="firstName" placeholder="First name" type="text" required />`,
253
+ lastName: `<input name="lastName" placeholder="Last name" type="text" required />`,
254
+ };
255
+
256
+ // Add fields to the form based on the parsed fields
257
+ fields.forEach((field) => {
258
+ if (fieldMap[field]) {
259
+ form.insertAdjacentHTML("beforeend", fieldMap[field]);
260
+ }
261
+ });
262
+
263
+ form.insertAdjacentHTML("beforeend", `<div id="checkbox-wrapper"></div>`);
264
+ const checkboxWrapper = document.getElementById("checkbox-wrapper");
265
+ checkboxWrapper.insertAdjacentHTML("beforeend", `<input type="checkbox" name="mailList" id="mailList" />`);
266
+ checkboxWrapper.insertAdjacentHTML("beforeend", `<label for="mailList">Subscribe to our mailing list</label>`);
267
+ form.insertAdjacentHTML("beforeend", `<button type="submit">${typeConfig[type].buttonText}</button>`);
268
+
269
+ // Show/hide the popup
270
+ function showPopup() {
271
+ if (!productData) {
272
+ alert("Product data not found");
273
+ return;
274
+ }
275
+ // Set the popup title and populate the size dropdown
276
+ popupTitle.innerHTML = productData.title;
277
+ productData.variants.forEach((variant) => {
278
+ const option = document.createElement("option");
279
+ option.value = variant.title;
280
+ option.textContent = variant.title;
281
+ sizeSelect.appendChild(option);
282
+ });
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;
313
+ } else {
314
+ formData.notifyMe = true;
315
+ }
316
+ if (fields.includes("firstName")) {
317
+ formData.firstName = form.querySelector("input[name='firstName']").value;
318
+ }
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-sandbox.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
+ }
355
+ });
356
+
357
+ ```
358
+
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.