@constructor-io/constructorio-ui-quizzes 1.13.0 → 1.14.0
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.
- package/dist/constructorio-ui-quizzes-bundled.js +13 -13
- package/lib/cjs/components/CoverTypeQuestion/CoverTypeQuestion.js +1 -1
- package/lib/cjs/components/OpenTextTypeQuestion/OpenTextTypeQuestion.js +1 -1
- package/lib/cjs/components/ResultCard/ResultCard.js +9 -9
- package/lib/cjs/components/SelectTypeQuestion/SelectTypeQuestion.js +1 -1
- package/lib/cjs/hooks/useQuizState/useQuizApiState.js +1 -6
- package/lib/cjs/stories/Quiz/argTypes.js +17 -5
- package/lib/cjs/utils.js +18 -1
- package/lib/cjs/version.js +1 -1
- package/lib/mjs/components/CoverTypeQuestion/CoverTypeQuestion.js +1 -1
- package/lib/mjs/components/OpenTextTypeQuestion/OpenTextTypeQuestion.js +1 -1
- package/lib/mjs/components/ResultCard/ResultCard.js +9 -8
- package/lib/mjs/components/SelectTypeQuestion/SelectTypeQuestion.js +1 -1
- package/lib/mjs/hooks/useQuizState/useQuizApiState.js +1 -0
- package/lib/mjs/stories/Quiz/argTypes.js +17 -5
- package/lib/mjs/utils.js +15 -0
- package/lib/mjs/version.js +1 -1
- package/lib/types/components/ResultCtaButton/ResultCtaButton.d.ts +1 -1
- package/lib/types/components/ResultFavoritesButton/ResultFavoritesButton.d.ts +1 -1
- package/lib/types/services/index.d.ts +1 -1
- package/lib/types/stories/Quiz/argTypes.d.ts +12 -0
- package/lib/types/types.d.ts +7 -5
- package/lib/types/utils.d.ts +2 -0
- package/lib/types/version.d.ts +1 -1
- package/package.json +2 -2
|
@@ -18,7 +18,7 @@ function CoverTypeQuestion() {
|
|
|
18
18
|
return (react_1.default.createElement("div", { className: `
|
|
19
19
|
cio-container${hasImage ? '--with-image' : ''}
|
|
20
20
|
cio-cover-question-container${hasImage ? '--with-image' : ''}
|
|
21
|
-
`, "data-question-key": question.key },
|
|
21
|
+
`, "data-cnstrc-question-type": question.type, "data-question-key": question.key },
|
|
22
22
|
hasImage ? (0, utils_1.renderImages)(question.images, 'cio-question-image-container') : '',
|
|
23
23
|
react_1.default.createElement("div", { className: 'cio-question-content' },
|
|
24
24
|
react_1.default.createElement(QuestionTitle_1.default, { title: question === null || question === void 0 ? void 0 : question.title }),
|
|
@@ -18,7 +18,7 @@ function OpenTextQuestion() {
|
|
|
18
18
|
return (react_1.default.createElement("div", { className: `
|
|
19
19
|
cio-container${hasImage ? '--with-image' : ''}
|
|
20
20
|
cio-open-text-question-container${hasImage ? '--with-image' : ''}
|
|
21
|
-
`, "data-question-key": question.key },
|
|
21
|
+
`, "data-cnstrc-question-type": question.type, "data-question-key": question.key },
|
|
22
22
|
hasImage ? (0, utils_1.renderImages)(question.images, 'cio-question-image-container') : '',
|
|
23
23
|
react_1.default.createElement("div", { className: 'cio-question-content' },
|
|
24
24
|
react_1.default.createElement(QuestionTitle_1.default, { title: question.title }),
|
|
@@ -5,14 +5,14 @@ const react_1 = tslib_1.__importStar(require("react"));
|
|
|
5
5
|
const ResultCtaButton_1 = tslib_1.__importDefault(require("../ResultCtaButton/ResultCtaButton"));
|
|
6
6
|
const ResultFavoritesButton_1 = tslib_1.__importDefault(require("../ResultFavoritesButton/ResultFavoritesButton"));
|
|
7
7
|
const context_1 = tslib_1.__importDefault(require("../CioQuiz/context"));
|
|
8
|
+
const utils_1 = require("../../utils");
|
|
8
9
|
function ResultCard(props) {
|
|
9
|
-
var _a, _b, _c, _d;
|
|
10
10
|
const { result, salePriceKey, regularPriceKey, resultPosition, ratingCountKey, ratingScoreKey, renderResultCardPriceDetails, } = props;
|
|
11
11
|
const { customAddToFavoritesCallback, customClickItemCallback, getQuizResultButtonProps, getQuizResultLinkProps, } = (0, react_1.useContext)(context_1.default);
|
|
12
|
-
const salePrice =
|
|
13
|
-
const regularPrice =
|
|
14
|
-
const ratingCount =
|
|
15
|
-
const ratingScore =
|
|
12
|
+
const salePrice = (0, utils_1.validateNumberOrString)((0, utils_1.getNestedValueUsingDotNotation)(result === null || result === void 0 ? void 0 : result.data, salePriceKey));
|
|
13
|
+
const regularPrice = (0, utils_1.validateNumberOrString)((0, utils_1.getNestedValueUsingDotNotation)(result === null || result === void 0 ? void 0 : result.data, regularPriceKey));
|
|
14
|
+
const ratingCount = (0, utils_1.validateNumberOrString)((0, utils_1.getNestedValueUsingDotNotation)(result === null || result === void 0 ? void 0 : result.data, ratingCountKey));
|
|
15
|
+
const ratingScore = (0, utils_1.validateNumberOrString)((0, utils_1.getNestedValueUsingDotNotation)(result === null || result === void 0 ? void 0 : result.data, ratingScoreKey));
|
|
16
16
|
const resultCardContent = () => {
|
|
17
17
|
var _a;
|
|
18
18
|
return (react_1.default.createElement(react_1.default.Fragment, null,
|
|
@@ -22,18 +22,18 @@ function ResultCard(props) {
|
|
|
22
22
|
react_1.default.createElement("p", { className: 'cio-result-card-title' }, result.value),
|
|
23
23
|
react_1.default.createElement("div", { className: 'cio-result-card-details' },
|
|
24
24
|
react_1.default.createElement("div", { className: 'cio-result-card-rating' },
|
|
25
|
-
ratingScore && (react_1.default.createElement("span", { className: 'cio-result-card-rating-score' },
|
|
25
|
+
!!ratingScore && (react_1.default.createElement("span", { className: 'cio-result-card-rating-score' },
|
|
26
26
|
Array(Number(ratingScore)).fill('★'),
|
|
27
27
|
Array(5 - Number(ratingScore)).fill('☆'))),
|
|
28
|
-
ratingCount && react_1.default.createElement("span", { className: 'cio-result-card-rating-count' },
|
|
28
|
+
!!ratingCount && react_1.default.createElement("span", { className: 'cio-result-card-rating-count' },
|
|
29
29
|
"(",
|
|
30
30
|
ratingCount,
|
|
31
31
|
")")),
|
|
32
32
|
renderResultCardPriceDetails ? (renderResultCardPriceDetails(result)) : (react_1.default.createElement("div", { className: 'cio-result-card-prices' },
|
|
33
|
-
salePrice && react_1.default.createElement("span", { className: 'cio-result-card-sale-price' },
|
|
33
|
+
!!salePrice && react_1.default.createElement("span", { className: 'cio-result-card-sale-price' },
|
|
34
34
|
"$",
|
|
35
35
|
salePrice),
|
|
36
|
-
regularPrice && (react_1.default.createElement("span", { className: `cio-result-card-regular-price${salePrice ? '--strike-through' : ''}` },
|
|
36
|
+
!!regularPrice && (react_1.default.createElement("span", { className: `cio-result-card-regular-price${salePrice ? '--strike-through' : ''}` },
|
|
37
37
|
"$",
|
|
38
38
|
regularPrice))))))));
|
|
39
39
|
};
|
|
@@ -19,7 +19,7 @@ function SelectTypeQuestion() {
|
|
|
19
19
|
instructions = (question === null || question === void 0 ? void 0 : question.type) === actions_1.QuestionTypes.MultipleSelect && 'Select one or more options';
|
|
20
20
|
}
|
|
21
21
|
if (question) {
|
|
22
|
-
return (react_1.default.createElement("div", { className: 'cio-select-question-container', "data-question-key": question.key },
|
|
22
|
+
return (react_1.default.createElement("div", { className: 'cio-select-question-container', "data-cnstrc-question-type": question.type, "data-question-key": question.key },
|
|
23
23
|
react_1.default.createElement("div", { className: 'cio-select-question-text' },
|
|
24
24
|
react_1.default.createElement(QuestionTitle_1.default, { title: question.title }),
|
|
25
25
|
(question === null || question === void 0 ? void 0 : question.description) ? react_1.default.createElement(QuestionDescription_1.default, { description: question.description }) : ''),
|
|
@@ -14,12 +14,7 @@ const useQuizApiState = (quizOptions, cioClient, quizLocalState, skipToResults,
|
|
|
14
14
|
const { queryItems, queryAttributes, isSharedResultsQuery } = (0, useQueryParams_1.default)();
|
|
15
15
|
const dispatchQuizResults = () => tslib_1.__awaiter(void 0, void 0, void 0, function* () {
|
|
16
16
|
try {
|
|
17
|
-
const quizResults = yield (0, services_1.getQuizResults)(cioClient, quizId, {
|
|
18
|
-
answers: quizLocalState.answers,
|
|
19
|
-
resultsPerPage: resultsPageOptions === null || resultsPageOptions === void 0 ? void 0 : resultsPageOptions.numResultsToDisplay,
|
|
20
|
-
quizVersionId: quizLocalState.quizVersionId,
|
|
21
|
-
quizSessionId: quizLocalState.quizSessionId,
|
|
22
|
-
});
|
|
17
|
+
const quizResults = yield (0, services_1.getQuizResults)(cioClient, quizId, Object.assign({ answers: quizLocalState.answers, resultsPerPage: resultsPageOptions === null || resultsPageOptions === void 0 ? void 0 : resultsPageOptions.numResultsToDisplay, quizVersionId: quizLocalState.quizVersionId, quizSessionId: quizLocalState.quizSessionId }, resultsPageOptions === null || resultsPageOptions === void 0 ? void 0 : resultsPageOptions.requestConfigs));
|
|
23
18
|
// Set quiz results state
|
|
24
19
|
dispatchApiState({
|
|
25
20
|
type: actions_1.QuizAPIActionTypes.SET_QUIZ_RESULTS,
|
|
@@ -112,7 +112,7 @@ exports.argTypes = {
|
|
|
112
112
|
},
|
|
113
113
|
},
|
|
114
114
|
'resultCardOptions.resultCardRegularPriceKey': {
|
|
115
|
-
description: 'Key name for the regular price in the API response',
|
|
115
|
+
description: 'Key name for the regular price value in the API response inside the `data` object. Supports nested keys using dot notation e.g., "priceDetails.regular_price"',
|
|
116
116
|
control: {
|
|
117
117
|
type: 'text',
|
|
118
118
|
},
|
|
@@ -127,7 +127,7 @@ exports.argTypes = {
|
|
|
127
127
|
},
|
|
128
128
|
},
|
|
129
129
|
'resultCardOptions.resultCardSalePriceKey': {
|
|
130
|
-
description: 'Key name for the sale price in the API response',
|
|
130
|
+
description: 'Key name for the sale price value in the API response inside the `data` object. Supports nested keys using dot notation e.g., "priceDetails.sale_price"',
|
|
131
131
|
control: {
|
|
132
132
|
type: 'text',
|
|
133
133
|
},
|
|
@@ -142,7 +142,7 @@ exports.argTypes = {
|
|
|
142
142
|
},
|
|
143
143
|
},
|
|
144
144
|
'resultCardOptions.resultCardRatingCountKey': {
|
|
145
|
-
description: 'Key name for the rating count in the API response',
|
|
145
|
+
description: 'Key name for the rating count value in the API response inside the `data` object. Supports nested keys using dot notation e.g., "ratingDetails.rating_count"',
|
|
146
146
|
control: {
|
|
147
147
|
type: 'text',
|
|
148
148
|
},
|
|
@@ -157,7 +157,7 @@ exports.argTypes = {
|
|
|
157
157
|
},
|
|
158
158
|
},
|
|
159
159
|
'resultCardOptions.resultCardRatingScoreKey': {
|
|
160
|
-
description: 'Key name for the rating score in the API response',
|
|
160
|
+
description: 'Key name for the rating score value in the API response inside the `data` object. Supports nested keys using dot notation e.g., "ratingDetails.rating_score"',
|
|
161
161
|
control: {
|
|
162
162
|
type: 'text',
|
|
163
163
|
},
|
|
@@ -216,7 +216,7 @@ exports.argTypes = {
|
|
|
216
216
|
type: 'boolean',
|
|
217
217
|
},
|
|
218
218
|
table: {
|
|
219
|
-
subcategory: '
|
|
219
|
+
subcategory: 'resultsPageOptions',
|
|
220
220
|
defaultValue: {
|
|
221
221
|
summary: true,
|
|
222
222
|
},
|
|
@@ -225,6 +225,18 @@ exports.argTypes = {
|
|
|
225
225
|
},
|
|
226
226
|
},
|
|
227
227
|
},
|
|
228
|
+
'resultsPageOptions.requestConfigs': {
|
|
229
|
+
description: `[Additional Quiz results API request parameters to further refine your results](https://constructor-io.github.io/constructorio-client-javascript/module-quizzes.html#~getQuizResults)`,
|
|
230
|
+
control: {
|
|
231
|
+
type: 'QuizzesResultsParameters',
|
|
232
|
+
},
|
|
233
|
+
table: {
|
|
234
|
+
subcategory: 'resultsPageOptions',
|
|
235
|
+
type: {
|
|
236
|
+
summary: 'QuizzesResultsParameters',
|
|
237
|
+
},
|
|
238
|
+
},
|
|
239
|
+
},
|
|
228
240
|
'sessionStateOptions.showSessionModal': {
|
|
229
241
|
description: 'Boolean for whether or not to show session modal to hydrate quiz on the results page',
|
|
230
242
|
control: {
|
package/lib/cjs/utils.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.formatMatchedOptions = exports.convertPrimaryColorsToString = exports.rgbToHsl = exports.sleep = exports.logger = exports.resetQuizSessionStorageState = exports.getStateFromSessionStorage = exports.isFunction = exports.getPreferredColorScheme = exports.getQuestionTypes = exports.stringify = exports.stringifyWithDefaults = exports.functionStrings = exports.renderImages = void 0;
|
|
3
|
+
exports.getNestedValueUsingDotNotation = exports.validateNumberOrString = exports.formatMatchedOptions = exports.convertPrimaryColorsToString = exports.rgbToHsl = exports.sleep = exports.logger = exports.resetQuizSessionStorageState = exports.getStateFromSessionStorage = exports.isFunction = exports.getPreferredColorScheme = exports.getQuestionTypes = exports.stringify = exports.stringifyWithDefaults = exports.functionStrings = exports.renderImages = void 0;
|
|
4
4
|
const tslib_1 = require("tslib");
|
|
5
5
|
/* eslint-disable no-console */
|
|
6
6
|
const react_1 = tslib_1.__importDefault(require("react"));
|
|
@@ -173,3 +173,20 @@ function formatMatchedOptions(options, separator, lastSeparator) {
|
|
|
173
173
|
return [firstPart, lastSeparator, options.at(-1)].join('');
|
|
174
174
|
}
|
|
175
175
|
exports.formatMatchedOptions = formatMatchedOptions;
|
|
176
|
+
const validateNumberOrString = (value) => {
|
|
177
|
+
if (typeof value === 'string') {
|
|
178
|
+
return value;
|
|
179
|
+
}
|
|
180
|
+
if (typeof value === 'number') {
|
|
181
|
+
return value;
|
|
182
|
+
}
|
|
183
|
+
return undefined;
|
|
184
|
+
};
|
|
185
|
+
exports.validateNumberOrString = validateNumberOrString;
|
|
186
|
+
function getNestedValueUsingDotNotation(object, key) {
|
|
187
|
+
if (!key || !object) {
|
|
188
|
+
return undefined;
|
|
189
|
+
}
|
|
190
|
+
return key.split('.').reduce((a, b) => a === null || a === void 0 ? void 0 : a[b], object);
|
|
191
|
+
}
|
|
192
|
+
exports.getNestedValueUsingDotNotation = getNestedValueUsingDotNotation;
|
package/lib/cjs/version.js
CHANGED
|
@@ -14,7 +14,7 @@ export default function CoverTypeQuestion() {
|
|
|
14
14
|
return (React.createElement("div", { className: `
|
|
15
15
|
cio-container${hasImage ? '--with-image' : ''}
|
|
16
16
|
cio-cover-question-container${hasImage ? '--with-image' : ''}
|
|
17
|
-
`, "data-question-key": question.key },
|
|
17
|
+
`, "data-cnstrc-question-type": question.type, "data-question-key": question.key },
|
|
18
18
|
hasImage ? renderImages(question.images, 'cio-question-image-container') : '',
|
|
19
19
|
React.createElement("div", { className: 'cio-question-content' },
|
|
20
20
|
React.createElement(QuestionTitle, { title: question?.title }),
|
|
@@ -14,7 +14,7 @@ function OpenTextQuestion() {
|
|
|
14
14
|
return (React.createElement("div", { className: `
|
|
15
15
|
cio-container${hasImage ? '--with-image' : ''}
|
|
16
16
|
cio-open-text-question-container${hasImage ? '--with-image' : ''}
|
|
17
|
-
`, "data-question-key": question.key },
|
|
17
|
+
`, "data-cnstrc-question-type": question.type, "data-question-key": question.key },
|
|
18
18
|
hasImage ? renderImages(question.images, 'cio-question-image-container') : '',
|
|
19
19
|
React.createElement("div", { className: 'cio-question-content' },
|
|
20
20
|
React.createElement(QuestionTitle, { title: question.title }),
|
|
@@ -2,13 +2,14 @@ import React, { useContext } from 'react';
|
|
|
2
2
|
import ResultCtaButton from '../ResultCtaButton/ResultCtaButton';
|
|
3
3
|
import ResultFavoritesButton from '../ResultFavoritesButton/ResultFavoritesButton';
|
|
4
4
|
import QuizContext from '../CioQuiz/context';
|
|
5
|
+
import { getNestedValueUsingDotNotation, validateNumberOrString } from '../../utils';
|
|
5
6
|
export default function ResultCard(props) {
|
|
6
7
|
const { result, salePriceKey, regularPriceKey, resultPosition, ratingCountKey, ratingScoreKey, renderResultCardPriceDetails, } = props;
|
|
7
8
|
const { customAddToFavoritesCallback, customClickItemCallback, getQuizResultButtonProps, getQuizResultLinkProps, } = useContext(QuizContext);
|
|
8
|
-
const salePrice =
|
|
9
|
-
const regularPrice =
|
|
10
|
-
const ratingCount =
|
|
11
|
-
const ratingScore =
|
|
9
|
+
const salePrice = validateNumberOrString(getNestedValueUsingDotNotation(result?.data, salePriceKey));
|
|
10
|
+
const regularPrice = validateNumberOrString(getNestedValueUsingDotNotation(result?.data, regularPriceKey));
|
|
11
|
+
const ratingCount = validateNumberOrString(getNestedValueUsingDotNotation(result?.data, ratingCountKey));
|
|
12
|
+
const ratingScore = validateNumberOrString(getNestedValueUsingDotNotation(result?.data, ratingScoreKey));
|
|
12
13
|
const resultCardContent = () => (React.createElement(React.Fragment, null,
|
|
13
14
|
React.createElement("div", { className: 'cio-result-card-image' },
|
|
14
15
|
React.createElement("img", { src: result.data?.image_url, alt: 'product' })),
|
|
@@ -16,18 +17,18 @@ export default function ResultCard(props) {
|
|
|
16
17
|
React.createElement("p", { className: 'cio-result-card-title' }, result.value),
|
|
17
18
|
React.createElement("div", { className: 'cio-result-card-details' },
|
|
18
19
|
React.createElement("div", { className: 'cio-result-card-rating' },
|
|
19
|
-
ratingScore && (React.createElement("span", { className: 'cio-result-card-rating-score' },
|
|
20
|
+
!!ratingScore && (React.createElement("span", { className: 'cio-result-card-rating-score' },
|
|
20
21
|
Array(Number(ratingScore)).fill('★'),
|
|
21
22
|
Array(5 - Number(ratingScore)).fill('☆'))),
|
|
22
|
-
ratingCount && React.createElement("span", { className: 'cio-result-card-rating-count' },
|
|
23
|
+
!!ratingCount && React.createElement("span", { className: 'cio-result-card-rating-count' },
|
|
23
24
|
"(",
|
|
24
25
|
ratingCount,
|
|
25
26
|
")")),
|
|
26
27
|
renderResultCardPriceDetails ? (renderResultCardPriceDetails(result)) : (React.createElement("div", { className: 'cio-result-card-prices' },
|
|
27
|
-
salePrice && React.createElement("span", { className: 'cio-result-card-sale-price' },
|
|
28
|
+
!!salePrice && React.createElement("span", { className: 'cio-result-card-sale-price' },
|
|
28
29
|
"$",
|
|
29
30
|
salePrice),
|
|
30
|
-
regularPrice && (React.createElement("span", { className: `cio-result-card-regular-price${salePrice ? '--strike-through' : ''}` },
|
|
31
|
+
!!regularPrice && (React.createElement("span", { className: `cio-result-card-regular-price${salePrice ? '--strike-through' : ''}` },
|
|
31
32
|
"$",
|
|
32
33
|
regularPrice))))))));
|
|
33
34
|
const resultCardContentWithoutLink = () => getQuizResultButtonProps && (React.createElement("div", { ...getQuizResultButtonProps({ result, position: resultPosition, type: 'button' }) }, resultCardContent()));
|
|
@@ -15,7 +15,7 @@ function SelectTypeQuestion() {
|
|
|
15
15
|
instructions = question?.type === QuestionTypes.MultipleSelect && 'Select one or more options';
|
|
16
16
|
}
|
|
17
17
|
if (question) {
|
|
18
|
-
return (React.createElement("div", { className: 'cio-select-question-container', "data-question-key": question.key },
|
|
18
|
+
return (React.createElement("div", { className: 'cio-select-question-container', "data-cnstrc-question-type": question.type, "data-question-key": question.key },
|
|
19
19
|
React.createElement("div", { className: 'cio-select-question-text' },
|
|
20
20
|
React.createElement(QuestionTitle, { title: question.title }),
|
|
21
21
|
question?.description ? React.createElement(QuestionDescription, { description: question.description }) : ''),
|
|
@@ -16,6 +16,7 @@ const useQuizApiState = (quizOptions, cioClient, quizLocalState, skipToResults,
|
|
|
16
16
|
resultsPerPage: resultsPageOptions?.numResultsToDisplay,
|
|
17
17
|
quizVersionId: quizLocalState.quizVersionId,
|
|
18
18
|
quizSessionId: quizLocalState.quizSessionId,
|
|
19
|
+
...resultsPageOptions?.requestConfigs,
|
|
19
20
|
});
|
|
20
21
|
// Set quiz results state
|
|
21
22
|
dispatchApiState({
|
|
@@ -109,7 +109,7 @@ export const argTypes = {
|
|
|
109
109
|
},
|
|
110
110
|
},
|
|
111
111
|
'resultCardOptions.resultCardRegularPriceKey': {
|
|
112
|
-
description: 'Key name for the regular price in the API response',
|
|
112
|
+
description: 'Key name for the regular price value in the API response inside the `data` object. Supports nested keys using dot notation e.g., "priceDetails.regular_price"',
|
|
113
113
|
control: {
|
|
114
114
|
type: 'text',
|
|
115
115
|
},
|
|
@@ -124,7 +124,7 @@ export const argTypes = {
|
|
|
124
124
|
},
|
|
125
125
|
},
|
|
126
126
|
'resultCardOptions.resultCardSalePriceKey': {
|
|
127
|
-
description: 'Key name for the sale price in the API response',
|
|
127
|
+
description: 'Key name for the sale price value in the API response inside the `data` object. Supports nested keys using dot notation e.g., "priceDetails.sale_price"',
|
|
128
128
|
control: {
|
|
129
129
|
type: 'text',
|
|
130
130
|
},
|
|
@@ -139,7 +139,7 @@ export const argTypes = {
|
|
|
139
139
|
},
|
|
140
140
|
},
|
|
141
141
|
'resultCardOptions.resultCardRatingCountKey': {
|
|
142
|
-
description: 'Key name for the rating count in the API response',
|
|
142
|
+
description: 'Key name for the rating count value in the API response inside the `data` object. Supports nested keys using dot notation e.g., "ratingDetails.rating_count"',
|
|
143
143
|
control: {
|
|
144
144
|
type: 'text',
|
|
145
145
|
},
|
|
@@ -154,7 +154,7 @@ export const argTypes = {
|
|
|
154
154
|
},
|
|
155
155
|
},
|
|
156
156
|
'resultCardOptions.resultCardRatingScoreKey': {
|
|
157
|
-
description: 'Key name for the rating score in the API response',
|
|
157
|
+
description: 'Key name for the rating score value in the API response inside the `data` object. Supports nested keys using dot notation e.g., "ratingDetails.rating_score"',
|
|
158
158
|
control: {
|
|
159
159
|
type: 'text',
|
|
160
160
|
},
|
|
@@ -213,7 +213,7 @@ export const argTypes = {
|
|
|
213
213
|
type: 'boolean',
|
|
214
214
|
},
|
|
215
215
|
table: {
|
|
216
|
-
subcategory: '
|
|
216
|
+
subcategory: 'resultsPageOptions',
|
|
217
217
|
defaultValue: {
|
|
218
218
|
summary: true,
|
|
219
219
|
},
|
|
@@ -222,6 +222,18 @@ export const argTypes = {
|
|
|
222
222
|
},
|
|
223
223
|
},
|
|
224
224
|
},
|
|
225
|
+
'resultsPageOptions.requestConfigs': {
|
|
226
|
+
description: `[Additional Quiz results API request parameters to further refine your results](https://constructor-io.github.io/constructorio-client-javascript/module-quizzes.html#~getQuizResults)`,
|
|
227
|
+
control: {
|
|
228
|
+
type: 'QuizzesResultsParameters',
|
|
229
|
+
},
|
|
230
|
+
table: {
|
|
231
|
+
subcategory: 'resultsPageOptions',
|
|
232
|
+
type: {
|
|
233
|
+
summary: 'QuizzesResultsParameters',
|
|
234
|
+
},
|
|
235
|
+
},
|
|
236
|
+
},
|
|
225
237
|
'sessionStateOptions.showSessionModal': {
|
|
226
238
|
description: 'Boolean for whether or not to show session modal to hydrate quiz on the results page',
|
|
227
239
|
control: {
|
package/lib/mjs/utils.js
CHANGED
|
@@ -152,3 +152,18 @@ export function formatMatchedOptions(options, separator, lastSeparator) {
|
|
|
152
152
|
const firstPart = options.slice(0, -1).join(separator);
|
|
153
153
|
return [firstPart, lastSeparator, options.at(-1)].join('');
|
|
154
154
|
}
|
|
155
|
+
export const validateNumberOrString = (value) => {
|
|
156
|
+
if (typeof value === 'string') {
|
|
157
|
+
return value;
|
|
158
|
+
}
|
|
159
|
+
if (typeof value === 'number') {
|
|
160
|
+
return value;
|
|
161
|
+
}
|
|
162
|
+
return undefined;
|
|
163
|
+
};
|
|
164
|
+
export function getNestedValueUsingDotNotation(object, key) {
|
|
165
|
+
if (!key || !object) {
|
|
166
|
+
return undefined;
|
|
167
|
+
}
|
|
168
|
+
return key.split('.').reduce((a, b) => a?.[b], object);
|
|
169
|
+
}
|
package/lib/mjs/version.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export default '1.
|
|
1
|
+
export default '1.14.0';
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
import { QuizResultDataPartial } from '../../types';
|
|
3
3
|
interface ResultCtaButtonProps {
|
|
4
4
|
item: QuizResultDataPartial;
|
|
5
|
-
price?: number;
|
|
5
|
+
price?: number | string;
|
|
6
6
|
}
|
|
7
7
|
export default function ResultCtaButton(props: ResultCtaButtonProps): JSX.Element | null;
|
|
8
8
|
export {};
|
|
@@ -7,4 +7,4 @@ export declare const getQuizResultsConfig: (cioClient: ConstructorIOClient, quiz
|
|
|
7
7
|
export declare const getBrowseResultsForItemIds: (cioClient: ConstructorIOClient, itemIds: string[]) => Promise<GetBrowseResultsForItemIdsResponse>;
|
|
8
8
|
export declare const trackQuizResultsLoaded: (cioClient: ConstructorIOClient, quizResults: QuizResultsResponse | QuizSharedResultsData) => void;
|
|
9
9
|
export declare const trackQuizResultClick: (cioClient: ConstructorIOClient, quizResults: QuizResultsResponse | QuizSharedResultsData, result: QuizResultDataPartial, position: number) => void;
|
|
10
|
-
export declare const trackQuizConversion: (cioClient: ConstructorIOClient, quizResults: QuizResultsResponse | QuizSharedResultsData, result: QuizResultDataPartial, price?: number, type?: string) => void;
|
|
10
|
+
export declare const trackQuizConversion: (cioClient: ConstructorIOClient, quizResults: QuizResultsResponse | QuizSharedResultsData, result: QuizResultDataPartial, price?: number | string, type?: string) => void;
|
|
@@ -221,6 +221,18 @@ export declare const argTypes: {
|
|
|
221
221
|
};
|
|
222
222
|
};
|
|
223
223
|
};
|
|
224
|
+
'resultsPageOptions.requestConfigs': {
|
|
225
|
+
description: string;
|
|
226
|
+
control: {
|
|
227
|
+
type: string;
|
|
228
|
+
};
|
|
229
|
+
table: {
|
|
230
|
+
subcategory: string;
|
|
231
|
+
type: {
|
|
232
|
+
summary: string;
|
|
233
|
+
};
|
|
234
|
+
};
|
|
235
|
+
};
|
|
224
236
|
'sessionStateOptions.showSessionModal': {
|
|
225
237
|
description: string;
|
|
226
238
|
control: {
|
package/lib/types/types.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { CSSProperties } from 'react';
|
|
2
|
-
import { QuizResultData, NextQuestionResponse, QuizResultsResponse, QuestionOption, Question, QuizResultsConfig } from '@constructor-io/constructorio-client-javascript/lib/types';
|
|
2
|
+
import { QuizResultData, NextQuestionResponse, QuizResultsResponse, QuestionOption, Question, QuizResultsConfig, QuizzesResultsParameters, QuizzesParameters } from '@constructor-io/constructorio-client-javascript/lib/types';
|
|
3
3
|
import ConstructorIOClient, { GetBrowseResultsForItemIdsResponse } from '@constructor-io/constructorio-client-javascript';
|
|
4
4
|
import { RequestStates } from './constants';
|
|
5
5
|
import { QuestionTypes } from './components/CioQuiz/actions';
|
|
@@ -25,10 +25,12 @@ export declare namespace QuizResultsEventsProps {
|
|
|
25
25
|
type OnQuizSkipQuestion = (question: QuestionWithAnswer) => void;
|
|
26
26
|
type OnEmailResults = (data: QuizEmailResults) => Promise<void>;
|
|
27
27
|
}
|
|
28
|
+
export type QuizResultsRequestConfigs = Omit<QuizzesResultsParameters, keyof QuizzesParameters | 'page' | 'resultsPerPage'>;
|
|
28
29
|
export interface ResultsPageOptions {
|
|
29
30
|
numResultsToDisplay?: number;
|
|
30
31
|
favoriteItems?: string[];
|
|
31
32
|
showShareResultsButton?: boolean;
|
|
33
|
+
requestConfigs?: QuizResultsRequestConfigs;
|
|
32
34
|
}
|
|
33
35
|
export interface QuestionsPageOptions {
|
|
34
36
|
skipQuestionButtonText?: string;
|
|
@@ -107,8 +109,8 @@ export declare namespace QuizEventsReturn {
|
|
|
107
109
|
type PreviousQuestion = () => void;
|
|
108
110
|
type ResetQuiz = () => void;
|
|
109
111
|
type ResultClick = (result: QuizResultDataPartial, position: number) => void;
|
|
110
|
-
type AddToCart = (e: React.MouseEvent<HTMLElement>, result: QuizResultDataPartial, price?: number) => void;
|
|
111
|
-
type AddToFavorites = (e: React.MouseEvent<HTMLElement>, result: QuizResultDataPartial, price?: number, sendEvent?: boolean) => void;
|
|
112
|
+
type AddToCart = (e: React.MouseEvent<HTMLElement>, result: QuizResultDataPartial, price?: number | string) => void;
|
|
113
|
+
type AddToFavorites = (e: React.MouseEvent<HTMLElement>, result: QuizResultDataPartial, price?: number | string, sendEvent?: boolean) => void;
|
|
112
114
|
type HydrateQuiz = () => void;
|
|
113
115
|
type ResetSessionStorageState = () => void;
|
|
114
116
|
}
|
|
@@ -212,8 +214,8 @@ export type GetPreviousQuestionButtonProps = () => PreviousQuestionButtonProps;
|
|
|
212
214
|
export type GetResetQuizButtonProps = (stylesType?: 'primary' | 'secondary') => ResetQuizButtonProps;
|
|
213
215
|
export type GetShareResultsButtonProps = () => ShareResultsButtonProps;
|
|
214
216
|
export type GetHydrateQuizButtonProps = () => HydrateQuizButtonProps;
|
|
215
|
-
export type GetAddToCartButtonProps = (result: QuizResultDataPartial, price?: number) => AddToCartButtonProps;
|
|
216
|
-
export type GetAddToFavoritesButtonProps = (result: QuizResultDataPartial, price?: number, clickHandler?: () => void) => AddToCartButtonProps;
|
|
217
|
+
export type GetAddToCartButtonProps = (result: QuizResultDataPartial, price?: number | string) => AddToCartButtonProps;
|
|
218
|
+
export type GetAddToFavoritesButtonProps = (result: QuizResultDataPartial, price?: number | string, clickHandler?: () => void) => AddToCartButtonProps;
|
|
217
219
|
export type GetQuizImageProps = () => QuizImageProps;
|
|
218
220
|
export type GetSelectQuestionImageProps = (option: QuestionOption) => QuizImageProps;
|
|
219
221
|
export interface QuizResultOptions<T = 'button' | 'link'> {
|
package/lib/types/utils.d.ts
CHANGED
|
@@ -37,3 +37,5 @@ export declare function sleep(ms: any): Promise<unknown>;
|
|
|
37
37
|
export declare function rgbToHsl(r: number, g: number, b: number): number[];
|
|
38
38
|
export declare function convertPrimaryColorsToString(primaryColorStyles: PrimaryColorStyles): string;
|
|
39
39
|
export declare function formatMatchedOptions(options: string[], separator?: string | null, lastSeparator?: string | null): string;
|
|
40
|
+
export declare const validateNumberOrString: (value: unknown) => string | number | undefined;
|
|
41
|
+
export declare function getNestedValueUsingDotNotation(object: any, key?: string): unknown | undefined;
|
package/lib/types/version.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
declare const _default: "1.
|
|
1
|
+
declare const _default: "1.14.0";
|
|
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.
|
|
3
|
+
"version": "1.14.0",
|
|
4
4
|
"description": "Constructor.io Quizzes UI library for web applications",
|
|
5
5
|
"author": "constructor.io",
|
|
6
6
|
"license": "MIT",
|
|
@@ -61,7 +61,7 @@
|
|
|
61
61
|
"check-license": "license-checker --production --onlyAllow 'Apache-2.0;BSD-3-Clause;MIT;0BSD;BSD-2-Clause' --excludePackages 'picocolors@1.0.0'"
|
|
62
62
|
},
|
|
63
63
|
"peerDependencies": {
|
|
64
|
-
"@constructor-io/constructorio-client-javascript": "^2.42.
|
|
64
|
+
"@constructor-io/constructorio-client-javascript": "^2.42.3",
|
|
65
65
|
"react": ">=16.12.0",
|
|
66
66
|
"react-dom": ">=16.12.0",
|
|
67
67
|
"tslib": "^2.4.0"
|