@constructor-io/constructorio-ui-quizzes 1.2.3 → 1.3.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/README.md +1 -1
- package/dist/constructorio-ui-quizzes-bundled.js +17 -17
- package/lib/cjs/components/CioQuiz/actions.js +11 -1
- package/lib/cjs/components/CioQuiz/index.js +15 -103
- package/lib/cjs/components/CioQuiz/quizApiReducer.js +32 -0
- package/lib/cjs/components/CioQuiz/{reducer.js → quizLocalReducer.js} +2 -2
- package/lib/cjs/components/CoverTypeQuestion/CoverTypeQuestion.js +6 -12
- package/lib/cjs/components/OpenTextTypeQuestion/OpenTextTypeQuestion.js +12 -18
- package/lib/cjs/components/QuizQuestions/index.js +6 -3
- package/lib/cjs/components/ResultCard/ResultCard.js +10 -30
- package/lib/cjs/components/ResultContainer/ResultContainer.js +8 -31
- package/lib/cjs/components/ResultCtaButton/ResultCtaButton.js +7 -26
- package/lib/cjs/components/ResultFilters/ResultFilters.js +6 -23
- package/lib/cjs/components/Results/Results.js +5 -5
- package/lib/cjs/components/SelectTypeQuestion/SelectTypeQuestion.js +16 -23
- package/lib/cjs/components/ZeroResults/ZeroResults.js +2 -2
- package/lib/cjs/constants.js +3 -2
- package/lib/cjs/hooks/useCioClient.js +4 -3
- package/lib/cjs/hooks/useConsoleErrors.js +20 -0
- package/lib/cjs/hooks/useQuiz.js +48 -0
- package/lib/cjs/hooks/useQuizApiState.js +91 -0
- package/lib/cjs/hooks/useQuizEvents/index.js +36 -0
- package/lib/cjs/hooks/useQuizEvents/useQuizAddToCart.js +20 -0
- package/lib/cjs/hooks/useQuizEvents/useQuizBackClick.js +13 -0
- package/lib/cjs/hooks/useQuizEvents/useQuizNextClick.js +48 -0
- package/lib/cjs/hooks/useQuizEvents/useQuizResultClick.js +19 -0
- package/lib/cjs/hooks/useQuizEvents/useQuizResultsLoaded.js +22 -0
- package/lib/cjs/hooks/useQuizLocalState.js +20 -0
- package/lib/cjs/services/index.js +72 -0
- package/lib/cjs/utils.js +42 -21
- package/lib/mjs/components/CioQuiz/actions.js +10 -0
- package/lib/mjs/components/CioQuiz/index.js +15 -103
- package/lib/mjs/components/CioQuiz/quizApiReducer.js +49 -0
- package/lib/mjs/components/CioQuiz/{reducer.js → quizLocalReducer.js} +1 -1
- package/lib/mjs/components/CoverTypeQuestion/CoverTypeQuestion.js +6 -12
- package/lib/mjs/components/OpenTextTypeQuestion/OpenTextTypeQuestion.js +11 -17
- package/lib/mjs/components/QuizQuestions/index.js +5 -3
- package/lib/mjs/components/ResultCard/ResultCard.js +10 -29
- package/lib/mjs/components/ResultContainer/ResultContainer.js +8 -31
- package/lib/mjs/components/ResultCtaButton/ResultCtaButton.js +7 -25
- package/lib/mjs/components/ResultFilters/ResultFilters.js +5 -23
- package/lib/mjs/components/Results/Results.js +3 -3
- package/lib/mjs/components/SelectTypeQuestion/SelectTypeQuestion.js +13 -20
- package/lib/mjs/components/ZeroResults/ZeroResults.js +2 -2
- package/lib/mjs/constants.js +3 -2
- package/lib/mjs/hooks/useCioClient.js +4 -3
- package/lib/mjs/hooks/useConsoleErrors.js +18 -0
- package/lib/mjs/hooks/useQuiz.js +47 -0
- package/lib/mjs/hooks/useQuizApiState.js +87 -0
- package/lib/mjs/hooks/useQuizEvents/index.js +33 -0
- package/lib/mjs/hooks/useQuizEvents/useQuizAddToCart.js +18 -0
- package/lib/mjs/hooks/useQuizEvents/useQuizBackClick.js +11 -0
- package/lib/mjs/hooks/useQuizEvents/useQuizNextClick.js +45 -0
- package/lib/mjs/hooks/useQuizEvents/useQuizResultClick.js +17 -0
- package/lib/mjs/hooks/useQuizEvents/useQuizResultsLoaded.js +19 -0
- package/lib/mjs/hooks/useQuizLocalState.js +17 -0
- package/lib/mjs/services/index.js +60 -0
- package/lib/mjs/utils.js +39 -17
- package/lib/types/components/CioQuiz/actions.d.ts +20 -0
- package/lib/types/components/CioQuiz/context.d.ts +10 -14
- package/lib/types/components/CioQuiz/index.d.ts +1 -12
- package/lib/types/components/CioQuiz/quizApiReducer.d.ts +14 -0
- package/lib/types/components/CioQuiz/{reducer.d.ts → quizLocalReducer.d.ts} +3 -3
- package/lib/types/components/QuizQuestions/index.d.ts +1 -4
- package/lib/types/components/ResultCard/ResultCard.d.ts +2 -4
- package/lib/types/components/ResultContainer/ResultContainer.d.ts +1 -2
- package/lib/types/components/ResultCtaButton/ResultCtaButton.d.ts +2 -3
- package/lib/types/components/ResultFilters/ResultFilters.d.ts +2 -5
- package/lib/types/components/Results/Results.d.ts +1 -7
- package/lib/types/components/ZeroResults/ZeroResults.d.ts +1 -1
- package/lib/types/constants.d.ts +1 -1
- package/lib/types/hooks/useCioClient.d.ts +1 -1
- package/lib/types/hooks/useConsoleErrors.d.ts +3 -0
- package/lib/types/hooks/useQuiz.d.ts +3 -0
- package/lib/types/hooks/useQuizApiState.d.ts +10 -0
- package/lib/types/hooks/useQuizEvents/index.d.ts +15 -0
- package/lib/types/hooks/useQuizEvents/useQuizAddToCart.d.ts +5 -0
- package/lib/types/hooks/useQuizEvents/useQuizBackClick.d.ts +4 -0
- package/lib/types/hooks/useQuizEvents/useQuizNextClick.d.ts +5 -0
- package/lib/types/hooks/useQuizEvents/useQuizResultClick.d.ts +5 -0
- package/lib/types/hooks/useQuizEvents/useQuizResultsLoaded.d.ts +5 -0
- package/lib/types/hooks/useQuizLocalState.d.ts +6 -0
- package/lib/types/services/index.d.ts +8 -0
- package/lib/types/types.d.ts +63 -0
- package/lib/types/utils.d.ts +12 -7
- package/package.json +1 -1
package/lib/types/constants.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
export declare const apiKey = "key_wJSdZSiesX5hiVLt";
|
|
2
2
|
export declare const quizId = "coffee-quiz";
|
|
3
|
-
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 - `
|
|
3
|
+
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
4
|
export declare const basicDescription = "Pass an `apiKey` and a `quizId` to request questions and quiz results from Constructor's servers";
|
|
5
5
|
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)";
|
|
6
6
|
export declare enum RequestStates {
|
|
@@ -3,6 +3,6 @@ export type CioClientConfig = {
|
|
|
3
3
|
apiKey?: string;
|
|
4
4
|
cioJsClient?: ConstructorIOClient;
|
|
5
5
|
};
|
|
6
|
-
type UseCioClient = (cioClientConfig: CioClientConfig) => ConstructorIOClient |
|
|
6
|
+
type UseCioClient = (cioClientConfig: CioClientConfig) => ConstructorIOClient | never;
|
|
7
7
|
declare const useCioClient: UseCioClient;
|
|
8
8
|
export default useCioClient;
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import ConstructorIOClient from '@constructor-io/constructorio-client-javascript';
|
|
2
|
+
import { QuizLocalReducerState } from '../components/CioQuiz/quizLocalReducer';
|
|
3
|
+
import { ResultsPageOptions } from '../types';
|
|
4
|
+
declare const useFetchQuiz: (quizId: string, quizLocalState: QuizLocalReducerState, resultsPageOptions: ResultsPageOptions, quizVersionIdProp: string | undefined, cioClient: ConstructorIOClient) => {
|
|
5
|
+
cioClient: ConstructorIOClient;
|
|
6
|
+
quizApiState: import("../components/CioQuiz/quizApiReducer").QuizAPIReducerState;
|
|
7
|
+
isFirstQuestion: boolean;
|
|
8
|
+
resetQuizApiState: () => void;
|
|
9
|
+
};
|
|
10
|
+
export default useFetchQuiz;
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
/// <reference types="react" />
|
|
2
|
+
import ConstructorIOClient from '@constructor-io/constructorio-client-javascript';
|
|
3
|
+
import { ActionAnswerQuestion } from '../../components/CioQuiz/actions';
|
|
4
|
+
import { QuizAPIReducerState } from '../../components/CioQuiz/quizApiReducer';
|
|
5
|
+
import { QuizEventsReturn, ResultsPageOptions } from '../../types';
|
|
6
|
+
export type UseQuizEventOptions = {
|
|
7
|
+
cioClient: ConstructorIOClient;
|
|
8
|
+
quizApiState: QuizAPIReducerState;
|
|
9
|
+
resultsPageOptions: ResultsPageOptions;
|
|
10
|
+
dispatchLocalState: React.Dispatch<ActionAnswerQuestion>;
|
|
11
|
+
resetQuizApiState: () => void;
|
|
12
|
+
resetQuizLocalState: () => void;
|
|
13
|
+
};
|
|
14
|
+
declare const useQuizEvents: (options: UseQuizEventOptions) => QuizEventsReturn;
|
|
15
|
+
export default useQuizEvents;
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import ConstructorIOClient from '@constructor-io/constructorio-client-javascript';
|
|
2
|
+
import { QuizAPIReducerState } from '../../components/CioQuiz/quizApiReducer';
|
|
3
|
+
import { QuizEventsReturn, QuizResultsEventsProps } from '../../types';
|
|
4
|
+
declare const useQuizAddToCart: (cioClient: ConstructorIOClient, quizApiState: QuizAPIReducerState, onAddToCartClick?: QuizResultsEventsProps.OnAddToCartClick) => QuizEventsReturn.AddToCart;
|
|
5
|
+
export default useQuizAddToCart;
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import { ActionAnswerQuestion } from '../../components/CioQuiz/actions';
|
|
2
|
+
import { QuizEventsReturn } from '../../types';
|
|
3
|
+
declare const useQuizBackClick: (dispatchLocalState: React.Dispatch<ActionAnswerQuestion>) => QuizEventsReturn.PreviousQuestion;
|
|
4
|
+
export default useQuizBackClick;
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import { ActionAnswerQuestion } from '../../components/CioQuiz/actions';
|
|
2
|
+
import { QuizAPIReducerState } from '../../components/CioQuiz/quizApiReducer';
|
|
3
|
+
import { QuizEventsReturn } from '../../types';
|
|
4
|
+
declare const useQuizNextClick: (quizApiState: QuizAPIReducerState, dispatchLocalState: React.Dispatch<ActionAnswerQuestion>) => QuizEventsReturn.NextQuestion;
|
|
5
|
+
export default useQuizNextClick;
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import ConstructorIOClient from '@constructor-io/constructorio-client-javascript';
|
|
2
|
+
import { QuizAPIReducerState } from '../../components/CioQuiz/quizApiReducer';
|
|
3
|
+
import { QuizEventsReturn, QuizResultsEventsProps } from '../../types';
|
|
4
|
+
declare const useQuizResultClick: (cioClient: ConstructorIOClient, quizApiState: QuizAPIReducerState, onQuizResultClick?: QuizResultsEventsProps.OnQuizResultClick) => QuizEventsReturn.ResultClick;
|
|
5
|
+
export default useQuizResultClick;
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import ConstructorIOClient from '@constructor-io/constructorio-client-javascript';
|
|
2
|
+
import { QuizAPIReducerState } from '../../components/CioQuiz/quizApiReducer';
|
|
3
|
+
import { QuizResultsEventsProps } from '../../types';
|
|
4
|
+
declare const useQuizResultsLoaded: (cioClient: ConstructorIOClient, quizApiState: QuizAPIReducerState, onQuizResultsLoaded?: QuizResultsEventsProps.OnQuizResultsLoaded) => void;
|
|
5
|
+
export default useQuizResultsLoaded;
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
declare const useQuizLocalState: () => {
|
|
2
|
+
quizLocalState: import("../components/CioQuiz/quizLocalReducer").QuizLocalReducerState;
|
|
3
|
+
resetQuizLocalState: () => void;
|
|
4
|
+
dispatchLocalState: import("react").Dispatch<import("../components/CioQuiz/actions").ActionAnswerQuestion>;
|
|
5
|
+
};
|
|
6
|
+
export default useQuizLocalState;
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import ConstructorIOClient from '@constructor-io/constructorio-client-javascript';
|
|
2
|
+
import { QuizzesParameters, QuizzesResultsParameters, NextQuestionResponse, QuizResultsResponse, QuizResultDataPartial } from '../types';
|
|
3
|
+
export declare const getCioClient: (apiKey?: string) => ConstructorIOClient | undefined;
|
|
4
|
+
export declare const nextQuestion: (cioClient: ConstructorIOClient, quizId: string, parameters: QuizzesParameters) => Promise<NextQuestionResponse>;
|
|
5
|
+
export declare const getQuizResults: (cioClient: ConstructorIOClient, quizId: string, parameters: QuizzesResultsParameters) => Promise<QuizResultsResponse>;
|
|
6
|
+
export declare const trackQuizResultsLoaded: (cioClient: ConstructorIOClient, quizResults: QuizResultsResponse) => void;
|
|
7
|
+
export declare const trackQuizResultClick: (cioClient: ConstructorIOClient, quizResults: QuizResultsResponse, result: QuizResultDataPartial, position: number) => void;
|
|
8
|
+
export declare const trackQuizConversion: (cioClient: ConstructorIOClient, quizResults: QuizResultsResponse, result: QuizResultDataPartial, price?: number) => void;
|
package/lib/types/types.d.ts
CHANGED
|
@@ -1 +1,64 @@
|
|
|
1
|
+
/// <reference types="react" />
|
|
2
|
+
import { QuizResultData, NextQuestionResponse, QuizResultsResponse } from '@constructor-io/constructorio-client-javascript/lib/types';
|
|
3
|
+
import ConstructorIOClient from '@constructor-io/constructorio-client-javascript';
|
|
4
|
+
import { RequestStates } from './constants';
|
|
1
5
|
export type { QuestionOption, QuestionImages, Question, NextQuestionResponse, QuizResultsResponse, BrowseResultData, BrowseRequestType, QuizzesParameters, QuizzesResultsParameters, } from '@constructor-io/constructorio-client-javascript/lib/types';
|
|
6
|
+
export type QuizResultDataPartial = Partial<QuizResultData>;
|
|
7
|
+
export interface ResultsProps {
|
|
8
|
+
resultCardSalePriceKey?: string;
|
|
9
|
+
resultCardRegularPriceKey?: string;
|
|
10
|
+
}
|
|
11
|
+
export declare namespace QuizResultsEventsProps {
|
|
12
|
+
type OnQuizResultsLoaded = (results: QuizResultDataPartial) => void;
|
|
13
|
+
type OnQuizResultClick = (result: QuizResultDataPartial, position: number) => void;
|
|
14
|
+
type OnAddToCartClick = (result: QuizResultDataPartial) => void;
|
|
15
|
+
}
|
|
16
|
+
export interface ResultsPageOptions extends ResultsProps {
|
|
17
|
+
numResultsToDisplay?: number;
|
|
18
|
+
onQuizResultsLoaded?: QuizResultsEventsProps.OnQuizResultsLoaded;
|
|
19
|
+
onQuizResultClick?: QuizResultsEventsProps.OnQuizResultClick;
|
|
20
|
+
onAddToCartClick: QuizResultsEventsProps.OnAddToCartClick;
|
|
21
|
+
}
|
|
22
|
+
export interface IQuizProps {
|
|
23
|
+
apiKey?: string;
|
|
24
|
+
cioJsClient?: ConstructorIOClient;
|
|
25
|
+
quizId: string;
|
|
26
|
+
quizVersionId?: string;
|
|
27
|
+
resultsPageOptions: ResultsPageOptions;
|
|
28
|
+
}
|
|
29
|
+
export interface QuizReturnState {
|
|
30
|
+
answers: {
|
|
31
|
+
inputs: Record<string, string | string[]>;
|
|
32
|
+
isLastAnswer: boolean;
|
|
33
|
+
};
|
|
34
|
+
quiz: {
|
|
35
|
+
requestState: RequestStates;
|
|
36
|
+
versionId?: string;
|
|
37
|
+
sessionId?: string;
|
|
38
|
+
firstQuestion?: NextQuestionResponse;
|
|
39
|
+
currentQuestion?: NextQuestionResponse;
|
|
40
|
+
results?: QuizResultsResponse;
|
|
41
|
+
resultsFilters?: string[];
|
|
42
|
+
isFirstQuestion?: boolean;
|
|
43
|
+
};
|
|
44
|
+
}
|
|
45
|
+
export declare namespace QuizEventsReturn {
|
|
46
|
+
type NextQuestion = (payload?: string | string[]) => void;
|
|
47
|
+
type PreviousQuestion = () => void;
|
|
48
|
+
type ResetQuiz = () => void;
|
|
49
|
+
type ResultClick = (result: QuizResultDataPartial, position: number) => void;
|
|
50
|
+
type AddToCart = (e: React.MouseEvent<HTMLElement>, result: QuizResultDataPartial, price?: number) => void;
|
|
51
|
+
}
|
|
52
|
+
export interface QuizEventsReturn {
|
|
53
|
+
nextQuestion: QuizEventsReturn.NextQuestion;
|
|
54
|
+
previousQuestion: QuizEventsReturn.PreviousQuestion;
|
|
55
|
+
resetQuiz: QuizEventsReturn.ResetQuiz;
|
|
56
|
+
resultClick: QuizEventsReturn.ResultClick;
|
|
57
|
+
addToCart: QuizEventsReturn.AddToCart;
|
|
58
|
+
}
|
|
59
|
+
export interface UseQuizReturn {
|
|
60
|
+
cioClient?: ConstructorIOClient;
|
|
61
|
+
state: QuizReturnState;
|
|
62
|
+
events: QuizEventsReturn;
|
|
63
|
+
}
|
|
64
|
+
export type UseQuiz = (quizProps: IQuizProps) => UseQuizReturn;
|
package/lib/types/utils.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import
|
|
1
|
+
import { FilterExpression } from '@constructor-io/constructorio-client-javascript/lib/types';
|
|
2
2
|
import { QuestionTypes } from './components/CioQuiz/actions';
|
|
3
|
-
import { QuestionImages
|
|
3
|
+
import { QuestionImages } from './types';
|
|
4
4
|
export declare const renderImages: (images: Partial<QuestionImages>, cssClasses?: string) => JSX.Element | "";
|
|
5
5
|
export declare const getStoryParams: (storyCode: any, templateCode: any, importCode: any) => {
|
|
6
6
|
docs: {
|
|
@@ -12,14 +12,18 @@ export declare const getStoryParams: (storyCode: any, templateCode: any, importC
|
|
|
12
12
|
};
|
|
13
13
|
};
|
|
14
14
|
};
|
|
15
|
-
export declare const
|
|
15
|
+
export declare const defaultOnAddToCartClickCode = "\"onAddToCartClick\": (item) => console.dir(item)";
|
|
16
|
+
export declare const defaultOnQuizResultClickCode = "\"onQuizResultClick\": (result, position) => console.dir(result, position)";
|
|
17
|
+
export declare const defaultOnQuizResultsLoadedCode = "\"onQuizResultsLoaded\": (results) => console.dir(results)";
|
|
16
18
|
export declare const stringifyWithDefaults: (obj: {
|
|
17
19
|
cioJsClient?: any;
|
|
18
|
-
|
|
20
|
+
resultsPageOptions: {
|
|
21
|
+
onAddToCartClick: any;
|
|
22
|
+
onQuizResultClick: any;
|
|
23
|
+
onQuizResultsLoaded: any;
|
|
24
|
+
};
|
|
19
25
|
}) => string;
|
|
20
26
|
export declare const stringify: (obj: any) => string;
|
|
21
|
-
export declare const getNextQuestion: (cioClient: ConstructorIOClient, quizId: string, parameters: QuizzesParameters) => Promise<NextQuestionResponse>;
|
|
22
|
-
export declare const getQuizResults: (cioClient: ConstructorIOClient, quizId: string, parameters: QuizzesResultsParameters) => Promise<QuizResultsResponse>;
|
|
23
27
|
export declare const getQuestionTypes: (questionType?: `${QuestionTypes}`) => {
|
|
24
28
|
isOpenQuestion: boolean;
|
|
25
29
|
isCoverQuestion: boolean;
|
|
@@ -27,5 +31,6 @@ export declare const getQuestionTypes: (questionType?: `${QuestionTypes}`) => {
|
|
|
27
31
|
isMultipleQuestion: boolean;
|
|
28
32
|
isSelectQuestion: boolean;
|
|
29
33
|
};
|
|
30
|
-
export declare const getCioClient: (apiKey?: string) => ConstructorIOClient | undefined;
|
|
31
34
|
export declare function getPreferredColorScheme(): string;
|
|
35
|
+
export declare function isFunction(fn: any): boolean;
|
|
36
|
+
export declare const getFilterValuesFromExpression: (exp: FilterExpression | null) => string[];
|