@constructor-io/constructorio-ui-quizzes 1.9.3 → 1.9.5

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.
@@ -39,10 +39,8 @@ function quizLocalReducer(state, action) {
39
39
  newAnswers.push(['seen']);
40
40
  break;
41
41
  case actions_1.QuestionTypes.SingleSelect:
42
- newAnswers.push(currentAnswerInput.value);
43
- break;
44
42
  case actions_1.QuestionTypes.MultipleSelect:
45
- newAnswers.push(currentAnswerInput.value);
43
+ newAnswers.push(currentAnswerInput.value.map((answer) => answer.id));
46
44
  break;
47
45
  default:
48
46
  newAnswers.push([]);
@@ -39,7 +39,7 @@ function useSelectInputProps(quizAnswerChanged, nextQuestion, currentQuestionDat
39
39
  const prevSelected = {};
40
40
  if (Array.isArray(currentAnswer === null || currentAnswer === void 0 ? void 0 : currentAnswer.value)) {
41
41
  (_a = currentAnswer === null || currentAnswer === void 0 ? void 0 : currentAnswer.value) === null || _a === void 0 ? void 0 : _a.forEach((answer) => {
42
- prevSelected[Number(answer)] = true;
42
+ prevSelected[Number(answer.id)] = true;
43
43
  setSelected(prevSelected);
44
44
  });
45
45
  }
@@ -52,11 +52,18 @@ function useSelectInputProps(quizAnswerChanged, nextQuestion, currentQuestionDat
52
52
  }, [currentQuestionData === null || currentQuestionData === void 0 ? void 0 : currentQuestionData.id]);
53
53
  // Update global state
54
54
  (0, react_1.useEffect)(() => {
55
+ var _a, _b;
55
56
  if ((currentQuestionData === null || currentQuestionData === void 0 ? void 0 : currentQuestionData.type) === 'multiple' || (currentQuestionData === null || currentQuestionData === void 0 ? void 0 : currentQuestionData.type) === 'single') {
56
- const selectedAnswers = Object.keys(selected).filter((key) => selected[Number(key)]);
57
+ const selectedAnswers = (_b = (_a = currentQuestionData === null || currentQuestionData === void 0 ? void 0 : currentQuestionData.options) === null || _a === void 0 ? void 0 : _a.filter((opt) => selected[Number(opt.id)])) === null || _b === void 0 ? void 0 : _b.map((opt) => ({ id: opt.id, value: opt.value }));
57
58
  quizAnswerChanged(selectedAnswers);
58
59
  }
59
- }, [selected, currentQuestionData === null || currentQuestionData === void 0 ? void 0 : currentQuestionData.id, currentQuestionData === null || currentQuestionData === void 0 ? void 0 : currentQuestionData.type, quizAnswerChanged]);
60
+ }, [
61
+ selected,
62
+ currentQuestionData === null || currentQuestionData === void 0 ? void 0 : currentQuestionData.id,
63
+ currentQuestionData === null || currentQuestionData === void 0 ? void 0 : currentQuestionData.type,
64
+ currentQuestionData === null || currentQuestionData === void 0 ? void 0 : currentQuestionData.options,
65
+ quizAnswerChanged,
66
+ ]);
60
67
  // Go to next question only every time answerInputs (answers input state) changes...
61
68
  // and it's a singleSelectQuestion and user has just clicked on an option
62
69
  (0, react_1.useEffect)(() => {
@@ -46,7 +46,7 @@ const trackQuizResultsLoaded = (cioClient, quizResults) => {
46
46
  };
47
47
  exports.trackQuizResultsLoaded = trackQuizResultsLoaded;
48
48
  const trackQuizResultClick = (cioClient, quizResults, result, position) => {
49
- var _a;
49
+ var _a, _b;
50
50
  if (quizResults.request && quizResults.response) {
51
51
  const { quiz_id, quiz_session_id, quiz_version_id, result_id, request: { section, page, num_results_per_page }, response: { total_num_results }, } = quizResults;
52
52
  cioClient === null || cioClient === void 0 ? void 0 : cioClient.tracker.trackQuizResultClick({
@@ -55,6 +55,7 @@ const trackQuizResultClick = (cioClient, quizResults, result, position) => {
55
55
  quizSessionId: quiz_session_id,
56
56
  itemId: (_a = result.data) === null || _a === void 0 ? void 0 : _a.id,
57
57
  itemName: result === null || result === void 0 ? void 0 : result.value,
58
+ variationId: (_b = result.data) === null || _b === void 0 ? void 0 : _b.variation_id,
58
59
  section,
59
60
  resultCount: total_num_results,
60
61
  resultPage: page,
@@ -1,3 +1,3 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.default = '1.9.3';
3
+ exports.default = '1.9.5';
@@ -58,10 +58,8 @@ export default function quizLocalReducer(state, action) {
58
58
  newAnswers.push(['seen']);
59
59
  break;
60
60
  case QuestionTypes.SingleSelect:
61
- newAnswers.push(currentAnswerInput.value);
62
- break;
63
61
  case QuestionTypes.MultipleSelect:
64
- newAnswers.push(currentAnswerInput.value);
62
+ newAnswers.push(currentAnswerInput.value.map((answer) => answer.id));
65
63
  break;
66
64
  default:
67
65
  newAnswers.push([]);
@@ -35,7 +35,7 @@ export default function useSelectInputProps(quizAnswerChanged, nextQuestion, cur
35
35
  const prevSelected = {};
36
36
  if (Array.isArray(currentAnswer?.value)) {
37
37
  currentAnswer?.value?.forEach((answer) => {
38
- prevSelected[Number(answer)] = true;
38
+ prevSelected[Number(answer.id)] = true;
39
39
  setSelected(prevSelected);
40
40
  });
41
41
  }
@@ -49,10 +49,18 @@ export default function useSelectInputProps(quizAnswerChanged, nextQuestion, cur
49
49
  // Update global state
50
50
  useEffect(() => {
51
51
  if (currentQuestionData?.type === 'multiple' || currentQuestionData?.type === 'single') {
52
- const selectedAnswers = Object.keys(selected).filter((key) => selected[Number(key)]);
52
+ const selectedAnswers = currentQuestionData?.options
53
+ ?.filter((opt) => selected[Number(opt.id)])
54
+ ?.map((opt) => ({ id: opt.id, value: opt.value }));
53
55
  quizAnswerChanged(selectedAnswers);
54
56
  }
55
- }, [selected, currentQuestionData?.id, currentQuestionData?.type, quizAnswerChanged]);
57
+ }, [
58
+ selected,
59
+ currentQuestionData?.id,
60
+ currentQuestionData?.type,
61
+ currentQuestionData?.options,
62
+ quizAnswerChanged,
63
+ ]);
56
64
  // Go to next question only every time answerInputs (answers input state) changes...
57
65
  // and it's a singleSelectQuestion and user has just clicked on an option
58
66
  useEffect(() => {
@@ -42,6 +42,7 @@ export const trackQuizResultClick = (cioClient, quizResults, result, position) =
42
42
  quizSessionId: quiz_session_id,
43
43
  itemId: result.data?.id,
44
44
  itemName: result?.value,
45
+ variationId: result.data?.variation_id,
45
46
  section,
46
47
  resultCount: total_num_results,
47
48
  resultPage: page,
@@ -1 +1 @@
1
- export default '1.9.3';
1
+ export default '1.9.5';
@@ -1,4 +1,4 @@
1
- import { CurrentQuestion, NextQuestionResponse, QuizResultsResponse } from '../../types';
1
+ import { CurrentQuestion, NextQuestionResponse, QuestionOption, QuizResultsResponse } from '../../types';
2
2
  import type { QuizLocalReducerState } from './quizLocalReducer';
3
3
  export declare enum QuestionTypes {
4
4
  OpenText = "open",
@@ -17,7 +17,7 @@ export interface QuestionAnswer<Value> {
17
17
  input: Value;
18
18
  isLastQuestion?: boolean;
19
19
  }
20
- export type SelectQuestionPayload = QuestionAnswer<string[]>;
20
+ export type SelectQuestionPayload = QuestionAnswer<Omit<QuestionOption, 'attribute' | 'images'>[]>;
21
21
  export type OpenTextQuestionPayload = QuestionAnswer<string>;
22
22
  export type CoverQuestionPayload = QuestionAnswer<string>;
23
23
  interface Action<Type, Payload = {}> {
@@ -68,7 +68,7 @@ export interface QuizReturnState {
68
68
  }
69
69
  export type AnswerInput = {
70
70
  type: InputQuestionsTypes;
71
- value: string | string[] | null;
71
+ value: string | Omit<QuestionOption, 'attribute' | 'images'>[] | null;
72
72
  };
73
73
  export type AnswerInputState = {
74
74
  [key: string]: AnswerInput;
@@ -88,7 +88,7 @@ export type CurrentQuestion = NextQuestionResponse & {
88
88
  isSelectQuestion: boolean;
89
89
  };
90
90
  export declare namespace QuizEventsReturn {
91
- type QuizAnswerChanged = (payload?: string | string[]) => void;
91
+ type QuizAnswerChanged = (payload?: string | Omit<QuestionOption, 'attribute' | 'images'>[]) => void;
92
92
  type NextQuestion = () => void;
93
93
  type SkipQuestion = () => void;
94
94
  type PreviousQuestion = () => void;
@@ -1,2 +1,2 @@
1
- declare const _default: "1.9.3";
1
+ declare const _default: "1.9.5";
2
2
  export default _default;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@constructor-io/constructorio-ui-quizzes",
3
- "version": "1.9.3",
3
+ "version": "1.9.5",
4
4
  "description": "Constructor.io Quizzes UI library for web applications",
5
5
  "author": "constructor.io",
6
6
  "license": "MIT",
@@ -59,7 +59,7 @@
59
59
  "check-license": "license-checker --production --onlyAllow 'Apache-2.0;BSD-3-Clause;MIT;0BSD;BSD-2-Clause' --excludePackages 'picocolors@1.0.0'"
60
60
  },
61
61
  "peerDependencies": {
62
- "@constructor-io/constructorio-client-javascript": "^2.35.17",
62
+ "@constructor-io/constructorio-client-javascript": "^2.36.4",
63
63
  "react": ">=16.12.0",
64
64
  "react-dom": ">=16.12.0",
65
65
  "tslib": "^2.4.0"