@product7/product7-js 0.4.5 → 0.4.6

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.
@@ -4212,14 +4212,46 @@
4212
4212
  line-height: var(--line-height-relaxed);
4213
4213
  }
4214
4214
 
4215
- .messenger-prechat-actions {
4215
+ .messenger-prechat-form {
4216
4216
  display: flex;
4217
4217
  flex-direction: column;
4218
- gap: var(--spacing-2);
4218
+ gap: var(--spacing-3);
4219
4219
  }
4220
4220
 
4221
- .messenger-prechat-yes,
4222
- .messenger-prechat-no {
4221
+ .messenger-prechat-field {
4222
+ display: flex;
4223
+ flex-direction: column;
4224
+ gap: var(--spacing-1);
4225
+ }
4226
+
4227
+ .messenger-prechat-input {
4228
+ width: 100%;
4229
+ padding: var(--spacing-3) var(--spacing-4);
4230
+ border: 1px solid var(--msg-border);
4231
+ border-radius: var(--radius-md);
4232
+ font-size: var(--font-size-sm);
4233
+ font-family: inherit;
4234
+ background: var(--msg-bg-surface);
4235
+ color: var(--msg-text);
4236
+ outline: none;
4237
+ transition: border-color var(--transition-fast);
4238
+ box-sizing: border-box;
4239
+ }
4240
+
4241
+ .messenger-prechat-input::placeholder {
4242
+ color: var(--msg-text-secondary);
4243
+ }
4244
+
4245
+ .messenger-prechat-input:focus {
4246
+ border-color: var(--color-primary);
4247
+ }
4248
+
4249
+ .messenger-prechat-error {
4250
+ font-size: var(--font-size-xs);
4251
+ color: #dc2626;
4252
+ }
4253
+
4254
+ .messenger-prechat-submit {
4223
4255
  display: flex;
4224
4256
  align-items: center;
4225
4257
  justify-content: center;
@@ -4233,42 +4265,24 @@
4233
4265
  transition: all var(--transition-fast);
4234
4266
  border: none;
4235
4267
  width: 100%;
4236
- }
4237
-
4238
- .messenger-prechat-yes {
4239
4268
  background: var(--color-primary);
4240
4269
  color: #ffffff;
4270
+ margin-top: var(--spacing-1);
4241
4271
  }
4242
4272
 
4243
- .messenger-prechat-yes:hover {
4273
+ .messenger-prechat-submit:hover {
4244
4274
  background: var(--color-primary-hover);
4245
4275
  }
4246
4276
 
4247
- .messenger-prechat-yes:active {
4277
+ .messenger-prechat-submit:active {
4248
4278
  transform: translateY(1px);
4249
4279
  transition-duration: 100ms;
4250
4280
  }
4251
4281
 
4252
- .messenger-prechat-yes:disabled {
4282
+ .messenger-prechat-submit:disabled {
4253
4283
  opacity: 0.7;
4254
4284
  cursor: not-allowed;
4255
4285
  }
4256
-
4257
- .messenger-prechat-no {
4258
- background: var(--msg-bg-surface);
4259
- color: var(--msg-text-secondary);
4260
- border: 1px solid var(--msg-border);
4261
- }
4262
-
4263
- .messenger-prechat-no:hover {
4264
- background: var(--msg-bg-hover);
4265
- color: var(--msg-text);
4266
- }
4267
-
4268
- .messenger-prechat-no:active {
4269
- transform: translateY(1px);
4270
- transition-duration: 100ms;
4271
- }
4272
4286
  `;
4273
4287
 
4274
4288
  const messengerCoreStyles = `
@@ -11202,9 +11216,7 @@
11202
11216
  render() {
11203
11217
  this.element = document.createElement('div');
11204
11218
  this.element.className = 'messenger-view messenger-prechat-view';
11205
-
11206
11219
  this._updateContent();
11207
-
11208
11220
  return this.element;
11209
11221
  }
11210
11222
 
@@ -11213,20 +11225,35 @@
11213
11225
  <div class="messenger-prechat-overlay">
11214
11226
  <div class="messenger-prechat-card">
11215
11227
  <div class="messenger-prechat-icon">
11216
- <iconify-icon icon="ph:bell-ringing-duotone" width="36" height="36"></iconify-icon>
11228
+ <iconify-icon icon="ph:chat-teardrop-dots-duotone" width="36" height="36"></iconify-icon>
11217
11229
  </div>
11218
- <h4 class="messenger-prechat-title">Get notified when we reply</h4>
11219
- <p class="messenger-prechat-subtitle">We'll send you an email so you never miss a response.</p>
11220
- <div class="messenger-prechat-actions">
11221
- <button type="button" class="messenger-prechat-yes">
11222
- <iconify-icon icon="ph:bell-ringing-duotone" width="16" height="16"></iconify-icon>
11223
- Yes, notify me
11224
- </button>
11225
- <button type="button" class="messenger-prechat-no">
11226
- <iconify-icon icon="ph:bell-slash-duotone" width="16" height="16"></iconify-icon>
11227
- No thanks
11230
+ <h4 class="messenger-prechat-title">Before we continue</h4>
11231
+ <p class="messenger-prechat-subtitle">Enter your details so we can get back to you.</p>
11232
+ <form class="messenger-prechat-form" novalidate>
11233
+ <div class="messenger-prechat-field">
11234
+ <input
11235
+ type="text"
11236
+ name="name"
11237
+ class="messenger-prechat-input"
11238
+ placeholder="Your name"
11239
+ autocomplete="name"
11240
+ />
11241
+ </div>
11242
+ <div class="messenger-prechat-field">
11243
+ <input
11244
+ type="email"
11245
+ name="email"
11246
+ class="messenger-prechat-input"
11247
+ placeholder="Your email address"
11248
+ autocomplete="email"
11249
+ required
11250
+ />
11251
+ <span class="messenger-prechat-error" style="display:none;"></span>
11252
+ </div>
11253
+ <button type="submit" class="messenger-prechat-submit">
11254
+ Start chat
11228
11255
  </button>
11229
- </div>
11256
+ </form>
11230
11257
  </div>
11231
11258
  </div>
11232
11259
  `;
@@ -11235,35 +11262,45 @@
11235
11262
  }
11236
11263
 
11237
11264
  _attachEvents() {
11238
- this.element
11239
- .querySelector('.messenger-prechat-yes')
11240
- .addEventListener('click', async () => {
11241
- await this._handleYes();
11242
- });
11243
-
11244
- this.element
11245
- .querySelector('.messenger-prechat-no')
11246
- .addEventListener('click', () => {
11247
- this._handleNo();
11248
- });
11265
+ const form = this.element.querySelector('.messenger-prechat-form');
11266
+ form.addEventListener('submit', async (e) => {
11267
+ e.preventDefault();
11268
+ await this._handleSubmit();
11269
+ });
11249
11270
  }
11250
11271
 
11251
- async _handleYes() {
11272
+ async _handleSubmit() {
11252
11273
  if (this._isSubmitting) return;
11253
- this._isSubmitting = true;
11254
11274
 
11255
- const yesBtn = this.element.querySelector('.messenger-prechat-yes');
11256
- yesBtn.disabled = true;
11257
- yesBtn.innerHTML = `
11275
+ const emailInput = this.element.querySelector('input[name="email"]');
11276
+ const nameInput = this.element.querySelector('input[name="name"]');
11277
+ const errorEl = this.element.querySelector('.messenger-prechat-error');
11278
+ const submitBtn = this.element.querySelector('.messenger-prechat-submit');
11279
+
11280
+ const email = emailInput.value.trim();
11281
+ const name = nameInput.value.trim();
11282
+
11283
+ if (!email || !/^[^\s@]+@[^\s@]+\.[^\s@]+$/.test(email)) {
11284
+ errorEl.textContent = 'Please enter a valid email address.';
11285
+ errorEl.style.display = 'block';
11286
+ emailInput.focus();
11287
+ return;
11288
+ }
11289
+
11290
+ errorEl.style.display = 'none';
11291
+ this._isSubmitting = true;
11292
+ submitBtn.disabled = true;
11293
+ submitBtn.innerHTML = `
11258
11294
  <iconify-icon icon="ph:circle-notch" width="16" height="16" style="animation: spin 0.8s linear infinite;"></iconify-icon>
11259
11295
  Just a moment...
11260
11296
  `;
11261
11297
 
11262
11298
  try {
11263
- const { name, email } = this.state.metadata || {};
11264
-
11265
11299
  if (this.options.onIdentifyContact) {
11266
- await this.options.onIdentifyContact({ name, email });
11300
+ await this.options.onIdentifyContact({
11301
+ name: name || undefined,
11302
+ email,
11303
+ });
11267
11304
  }
11268
11305
 
11269
11306
  this.state.setIdentified(true, { name, email });
@@ -11281,19 +11318,14 @@
11281
11318
  }
11282
11319
  } catch (error) {
11283
11320
  console.error('[PreChatFormView] Error:', error);
11321
+ errorEl.textContent = 'Something went wrong. Please try again.';
11322
+ errorEl.style.display = 'block';
11284
11323
  this._isSubmitting = false;
11285
- yesBtn.disabled = false;
11286
- yesBtn.innerHTML = `
11287
- <iconify-icon icon="ph:bell-ringing-duotone" width="16" height="16"></iconify-icon>
11288
- Yes, notify me
11289
- `;
11324
+ submitBtn.disabled = false;
11325
+ submitBtn.textContent = 'Start chat';
11290
11326
  }
11291
11327
  }
11292
11328
 
11293
- _handleNo() {
11294
- this.state.setView('chat');
11295
- }
11296
-
11297
11329
  destroy() {
11298
11330
  if (this.element && this.element.parentNode) {
11299
11331
  this.element.parentNode.removeChild(this.element);
@@ -11357,6 +11389,8 @@
11357
11389
  onChangelogClick: options.onChangelogClick || null,
11358
11390
  };
11359
11391
 
11392
+ const sdkMetadata = this.sdk?.apiService?.getMetadata() || null;
11393
+
11360
11394
  this.messengerState = new MessengerState({
11361
11395
  teamName: this.messengerOptions.teamName,
11362
11396
  teamAvatars: this.messengerOptions.teamAvatars,
@@ -11366,7 +11400,7 @@
11366
11400
  responseTime: this.messengerOptions.responseTime,
11367
11401
  enableHelp: this.messengerOptions.enableHelp,
11368
11402
  enableChangelog: this.messengerOptions.enableChangelog,
11369
- metadata: this.sdk?.apiService?.getMetadata() || null,
11403
+ metadata: sdkMetadata,
11370
11404
  urls: {
11371
11405
  feedback: this.messengerOptions.feedbackUrl,
11372
11406
  changelog: this.messengerOptions.changelogUrl,
@@ -11375,6 +11409,11 @@
11375
11409
  },
11376
11410
  });
11377
11411
 
11412
+ // If identify() was called before this widget was created, pre-seed identity
11413
+ if (this.sdk?.identified && sdkMetadata) {
11414
+ this.messengerState.isIdentified = true;
11415
+ }
11416
+
11378
11417
  this.launcher = null;
11379
11418
  this.panel = null;
11380
11419
  this.wsService = null;