@constructor-io/constructorio-ui-quizzes 1.4.2 → 1.4.4
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 +14 -14
- package/lib/cjs/components/ResultCard/ResultCard.js +20 -9
- package/lib/cjs/components/ResultContainer/ResultContainer.js +4 -4
- package/lib/cjs/components/ResultFilters/ResultFilters.js +2 -2
- package/lib/cjs/components/Results/Results.js +2 -2
- package/lib/cjs/components/ZeroResults/ZeroResults.js +2 -3
- package/lib/cjs/constants.js +3 -1
- package/lib/cjs/hooks/useQuiz.js +0 -1
- package/lib/cjs/stories/Quiz/tests/mocks.js +9 -3
- package/lib/mjs/components/ResultCard/ResultCard.js +19 -8
- package/lib/mjs/components/ResultContainer/ResultContainer.js +4 -4
- package/lib/mjs/components/ResultFilters/ResultFilters.js +2 -2
- package/lib/mjs/components/Results/Results.js +2 -2
- package/lib/mjs/components/ZeroResults/ZeroResults.js +2 -3
- package/lib/mjs/constants.js +3 -1
- package/lib/mjs/hooks/useQuiz.js +0 -1
- package/lib/mjs/stories/Quiz/tests/mocks.js +9 -3
- package/lib/styles.css +7 -6
- package/lib/types/components/ResultCard/ResultCard.d.ts +2 -0
- package/lib/types/components/ResultContainer/ResultContainer.d.ts +2 -2
- package/lib/types/components/ResultFilters/ResultFilters.d.ts +4 -1
- package/lib/types/components/Results/Results.d.ts +3 -1
- package/lib/types/constants.d.ts +1 -1
- package/lib/types/types.d.ts +4 -2
- package/package.json +1 -1
|
@@ -5,11 +5,13 @@ const react_1 = tslib_1.__importStar(require("react"));
|
|
|
5
5
|
const ResultCtaButton_1 = tslib_1.__importDefault(require("../ResultCtaButton/ResultCtaButton"));
|
|
6
6
|
const context_1 = tslib_1.__importDefault(require("../CioQuiz/context"));
|
|
7
7
|
function ResultCard(props) {
|
|
8
|
-
var _a, _b;
|
|
9
|
-
const { result, salePriceKey, regularPriceKey, resultPosition } = props;
|
|
8
|
+
var _a, _b, _c, _d;
|
|
9
|
+
const { result, salePriceKey, regularPriceKey, resultPosition, ratingCountKey, ratingScoreKey } = props;
|
|
10
10
|
const { customClickItemCallback, getQuizResultButtonProps, getQuizResultLinkProps } = (0, react_1.useContext)(context_1.default);
|
|
11
11
|
const salePrice = salePriceKey && ((_a = result === null || result === void 0 ? void 0 : result.data) === null || _a === void 0 ? void 0 : _a[salePriceKey]);
|
|
12
12
|
const regularPrice = regularPriceKey && ((_b = result === null || result === void 0 ? void 0 : result.data) === null || _b === void 0 ? void 0 : _b[regularPriceKey]);
|
|
13
|
+
const ratingCount = ratingCountKey && ((_c = result === null || result === void 0 ? void 0 : result.data) === null || _c === void 0 ? void 0 : _c[ratingCountKey]);
|
|
14
|
+
const ratingScore = ratingScoreKey && ((_d = result === null || result === void 0 ? void 0 : result.data) === null || _d === void 0 ? void 0 : _d[ratingScoreKey]);
|
|
13
15
|
const resultCardContent = () => {
|
|
14
16
|
var _a;
|
|
15
17
|
return (react_1.default.createElement(react_1.default.Fragment, null,
|
|
@@ -17,13 +19,22 @@ function ResultCard(props) {
|
|
|
17
19
|
react_1.default.createElement("img", { src: (_a = result.data) === null || _a === void 0 ? void 0 : _a.image_url, alt: 'product' })),
|
|
18
20
|
react_1.default.createElement("div", { className: 'cio-result-card-text' },
|
|
19
21
|
react_1.default.createElement("p", { className: 'cio-result-card-title' }, result.value),
|
|
20
|
-
react_1.default.createElement("div", { className: 'cio-result-card-
|
|
21
|
-
|
|
22
|
-
"
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
"
|
|
26
|
-
|
|
22
|
+
react_1.default.createElement("div", { className: 'cio-result-card-details' },
|
|
23
|
+
react_1.default.createElement("div", { className: 'cio-result-card-rating' },
|
|
24
|
+
ratingScore && (react_1.default.createElement("span", { className: 'cio-result-card-rating-score' },
|
|
25
|
+
Array(Number(ratingScore)).fill('★'),
|
|
26
|
+
Array(5 - Number(ratingScore)).fill('☆'))),
|
|
27
|
+
ratingCount && react_1.default.createElement("span", { className: 'cio-result-card-rating-count' },
|
|
28
|
+
"(",
|
|
29
|
+
ratingCount,
|
|
30
|
+
")")),
|
|
31
|
+
react_1.default.createElement("div", { className: 'cio-result-card-prices' },
|
|
32
|
+
salePrice && react_1.default.createElement("span", { className: 'cio-result-card-sale-price' },
|
|
33
|
+
"$",
|
|
34
|
+
salePrice),
|
|
35
|
+
regularPrice && (react_1.default.createElement("span", { className: `cio-result-card-regular-price${salePrice ? '--strike-through' : ''}` },
|
|
36
|
+
"$",
|
|
37
|
+
regularPrice)))))));
|
|
27
38
|
};
|
|
28
39
|
const resultCardContentWithoutLink = () => getQuizResultButtonProps && (react_1.default.createElement("div", Object.assign({}, getQuizResultButtonProps({ result, position: resultPosition, type: 'button' })), resultCardContent()));
|
|
29
40
|
const resultCardContentWithLink = () => getQuizResultLinkProps && (react_1.default.createElement("a", Object.assign({ className: 'cio-result-card-anchor' }, getQuizResultLinkProps({ result, position: resultPosition, type: 'link' })), resultCardContent()));
|
|
@@ -10,17 +10,17 @@ const Results_1 = tslib_1.__importDefault(require("../Results/Results"));
|
|
|
10
10
|
function ResultContainer(props) {
|
|
11
11
|
var _a, _b, _c;
|
|
12
12
|
const { options } = props;
|
|
13
|
-
const { resultCardSalePriceKey, resultCardRegularPriceKey } = options;
|
|
13
|
+
const { resultCardSalePriceKey, resultCardRegularPriceKey, resultCardRatingCountKey, resultCardRatingScoreKey, } = options;
|
|
14
14
|
const { state } = (0, react_1.useContext)(context_1.default);
|
|
15
15
|
const zeroResults = !((_c = (_b = (_a = state === null || state === void 0 ? void 0 : state.quiz.results) === null || _a === void 0 ? void 0 : _a.response) === null || _b === void 0 ? void 0 : _b.results) === null || _c === void 0 ? void 0 : _c.length);
|
|
16
|
-
const resultsTitle = zeroResults ? '
|
|
16
|
+
const resultsTitle = zeroResults ? '' : 'Here are your results';
|
|
17
17
|
if (state === null || state === void 0 ? void 0 : state.quiz.results) {
|
|
18
18
|
return (react_1.default.createElement("div", { className: 'cio-results-container' },
|
|
19
19
|
react_1.default.createElement("h1", { className: 'cio-results-title' }, resultsTitle),
|
|
20
20
|
react_1.default.createElement("div", { className: 'cio-results-filter-and-redo-container' },
|
|
21
|
-
react_1.default.createElement(ResultFilters_1.default,
|
|
21
|
+
react_1.default.createElement(ResultFilters_1.default, { hasNoResults: zeroResults }),
|
|
22
22
|
react_1.default.createElement(RedoButton_1.default, null)),
|
|
23
|
-
!zeroResults && (react_1.default.createElement(Results_1.default, { resultCardSalePriceKey: resultCardSalePriceKey, resultCardRegularPriceKey: resultCardRegularPriceKey })),
|
|
23
|
+
!zeroResults && (react_1.default.createElement(Results_1.default, { resultCardSalePriceKey: resultCardSalePriceKey, resultCardRegularPriceKey: resultCardRegularPriceKey, resultCardRatingCountKey: resultCardRatingCountKey, resultCardRatingScoreKey: resultCardRatingScoreKey })),
|
|
24
24
|
zeroResults && react_1.default.createElement(ZeroResults_1.default, null)));
|
|
25
25
|
}
|
|
26
26
|
return react_1.default.createElement("div", null, "Loading");
|
|
@@ -3,11 +3,11 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
const tslib_1 = require("tslib");
|
|
4
4
|
const react_1 = tslib_1.__importStar(require("react"));
|
|
5
5
|
const context_1 = tslib_1.__importDefault(require("../CioQuiz/context"));
|
|
6
|
-
function ResultFilters() {
|
|
6
|
+
function ResultFilters({ hasNoResults }) {
|
|
7
7
|
var _a;
|
|
8
8
|
const { state } = (0, react_1.useContext)(context_1.default);
|
|
9
9
|
return (react_1.default.createElement("div", { className: 'cio-results-filter-container' },
|
|
10
|
-
react_1.default.createElement("p", null,
|
|
10
|
+
react_1.default.createElement("p", null, hasNoResults ? 'Your preferences' : 'Because you answered'),
|
|
11
11
|
react_1.default.createElement("div", { className: 'cio-results-filter-options' }, (_a = state === null || state === void 0 ? void 0 : state.quiz.selectedOptionsWithAttributes) === null || _a === void 0 ? void 0 : _a.map((option) => (react_1.default.createElement("div", { className: 'cio-results-filter-option', key: option }, option))))));
|
|
12
12
|
}
|
|
13
13
|
exports.default = ResultFilters;
|
|
@@ -6,11 +6,11 @@ const context_1 = tslib_1.__importDefault(require("../CioQuiz/context"));
|
|
|
6
6
|
const ResultCard_1 = tslib_1.__importDefault(require("../ResultCard/ResultCard"));
|
|
7
7
|
function Results(props) {
|
|
8
8
|
var _a, _b, _c, _d;
|
|
9
|
-
const { resultCardSalePriceKey, resultCardRegularPriceKey } = props;
|
|
9
|
+
const { resultCardSalePriceKey, resultCardRegularPriceKey, resultCardRatingCountKey, resultCardRatingScoreKey, } = props;
|
|
10
10
|
const { state } = (0, react_1.useContext)(context_1.default);
|
|
11
11
|
return (react_1.default.createElement("div", { className: 'cio-results' }, (_d = (_c = (_b = (_a = state === null || state === void 0 ? void 0 : state.quiz) === null || _a === void 0 ? void 0 : _a.results) === null || _b === void 0 ? void 0 : _b.response) === null || _c === void 0 ? void 0 : _c.results) === null || _d === void 0 ? void 0 : _d.map((result, index) => {
|
|
12
12
|
var _a;
|
|
13
|
-
return (react_1.default.createElement(ResultCard_1.default, { result: result, key: (_a = result.data) === null || _a === void 0 ? void 0 : _a.id, salePriceKey: resultCardSalePriceKey, regularPriceKey: resultCardRegularPriceKey, resultPosition: index + 1 }));
|
|
13
|
+
return (react_1.default.createElement(ResultCard_1.default, { result: result, key: (_a = result.data) === null || _a === void 0 ? void 0 : _a.id, salePriceKey: resultCardSalePriceKey, regularPriceKey: resultCardRegularPriceKey, ratingCountKey: resultCardRatingCountKey, ratingScoreKey: resultCardRatingScoreKey, resultPosition: index + 1 }));
|
|
14
14
|
})));
|
|
15
15
|
}
|
|
16
16
|
exports.default = Results;
|
|
@@ -7,8 +7,7 @@ const context_1 = tslib_1.__importDefault(require("../CioQuiz/context"));
|
|
|
7
7
|
function ZeroResults() {
|
|
8
8
|
const { getResetQuizButtonProps } = (0, react_1.useContext)(context_1.default);
|
|
9
9
|
return (react_1.default.createElement("div", { className: 'cio-zero-results' },
|
|
10
|
-
react_1.default.createElement("h3", { className: 'cio-zero-results-subtitle' }, "Sorry,
|
|
11
|
-
react_1.default.createElement(
|
|
12
|
-
react_1.default.createElement(CTAButton_1.default, { ctaText: 'Try Again', propsGetters: getResetQuizButtonProps })));
|
|
10
|
+
react_1.default.createElement("h3", { className: 'cio-zero-results-subtitle' }, "Sorry, we couldn\u2019t find products that perfectly match your preferences."),
|
|
11
|
+
react_1.default.createElement(CTAButton_1.default, { ctaText: 'Redo Quiz', propsGetters: getResetQuizButtonProps })));
|
|
13
12
|
}
|
|
14
13
|
exports.default = ZeroResults;
|
package/lib/cjs/constants.js
CHANGED
|
@@ -17,7 +17,9 @@ exports.componentDescription = `- import \`CioQuiz\` to render in your JSX.
|
|
|
17
17
|
- \`onQuizResultClick\` is an optional callback function that will be called when the result card is clicked. The default behavior is redirecting the user to the item's URL
|
|
18
18
|
- \`onQuizResultsLoaded\` is an optional callback function that will be called when the quiz results are loaded
|
|
19
19
|
- \`resultCardRegularPriceKey\` is a parameter that specifies the metadata field name for the regular price
|
|
20
|
-
- \`resultCardSalePriceKey\` is an optional parameter that specifies the metadata field name for the sale price
|
|
20
|
+
- \`resultCardSalePriceKey\` is an optional parameter that specifies the metadata field name for the sale price
|
|
21
|
+
- \`resultCardRatingCountKey\` is an optional parameter that specifies the metadata field name for the ratings count
|
|
22
|
+
- \`resultCardRatingScoreKey\` is an optional parameter that specifies the metadata field name for the ratings score
|
|
21
23
|
- Use different props to configure the behavior of this component.
|
|
22
24
|
- The following stories show how different props affect the component's behavior
|
|
23
25
|
|
package/lib/cjs/hooks/useQuiz.js
CHANGED
|
@@ -21,7 +21,6 @@ const useQuiz = (quizOptions) => {
|
|
|
21
21
|
const { quizApiState, quizLocalState } = quizState;
|
|
22
22
|
const propGetters = (0, usePropsGetters_1.default)(quizEvents, quizApiState, quizLocalState);
|
|
23
23
|
const primaryColorStyles = (0, usePrimaryColorStyles_1.default)(primaryColor);
|
|
24
|
-
console.log('quizLocalState.answerInputs', quizLocalState.answerInputs);
|
|
25
24
|
return Object.assign(Object.assign({ cioClient, state: {
|
|
26
25
|
answers: {
|
|
27
26
|
inputs: quizLocalState.answerInputs,
|
|
@@ -72,6 +72,8 @@ const getMockState = (question) => ({
|
|
|
72
72
|
data: {
|
|
73
73
|
id: '0',
|
|
74
74
|
price: 100,
|
|
75
|
+
ratingCount: '12',
|
|
76
|
+
ratingScore: '4',
|
|
75
77
|
image_url: 'https://demo.constructor.io/sandbox_files/farmstandquizassets/HiThereNameInput.png',
|
|
76
78
|
},
|
|
77
79
|
},
|
|
@@ -81,6 +83,8 @@ const getMockState = (question) => ({
|
|
|
81
83
|
id: '1',
|
|
82
84
|
price: 200,
|
|
83
85
|
salePrice: 150,
|
|
86
|
+
ratingCount: '6',
|
|
87
|
+
ratingScore: '3',
|
|
84
88
|
image_url: 'https://demo.constructor.io/sandbox_files/farmstandquizassets/HiThereNameInput.png',
|
|
85
89
|
},
|
|
86
90
|
},
|
|
@@ -90,6 +94,8 @@ const getMockState = (question) => ({
|
|
|
90
94
|
id: '2',
|
|
91
95
|
price: 300,
|
|
92
96
|
salePrice: 250,
|
|
97
|
+
ratingCount: '2',
|
|
98
|
+
ratingScore: '5',
|
|
93
99
|
image_url: 'https://demo.constructor.io/sandbox_files/farmstandquizassets/HiThereNameInput.png',
|
|
94
100
|
},
|
|
95
101
|
},
|
|
@@ -106,11 +112,11 @@ const getMockState = (question) => ({
|
|
|
106
112
|
quiz_session_id: '',
|
|
107
113
|
quiz_version_id: '',
|
|
108
114
|
quiz_selected_options: [
|
|
109
|
-
{ value: '
|
|
110
|
-
{ value: '
|
|
115
|
+
{ value: 'Chocolate', has_attribute: true },
|
|
116
|
+
{ value: 'Medium', has_attribute: true },
|
|
111
117
|
],
|
|
112
118
|
},
|
|
113
|
-
selectedOptionsWithAttributes: ['
|
|
119
|
+
selectedOptionsWithAttributes: ['Chocolate', 'Medium'],
|
|
114
120
|
},
|
|
115
121
|
});
|
|
116
122
|
exports.getMockState = getMockState;
|
|
@@ -2,22 +2,33 @@ import React, { useContext } from 'react';
|
|
|
2
2
|
import ResultCtaButton from '../ResultCtaButton/ResultCtaButton';
|
|
3
3
|
import QuizContext from '../CioQuiz/context';
|
|
4
4
|
export default function ResultCard(props) {
|
|
5
|
-
const { result, salePriceKey, regularPriceKey, resultPosition } = props;
|
|
5
|
+
const { result, salePriceKey, regularPriceKey, resultPosition, ratingCountKey, ratingScoreKey } = props;
|
|
6
6
|
const { customClickItemCallback, getQuizResultButtonProps, getQuizResultLinkProps } = useContext(QuizContext);
|
|
7
7
|
const salePrice = salePriceKey && result?.data?.[salePriceKey];
|
|
8
8
|
const regularPrice = regularPriceKey && result?.data?.[regularPriceKey];
|
|
9
|
+
const ratingCount = ratingCountKey && result?.data?.[ratingCountKey];
|
|
10
|
+
const ratingScore = ratingScoreKey && result?.data?.[ratingScoreKey];
|
|
9
11
|
const resultCardContent = () => (React.createElement(React.Fragment, null,
|
|
10
12
|
React.createElement("div", { className: 'cio-result-card-image' },
|
|
11
13
|
React.createElement("img", { src: result.data?.image_url, alt: 'product' })),
|
|
12
14
|
React.createElement("div", { className: 'cio-result-card-text' },
|
|
13
15
|
React.createElement("p", { className: 'cio-result-card-title' }, result.value),
|
|
14
|
-
React.createElement("div", { className: 'cio-result-card-
|
|
15
|
-
|
|
16
|
-
"
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
"
|
|
20
|
-
|
|
16
|
+
React.createElement("div", { className: 'cio-result-card-details' },
|
|
17
|
+
React.createElement("div", { className: 'cio-result-card-rating' },
|
|
18
|
+
ratingScore && (React.createElement("span", { className: 'cio-result-card-rating-score' },
|
|
19
|
+
Array(Number(ratingScore)).fill('★'),
|
|
20
|
+
Array(5 - Number(ratingScore)).fill('☆'))),
|
|
21
|
+
ratingCount && React.createElement("span", { className: 'cio-result-card-rating-count' },
|
|
22
|
+
"(",
|
|
23
|
+
ratingCount,
|
|
24
|
+
")")),
|
|
25
|
+
React.createElement("div", { className: 'cio-result-card-prices' },
|
|
26
|
+
salePrice && React.createElement("span", { className: 'cio-result-card-sale-price' },
|
|
27
|
+
"$",
|
|
28
|
+
salePrice),
|
|
29
|
+
regularPrice && (React.createElement("span", { className: `cio-result-card-regular-price${salePrice ? '--strike-through' : ''}` },
|
|
30
|
+
"$",
|
|
31
|
+
regularPrice)))))));
|
|
21
32
|
const resultCardContentWithoutLink = () => getQuizResultButtonProps && (React.createElement("div", { ...getQuizResultButtonProps({ result, position: resultPosition, type: 'button' }) }, resultCardContent()));
|
|
22
33
|
const resultCardContentWithLink = () => getQuizResultLinkProps && (React.createElement("a", { className: 'cio-result-card-anchor', ...getQuizResultLinkProps({ result, position: resultPosition, type: 'link' }) }, resultCardContent()));
|
|
23
34
|
return (React.createElement("div", { className: 'cio-result-card' },
|
|
@@ -6,17 +6,17 @@ import ZeroResults from '../ZeroResults/ZeroResults';
|
|
|
6
6
|
import Results from '../Results/Results';
|
|
7
7
|
export default function ResultContainer(props) {
|
|
8
8
|
const { options } = props;
|
|
9
|
-
const { resultCardSalePriceKey, resultCardRegularPriceKey } = options;
|
|
9
|
+
const { resultCardSalePriceKey, resultCardRegularPriceKey, resultCardRatingCountKey, resultCardRatingScoreKey, } = options;
|
|
10
10
|
const { state } = useContext(QuizContext);
|
|
11
11
|
const zeroResults = !state?.quiz.results?.response?.results?.length;
|
|
12
|
-
const resultsTitle = zeroResults ? '
|
|
12
|
+
const resultsTitle = zeroResults ? '' : 'Here are your results';
|
|
13
13
|
if (state?.quiz.results) {
|
|
14
14
|
return (React.createElement("div", { className: 'cio-results-container' },
|
|
15
15
|
React.createElement("h1", { className: 'cio-results-title' }, resultsTitle),
|
|
16
16
|
React.createElement("div", { className: 'cio-results-filter-and-redo-container' },
|
|
17
|
-
React.createElement(ResultFilters,
|
|
17
|
+
React.createElement(ResultFilters, { hasNoResults: zeroResults }),
|
|
18
18
|
React.createElement(RedoButton, null)),
|
|
19
|
-
!zeroResults && (React.createElement(Results, { resultCardSalePriceKey: resultCardSalePriceKey, resultCardRegularPriceKey: resultCardRegularPriceKey })),
|
|
19
|
+
!zeroResults && (React.createElement(Results, { resultCardSalePriceKey: resultCardSalePriceKey, resultCardRegularPriceKey: resultCardRegularPriceKey, resultCardRatingCountKey: resultCardRatingCountKey, resultCardRatingScoreKey: resultCardRatingScoreKey })),
|
|
20
20
|
zeroResults && React.createElement(ZeroResults, null)));
|
|
21
21
|
}
|
|
22
22
|
return React.createElement("div", null, "Loading");
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import React, { useContext } from 'react';
|
|
2
2
|
import QuizContext from '../CioQuiz/context';
|
|
3
|
-
function ResultFilters() {
|
|
3
|
+
function ResultFilters({ hasNoResults }) {
|
|
4
4
|
const { state } = useContext(QuizContext);
|
|
5
5
|
return (React.createElement("div", { className: 'cio-results-filter-container' },
|
|
6
|
-
React.createElement("p", null,
|
|
6
|
+
React.createElement("p", null, hasNoResults ? 'Your preferences' : 'Because you answered'),
|
|
7
7
|
React.createElement("div", { className: 'cio-results-filter-options' }, state?.quiz.selectedOptionsWithAttributes?.map((option) => (React.createElement("div", { className: 'cio-results-filter-option', key: option }, option))))));
|
|
8
8
|
}
|
|
9
9
|
export default ResultFilters;
|
|
@@ -2,8 +2,8 @@ import React, { useContext } from 'react';
|
|
|
2
2
|
import QuizContext from '../CioQuiz/context';
|
|
3
3
|
import ResultCard from '../ResultCard/ResultCard';
|
|
4
4
|
function Results(props) {
|
|
5
|
-
const { resultCardSalePriceKey, resultCardRegularPriceKey } = props;
|
|
5
|
+
const { resultCardSalePriceKey, resultCardRegularPriceKey, resultCardRatingCountKey, resultCardRatingScoreKey, } = props;
|
|
6
6
|
const { state } = useContext(QuizContext);
|
|
7
|
-
return (React.createElement("div", { className: 'cio-results' }, state?.quiz?.results?.response?.results?.map((result, index) => (React.createElement(ResultCard, { result: result, key: result.data?.id, salePriceKey: resultCardSalePriceKey, regularPriceKey: resultCardRegularPriceKey, resultPosition: index + 1 })))));
|
|
7
|
+
return (React.createElement("div", { className: 'cio-results' }, state?.quiz?.results?.response?.results?.map((result, index) => (React.createElement(ResultCard, { result: result, key: result.data?.id, salePriceKey: resultCardSalePriceKey, regularPriceKey: resultCardRegularPriceKey, ratingCountKey: resultCardRatingCountKey, ratingScoreKey: resultCardRatingScoreKey, resultPosition: index + 1 })))));
|
|
8
8
|
}
|
|
9
9
|
export default Results;
|
|
@@ -4,8 +4,7 @@ import QuizContext from '../CioQuiz/context';
|
|
|
4
4
|
function ZeroResults() {
|
|
5
5
|
const { getResetQuizButtonProps } = useContext(QuizContext);
|
|
6
6
|
return (React.createElement("div", { className: 'cio-zero-results' },
|
|
7
|
-
React.createElement("h3", { className: 'cio-zero-results-subtitle' }, "Sorry,
|
|
8
|
-
React.createElement(
|
|
9
|
-
React.createElement(CTAButton, { ctaText: 'Try Again', propsGetters: getResetQuizButtonProps })));
|
|
7
|
+
React.createElement("h3", { className: 'cio-zero-results-subtitle' }, "Sorry, we couldn\u2019t find products that perfectly match your preferences."),
|
|
8
|
+
React.createElement(CTAButton, { ctaText: 'Redo Quiz', propsGetters: getResetQuizButtonProps })));
|
|
10
9
|
}
|
|
11
10
|
export default ZeroResults;
|
package/lib/mjs/constants.js
CHANGED
|
@@ -14,7 +14,9 @@ export const componentDescription = `- import \`CioQuiz\` to render in your JSX.
|
|
|
14
14
|
- \`onQuizResultClick\` is an optional callback function that will be called when the result card is clicked. The default behavior is redirecting the user to the item's URL
|
|
15
15
|
- \`onQuizResultsLoaded\` is an optional callback function that will be called when the quiz results are loaded
|
|
16
16
|
- \`resultCardRegularPriceKey\` is a parameter that specifies the metadata field name for the regular price
|
|
17
|
-
- \`resultCardSalePriceKey\` is an optional parameter that specifies the metadata field name for the sale price
|
|
17
|
+
- \`resultCardSalePriceKey\` is an optional parameter that specifies the metadata field name for the sale price
|
|
18
|
+
- \`resultCardRatingCountKey\` is an optional parameter that specifies the metadata field name for the ratings count
|
|
19
|
+
- \`resultCardRatingScoreKey\` is an optional parameter that specifies the metadata field name for the ratings score
|
|
18
20
|
- Use different props to configure the behavior of this component.
|
|
19
21
|
- The following stories show how different props affect the component's behavior
|
|
20
22
|
|
package/lib/mjs/hooks/useQuiz.js
CHANGED
|
@@ -18,7 +18,6 @@ const useQuiz = (quizOptions) => {
|
|
|
18
18
|
const { quizApiState, quizLocalState } = quizState;
|
|
19
19
|
const propGetters = usePropsGetters(quizEvents, quizApiState, quizLocalState);
|
|
20
20
|
const primaryColorStyles = usePrimaryColorStyles(primaryColor);
|
|
21
|
-
console.log('quizLocalState.answerInputs', quizLocalState.answerInputs);
|
|
22
21
|
return {
|
|
23
22
|
cioClient,
|
|
24
23
|
state: {
|
|
@@ -84,6 +84,8 @@ export const getMockState = (question) => ({
|
|
|
84
84
|
data: {
|
|
85
85
|
id: '0',
|
|
86
86
|
price: 100,
|
|
87
|
+
ratingCount: '12',
|
|
88
|
+
ratingScore: '4',
|
|
87
89
|
image_url: 'https://demo.constructor.io/sandbox_files/farmstandquizassets/HiThereNameInput.png',
|
|
88
90
|
},
|
|
89
91
|
},
|
|
@@ -93,6 +95,8 @@ export const getMockState = (question) => ({
|
|
|
93
95
|
id: '1',
|
|
94
96
|
price: 200,
|
|
95
97
|
salePrice: 150,
|
|
98
|
+
ratingCount: '6',
|
|
99
|
+
ratingScore: '3',
|
|
96
100
|
image_url: 'https://demo.constructor.io/sandbox_files/farmstandquizassets/HiThereNameInput.png',
|
|
97
101
|
},
|
|
98
102
|
},
|
|
@@ -102,6 +106,8 @@ export const getMockState = (question) => ({
|
|
|
102
106
|
id: '2',
|
|
103
107
|
price: 300,
|
|
104
108
|
salePrice: 250,
|
|
109
|
+
ratingCount: '2',
|
|
110
|
+
ratingScore: '5',
|
|
105
111
|
image_url: 'https://demo.constructor.io/sandbox_files/farmstandquizassets/HiThereNameInput.png',
|
|
106
112
|
},
|
|
107
113
|
},
|
|
@@ -118,11 +124,11 @@ export const getMockState = (question) => ({
|
|
|
118
124
|
quiz_session_id: '',
|
|
119
125
|
quiz_version_id: '',
|
|
120
126
|
quiz_selected_options: [
|
|
121
|
-
{ value: '
|
|
122
|
-
{ value: '
|
|
127
|
+
{ value: 'Chocolate', has_attribute: true },
|
|
128
|
+
{ value: 'Medium', has_attribute: true },
|
|
123
129
|
],
|
|
124
130
|
},
|
|
125
|
-
selectedOptionsWithAttributes: ['
|
|
131
|
+
selectedOptionsWithAttributes: ['Chocolate', 'Medium'],
|
|
126
132
|
},
|
|
127
133
|
});
|
|
128
134
|
const mockElementProps = {
|
package/lib/styles.css
CHANGED
|
@@ -432,15 +432,10 @@
|
|
|
432
432
|
font-weight: 500;
|
|
433
433
|
font-size: 1.25rem;
|
|
434
434
|
line-height: 1.5rem;
|
|
435
|
+
margin-bottom: 2rem;
|
|
435
436
|
color: var(--gray-dust-500);
|
|
436
437
|
margin-top: 0;
|
|
437
438
|
}
|
|
438
|
-
.cio-zero-results-description {
|
|
439
|
-
color: var(--gray-dust-100);
|
|
440
|
-
line-height: 1.25rem;
|
|
441
|
-
margin-top: 0;
|
|
442
|
-
}
|
|
443
|
-
|
|
444
439
|
.cio-zero-results .cio-button-container {
|
|
445
440
|
width: 14rem;
|
|
446
441
|
margin-right: auto;
|
|
@@ -509,6 +504,12 @@
|
|
|
509
504
|
.cio-result-card-regular-price--strike-through {
|
|
510
505
|
text-decoration: line-through;
|
|
511
506
|
}
|
|
507
|
+
.cio-result-card-rating {
|
|
508
|
+
margin-bottom: 10px;
|
|
509
|
+
}
|
|
510
|
+
.cio-result-card-rating-score {
|
|
511
|
+
margin-right: 5px;
|
|
512
|
+
}
|
|
512
513
|
|
|
513
514
|
/* Result CTA Button */
|
|
514
515
|
.cio-result-card-cta-button {
|
|
@@ -4,6 +4,8 @@ interface ResultCardProps {
|
|
|
4
4
|
result: QuizResultDataPartial;
|
|
5
5
|
salePriceKey?: string;
|
|
6
6
|
regularPriceKey?: string;
|
|
7
|
+
ratingCountKey?: string;
|
|
8
|
+
ratingScoreKey?: string;
|
|
7
9
|
resultPosition: number;
|
|
8
10
|
}
|
|
9
11
|
export default function ResultCard(props: ResultCardProps): JSX.Element;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
/// <reference types="react" />
|
|
2
|
-
import {
|
|
2
|
+
import { ResultCardProps } from '../../types';
|
|
3
3
|
export interface IResultContainerProps {
|
|
4
|
-
options:
|
|
4
|
+
options: ResultCardProps;
|
|
5
5
|
}
|
|
6
6
|
export default function ResultContainer(props: IResultContainerProps): JSX.Element;
|
|
@@ -1,4 +1,6 @@
|
|
|
1
1
|
/// <reference types="react" />
|
|
2
|
-
import {
|
|
2
|
+
import { ResultCardProps } from '../../types';
|
|
3
|
+
interface ResultsProps extends ResultCardProps {
|
|
4
|
+
}
|
|
3
5
|
declare function Results(props: ResultsProps): JSX.Element;
|
|
4
6
|
export default Results;
|
package/lib/types/constants.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
export declare const apiKey = "key_wJSdZSiesX5hiVLt";
|
|
2
2
|
export declare const quizId = "coffee-quiz";
|
|
3
3
|
export declare const quizSessionStateKey = "constructorIOQuizState";
|
|
4
|
-
export declare const componentDescription = "- import `CioQuiz` to render in your JSX.\n- This component handles state management, data fetching, and rendering logic.\n- To use this component, `quizId`, `resultsPageOptions`, and one of `apiKey` or `cioJsClient` are required.\n- `resultsPageOptions` lets you configure the results page\n - `onAddToCartClick` is a callback function that will be called when the \"Add to cart\" button is clicked\n - `onQuizResultClick` is an optional callback function that will be called when the result card is clicked. The default behavior is redirecting the user to the item's URL\n - `onQuizResultsLoaded` is an optional callback function that will be called when the quiz results are loaded\n - `resultCardRegularPriceKey` is a parameter that specifies the metadata field name for the regular price\n - `resultCardSalePriceKey` is an optional parameter that specifies the metadata field name for the sale price\n- Use different props to configure the behavior of this component.\n- The following stories show how different props affect the component's behavior\n\n> Note: `cioJsClient` refers to an instance of the [constructorio-client-javascript](https://www.npmjs.com/package/@constructor-io/constructorio-client-javascript)\n";
|
|
4
|
+
export declare const componentDescription = "- import `CioQuiz` to render in your JSX.\n- This component handles state management, data fetching, and rendering logic.\n- To use this component, `quizId`, `resultsPageOptions`, and one of `apiKey` or `cioJsClient` are required.\n- `resultsPageOptions` lets you configure the results page\n - `onAddToCartClick` is a callback function that will be called when the \"Add to cart\" button is clicked\n - `onQuizResultClick` is an optional callback function that will be called when the result card is clicked. The default behavior is redirecting the user to the item's URL\n - `onQuizResultsLoaded` is an optional callback function that will be called when the quiz results are loaded\n - `resultCardRegularPriceKey` is a parameter that specifies the metadata field name for the regular price\n - `resultCardSalePriceKey` is an optional parameter that specifies the metadata field name for the sale price \n - `resultCardRatingCountKey` is an optional parameter that specifies the metadata field name for the ratings count \n - `resultCardRatingScoreKey` is an optional parameter that specifies the metadata field name for the ratings score \n- Use different props to configure the behavior of this component.\n- The following stories show how different props affect the component's behavior\n\n> Note: `cioJsClient` refers to an instance of the [constructorio-client-javascript](https://www.npmjs.com/package/@constructor-io/constructorio-client-javascript)\n";
|
|
5
5
|
export declare const hookDescription = "- import `useCioQuiz` and call this custom hook in a functional component.\n- This hook leaves rendering logic up to you, while handling:\n - state management\n - data fetching\n - keyboard navigation\n - mouse interactions\n - focus and submit event handling\n- Since the markup is controlled by you, the default styles might not be applied if you have a different DOM structure\n- To use this hook, an `apiKey` and `quizId` are required, and `resultsPageOptions` must be passed to the `useCioQuiz` hook to configure behavior. All other values are optional.\n- use the <a href=\"https://kentcdodds.com/blog/how-to-give-rendering-control-to-users-with-prop-getters\" target=\"__blank\">prop getters</a> and other variables returned by this hook (below) to leverage the functionality described above with jsx elements in your react component definitions\n\nCalling the `useCioQuiz` hook returns an object with the following keys:\n\n```jsx\nconst {\n // must be used for a hooks integrations\n state: QuizReturnState, // Quiz state\n events: [{...}], // array of quiz events\n getAddToCartButtonProps: () => ({...})), // prop getter for jsx add to cart button for quiz result,\n getCoverQuestionProps: () => ({...})), // prop getter for jsx quiz cover question,\n getHydrateQuizButtonProps: () => ({...})), // prop getter for jsx hydrate quiz button,\n getNextQuestionButtonProps: () => ({...})), // prop getter for jsx next button to traverse the quiz,\n getPreviousQuestionButtonProps: () => ({...})), // prop getter for jsx back button to traverse the quiz, \n getOpenTextInputProps: () => ({...})), // prop getter for jsx open text input,\n getSelectInputProps: () => ({...})), // prop getter for jsx select input for select type questions,\n getQuizImageProps: () => ({...})), // prop getter for jsx quiz image,\n getQuizResultButtonProps: () => ({...})), // prop getter for jsx result card click as a button,\n getQuizResultLinkProps: () => ({...})), // prop getter for jsx result card click as a link. Should be spread into <a> tags,\n getResetQuizButtonProps: () => ({...})), // prop getter for jsx reset quiz button,\n cioClient, // instance of constructorio-client-javascript\n } = useCioQuiz(args);\n```\n\n> Note: when we say `cioClient`, we are referring to an instance of the [constructorio-client-javascript](https://www.npmjs.com/package/@constructor-io/constructorio-client-javascript)\n";
|
|
6
6
|
export declare const basicDescription = "Pass an `apiKey` and a `quizId` to request questions and quiz results from Constructor's servers";
|
|
7
7
|
export declare const cioJsClientDescription = "If you are already using an instance of the `ConstructorIOClient`, you can pass a `cioJsClient` instead of an `apiKey` to request results from Constructor's servers\n\n> Note: `cioJsClient` refers to an instance of the [constructorio-client-javascript](https://www.npmjs.com/package/@constructor-io/constructorio-client-javascript)";
|
package/lib/types/types.d.ts
CHANGED
|
@@ -5,16 +5,18 @@ import { RequestStates } from './constants';
|
|
|
5
5
|
import { QuestionTypes } from './components/CioQuiz/actions';
|
|
6
6
|
export type { QuestionOption, QuestionImages, Question, NextQuestionResponse, QuizResultsResponse, BrowseResultData, BrowseRequestType, QuizzesParameters, QuizzesResultsParameters, } from '@constructor-io/constructorio-client-javascript/lib/types';
|
|
7
7
|
export type QuizResultDataPartial = Partial<QuizResultData>;
|
|
8
|
-
export interface
|
|
8
|
+
export interface ResultCardProps {
|
|
9
9
|
resultCardSalePriceKey?: string;
|
|
10
10
|
resultCardRegularPriceKey?: string;
|
|
11
|
+
resultCardRatingCountKey?: string;
|
|
12
|
+
resultCardRatingScoreKey?: string;
|
|
11
13
|
}
|
|
12
14
|
export declare namespace QuizResultsEventsProps {
|
|
13
15
|
type OnQuizResultsLoaded = (results: QuizResultDataPartial) => void;
|
|
14
16
|
type OnQuizResultClick = (result: QuizResultDataPartial, position: number) => void;
|
|
15
17
|
type OnAddToCartClick = (result: QuizResultDataPartial) => void;
|
|
16
18
|
}
|
|
17
|
-
export interface ResultsPageOptions extends
|
|
19
|
+
export interface ResultsPageOptions extends ResultCardProps {
|
|
18
20
|
numResultsToDisplay?: number;
|
|
19
21
|
onQuizResultsLoaded?: QuizResultsEventsProps.OnQuizResultsLoaded;
|
|
20
22
|
onQuizResultClick?: QuizResultsEventsProps.OnQuizResultClick;
|