@product7/product7-js 0.4.9 → 0.5.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.
@@ -964,9 +964,8 @@
964
964
  const contact = this.api.getContactIdentity?.() || null;
965
965
 
966
966
  const payload = {
967
- rating: responseData.rating,
968
- feedback: responseData.feedback || '',
969
- answers: responseData.answers || {},
967
+ answers: Array.isArray(responseData.answers) ? responseData.answers : [],
968
+ ...(responseData.feedback && { feedback: responseData.feedback }),
970
969
  ...(respondent.respondent_id && {
971
970
  respondent_id: respondent.respondent_id,
972
971
  }),
@@ -6222,6 +6221,12 @@
6222
6221
  }
6223
6222
 
6224
6223
  .feedback-survey-page-choice-btn.selected::after {
6224
+ content: '✓';
6225
+ color: #ffffff;
6226
+ font-size: 11px;
6227
+ font-weight: 700;
6228
+ line-height: 18px;
6229
+ text-align: center;
6225
6230
  border-color: var(--color-primary);
6226
6231
  background-color: var(--color-primary);
6227
6232
  }
@@ -13314,28 +13319,18 @@
13314
13319
  this._setSubmitLoading(true);
13315
13320
 
13316
13321
  const respondent = this._getRespondentContext();
13317
- const normalizedPageAnswers = this._normalizePageAnswersForSubmit();
13318
- const mergedAnswers = {
13319
- ...this.surveyState.customAnswers,
13320
- ...(Object.keys(normalizedPageAnswers).length > 0 && {
13321
- page_answers: normalizedPageAnswers,
13322
- }),
13323
- };
13324
13322
 
13325
13323
  const responseData = {
13326
- rating: this._getSubmissionRating(),
13327
- feedback: this.surveyState.feedback,
13328
- answers: mergedAnswers,
13324
+ answers: this._normalizePageAnswersForSubmit(),
13325
+ ...(this.surveyState.feedback && { feedback: this.surveyState.feedback }),
13329
13326
  ...(respondent.respondentId && { respondentId: respondent.respondentId }),
13330
13327
  ...(respondent.email && { email: respondent.email }),
13331
13328
  };
13332
13329
 
13333
13330
  const response = {
13334
13331
  type: type,
13335
- score: this._getSubmissionRating(),
13332
+ answers: responseData.answers,
13336
13333
  feedback: this.surveyState.feedback,
13337
- customAnswers: mergedAnswers,
13338
- pageAnswers: normalizedPageAnswers,
13339
13334
  timestamp: new Date().toISOString(),
13340
13335
  };
13341
13336
 
@@ -13519,27 +13514,58 @@
13519
13514
  }
13520
13515
 
13521
13516
  _normalizePageAnswersForSubmit() {
13522
- const output = {};
13523
- for (const [pageId, answer] of Object.entries(
13524
- this.surveyState.pageAnswers
13525
- )) {
13526
- if (answer == null) continue;
13527
- if (Array.isArray(answer.values) && answer.values.length > 0) {
13528
- output[pageId] = answer.values;
13529
- continue;
13530
- }
13531
- if (answer.value != null && answer.value !== '') {
13532
- output[pageId] = answer.value;
13533
- continue;
13517
+ // Single-rating surveys (NPS / CSAT / CES / star / emoji) have no pages
13518
+ if (!this._isMultiPageSurvey()) {
13519
+ if (typeof this.surveyState.score === 'number') {
13520
+ return [{ page_id: 'p1', value: this.surveyState.score }];
13534
13521
  }
13535
- if (typeof answer.rating === 'number') {
13536
- output[pageId] = answer.rating;
13537
- continue;
13522
+ return [];
13523
+ }
13524
+
13525
+ const output = [];
13526
+
13527
+ for (const page of this.surveyOptions.pages) {
13528
+ const pageId =
13529
+ page.id || `page_${this.surveyOptions.pages.indexOf(page)}`;
13530
+ const answer = this.surveyState.pageAnswers[pageId];
13531
+ if (answer == null) continue;
13532
+
13533
+ let value = null;
13534
+
13535
+ if (page.type === 'rating' && typeof answer.rating === 'number') {
13536
+ value = answer.rating;
13537
+ } else if (page.type === 'multiple_choice') {
13538
+ const config =
13539
+ page.multipleChoiceConfig || page.multiple_choice_config || {};
13540
+ const allowMultiple =
13541
+ config.allow_multiple === true ||
13542
+ config.multiple === true ||
13543
+ config.allow_multiple_selection === true;
13544
+
13545
+ if (
13546
+ allowMultiple &&
13547
+ Array.isArray(answer.values) &&
13548
+ answer.values.length > 0
13549
+ ) {
13550
+ value = answer.values;
13551
+ } else if (answer.value != null && answer.value !== '') {
13552
+ value = answer.value;
13553
+ }
13554
+ } else if (
13555
+ page.type === 'text' &&
13556
+ typeof answer.text === 'string' &&
13557
+ answer.text.trim()
13558
+ ) {
13559
+ value = answer.text.trim();
13560
+ } else if (page.type === 'link' && typeof answer.clicked === 'boolean') {
13561
+ value = answer.clicked;
13538
13562
  }
13539
- if (typeof answer.text === 'string' && answer.text.trim()) {
13540
- output[pageId] = answer.text.trim();
13563
+
13564
+ if (value !== null) {
13565
+ output.push({ page_id: pageId, value });
13541
13566
  }
13542
13567
  }
13568
+
13543
13569
  return output;
13544
13570
  }
13545
13571
 
@@ -13602,7 +13628,17 @@
13602
13628
  _showThankYouScreen(onAfterClose) {
13603
13629
  if (!this.surveyElement) return;
13604
13630
 
13605
- const config = this.surveyOptions.thankYouConfig || {};
13631
+ const pages = this.surveyOptions.pages || [];
13632
+ const currentPage =
13633
+ pages[this.surveyState.currentPageIndex] ||
13634
+ pages[pages.length - 1] ||
13635
+ null;
13636
+ const pageConfig = currentPage?.thankYouConfig || null;
13637
+ const surveyConfig = this.surveyOptions.thankYouConfig || null;
13638
+ const config =
13639
+ (pageConfig?.title ? pageConfig : null) ||
13640
+ (surveyConfig?.title ? surveyConfig : null) ||
13641
+ {};
13606
13642
  const title = config.title || 'Thanks for your feedback!';
13607
13643
  const buttonText = config.button_text || null;
13608
13644
  const buttonUrl = config.button_url || '#';
@@ -14285,6 +14321,7 @@
14285
14321
  page.multipleChoiceConfig || page.multiple_choice_config || null,
14286
14322
  linkConfig: page.linkConfig || page.link_config || null,
14287
14323
  afterThisPage: page.afterThisPage || page.after_this_page || null,
14324
+ thankYouConfig: page.thankYouConfig || page.thank_you_config || null,
14288
14325
  }))
14289
14326
  .sort((a, b) => a.position - b.position);
14290
14327
  }