@constructor-io/constructorio-ui-quizzes 1.4.3 → 1.4.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.
- package/dist/constructorio-ui-quizzes-bundled.js +14 -14
- package/lib/cjs/components/CioQuiz/actions.js +1 -0
- package/lib/cjs/components/CioQuiz/index.js +7 -5
- package/lib/cjs/components/CioQuiz/quizLocalReducer.js +9 -6
- package/lib/cjs/components/ResultCard/ResultCard.js +21 -10
- package/lib/cjs/components/ResultContainer/ResultContainer.js +5 -3
- package/lib/cjs/components/Results/Results.js +2 -2
- package/lib/cjs/constants.js +7 -1
- package/lib/cjs/hooks/useQuiz.js +2 -2
- package/lib/cjs/hooks/useQuizEvents/index.js +1 -1
- package/lib/cjs/hooks/useQuizEvents/useQuizResetClick.js +3 -4
- package/lib/cjs/hooks/useQuizState/index.js +3 -2
- package/lib/cjs/hooks/useQuizState/useQuizApiState.js +8 -2
- package/lib/cjs/hooks/useQuizState/useQuizLocalState.js +6 -2
- package/lib/cjs/stories/Quiz/tests/mocks.js +10 -3
- package/lib/mjs/components/CioQuiz/actions.js +1 -0
- package/lib/mjs/components/CioQuiz/index.js +7 -5
- package/lib/mjs/components/CioQuiz/quizLocalReducer.js +12 -0
- package/lib/mjs/components/ResultCard/ResultCard.js +20 -9
- package/lib/mjs/components/ResultContainer/ResultContainer.js +5 -3
- package/lib/mjs/components/Results/Results.js +2 -2
- package/lib/mjs/constants.js +7 -1
- package/lib/mjs/hooks/useQuiz.js +2 -2
- package/lib/mjs/hooks/useQuizEvents/index.js +1 -1
- package/lib/mjs/hooks/useQuizEvents/useQuizResetClick.js +3 -4
- package/lib/mjs/hooks/useQuizState/index.js +3 -2
- package/lib/mjs/hooks/useQuizState/useQuizApiState.js +8 -2
- package/lib/mjs/hooks/useQuizState/useQuizLocalState.js +5 -2
- package/lib/mjs/stories/Quiz/tests/mocks.js +10 -3
- package/lib/styles.css +6 -0
- package/lib/types/components/CioQuiz/actions.d.ts +3 -2
- package/lib/types/components/CioQuiz/quizLocalReducer.d.ts +1 -0
- package/lib/types/components/ResultCard/ResultCard.d.ts +2 -0
- package/lib/types/components/ResultContainer/ResultContainer.d.ts +2 -2
- package/lib/types/components/Results/Results.d.ts +3 -1
- package/lib/types/constants.d.ts +1 -1
- package/lib/types/hooks/useQuizEvents/useQuizResetClick.d.ts +1 -1
- package/lib/types/hooks/useQuizState/index.d.ts +1 -0
- package/lib/types/hooks/useQuizState/useQuizApiState.d.ts +1 -1
- package/lib/types/hooks/useQuizState/useQuizLocalState.d.ts +3 -1
- package/lib/types/types.d.ts +6 -2
- package/package.json +1 -1
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import { useCallback } from 'react';
|
|
2
2
|
import { QuestionTypes, QuizAPIActionTypes, } from '../../components/CioQuiz/actions';
|
|
3
|
-
|
|
4
|
-
const useQuizResetClick = (quizStateKey, dispatchLocalState, dispatchApiState, quizResults) => {
|
|
3
|
+
const useQuizResetClick = (resetQuizSessionStorageState, dispatchLocalState, dispatchApiState, quizResults) => {
|
|
5
4
|
const quizResetClickHandler = useCallback(() => {
|
|
6
5
|
if (quizResults) {
|
|
7
6
|
dispatchLocalState({
|
|
@@ -10,9 +9,9 @@ const useQuizResetClick = (quizStateKey, dispatchLocalState, dispatchApiState, q
|
|
|
10
9
|
dispatchApiState({
|
|
11
10
|
type: QuizAPIActionTypes.RESET_QUIZ,
|
|
12
11
|
});
|
|
13
|
-
resetQuizSessionStorageState(
|
|
12
|
+
resetQuizSessionStorageState();
|
|
14
13
|
}
|
|
15
|
-
}, [dispatchLocalState, dispatchApiState,
|
|
14
|
+
}, [dispatchLocalState, dispatchApiState, resetQuizSessionStorageState, quizResults]);
|
|
16
15
|
return quizResetClickHandler;
|
|
17
16
|
};
|
|
18
17
|
export default useQuizResetClick;
|
|
@@ -3,15 +3,16 @@ import useQuizLocalState from './useQuizLocalState';
|
|
|
3
3
|
const useQuizState = (quizOptions, cioClient) => {
|
|
4
4
|
const { sessionStateOptions } = quizOptions;
|
|
5
5
|
// Quiz Local state
|
|
6
|
-
const { quizLocalState, dispatchLocalState, hasQuizStoredState, quizStateKey } = useQuizLocalState(sessionStateOptions
|
|
6
|
+
const { quizLocalState, dispatchLocalState, hasQuizStoredState, skipToResults, quizStateKey } = useQuizLocalState(sessionStateOptions);
|
|
7
7
|
// Quiz API state
|
|
8
|
-
const { quizApiState, dispatchApiState } = useQuizApiState(quizOptions, cioClient, quizLocalState, dispatchLocalState);
|
|
8
|
+
const { quizApiState, dispatchApiState } = useQuizApiState(quizOptions, cioClient, quizLocalState, skipToResults, dispatchLocalState);
|
|
9
9
|
return {
|
|
10
10
|
quizApiState,
|
|
11
11
|
quizLocalState,
|
|
12
12
|
dispatchApiState,
|
|
13
13
|
dispatchLocalState,
|
|
14
14
|
hasQuizStoredState,
|
|
15
|
+
skipToResults,
|
|
15
16
|
quizStateKey,
|
|
16
17
|
};
|
|
17
18
|
};
|
|
@@ -2,7 +2,9 @@ import { useEffect, useReducer } from 'react';
|
|
|
2
2
|
import { QuestionTypes, QuizAPIActionTypes, } from '../../components/CioQuiz/actions';
|
|
3
3
|
import apiReducer, { initialState, } from '../../components/CioQuiz/quizApiReducer';
|
|
4
4
|
import { getNextQuestion, getQuizResults } from '../../services';
|
|
5
|
-
const useQuizApiState = (quizOptions, cioClient, quizLocalState, dispatchLocalState
|
|
5
|
+
const useQuizApiState = (quizOptions, cioClient, quizLocalState, skipToResults, dispatchLocalState
|
|
6
|
+
// eslint-disable-next-line max-params
|
|
7
|
+
) => {
|
|
6
8
|
const [quizApiState, dispatchApiState] = useReducer(apiReducer, initialState);
|
|
7
9
|
const { quizId, quizVersionId: quizVersionIdProp, resultsPageOptions } = quizOptions;
|
|
8
10
|
useEffect(() => {
|
|
@@ -10,7 +12,7 @@ const useQuizApiState = (quizOptions, cioClient, quizLocalState, dispatchLocalSt
|
|
|
10
12
|
dispatchApiState({
|
|
11
13
|
type: QuizAPIActionTypes.SET_IS_LOADING,
|
|
12
14
|
});
|
|
13
|
-
if (quizLocalState.isLastAnswer) {
|
|
15
|
+
if (quizLocalState.isLastAnswer || skipToResults) {
|
|
14
16
|
try {
|
|
15
17
|
const quizResults = await getQuizResults(cioClient, quizId, {
|
|
16
18
|
answers: quizLocalState.answers,
|
|
@@ -25,6 +27,10 @@ const useQuizApiState = (quizOptions, cioClient, quizLocalState, dispatchLocalSt
|
|
|
25
27
|
quizResults,
|
|
26
28
|
},
|
|
27
29
|
});
|
|
30
|
+
if (!quizLocalState.isQuizCompleted)
|
|
31
|
+
dispatchLocalState({
|
|
32
|
+
type: QuestionTypes.Complete,
|
|
33
|
+
});
|
|
28
34
|
}
|
|
29
35
|
catch (error) {
|
|
30
36
|
dispatchApiState({
|
|
@@ -2,9 +2,9 @@ import { useCallback, useEffect, useReducer } from 'react';
|
|
|
2
2
|
import quizLocalReducer, { initialState } from '../../components/CioQuiz/quizLocalReducer';
|
|
3
3
|
import { quizSessionStateKey } from '../../constants';
|
|
4
4
|
import { getStateFromSessionStorage, logger } from '../../utils';
|
|
5
|
-
const useQuizLocalState = (
|
|
5
|
+
const useQuizLocalState = (sessionStateOptions) => {
|
|
6
6
|
const [quizLocalState, dispatch] = useReducer(quizLocalReducer, initialState);
|
|
7
|
-
const quizStateKey = sessionStateKey || quizSessionStateKey;
|
|
7
|
+
const quizStateKey = sessionStateOptions?.sessionStateKey || quizSessionStateKey;
|
|
8
8
|
useEffect(() => {
|
|
9
9
|
// don't save state if initial state
|
|
10
10
|
if (quizLocalState?.answers?.length) {
|
|
@@ -12,6 +12,8 @@ const useQuizLocalState = (sessionStateKey) => {
|
|
|
12
12
|
}
|
|
13
13
|
}, [quizLocalState, quizStateKey]);
|
|
14
14
|
const hasQuizStoredState = () => getStateFromSessionStorage(quizStateKey) !== null;
|
|
15
|
+
const skipToResults = !!getStateFromSessionStorage(quizStateKey)?.isQuizCompleted &&
|
|
16
|
+
!sessionStateOptions?.showSessionModalOnResults;
|
|
15
17
|
const dispatchLocalState = useCallback((action) => {
|
|
16
18
|
logger(action);
|
|
17
19
|
dispatch(action);
|
|
@@ -20,6 +22,7 @@ const useQuizLocalState = (sessionStateKey) => {
|
|
|
20
22
|
quizLocalState,
|
|
21
23
|
hasQuizStoredState,
|
|
22
24
|
dispatchLocalState,
|
|
25
|
+
skipToResults,
|
|
23
26
|
quizStateKey,
|
|
24
27
|
};
|
|
25
28
|
};
|
|
@@ -67,6 +67,7 @@ export const getMockState = (question) => ({
|
|
|
67
67
|
requestState: RequestStates.Success,
|
|
68
68
|
versionId: '',
|
|
69
69
|
sessionId: '',
|
|
70
|
+
skipToResults: false,
|
|
70
71
|
currentQuestion: {
|
|
71
72
|
next_question: question,
|
|
72
73
|
isFirstQuestion: false,
|
|
@@ -84,6 +85,8 @@ export const getMockState = (question) => ({
|
|
|
84
85
|
data: {
|
|
85
86
|
id: '0',
|
|
86
87
|
price: 100,
|
|
88
|
+
ratingCount: '12',
|
|
89
|
+
ratingScore: '4',
|
|
87
90
|
image_url: 'https://demo.constructor.io/sandbox_files/farmstandquizassets/HiThereNameInput.png',
|
|
88
91
|
},
|
|
89
92
|
},
|
|
@@ -93,6 +96,8 @@ export const getMockState = (question) => ({
|
|
|
93
96
|
id: '1',
|
|
94
97
|
price: 200,
|
|
95
98
|
salePrice: 150,
|
|
99
|
+
ratingCount: '6',
|
|
100
|
+
ratingScore: '3',
|
|
96
101
|
image_url: 'https://demo.constructor.io/sandbox_files/farmstandquizassets/HiThereNameInput.png',
|
|
97
102
|
},
|
|
98
103
|
},
|
|
@@ -102,6 +107,8 @@ export const getMockState = (question) => ({
|
|
|
102
107
|
id: '2',
|
|
103
108
|
price: 300,
|
|
104
109
|
salePrice: 250,
|
|
110
|
+
ratingCount: '2',
|
|
111
|
+
ratingScore: '5',
|
|
105
112
|
image_url: 'https://demo.constructor.io/sandbox_files/farmstandquizassets/HiThereNameInput.png',
|
|
106
113
|
},
|
|
107
114
|
},
|
|
@@ -118,11 +125,11 @@ export const getMockState = (question) => ({
|
|
|
118
125
|
quiz_session_id: '',
|
|
119
126
|
quiz_version_id: '',
|
|
120
127
|
quiz_selected_options: [
|
|
121
|
-
{ value: '
|
|
122
|
-
{ value: '
|
|
128
|
+
{ value: 'Chocolate', has_attribute: true },
|
|
129
|
+
{ value: 'Medium', has_attribute: true },
|
|
123
130
|
],
|
|
124
131
|
},
|
|
125
|
-
selectedOptionsWithAttributes: ['
|
|
132
|
+
selectedOptionsWithAttributes: ['Chocolate', 'Medium'],
|
|
126
133
|
},
|
|
127
134
|
});
|
|
128
135
|
const mockElementProps = {
|
package/lib/styles.css
CHANGED
|
@@ -504,6 +504,12 @@
|
|
|
504
504
|
.cio-result-card-regular-price--strike-through {
|
|
505
505
|
text-decoration: line-through;
|
|
506
506
|
}
|
|
507
|
+
.cio-result-card-rating {
|
|
508
|
+
margin-bottom: 10px;
|
|
509
|
+
}
|
|
510
|
+
.cio-result-card-rating-score {
|
|
511
|
+
margin-right: 5px;
|
|
512
|
+
}
|
|
507
513
|
|
|
508
514
|
/* Result CTA Button */
|
|
509
515
|
.cio-result-card-cta-button {
|
|
@@ -8,7 +8,8 @@ export declare enum QuestionTypes {
|
|
|
8
8
|
Next = "next",
|
|
9
9
|
Back = "back",
|
|
10
10
|
Reset = "reset",
|
|
11
|
-
Hydrate = "hydrate"
|
|
11
|
+
Hydrate = "hydrate",
|
|
12
|
+
Complete = "complete"
|
|
12
13
|
}
|
|
13
14
|
export interface QuestionAnswer<Value> {
|
|
14
15
|
questionId: number;
|
|
@@ -23,7 +24,7 @@ interface Action<Type, Payload = {}> {
|
|
|
23
24
|
payload?: Payload;
|
|
24
25
|
}
|
|
25
26
|
export type ActionAnswerInputQuestion = Action<QuestionTypes.OpenText, OpenTextQuestionPayload> | Action<QuestionTypes.SingleSelect, SelectQuestionPayload> | Action<QuestionTypes.MultipleSelect, SelectQuestionPayload> | Action<QuestionTypes.Cover, CoverQuestionPayload>;
|
|
26
|
-
export type ActionAnswerQuestion = ActionAnswerInputQuestion | Action<QuestionTypes.Next, CurrentQuestion> | Action<QuestionTypes.Back, CurrentQuestion> | Action<QuestionTypes.Reset> | Action<QuestionTypes.Hydrate, Partial<QuizLocalReducerState>>;
|
|
27
|
+
export type ActionAnswerQuestion = ActionAnswerInputQuestion | Action<QuestionTypes.Next, CurrentQuestion> | Action<QuestionTypes.Back, CurrentQuestion> | Action<QuestionTypes.Reset> | Action<QuestionTypes.Complete> | Action<QuestionTypes.Hydrate, Partial<QuizLocalReducerState>>;
|
|
27
28
|
export declare enum QuizAPIActionTypes {
|
|
28
29
|
SET_IS_LOADING = 0,
|
|
29
30
|
SET_IS_ERROR = 1,
|
|
@@ -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- `sessionStateOptions` lets you configure the session modal behavior\n - `showSessionModal` is a boolean used to decide whether to show the session modal. The default behavior is to show the session modal\n - `showSessionModalOnResults` is a boolean to decide whether to show the session modal after reaching the results page. The default behavior is to not show the session modal\n - `sessionStateKey` is a custom string that will be used as a session storage key\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)";
|
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
import { ActionAnswerQuestion, ActionQuizAPI } from '../../components/CioQuiz/actions';
|
|
2
2
|
import { QuizEventsReturn, QuizResultsResponse } from '../../types';
|
|
3
|
-
declare const useQuizResetClick: (
|
|
3
|
+
declare const useQuizResetClick: (resetQuizSessionStorageState: () => void, dispatchLocalState: React.Dispatch<ActionAnswerQuestion>, dispatchApiState: React.Dispatch<ActionQuizAPI>, quizResults?: QuizResultsResponse) => QuizEventsReturn.NextQuestion;
|
|
4
4
|
export default useQuizResetClick;
|
|
@@ -10,6 +10,7 @@ type UseQuizState = (quizOptions: IQuizProps, cioClient: ConstructorIOClient) =>
|
|
|
10
10
|
dispatchApiState: React.Dispatch<ActionQuizAPI>;
|
|
11
11
|
dispatchLocalState: React.Dispatch<ActionAnswerQuestion>;
|
|
12
12
|
hasQuizStoredState: () => boolean;
|
|
13
|
+
skipToResults: boolean;
|
|
13
14
|
quizStateKey: string;
|
|
14
15
|
};
|
|
15
16
|
declare const useQuizState: UseQuizState;
|
|
@@ -4,7 +4,7 @@ import { ActionAnswerQuestion, ActionQuizAPI } from '../../components/CioQuiz/ac
|
|
|
4
4
|
import { QuizAPIReducerState } from '../../components/CioQuiz/quizApiReducer';
|
|
5
5
|
import { QuizLocalReducerState } from '../../components/CioQuiz/quizLocalReducer';
|
|
6
6
|
import { IQuizProps } from '../../types';
|
|
7
|
-
type UseQuizApiState = (quizOptions: IQuizProps, cioClient: ConstructorIOClient, quizLocalState: QuizLocalReducerState, dispatchLocalState: React.Dispatch<ActionAnswerQuestion>) => {
|
|
7
|
+
type UseQuizApiState = (quizOptions: IQuizProps, cioClient: ConstructorIOClient, quizLocalState: QuizLocalReducerState, skipToResults: boolean, dispatchLocalState: React.Dispatch<ActionAnswerQuestion>) => {
|
|
8
8
|
quizApiState: QuizAPIReducerState;
|
|
9
9
|
dispatchApiState: React.Dispatch<ActionQuizAPI>;
|
|
10
10
|
};
|
|
@@ -1,8 +1,10 @@
|
|
|
1
1
|
import { ActionAnswerQuestion } from '../../components/CioQuiz/actions';
|
|
2
|
-
|
|
2
|
+
import { SessionStateOptions } from '../../types';
|
|
3
|
+
declare const useQuizLocalState: (sessionStateOptions?: SessionStateOptions) => {
|
|
3
4
|
quizLocalState: import("../../components/CioQuiz/quizLocalReducer").QuizLocalReducerState;
|
|
4
5
|
hasQuizStoredState: () => boolean;
|
|
5
6
|
dispatchLocalState: (action: ActionAnswerQuestion) => void;
|
|
7
|
+
skipToResults: boolean;
|
|
6
8
|
quizStateKey: string;
|
|
7
9
|
};
|
|
8
10
|
export default useQuizLocalState;
|
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;
|
|
@@ -22,6 +24,7 @@ export interface ResultsPageOptions extends ResultsProps {
|
|
|
22
24
|
}
|
|
23
25
|
export interface SessionStateOptions {
|
|
24
26
|
showSessionModal?: boolean;
|
|
27
|
+
showSessionModalOnResults?: boolean;
|
|
25
28
|
sessionStateKey?: string;
|
|
26
29
|
}
|
|
27
30
|
export interface IQuizProps {
|
|
@@ -44,6 +47,7 @@ export interface QuizReturnState {
|
|
|
44
47
|
sessionId?: string;
|
|
45
48
|
currentQuestion?: CurrentQuestion | undefined;
|
|
46
49
|
results?: QuizResultsResponse | undefined;
|
|
50
|
+
skipToResults: boolean;
|
|
47
51
|
selectedOptionsWithAttributes?: string[];
|
|
48
52
|
};
|
|
49
53
|
}
|