@coorpacademy/app-review 0.1.5 → 0.1.8

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 (192) hide show
  1. package/es/actions/api/fetch-skills.d.ts +10 -0
  2. package/es/actions/api/fetch-skills.js +8 -0
  3. package/es/actions/api/fetch-slide.d.ts +10 -0
  4. package/es/actions/api/fetch-slide.js +8 -0
  5. package/es/actions/api/post-progression.d.ts +10 -0
  6. package/es/actions/api/post-progression.js +15 -0
  7. package/es/actions/data/slides.d.ts +7 -24
  8. package/es/actions/data/slides.js +0 -6
  9. package/es/actions/data/token.d.ts +2 -2
  10. package/es/actions/data/token.js +1 -1
  11. package/es/actions/index.d.ts +5 -3
  12. package/es/actions/ui/navigation.d.ts +0 -1
  13. package/es/actions/ui/navigation.js +0 -4
  14. package/es/actions/ui/step-items.d.ts +2 -8
  15. package/es/actions/ui/step-items.js +0 -6
  16. package/es/configure-store.d.ts +3 -34
  17. package/es/configure-store.js +4 -4
  18. package/es/fixtures/qcm-slide.d.ts +2 -2
  19. package/es/index.d.ts +1 -1
  20. package/es/index.js +78 -42
  21. package/es/reducers/data/index.d.ts +16 -5
  22. package/es/reducers/data/progression.d.ts +14 -9
  23. package/es/reducers/data/progression.js +18 -58
  24. package/es/reducers/data/skills.d.ts +4 -5
  25. package/es/reducers/data/skills.js +3 -6
  26. package/es/reducers/data/slides.d.ts +2 -1
  27. package/es/reducers/data/slides.js +14 -9
  28. package/es/reducers/data/token.d.ts +0 -1
  29. package/es/reducers/data/token.js +1 -5
  30. package/es/reducers/index.d.ts +9 -3
  31. package/es/reducers/ui/finished-slides.d.ts +0 -1
  32. package/es/reducers/ui/finished-slides.js +1 -3
  33. package/es/reducers/ui/index.d.ts +14 -4
  34. package/es/reducers/ui/navigation.d.ts +0 -1
  35. package/es/reducers/ui/navigation.js +1 -3
  36. package/es/reducers/ui/review-status.d.ts +0 -1
  37. package/es/reducers/ui/review-status.js +1 -4
  38. package/es/reducers/ui/step-items.d.ts +5 -5
  39. package/es/reducers/ui/step-items.js +0 -1
  40. package/es/services/fetch-skills.d.ts +2 -8
  41. package/es/services/fetch-skills.js +3 -16
  42. package/es/services/fetch-slide.d.ts +2 -0
  43. package/es/services/fetch-slide.js +11 -0
  44. package/es/services/index.d.ts +2 -0
  45. package/es/services/index.js +8 -0
  46. package/es/services/post-progression.d.ts +2 -0
  47. package/es/services/post-progression.js +21 -0
  48. package/es/services/test/fetch-skills.test.js +29 -0
  49. package/es/services/test/post-progression.test.js +35 -0
  50. package/es/services/tools/fetch-responses.d.ts +1 -1
  51. package/es/services/tools/sleep.d.ts +1 -0
  52. package/es/services/tools/sleep.js +3 -0
  53. package/es/{index.test.js → test/index.test.js} +18 -7
  54. package/es/test/util/services.mock.d.ts +2 -0
  55. package/es/test/util/services.mock.js +68 -0
  56. package/es/types/common.d.ts +66 -2
  57. package/es/types/common.js +5 -0
  58. package/es/types/slides.d.ts +1 -1
  59. package/es/types/ui-progression.d.ts +10 -0
  60. package/es/types/views/slides.d.ts +1 -1
  61. package/lib/actions/api/fetch-skills.d.ts +10 -0
  62. package/lib/actions/api/fetch-skills.js +13 -0
  63. package/lib/actions/api/fetch-slide.d.ts +10 -0
  64. package/lib/actions/api/fetch-slide.js +13 -0
  65. package/lib/actions/api/post-progression.d.ts +10 -0
  66. package/lib/actions/api/post-progression.js +18 -0
  67. package/lib/actions/data/slides.d.ts +7 -24
  68. package/lib/actions/data/slides.js +0 -6
  69. package/lib/actions/data/token.d.ts +2 -2
  70. package/lib/actions/data/token.js +1 -1
  71. package/lib/actions/index.d.ts +5 -3
  72. package/lib/actions/ui/navigation.d.ts +0 -1
  73. package/lib/actions/ui/navigation.js +0 -4
  74. package/lib/actions/ui/step-items.d.ts +2 -8
  75. package/lib/actions/ui/step-items.js +0 -6
  76. package/lib/configure-store.d.ts +3 -34
  77. package/lib/configure-store.js +4 -4
  78. package/lib/fixtures/qcm-slide.d.ts +2 -2
  79. package/lib/index.d.ts +1 -1
  80. package/lib/index.js +78 -86
  81. package/lib/reducers/data/index.d.ts +16 -5
  82. package/lib/reducers/data/progression.d.ts +14 -9
  83. package/lib/reducers/data/progression.js +18 -58
  84. package/lib/reducers/data/skills.d.ts +4 -5
  85. package/lib/reducers/data/skills.js +3 -6
  86. package/lib/reducers/data/slides.d.ts +2 -1
  87. package/lib/reducers/data/slides.js +14 -9
  88. package/lib/reducers/data/token.d.ts +0 -1
  89. package/lib/reducers/data/token.js +1 -5
  90. package/lib/reducers/index.d.ts +9 -3
  91. package/lib/reducers/ui/finished-slides.d.ts +0 -1
  92. package/lib/reducers/ui/finished-slides.js +1 -3
  93. package/lib/reducers/ui/index.d.ts +14 -4
  94. package/lib/reducers/ui/navigation.d.ts +0 -1
  95. package/lib/reducers/ui/navigation.js +1 -3
  96. package/lib/reducers/ui/review-status.d.ts +0 -1
  97. package/lib/reducers/ui/review-status.js +1 -4
  98. package/lib/reducers/ui/step-items.d.ts +5 -5
  99. package/lib/reducers/ui/step-items.js +0 -1
  100. package/lib/services/fetch-skills.d.ts +2 -8
  101. package/lib/services/fetch-skills.js +5 -20
  102. package/lib/services/fetch-slide.d.ts +2 -0
  103. package/lib/services/fetch-slide.js +57 -0
  104. package/lib/services/index.d.ts +2 -0
  105. package/lib/services/index.js +8 -0
  106. package/lib/services/post-progression.d.ts +2 -0
  107. package/lib/services/post-progression.js +65 -0
  108. package/lib/services/{fetch-skills.test.js → test/fetch-skills.test.js} +23 -16
  109. package/lib/services/test/post-progression.test.js +89 -0
  110. package/lib/services/tools/fetch-responses.d.ts +1 -1
  111. package/lib/services/tools/sleep.d.ts +1 -0
  112. package/lib/services/tools/sleep.js +5 -0
  113. package/lib/test/index.test.d.ts +1 -0
  114. package/lib/{index.test.js → test/index.test.js} +23 -15
  115. package/lib/test/util/services.mock.d.ts +2 -0
  116. package/lib/test/util/services.mock.js +68 -0
  117. package/lib/types/common.d.ts +66 -2
  118. package/lib/types/common.js +5 -0
  119. package/lib/types/slides.d.ts +1 -1
  120. package/lib/types/ui-progression.d.ts +10 -0
  121. package/lib/types/ui-progression.js +1 -0
  122. package/lib/types/views/slides.d.ts +1 -1
  123. package/package.json +6 -5
  124. package/readme.md +4 -5
  125. package/src/actions/api/fetch-skills.ts +20 -0
  126. package/src/actions/api/fetch-slide.ts +20 -0
  127. package/src/actions/api/post-progression.ts +26 -0
  128. package/src/actions/data/slides.ts +8 -32
  129. package/src/actions/data/token.ts +2 -2
  130. package/src/actions/index.ts +7 -10
  131. package/src/actions/ui/navigation.ts +0 -5
  132. package/src/actions/ui/step-items.ts +2 -14
  133. package/src/configure-store.ts +6 -45
  134. package/src/fixtures/qcm-slide.ts +2 -2
  135. package/src/index.tsx +94 -45
  136. package/src/reducers/data/index.ts +12 -4
  137. package/src/reducers/data/progression.ts +34 -79
  138. package/src/reducers/data/skills.ts +5 -10
  139. package/src/reducers/data/slides.ts +16 -15
  140. package/src/reducers/data/token.ts +1 -11
  141. package/src/reducers/index.ts +7 -2
  142. package/src/reducers/ui/finished-slides.ts +1 -7
  143. package/src/reducers/ui/index.ts +11 -4
  144. package/src/reducers/ui/navigation.ts +1 -6
  145. package/src/reducers/ui/review-status.ts +1 -8
  146. package/src/reducers/ui/step-items.ts +5 -14
  147. package/src/services/fetch-skills.ts +4 -30
  148. package/src/services/fetch-slide.ts +15 -0
  149. package/src/services/index.ts +10 -0
  150. package/src/services/post-progression.ts +28 -0
  151. package/src/services/test/fetch-skills.test.ts +39 -0
  152. package/src/services/test/post-progression.test.ts +45 -0
  153. package/src/services/tools/fetch-responses.ts +1 -1
  154. package/src/services/tools/sleep.ts +4 -0
  155. package/src/{index.test.tsx → test/index.test.tsx} +16 -10
  156. package/src/test/util/services.mock.ts +70 -0
  157. package/src/types/common.ts +78 -2
  158. package/src/types/globals.d.ts +2 -0
  159. package/src/types/slides.ts +1 -1
  160. package/src/types/ui-progression.ts +25 -0
  161. package/src/types/views/slides.ts +1 -1
  162. package/es/actions/data/skills.d.ts +0 -13
  163. package/es/actions/data/skills.js +0 -10
  164. package/es/middlewares/on-start-app.d.ts +0 -5
  165. package/es/middlewares/on-start-app.js +0 -29
  166. package/es/services/fetch-skills.mock.d.ts +0 -3
  167. package/es/services/fetch-skills.mock.js +0 -17
  168. package/es/services/fetch-skills.test.js +0 -22
  169. package/es/services/tools/fetch.mocks.d.ts +0 -8
  170. package/es/services/tools/fetch.mocks.js +0 -13
  171. package/es/types/skills.d.ts +0 -7
  172. package/lib/actions/data/skills.d.ts +0 -13
  173. package/lib/actions/data/skills.js +0 -10
  174. package/lib/middlewares/on-start-app.d.ts +0 -5
  175. package/lib/middlewares/on-start-app.js +0 -34
  176. package/lib/services/fetch-skills.mock.d.ts +0 -3
  177. package/lib/services/fetch-skills.mock.js +0 -17
  178. package/lib/services/tools/fetch.mocks.d.ts +0 -8
  179. package/lib/services/tools/fetch.mocks.js +0 -35
  180. package/lib/types/skills.d.ts +0 -7
  181. package/src/actions/data/skills.ts +0 -24
  182. package/src/middlewares/on-start-app.ts +0 -42
  183. package/src/services/fetch-skills.mock.ts +0 -21
  184. package/src/services/fetch-skills.test.ts +0 -32
  185. package/src/services/tools/fetch.mocks.ts +0 -41
  186. package/src/types/skills.ts +0 -8
  187. /package/es/services/{fetch-skills.test.d.ts → test/fetch-skills.test.d.ts} +0 -0
  188. /package/es/{index.test.d.ts → services/test/post-progression.test.d.ts} +0 -0
  189. /package/{lib → es/test}/index.test.d.ts +0 -0
  190. /package/es/types/{skills.js → ui-progression.js} +0 -0
  191. /package/lib/services/{fetch-skills.test.d.ts → test/fetch-skills.test.d.ts} +0 -0
  192. /package/lib/{types/skills.js → services/test/post-progression.test.d.ts} +0 -0
@@ -0,0 +1,10 @@
1
+ import { Action } from 'redux';
2
+ import { Skill } from '../../types/common';
3
+ export declare const SKILLS_FETCH_REQUEST: "@@skills/FETCH_REQUEST";
4
+ export declare const SKILLS_FETCH_SUCCESS: "@@skills/FETCH_SUCCESS";
5
+ export declare const SKILLS_FETCH_FAILURE: "@@skills/FETCH_FAILURE";
6
+ export declare type ReceivedSkills = {
7
+ type: '@@skills/FETCH_SUCCESS';
8
+ payload: Skill[];
9
+ };
10
+ export declare const fetchSkills: (token: string) => Action;
@@ -0,0 +1,8 @@
1
+ import buildTask from '@coorpacademy/redux-task';
2
+ export const SKILLS_FETCH_REQUEST = '@@skills/FETCH_REQUEST';
3
+ export const SKILLS_FETCH_SUCCESS = '@@skills/FETCH_SUCCESS';
4
+ export const SKILLS_FETCH_FAILURE = '@@skills/FETCH_FAILURE';
5
+ export const fetchSkills = (token) => buildTask({
6
+ types: [SKILLS_FETCH_REQUEST, SKILLS_FETCH_SUCCESS, SKILLS_FETCH_FAILURE],
7
+ task: (dispatch, getState, { services }) => services.fetchSkills(token)
8
+ });
@@ -0,0 +1,10 @@
1
+ import type { Action } from 'redux';
2
+ import { SlideFromAPI } from '../../types/common';
3
+ export declare const SLIDE_FETCH_REQUEST: "@@slides/FETCH_REQUEST";
4
+ export declare const SLIDE_FETCH_SUCCESS: "@@slides/FETCH_SUCCESS";
5
+ export declare const SLIDE_FETCH_FAILURE: "@@slides/FETCH_FAILURE";
6
+ export declare type ReceivedSlide = {
7
+ type: typeof SLIDE_FETCH_SUCCESS;
8
+ payload: SlideFromAPI;
9
+ };
10
+ export declare const fetchSlide: (slideRef: string, token: string) => Action;
@@ -0,0 +1,8 @@
1
+ import buildTask from '@coorpacademy/redux-task';
2
+ export const SLIDE_FETCH_REQUEST = '@@slides/FETCH_REQUEST';
3
+ export const SLIDE_FETCH_SUCCESS = '@@slides/FETCH_SUCCESS';
4
+ export const SLIDE_FETCH_FAILURE = '@@slides/FETCH_FAILURE';
5
+ export const fetchSlide = (slideRef, token) => buildTask({
6
+ types: [SLIDE_FETCH_REQUEST, SLIDE_FETCH_SUCCESS, SLIDE_FETCH_FAILURE],
7
+ task: (dispatch, getState, { services }) => services.fetchSlide(slideRef, token)
8
+ });
@@ -0,0 +1,10 @@
1
+ import type { Action } from 'redux';
2
+ import { ProgressionFromAPI } from '../../types/common';
3
+ export declare const POST_PROGRESSION_REQUEST: "@@progression/POST_REQUEST";
4
+ export declare const POST_PROGRESSION_SUCCESS: "@@progression/POST_SUCCESS";
5
+ export declare const POST_PROGRESSION_FAILURE: "@@progression/POST_FAILURE";
6
+ export declare type ReceiveProgression = {
7
+ type: typeof POST_PROGRESSION_SUCCESS;
8
+ payload: ProgressionFromAPI;
9
+ };
10
+ export declare const postProgression: (skillRef: string, token: string) => Action;
@@ -0,0 +1,15 @@
1
+ import buildTask from '@coorpacademy/redux-task';
2
+ import { fetchSlide } from './fetch-slide';
3
+ export const POST_PROGRESSION_REQUEST = '@@progression/POST_REQUEST';
4
+ export const POST_PROGRESSION_SUCCESS = '@@progression/POST_SUCCESS';
5
+ export const POST_PROGRESSION_FAILURE = '@@progression/POST_FAILURE';
6
+ export const postProgression = (skillRef, token) => buildTask({
7
+ types: [POST_PROGRESSION_REQUEST, POST_PROGRESSION_SUCCESS, POST_PROGRESSION_FAILURE],
8
+ task: (dispatch, getState, { services }) => {
9
+ return services.postProgression(skillRef, token).then((progression) => {
10
+ const { ref } = progression.state.nextContent;
11
+ dispatch(fetchSlide(ref, token));
12
+ return progression;
13
+ });
14
+ }
15
+ });
@@ -1,36 +1,24 @@
1
- import { Slide as SlideFromAPI } from '../../types/slides';
2
- export declare const STORE_FIRST_SLIDE = "@@slide/STORE_FIRST_SLIDE";
1
+ import { UISlide } from '../../types/slides';
2
+ import { ReceivedSlide } from '../api/fetch-slide';
3
3
  export declare const UPDATE_SLIDES_ON_VALIDATION = "@@slide/UPDATE_SLIDES_ON_VALIDATION";
4
4
  export declare const UPDATE_SLIDES_ON_NEXT = "@@slide/UPDATE_SLIDES_ON_NEXT";
5
5
  export declare const VALIDATE_SLIDE = "@@slide/VALIDATE";
6
- export declare const FETCH_NEXT_CONTENT = "@@slide/FETCH_NEXT_CONTENT";
7
6
  declare type SlideUIAnimations = 'unstack' | 'restack';
8
- export declare type Slide = SlideFromAPI & {
7
+ export declare type Slide = UISlide & {
9
8
  hidden?: boolean;
10
9
  position: number;
11
10
  animationType?: SlideUIAnimations;
12
11
  isCorrect?: boolean;
13
12
  endReview?: boolean;
14
- nextSlide?: Omit<Slide, 'endReview' | 'hidden' | 'position' | 'nextSlide'>;
13
+ nextContent?: Omit<Slide, 'endReview' | 'hidden' | 'position' | 'nextContent'>;
15
14
  };
16
15
  export declare type ValidationPayload = {
17
16
  slideNumber: number;
18
17
  newSlideContent: Slide;
19
18
  numberOfFinishedSlides: number;
20
- nextSlide: Slide;
21
- };
22
- export declare type OnNextPayload = Omit<ValidationPayload, 'nextSlide'>;
23
- export declare type FetchNextPayload = {
24
- answer: string[];
25
- content: {
26
- ref: string;
27
- type: string;
28
- };
29
- };
30
- export declare type StoreFirstSlide = {
31
- type: typeof STORE_FIRST_SLIDE;
32
- payload: SlideFromAPI;
19
+ nextContent: Slide;
33
20
  };
21
+ export declare type OnNextPayload = Omit<ValidationPayload, 'nextContent'>;
34
22
  export declare type UpdateSlidesOnValidation = {
35
23
  type: typeof UPDATE_SLIDES_ON_VALIDATION;
36
24
  payload: ValidationPayload;
@@ -42,12 +30,7 @@ export declare type UpdateSlidesOnNext = {
42
30
  export declare type ValidateSlide = {
43
31
  type: typeof VALIDATE_SLIDE;
44
32
  };
45
- export declare type FetchNextContent = {
46
- type: typeof FETCH_NEXT_CONTENT;
47
- payload: FetchNextPayload;
48
- };
49
- export declare type SlidesAction = StoreFirstSlide | UpdateSlidesOnValidation | UpdateSlidesOnNext;
50
- export declare const storeFirstSlide: (slide: SlideFromAPI) => StoreFirstSlide;
33
+ export declare type SlidesAction = ReceivedSlide | UpdateSlidesOnValidation | UpdateSlidesOnNext;
51
34
  export declare const updateSlidesOnValidation: (payload: ValidationPayload) => UpdateSlidesOnValidation;
52
35
  export declare const updateSlidesOnNext: (payload: OnNextPayload) => UpdateSlidesOnNext;
53
36
  export declare const validateSlide: () => ValidateSlide;
@@ -1,14 +1,8 @@
1
1
  // -----------------------------------------------------------------------------
2
- export const STORE_FIRST_SLIDE = '@@slide/STORE_FIRST_SLIDE';
3
2
  export const UPDATE_SLIDES_ON_VALIDATION = '@@slide/UPDATE_SLIDES_ON_VALIDATION';
4
3
  export const UPDATE_SLIDES_ON_NEXT = '@@slide/UPDATE_SLIDES_ON_NEXT';
5
4
  export const VALIDATE_SLIDE = '@@slide/VALIDATE';
6
- export const FETCH_NEXT_CONTENT = '@@slide/FETCH_NEXT_CONTENT';
7
5
  // -----------------------------------------------------------------------------
8
- export const storeFirstSlide = (slide) => ({
9
- type: STORE_FIRST_SLIDE,
10
- payload: slide
11
- });
12
6
  export const updateSlidesOnValidation = (payload) => ({
13
7
  type: UPDATE_SLIDES_ON_VALIDATION,
14
8
  payload
@@ -1,6 +1,6 @@
1
- export declare const STORE_TOKEN = "@@token/STORE_TOKEN";
1
+ export declare const STORE_TOKEN = "@@data/token/STORE_TOKEN";
2
2
  export declare type StoreToken = {
3
- type: '@@token/STORE_TOKEN';
3
+ type: typeof STORE_TOKEN;
4
4
  payload: string;
5
5
  };
6
6
  export declare const storeToken: (token: string) => StoreToken;
@@ -1,4 +1,4 @@
1
- export const STORE_TOKEN = '@@token/STORE_TOKEN';
1
+ export const STORE_TOKEN = '@@data/token/STORE_TOKEN';
2
2
  export const storeToken = (token) => ({
3
3
  type: STORE_TOKEN,
4
4
  payload: token
@@ -1,11 +1,13 @@
1
- import { StoreFirstSlide, updateSlidesOnValidation, updateSlidesOnNext, validateSlide } from './data/slides';
2
- import { ErrorFetchingSkills, ReceivedSkills } from './data/skills';
1
+ import { updateSlidesOnValidation, updateSlidesOnNext, validateSlide } from './data/slides';
3
2
  import { StoreToken } from './data/token';
4
3
  import { updateFinishedSlides } from './ui/finished-slides';
5
4
  import { navigateBack, navigateTo, NavigateBack, NavigateTo, StartApp } from './ui/navigation';
6
5
  import { updateReviewStatus } from './ui/review-status';
7
6
  import { updateStepItemsOnValidation, updateStepItemsOnNext } from './ui/step-items';
8
- export declare type Action = NavigateBack | NavigateTo | ReceivedSkills | ErrorFetchingSkills | StartApp | StoreFirstSlide | StoreToken;
7
+ import { ReceivedSlide } from './api/fetch-slide';
8
+ import { ReceiveProgression } from './api/post-progression';
9
+ import { ReceivedSkills } from './api/fetch-skills';
10
+ export declare type Action = NavigateBack | NavigateTo | ReceivedSkills | StartApp | ReceivedSlide | StoreToken | ReceiveProgression;
9
11
  export declare type Dispatchers = {
10
12
  navigateTo: typeof navigateTo;
11
13
  navigateBack: typeof navigateBack;
@@ -16,4 +16,3 @@ export declare type StartApp = {
16
16
  };
17
17
  export declare const navigateTo: (newPath: ViewPath) => NavigateTo;
18
18
  export declare const navigateBack: () => NavigateBack;
19
- export declare const startApp: (options: AppOptions) => StartApp;
@@ -8,7 +8,3 @@ export const navigateTo = (newPath) => ({
8
8
  export const navigateBack = () => ({
9
9
  type: NAVIGATE_BACK
10
10
  });
11
- export const startApp = (options) => ({
12
- type: START_APP,
13
- payload: options
14
- });
@@ -1,19 +1,13 @@
1
- import { FinishedSlidesState } from '../../reducers/ui/finished-slides';
1
+ import { FinishedSlides, IconValue } from '../../types/common';
2
2
  export declare const UPDATE_STEP_ITEMS_ON_VALIDATION = "@@step-items/UPDATE_STEP_ITEMS_ON_VALIDATION";
3
3
  export declare const UPDATE_STEP_ITEMS_ON_NEXT = "@@step-items/UPDATE_STEP_ITEMS_ON_NEXT";
4
- declare const ICON_VALUES: {
5
- readonly right: "right";
6
- readonly wrong: "wrong";
7
- readonly 'no-answer': "no-answer";
8
- };
9
- export declare type IconValue = keyof typeof ICON_VALUES;
10
4
  declare type UpdateStepItemsOnValidationClickPayload = {
11
5
  stepNumber: number;
12
6
  icon: IconValue;
13
7
  };
14
8
  declare type UpdateStepItemsOnNextClickPayload = {
15
9
  stepNumber: number;
16
- finishedSlides: FinishedSlidesState;
10
+ finishedSlides: FinishedSlides;
17
11
  current: boolean;
18
12
  };
19
13
  export declare type UpdateStepItemsOnValidation = {
@@ -1,11 +1,5 @@
1
- // -----------------------------------------------------------------------------
2
1
  export const UPDATE_STEP_ITEMS_ON_VALIDATION = '@@step-items/UPDATE_STEP_ITEMS_ON_VALIDATION';
3
2
  export const UPDATE_STEP_ITEMS_ON_NEXT = '@@step-items/UPDATE_STEP_ITEMS_ON_NEXT';
4
- const ICON_VALUES = {
5
- right: 'right',
6
- wrong: 'wrong',
7
- 'no-answer': 'no-answer'
8
- };
9
3
  // -----------------------------------------------------------------------------
10
4
  export const updateStepItemsOnValidation = (payload) => ({
11
5
  type: UPDATE_STEP_ITEMS_ON_VALIDATION,
@@ -1,35 +1,4 @@
1
1
  import { AnyAction, Store } from 'redux';
2
- import { SkillsState } from './reducers/data/skills';
3
- import { SlidesState } from './reducers/data/slides';
4
- import { TokenState } from './reducers/data/token';
5
- import { NavigationState } from './reducers/ui/navigation';
6
- import { ReviewStatusState } from './reducers/ui/review-status';
7
- import { StepItemsState } from './reducers/ui/step-items';
8
- import { FinishedSlidesState } from './reducers/ui/finished-slides';
9
- import { AnswerUI } from './types/slides';
10
- declare type DataState = {
11
- isFetching?: boolean;
12
- progression?: {
13
- slideNumber: number;
14
- isCorrect?: boolean;
15
- exitNode?: 'successExitNode' | 'failExitNode';
16
- nextSlide?: {
17
- questionText?: string;
18
- answerUI?: AnswerUI;
19
- };
20
- } | null;
21
- skills: SkillsState;
22
- slides: SlidesState;
23
- token?: TokenState;
24
- };
25
- export declare type StoreState = {
26
- ui: {
27
- navigation: NavigationState;
28
- stepItems: StepItemsState;
29
- finishedSlides: FinishedSlidesState;
30
- reviewStatus: ReviewStatusState;
31
- };
32
- data: DataState;
33
- };
34
- export default function configureStore(): Store<StoreState, AnyAction>;
35
- export {};
2
+ import { StoreState } from './reducers';
3
+ import { AppOptions } from './types/common';
4
+ export default function configureStore(options: AppOptions): Store<StoreState, AnyAction>;
@@ -1,9 +1,8 @@
1
1
  import { applyMiddleware, compose, createStore } from 'redux';
2
2
  import thunk from 'redux-thunk';
3
3
  import rootReducer from './reducers';
4
- import onStartApp from './middlewares/on-start-app';
5
- // -----------------------------------------------------------------------------
6
- export default function configureStore() {
4
+ import { getServices } from './services';
5
+ export default function configureStore(options) {
7
6
  const _compose = window.__REDUX_DEVTOOLS_EXTENSION_COMPOSE__
8
7
  ? window.__REDUX_DEVTOOLS_EXTENSION_COMPOSE__({
9
8
  name: 'app-review',
@@ -11,7 +10,8 @@ export default function configureStore() {
11
10
  traceLimit: 25
12
11
  })
13
12
  : compose;
14
- const enhancer = _compose(applyMiddleware(thunk, onStartApp));
13
+ const thunkMiddleware = thunk.withExtraArgument({ services: options.services || getServices() });
14
+ const enhancer = _compose(applyMiddleware(thunkMiddleware));
15
15
  const store = createStore(rootReducer, undefined, enhancer);
16
16
  return store;
17
17
  }
@@ -1,2 +1,2 @@
1
- import { Slide } from '../types/slides';
2
- export declare const slide: Slide;
1
+ import { UISlide } from '../types/slides';
2
+ export declare const slide: UISlide;
package/es/index.d.ts CHANGED
@@ -1,7 +1,7 @@
1
1
  import type { AppOptions } from './types/common';
2
2
  declare const AppReview: ({ options }: {
3
3
  options: AppOptions;
4
- }) => JSX.Element;
4
+ }) => JSX.Element | null;
5
5
  declare global {
6
6
  interface Window {
7
7
  __REDUX_DEVTOOLS_EXTENSION__?: boolean;
package/es/index.js CHANGED
@@ -1,13 +1,18 @@
1
1
  import React, { useEffect, useState } from 'react';
2
2
  import { connect, Provider } from 'react-redux';
3
3
  import AppReviewTemplate from '@coorpacademy/components/es/template/app-review';
4
+ import { TemplateContext } from '@coorpacademy/components/es/template/app-review/template-context';
4
5
  import configureStore from './configure-store';
5
6
  import { congratsProps, correctionPopinProps } from './fixtures/temp-fixture';
6
7
  import { updateSlidesOnNext, updateSlidesOnValidation, validateSlide } from './actions/data/slides';
7
- import { navigateTo, navigateBack, startApp } from './actions/ui/navigation';
8
+ import { navigateTo, navigateBack } from './actions/ui/navigation';
9
+ import { storeToken } from './actions/data/token';
8
10
  import { updateFinishedSlides } from './actions/ui/finished-slides';
9
11
  import { updateReviewStatus } from './actions/ui/review-status';
10
12
  import { updateStepItemsOnValidation, updateStepItemsOnNext } from './actions/ui/step-items';
13
+ import { fetchSkills } from './actions/api/fetch-skills';
14
+ import { postProgression } from './actions/api/post-progression';
15
+ import { VIEWS } from './common';
11
16
  // -----------------------------------------------------------------------------
12
17
  const mapDispatchToProps = {
13
18
  navigateTo,
@@ -21,29 +26,38 @@ const mapDispatchToProps = {
21
26
  updateFinishedSlides
22
27
  };
23
28
  const getCurrentViewName = (storeState) => storeState.ui.navigation[storeState.ui.navigation.length - 1];
24
- const mapStateToSkillsProps = (state) => ({
25
- title: '@todo title',
26
- titleNoSkills: '@todo titleNoSkills',
27
- textNoSkills: '@todo textNoSkills',
28
- iconSkillAriaLabel: '@todo iconSkillAriaLabel',
29
- isLoading: false,
30
- isLoadingAriaLabel: '@todo loading',
31
- listSkills: state.data.skills.map(skill => ({
32
- 'aria-label': '',
33
- isCustom: skill.custom,
34
- skillTitle: skill.name,
35
- skillAriaLabel: '@todo skill aria label',
36
- buttonLabel: '@todo button',
37
- buttonAriaLabel: '@todo button aria label',
38
- reviseLabel: '@todo revise',
39
- reviseAriaLabel: '@todo revise aria label',
40
- // eslint-disable-next-line no-console
41
- onClick: () => console.log('@todo plug dispatcher select skill')
42
- }))
43
- });
44
- const mapStateToProps = (state) => ({
45
- viewName: getCurrentViewName(state),
46
- slides: {
29
+ // -----------------------------------------------------------------------------
30
+ const mapStateToSkillsProps = (state) => {
31
+ if (!state.data.skills) {
32
+ return null;
33
+ }
34
+ return {
35
+ title: '@todo title',
36
+ titleNoSkills: '@todo titleNoSkills',
37
+ textNoSkills: '@todo textNoSkills',
38
+ iconSkillAriaLabel: '@todo iconSkillAriaLabel',
39
+ isLoading: false,
40
+ isLoadingAriaLabel: '@todo loading',
41
+ listSkills: state.data.skills.map(skill => ({
42
+ 'aria-label': '',
43
+ isCustom: skill.custom,
44
+ skillTitle: skill.name,
45
+ skillAriaLabel: '@todo skill aria label',
46
+ buttonLabel: '@todo button',
47
+ buttonAriaLabel: '@todo button aria label',
48
+ reviseLabel: '@todo revise',
49
+ reviseAriaLabel: '@todo revise aria label',
50
+ // eslint-disable-next-line no-console
51
+ onClick: () => console.log('@todo plug dispatcher select skill')
52
+ }))
53
+ };
54
+ };
55
+ // -----------------------------------------------------------------------------
56
+ const mapStateToSlidesProps = (state) => {
57
+ if (!state.data.slides) {
58
+ return null;
59
+ }
60
+ return {
47
61
  headerProps: {
48
62
  mode: '__revision_mode',
49
63
  skillName: '__agility',
@@ -64,32 +78,54 @@ const mapStateToProps = (state) => ({
64
78
  correctionPopinProps,
65
79
  congratsProps,
66
80
  progression: state.data.progression
67
- },
68
- skills: mapStateToSkillsProps(state)
69
- });
81
+ };
82
+ };
83
+ // -----------------------------------------------------------------------------
84
+ const mapStateToProps = (state) => {
85
+ return {
86
+ viewName: getCurrentViewName(state),
87
+ slides: mapStateToSlidesProps(state),
88
+ skills: mapStateToSkillsProps(state)
89
+ };
90
+ };
70
91
  // Props = StaticProps && Dispatchers
71
92
  const App = connect(mapStateToProps, mapDispatchToProps)(AppReviewTemplate);
72
93
  // -----------------------------------------------------------------------------
73
94
  const AppReview = ({ options }) => {
74
95
  const [store, setStore] = useState(null);
75
- const [appStarted, setAppStarted] = useState(false);
76
96
  useEffect(() => {
77
- if (store) {
78
- store.dispatch(startApp(options));
79
- setAppStarted(true);
80
- }
81
- else {
82
- const _configure = async () => {
83
- const newStore = await configureStore();
84
- setStore(newStore);
85
- };
86
- _configure();
87
- }
97
+ if (store)
98
+ return;
99
+ const newStore = configureStore(options);
100
+ setStore(newStore);
101
+ }, [options, store]);
102
+ useEffect(() => {
103
+ if (store === null)
104
+ return;
105
+ const { skillRef } = options;
106
+ const initialView = skillRef ? VIEWS.slides : VIEWS.skills;
107
+ store.dispatch(navigateTo(initialView));
108
+ }, [options, store]);
109
+ useEffect(() => {
110
+ if (store === null)
111
+ return;
112
+ const { token } = options;
113
+ store.dispatch(storeToken(token));
114
+ }, [options, store]);
115
+ useEffect(() => {
116
+ if (store === null)
117
+ return;
118
+ const { skillRef, token } = options;
119
+ skillRef
120
+ ? store.dispatch(postProgression(skillRef, token))
121
+ : store.dispatch(fetchSkills(token));
88
122
  }, [options, store]);
89
- if (!store || !appStarted)
90
- return React.createElement("div", null);
123
+ if (!store)
124
+ return null;
125
+ const { templateContext: values } = options;
91
126
  return (React.createElement(Provider, { store: store },
92
- React.createElement(App, null)));
127
+ React.createElement(TemplateContext, { values: values },
128
+ React.createElement(App, null))));
93
129
  };
94
130
  // -----------------------------------------------------------------------------
95
131
  export default AppReview;
@@ -1,7 +1,18 @@
1
+ import { ProgressionState } from './progression';
2
+ import { SkillsState } from './skills';
3
+ import { SlidesState } from './slides';
4
+ import { TokenState } from './token';
5
+ export declare type DataState = {
6
+ isFetching?: boolean;
7
+ progression?: ProgressionState;
8
+ skills: SkillsState;
9
+ slides: SlidesState;
10
+ token?: TokenState;
11
+ };
1
12
  declare const _default: import("redux").Reducer<import("redux").CombinedState<{
2
- progression: import("./progression").ProgressionState;
3
- skills: import("../../types/skills").Skills;
4
- slides: import("./slides").SlidesState;
5
- token: import("./token").TokenState;
6
- }>, import("../../actions/data/slides").ValidateSlide | import("../../actions/data/slides").SlidesAction | import("../../actions/data/skills").ReceivedSkills | import("../../actions/data/token").StoreToken>;
13
+ progression: ProgressionState;
14
+ skills: SkillsState;
15
+ slides: SlidesState;
16
+ token: TokenState;
17
+ }>, import("../../actions/data/slides").ValidateSlide | import("../../actions/data/slides").SlidesAction | import("../../actions/api/post-progression").ReceiveProgression | import("../../actions/api/fetch-skills").ReceivedSkills | import("../../actions/data/token").StoreToken>;
7
18
  export default _default;
@@ -1,14 +1,19 @@
1
1
  import { ValidateSlide } from '../../actions/data/slides';
2
- import { AnswerUI } from '../../types/slides';
2
+ import { ReceiveProgression } from '../../actions/api/post-progression';
3
3
  export declare type ProgressionState = {
4
- slideNumber: number;
5
- isCorrect?: boolean;
6
- exitNode?: 'successExitNode' | 'failExitNode';
7
- nextSlide?: {
8
- questionText?: string;
9
- answerUI?: AnswerUI;
4
+ _id?: string;
5
+ state: {
6
+ isCorrect: boolean;
7
+ nextContent: {
8
+ ref: 'successExitNode' | string;
9
+ type: 'success' | 'slide';
10
+ };
11
+ pendingSlides: string[];
12
+ step: {
13
+ current: number;
14
+ };
10
15
  };
16
+ slideNumber?: number;
11
17
  } | null;
12
- export declare const initialState: ProgressionState;
13
- declare const reducer: (state: ProgressionState | undefined, action: ValidateSlide) => ProgressionState;
18
+ declare const reducer: (state: ProgressionState | undefined, action: ValidateSlide | ReceiveProgression) => ProgressionState;
14
19
  export default reducer;
@@ -1,75 +1,35 @@
1
- import { getOr, noop } from 'lodash/fp';
1
+ import { getOr } from 'lodash/fp';
2
2
  import { VALIDATE_SLIDE } from '../../actions/data/slides';
3
- // -----------------------------------------------------------------------------
4
- export const initialState = null;
5
- // -----------------------------------------------------------------------------
3
+ import { POST_PROGRESSION_SUCCESS } from '../../actions/api/post-progression';
6
4
  const reducer = (
7
5
  // eslint-disable-next-line default-param-last
8
- state = initialState, action) => {
6
+ state = null, action) => {
9
7
  switch (action.type) {
10
8
  case VALIDATE_SLIDE: {
11
9
  const previousSlideNumber = getOr(-1, 'slideNumber', state);
12
10
  // hard coded for now
11
+ // TODO: fix on VALIDATE ticket
13
12
  return {
13
+ _id: '1234',
14
14
  // virtual field
15
15
  slideNumber: previousSlideNumber + 1,
16
- isCorrect: true,
17
- // exitNode
18
- // TODO: create another action, to retrieve the next slide
19
- // nextSlide should be corrected to nextContent, when this new action is created
20
- // ex: nextContent: {ref: "sli_E1n2i2sBo", type: "slide"}
21
- // the middleware should trigger a next content request once the result is
22
- // received && update the state accordingly,
23
- //
24
- nextSlide: {
25
- questionText: 'Test',
26
- answerUI: {
27
- model: {
28
- answers: [
29
- {
30
- title: 'There is no need for a password',
31
- // TODO: onClick of each answer should use a dispatcher to
32
- // update selected answers (in order to use them on validation)
33
- // in each retrieval, the answers of answerUI need to be augmented
34
- // for the onClick prop to achieve this.
35
- onClick: noop,
36
- selected: false,
37
- help: 'help'
38
- },
39
- {
40
- title: 'Lorem ipsum',
41
- onClick: noop,
42
- selected: false,
43
- help: 'help'
44
- },
45
- {
46
- title: 'Lorem',
47
- onClick: noop,
48
- selected: true,
49
- order: 1,
50
- help: 'help'
51
- },
52
- {
53
- title: 'You need to have a password',
54
- onClick: noop,
55
- selected: false,
56
- help: 'help'
57
- },
58
- {
59
- title: 'Pouet',
60
- onClick: noop,
61
- selected: true,
62
- order: 0,
63
- help: 'help'
64
- }
65
- ],
66
- type: 'qcmDrag'
67
- },
68
- help: 'Help text will appear here'
16
+ state: {
17
+ pendingSlides: [],
18
+ step: {
19
+ current: Number.NaN
20
+ },
21
+ isCorrect: true,
22
+ nextContent: {
23
+ ref: 'sli_V1gKpYYZ2',
24
+ type: 'slide'
69
25
  }
70
26
  }
71
27
  };
72
28
  }
29
+ case POST_PROGRESSION_SUCCESS: {
30
+ const progression = action.payload;
31
+ return progression;
32
+ }
73
33
  default:
74
34
  return state;
75
35
  }
@@ -1,6 +1,5 @@
1
- import { ReceivedSkills } from '../../actions/data/skills';
2
- import { Skills } from '../../types/skills';
3
- export declare type SkillsState = Skills;
4
- export declare const initialState: SkillsState;
5
- declare const reducer: (state: Skills | undefined, action: ReceivedSkills) => Skills;
1
+ import { Skill } from '../../types/common';
2
+ import { ReceivedSkills } from '../../actions/api/fetch-skills';
3
+ export declare type SkillsState = Skill[];
4
+ declare const reducer: (state: SkillsState | undefined, action: ReceivedSkills) => SkillsState;
6
5
  export default reducer;