@constructor-io/constructorio-ui-quizzes 1.2.3 → 1.3.1

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.
Files changed (87) hide show
  1. package/README.md +3 -1
  2. package/dist/constructorio-ui-quizzes-bundled.js +18 -18
  3. package/lib/cjs/components/CioQuiz/actions.js +11 -1
  4. package/lib/cjs/components/CioQuiz/index.js +15 -103
  5. package/lib/cjs/components/CioQuiz/quizApiReducer.js +32 -0
  6. package/lib/cjs/components/CioQuiz/{reducer.js → quizLocalReducer.js} +2 -2
  7. package/lib/cjs/components/CoverTypeQuestion/CoverTypeQuestion.js +6 -12
  8. package/lib/cjs/components/OpenTextTypeQuestion/OpenTextTypeQuestion.js +12 -18
  9. package/lib/cjs/components/QuizQuestions/index.js +6 -3
  10. package/lib/cjs/components/ResultCard/ResultCard.js +10 -30
  11. package/lib/cjs/components/ResultContainer/ResultContainer.js +8 -31
  12. package/lib/cjs/components/ResultCtaButton/ResultCtaButton.js +7 -26
  13. package/lib/cjs/components/ResultFilters/ResultFilters.js +6 -23
  14. package/lib/cjs/components/Results/Results.js +5 -5
  15. package/lib/cjs/components/SelectTypeQuestion/SelectTypeQuestion.js +16 -23
  16. package/lib/cjs/components/ZeroResults/ZeroResults.js +2 -2
  17. package/lib/cjs/constants.js +5 -3
  18. package/lib/cjs/hooks/useCioClient.js +4 -3
  19. package/lib/cjs/hooks/useConsoleErrors.js +20 -0
  20. package/lib/cjs/hooks/useQuiz.js +48 -0
  21. package/lib/cjs/hooks/useQuizApiState.js +91 -0
  22. package/lib/cjs/hooks/useQuizEvents/index.js +36 -0
  23. package/lib/cjs/hooks/useQuizEvents/useQuizAddToCart.js +20 -0
  24. package/lib/cjs/hooks/useQuizEvents/useQuizBackClick.js +13 -0
  25. package/lib/cjs/hooks/useQuizEvents/useQuizNextClick.js +48 -0
  26. package/lib/cjs/hooks/useQuizEvents/useQuizResultClick.js +19 -0
  27. package/lib/cjs/hooks/useQuizEvents/useQuizResultsLoaded.js +22 -0
  28. package/lib/cjs/hooks/useQuizLocalState.js +20 -0
  29. package/lib/cjs/services/index.js +72 -0
  30. package/lib/cjs/utils.js +42 -21
  31. package/lib/mjs/components/CioQuiz/actions.js +10 -0
  32. package/lib/mjs/components/CioQuiz/index.js +15 -103
  33. package/lib/mjs/components/CioQuiz/quizApiReducer.js +49 -0
  34. package/lib/mjs/components/CioQuiz/{reducer.js → quizLocalReducer.js} +1 -1
  35. package/lib/mjs/components/CoverTypeQuestion/CoverTypeQuestion.js +6 -12
  36. package/lib/mjs/components/OpenTextTypeQuestion/OpenTextTypeQuestion.js +11 -17
  37. package/lib/mjs/components/QuizQuestions/index.js +5 -3
  38. package/lib/mjs/components/ResultCard/ResultCard.js +10 -29
  39. package/lib/mjs/components/ResultContainer/ResultContainer.js +8 -31
  40. package/lib/mjs/components/ResultCtaButton/ResultCtaButton.js +7 -25
  41. package/lib/mjs/components/ResultFilters/ResultFilters.js +5 -23
  42. package/lib/mjs/components/Results/Results.js +3 -3
  43. package/lib/mjs/components/SelectTypeQuestion/SelectTypeQuestion.js +13 -20
  44. package/lib/mjs/components/ZeroResults/ZeroResults.js +2 -2
  45. package/lib/mjs/constants.js +4 -2
  46. package/lib/mjs/hooks/useCioClient.js +4 -3
  47. package/lib/mjs/hooks/useConsoleErrors.js +18 -0
  48. package/lib/mjs/hooks/useQuiz.js +47 -0
  49. package/lib/mjs/hooks/useQuizApiState.js +87 -0
  50. package/lib/mjs/hooks/useQuizEvents/index.js +33 -0
  51. package/lib/mjs/hooks/useQuizEvents/useQuizAddToCart.js +18 -0
  52. package/lib/mjs/hooks/useQuizEvents/useQuizBackClick.js +11 -0
  53. package/lib/mjs/hooks/useQuizEvents/useQuizNextClick.js +45 -0
  54. package/lib/mjs/hooks/useQuizEvents/useQuizResultClick.js +17 -0
  55. package/lib/mjs/hooks/useQuizEvents/useQuizResultsLoaded.js +19 -0
  56. package/lib/mjs/hooks/useQuizLocalState.js +17 -0
  57. package/lib/mjs/services/index.js +60 -0
  58. package/lib/mjs/utils.js +39 -17
  59. package/lib/styles.css +23 -20
  60. package/lib/types/components/CioQuiz/actions.d.ts +20 -0
  61. package/lib/types/components/CioQuiz/context.d.ts +10 -14
  62. package/lib/types/components/CioQuiz/index.d.ts +1 -12
  63. package/lib/types/components/CioQuiz/quizApiReducer.d.ts +14 -0
  64. package/lib/types/components/CioQuiz/{reducer.d.ts → quizLocalReducer.d.ts} +3 -3
  65. package/lib/types/components/QuizQuestions/index.d.ts +1 -4
  66. package/lib/types/components/ResultCard/ResultCard.d.ts +2 -4
  67. package/lib/types/components/ResultContainer/ResultContainer.d.ts +1 -2
  68. package/lib/types/components/ResultCtaButton/ResultCtaButton.d.ts +2 -3
  69. package/lib/types/components/ResultFilters/ResultFilters.d.ts +2 -5
  70. package/lib/types/components/Results/Results.d.ts +1 -7
  71. package/lib/types/components/ZeroResults/ZeroResults.d.ts +1 -1
  72. package/lib/types/constants.d.ts +2 -1
  73. package/lib/types/hooks/useCioClient.d.ts +1 -1
  74. package/lib/types/hooks/useConsoleErrors.d.ts +3 -0
  75. package/lib/types/hooks/useQuiz.d.ts +3 -0
  76. package/lib/types/hooks/useQuizApiState.d.ts +10 -0
  77. package/lib/types/hooks/useQuizEvents/index.d.ts +15 -0
  78. package/lib/types/hooks/useQuizEvents/useQuizAddToCart.d.ts +5 -0
  79. package/lib/types/hooks/useQuizEvents/useQuizBackClick.d.ts +4 -0
  80. package/lib/types/hooks/useQuizEvents/useQuizNextClick.d.ts +5 -0
  81. package/lib/types/hooks/useQuizEvents/useQuizResultClick.d.ts +5 -0
  82. package/lib/types/hooks/useQuizEvents/useQuizResultsLoaded.d.ts +5 -0
  83. package/lib/types/hooks/useQuizLocalState.d.ts +6 -0
  84. package/lib/types/services/index.d.ts +8 -0
  85. package/lib/types/types.d.ts +63 -0
  86. package/lib/types/utils.d.ts +12 -7
  87. package/package.json +12 -12
package/lib/styles.css CHANGED
@@ -31,6 +31,7 @@
31
31
  --bottom-bar-height: 80px;
32
32
  --primary-color: var(--blue-denim-400);
33
33
  --container-image-small-height: 250px;
34
+ container: quiz / inline-size;
34
35
  }
35
36
 
36
37
  /* Mobile + global styles */
@@ -40,8 +41,11 @@
40
41
  font-family: 'Inter', sans-serif;
41
42
  }
42
43
  .cio-quiz {
44
+ position: relative;
43
45
  min-width: 100%;
44
46
  min-height: 100%;
47
+ height: 100%;
48
+ overflow: auto;
45
49
  display: flex;
46
50
  justify-content: center;
47
51
  background-color: #ffffff;
@@ -128,7 +132,7 @@
128
132
  height: var(--bottom-bar-height);
129
133
  padding: 8px 16px;
130
134
  display: flex;
131
- position: fixed;
135
+ position: absolute;
132
136
  bottom: 0px;
133
137
  left: 0px;
134
138
  background: white;
@@ -223,14 +227,15 @@
223
227
  box-shadow: 0px 4px 10px rgba(93, 124, 232, 0.25);
224
228
  }
225
229
  .cio-select-question-container {
230
+ position: relative;
226
231
  display: flex;
227
232
  flex-direction: column;
228
233
  align-items: center;
229
- justify-content: center;
234
+ align-self: start;
230
235
  max-width: 1200px;
231
- margin-bottom: var(--bottom-bar-height);
232
236
  padding: 1rem;
233
237
  margin-top: 2rem;
238
+ min-height: calc(100% - 3rem); /* Full height - padding - margin */
234
239
  width: 100%;
235
240
  }
236
241
  .cio-question-options-container {
@@ -239,7 +244,7 @@
239
244
  flex-wrap: wrap;
240
245
  gap: 1rem;
241
246
  width: 100%;
242
- margin-bottom: auto;
247
+ margin-bottom: var(--bottom-bar-height);
243
248
  margin-top: 2rem;
244
249
  }
245
250
  .cio-question-options-container-text-only {
@@ -464,13 +469,18 @@
464
469
  /* Media Queries */
465
470
 
466
471
  /* Small Tablet */
467
- @media screen and (min-width: 640px) {
468
- /* Container */
472
+ @container quiz (min-width: 640px) {
473
+ .cio-container {
474
+ padding-bottom: 0;
475
+ }
476
+
477
+ /* Container */
469
478
  .cio-container--with-image {
470
479
  display: flex;
471
480
  justify-content: center;
472
481
  align-items: center;
473
482
  margin-bottom: 0;
483
+ padding-bottom: 0;
474
484
  }
475
485
 
476
486
  /* Image */
@@ -485,6 +495,7 @@
485
495
  .cio-cover-question-container--with-image {
486
496
  justify-content: center;
487
497
  margin-bottom: 0;
498
+ padding-bottom: 0;
488
499
  }
489
500
 
490
501
  /* Select Component */
@@ -519,23 +530,18 @@
519
530
  }
520
531
 
521
532
  /* Big Tablet */
522
- @media screen and (min-width: 768px) {
523
- /* Quiz */
524
- .cio-quiz {
525
- font-size: 18px;
526
- }
527
-
533
+ @container quiz (min-width: 768px) {
528
534
  /* Container */
529
535
  .cio-container {
530
536
  align-items: center;
531
537
  margin-top: 0;
532
538
  }
533
539
  .cio-container--with-image {
534
- padding: 6rem 2rem;
540
+ padding: 6% 2%;
535
541
  align-items: center;
536
542
  flex-direction: row;
537
543
  }
538
-
544
+
539
545
  /* Input */
540
546
  .cio-question-input-text {
541
547
  margin-bottom: 1rem;
@@ -543,7 +549,7 @@
543
549
 
544
550
  /* Image */
545
551
  .cio-question-image-container {
546
- max-height: 1000px;
552
+ max-height: 100%;
547
553
  }
548
554
  .cio-cover-question-container--with-image .cio-question-image-container {
549
555
  max-height: unset;
@@ -587,6 +593,7 @@
587
593
  padding: 1rem 5rem;
588
594
  }
589
595
  .cio-select-question-container {
596
+ justify-content: center;
590
597
  margin: 0;
591
598
  padding: 2rem;
592
599
  padding-bottom: 0;
@@ -612,11 +619,8 @@
612
619
  }
613
620
 
614
621
  /* Desktop */
615
- @media screen and (min-width: 1280px) {
622
+ @container quiz (min-width: 1280px) {
616
623
  /* Container */
617
- .cio-container--with-image {
618
- padding: 6rem 2rem;
619
- }
620
624
  .cio-cover-question-container--with-image {
621
625
  padding: 0;
622
626
  }
@@ -632,7 +636,6 @@
632
636
  padding: 2.5rem 0rem;
633
637
  }
634
638
 
635
-
636
639
  /* Results component */
637
640
  .cio-results-container {
638
641
  margin-top: 3rem;
@@ -1,3 +1,4 @@
1
+ import { NextQuestionResponse, QuizResultsResponse } from '../../types';
1
2
  export declare enum QuestionTypes {
2
3
  OpenText = "open",
3
4
  Cover = "cover",
@@ -22,4 +23,23 @@ interface Action<Type, Payload = {}> {
22
23
  }
23
24
  export type ActionAnswerInputQuestion = Action<QuestionTypes.OpenText, OpenTextQuestionPayload> | Action<QuestionTypes.SingleSelect, SelectQuestionPayload> | Action<QuestionTypes.MultipleSelect, SelectQuestionPayload>;
24
25
  export type ActionAnswerQuestion = ActionAnswerInputQuestion | Action<QuestionTypes.Cover, CoverQuestionPayload> | Action<QuestionTypes.Back> | Action<QuestionTypes.Reset>;
26
+ export declare enum QuizAPIActionTypes {
27
+ SET_IS_LOADING = 0,
28
+ SET_IS_ERROR = 1,
29
+ SET_QUIZ_RESULTS = 2,
30
+ SET_CURRENT_QUESTION = 3,
31
+ RESET_QUIZ = 4
32
+ }
33
+ export type ActionSetIsLoading = Action<QuizAPIActionTypes.SET_IS_LOADING>;
34
+ export type ActionSetIsError = Action<QuizAPIActionTypes.SET_IS_ERROR>;
35
+ export type ActionSetQuizResults = Action<QuizAPIActionTypes.SET_QUIZ_RESULTS, {
36
+ quizResults: QuizResultsResponse;
37
+ }>;
38
+ export type ActionSetCurrentQuestion = Action<QuizAPIActionTypes.SET_CURRENT_QUESTION, {
39
+ quizCurrentQuestion: NextQuestionResponse;
40
+ quizSessionId?: string;
41
+ quizVersionId?: string;
42
+ }>;
43
+ export type ActionResetQuiz = Action<QuizAPIActionTypes.RESET_QUIZ>;
44
+ export type ActionQuizAPI = ActionSetIsLoading | ActionSetIsError | ActionSetQuizResults | ActionSetCurrentQuestion | ActionResetQuiz;
25
45
  export {};
@@ -1,19 +1,15 @@
1
1
  import React from 'react';
2
2
  import ConstructorIOClient from '@constructor-io/constructorio-client-javascript';
3
- import { RequestStates } from '../../constants';
4
- import { NextQuestionResponse, QuizResultsResponse } from '../../types';
5
- import { ActionAnswerQuestion } from './actions';
6
- import { QuizReducerState } from './reducer';
7
- interface QuizContextValue {
8
- state: QuizReducerState;
9
- requestState: RequestStates;
10
- questionResponse: NextQuestionResponse;
11
- resultsResponse: QuizResultsResponse;
12
- isFirstQuestion: boolean;
13
- quizNextHandler: (action?: ActionAnswerQuestion) => void;
14
- quizBackHandler: () => void;
15
- dispatch: React.Dispatch<ActionAnswerQuestion>;
16
- cioClient: ConstructorIOClient;
3
+ import { QuizEventsReturn, QuizReturnState } from '../../types';
4
+ export interface QuizContextValue {
5
+ cioClient?: ConstructorIOClient;
6
+ state?: QuizReturnState;
7
+ resetQuiz: QuizEventsReturn.ResetQuiz;
8
+ nextQuestion?: QuizEventsReturn.NextQuestion;
9
+ previousQuestion?: QuizEventsReturn.PreviousQuestion;
10
+ addToCart: QuizEventsReturn.AddToCart;
11
+ resultClick: QuizEventsReturn.ResultClick;
12
+ customClickItemCallback: boolean;
17
13
  }
18
14
  declare const _default: React.Context<Partial<QuizContextValue>>;
19
15
  export default _default;
@@ -1,14 +1,3 @@
1
1
  /// <reference types="react" />
2
- import ConstructorIOClient from '@constructor-io/constructorio-client-javascript';
3
- import { ResultsProps } from '../Results/Results';
4
- export interface ResultsPageOptions extends ResultsProps {
5
- numResultsToDisplay?: number;
6
- }
7
- export interface IQuizProps {
8
- quizId: string;
9
- apiKey?: string;
10
- cioJsClient?: ConstructorIOClient;
11
- resultsPageOptions: ResultsPageOptions;
12
- quizVersionId?: string;
13
- }
2
+ import { IQuizProps } from '../../types';
14
3
  export default function CioQuiz(props: IQuizProps): JSX.Element | null;
@@ -0,0 +1,14 @@
1
+ import { RequestStates } from '../../constants';
2
+ import { NextQuestionResponse, QuizResultsResponse } from '../../types';
3
+ import { ActionQuizAPI } from './actions';
4
+ export type QuizAPIReducerState = {
5
+ quizRequestState: RequestStates;
6
+ quizVersionId?: string;
7
+ quizSessionId?: string;
8
+ quizFirstQuestion?: NextQuestionResponse;
9
+ quizCurrentQuestion?: NextQuestionResponse;
10
+ quizResults?: QuizResultsResponse;
11
+ quizResultsFilters?: string[];
12
+ };
13
+ export declare const initialState: QuizAPIReducerState;
14
+ export default function apiReducer(state: QuizAPIReducerState, action: ActionQuizAPI): QuizAPIReducerState;
@@ -1,6 +1,6 @@
1
1
  import { ActionAnswerQuestion, OpenTextQuestionPayload, SelectQuestionPayload } from './actions';
2
2
  export type Answers = string[][];
3
- export type QuizReducerState = {
3
+ export type QuizLocalReducerState = {
4
4
  answers: Answers;
5
5
  answerInputs: {};
6
6
  isLastAnswer: boolean;
@@ -8,5 +8,5 @@ export type QuizReducerState = {
8
8
  export type AnswerInputState = {
9
9
  [key: string]: OpenTextQuestionPayload | SelectQuestionPayload;
10
10
  };
11
- export declare const initialState: QuizReducerState;
12
- export default function reducer(state: QuizReducerState, action: ActionAnswerQuestion): QuizReducerState;
11
+ export declare const initialState: QuizLocalReducerState;
12
+ export default function quizLocalReducer(state: QuizLocalReducerState, action: ActionAnswerQuestion): QuizLocalReducerState;
@@ -1,5 +1,2 @@
1
1
  /// <reference types="react" />
2
- import { NextQuestionResponse } from '../../types';
3
- export default function QuizQuestions(props: {
4
- questionResponse: NextQuestionResponse;
5
- }): JSX.Element;
2
+ export default function QuizQuestions(): JSX.Element;
@@ -1,9 +1,7 @@
1
1
  /// <reference types="react" />
2
- import { BrowseResultData } from '../../types';
2
+ import { QuizResultDataPartial } from '../../types';
3
3
  interface ResultCardProps {
4
- result: Partial<BrowseResultData>;
5
- addToCartCallback: (clickedResult: Partial<BrowseResultData>) => any;
6
- clickItemCallback?: (clickedResult: Partial<BrowseResultData>) => any;
4
+ result: QuizResultDataPartial;
7
5
  salePriceKey?: string;
8
6
  regularPriceKey?: string;
9
7
  resultPosition: number;
@@ -1,7 +1,6 @@
1
1
  /// <reference types="react" />
2
- import { ResultsProps } from '../Results/Results';
2
+ import { ResultsProps } from '../../types';
3
3
  export interface IResultContainerProps {
4
4
  options: ResultsProps;
5
- resetQuizSessionId: () => void;
6
5
  }
7
6
  export default function ResultContainer(props: IResultContainerProps): JSX.Element;
@@ -1,9 +1,8 @@
1
1
  /// <reference types="react" />
2
- import { BrowseResultData } from '../../types';
2
+ import { QuizResultDataPartial } from '../../types';
3
3
  interface ResultCtaButtonProps {
4
- item: Partial<BrowseResultData>;
4
+ item: QuizResultDataPartial;
5
5
  className?: string;
6
- callback?: (item: Partial<BrowseResultData>) => any;
7
6
  price?: number;
8
7
  }
9
8
  export default function ResultCtaButton(props: ResultCtaButtonProps): JSX.Element;
@@ -1,6 +1,3 @@
1
- import React from 'react';
2
- interface ResultFiltersProps extends React.ButtonHTMLAttributes<HTMLButtonElement> {
3
- filters?: any;
4
- }
5
- declare function ResultFilters(props: ResultFiltersProps): JSX.Element;
1
+ /// <reference types="react" />
2
+ declare function ResultFilters(): JSX.Element;
6
3
  export default ResultFilters;
@@ -1,10 +1,4 @@
1
1
  /// <reference types="react" />
2
- import { BrowseResultData } from '../../types';
3
- export interface ResultsProps {
4
- addToCartCallback: (item: Partial<BrowseResultData>) => any;
5
- clickItemCallback?: (item: Partial<BrowseResultData>) => any;
6
- resultCardSalePriceKey?: string;
7
- resultCardRegularPriceKey?: string;
8
- }
2
+ import { ResultsProps } from '../../types';
9
3
  declare function Results(props: ResultsProps): JSX.Element;
10
4
  export default Results;
@@ -1,6 +1,6 @@
1
1
  import React from 'react';
2
2
  interface ZeroResultsProps extends React.ButtonHTMLAttributes<HTMLButtonElement> {
3
- onResetClick?: () => {};
3
+ resetQuizClickHandler?: () => {};
4
4
  }
5
5
  declare function ZeroResults(props: ZeroResultsProps): JSX.Element;
6
6
  export default ZeroResults;
@@ -1,8 +1,9 @@
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 - `addToCartCallback` is a callback function that will be called when the \"Add to cart\" button is clicked\n - `clickItemCallback` 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 - `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";
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
+ export declare const smallContainerDescription = "If you are using the provided styles, CioQuiz component will respect the height and width of its parent container and use responsive styles based on the parent container's dimensions";
6
7
  export declare enum RequestStates {
7
8
  Stale = 0,
8
9
  Loading = 1,
@@ -3,6 +3,6 @@ export type CioClientConfig = {
3
3
  apiKey?: string;
4
4
  cioJsClient?: ConstructorIOClient;
5
5
  };
6
- type UseCioClient = (cioClientConfig: CioClientConfig) => ConstructorIOClient | undefined;
6
+ type UseCioClient = (cioClientConfig: CioClientConfig) => ConstructorIOClient | never;
7
7
  declare const useCioClient: UseCioClient;
8
8
  export default useCioClient;
@@ -0,0 +1,3 @@
1
+ import { ResultsPageOptions } from '../types';
2
+ declare const useConsoleErrors: (quizId: string, resultsPageOptions: ResultsPageOptions) => void;
3
+ export default useConsoleErrors;
@@ -0,0 +1,3 @@
1
+ import { UseQuiz } from '../types';
2
+ declare const useQuiz: UseQuiz;
3
+ export default useQuiz;
@@ -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;
@@ -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;
@@ -1,6 +1,6 @@
1
- import ConstructorIOClient from '@constructor-io/constructorio-client-javascript';
1
+ import { FilterExpression } from '@constructor-io/constructorio-client-javascript/lib/types';
2
2
  import { QuestionTypes } from './components/CioQuiz/actions';
3
- import { QuestionImages, QuizzesParameters, QuizzesResultsParameters, NextQuestionResponse, QuizResultsResponse } from './types';
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 defaultAddToCartCallbackCode = "\"addToCartCallback\": (item) => console.dir(item)";
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
- addToCartCallback: any;
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[];
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@constructor-io/constructorio-ui-quizzes",
3
- "version": "1.2.3",
3
+ "version": "1.3.1",
4
4
  "description": "Constructor.io Quizzes UI library for web applications",
5
5
  "author": "constructor.io",
6
6
  "license": "MIT",
@@ -61,15 +61,15 @@
61
61
  },
62
62
  "devDependencies": {
63
63
  "@cspell/eslint-plugin": "^6.18.1",
64
- "@storybook/addon-a11y": "^7.0.0-beta.40",
65
- "@storybook/addon-actions": "7.0.0-beta.40",
66
- "@storybook/addon-essentials": "7.0.0-beta.40",
67
- "@storybook/addon-interactions": "^7.0.0-beta.40",
68
- "@storybook/addon-links": "7.0.0-beta.40",
69
- "@storybook/jest": "^0.0.11-next.0",
70
- "@storybook/react-webpack5": "7.0.0-beta.40",
71
- "@storybook/test-runner": "0.10.0-next.8",
72
- "@storybook/testing-library": "^0.0.14-next.1",
64
+ "@storybook/addon-a11y": "^7.0.11",
65
+ "@storybook/addon-actions": "7.0.11",
66
+ "@storybook/addon-essentials": "7.0.11",
67
+ "@storybook/addon-interactions": "^7.0.11",
68
+ "@storybook/addon-links": "7.0.11",
69
+ "@storybook/jest": "^0.1.0",
70
+ "@storybook/react-webpack5": "7.0.11",
71
+ "@storybook/test-runner": "0.10.0",
72
+ "@storybook/testing-library": "^0.1.0",
73
73
  "@types/react": "^18.0.26",
74
74
  "@types/react-dom": "^18.0.9",
75
75
  "@typescript-eslint/eslint-plugin": "^5.47.0",
@@ -83,13 +83,13 @@
83
83
  "eslint-plugin-prettier": "^4.2.1",
84
84
  "eslint-plugin-react": "^7.31.11",
85
85
  "eslint-plugin-react-hooks": "^4.6.0",
86
- "eslint-plugin-storybook": "^0.6.8",
86
+ "eslint-plugin-storybook": "^0.6.12",
87
87
  "husky": "^8.0.1",
88
88
  "license-checker": "^25.0.1",
89
89
  "react": "^18.2.0",
90
90
  "react-dom": "^18.2.0",
91
91
  "start-server-and-test": "^2.0.0",
92
- "storybook": "7.0.0-beta.40",
92
+ "storybook": "7.0.11",
93
93
  "typescript": "^4.9.4",
94
94
  "webpack": "^5.75.0",
95
95
  "vite": "^4.2.1",