@@ -5,47 +5,59 @@ import * as G from 'typings/graphql'
55import Stage from './Stage'
66
77interface PageProps {
8- context :CR . MachineContext
8+ context :CR . MachineContext
99send ( action :CR . Action ) :void
1010}
1111
1212const StageSummaryPageContainer = ( props :PageProps ) => {
13- const { tutorial, position, progress} = props . context
13+ const { tutorial, position, progress} = props . context
14+
15+ if ( ! tutorial ) {
16+ throw new Error ( 'Tutorial not found in StageSummaryPageContainer' )
17+ }
18+
19+ const level :G . Level | undefined = tutorial . version . levels . find ( ( l :G . Level ) => l . id === position . levelId )
20+
21+ if ( ! level ) {
22+ throw new Error ( 'Level not found in StageSummaryPageContainer' )
23+ }
24+
25+ const stage :G . Stage | undefined = level . stages . find ( ( s :G . Stage ) => s . id === position . stageId )
26+
27+ if ( ! stage ) {
28+ throw new Error ( 'Stage not found in StageSummaryPageContainer' )
29+ }
1430
15- const stage :G . Stage = tutorial . version
16- . levels . find ( ( l :G . Level ) => l . id === position . levelId )
17- . stages . find ( ( s :G . Stage ) => s . id === position . stageId )
18-
1931const onContinue = ( ) :void => {
2032props . send ( {
21- type :'STAGE_NEXT' ,
22- payload :{
23- stageId :position . stageId ,
24- }
25- } )
26- }
27-
28- const onSave = ( ) :void => {
29- props . send ( {
30- type :'TEST_RUN' ,
31- payload :{
32- stepId :position . stepId ,
33- }
34- } )
35- }
36-
37- stage . steps . forEach ( ( step :G . Step ) => {
38- if ( progress . steps [ step . id ] ) {
39- step . status = 'COMPLETE'
40- } else if ( step . id === position . stepId ) {
41- step . status = 'ACTIVE'
42- } else {
43- step . status = 'INCOMPLETE'
44- }
45- } )
46- stage . status = progress . stages [ position . stageId ] ?'COMPLETE' :'ACTIVE'
47-
48- return < Stage stage = { stage } onContinue = { onContinue } onSave = { onSave } />
33+ type :'STAGE_NEXT' ,
34+ payload :{
35+ stageId :position . stageId ,
36+ } ,
37+ } )
38+ }
39+
40+ const onSave = ( ) :void => {
41+ props . send ( {
42+ type :'TEST_RUN' ,
43+ payload :{
44+ stepId :position . stepId ,
45+ } ,
46+ } )
47+ }
48+
49+ stage . steps . forEach ( ( step :G . Step ) => {
50+ if ( progress . steps [ step . id ] ) {
51+ step . status = 'COMPLETE'
52+ } else if ( step . id === position . stepId ) {
53+ step . status = 'ACTIVE'
54+ } else {
55+ step . status = 'INCOMPLETE'
56+ }
57+ } )
58+ stage . status = progress . stages [ position . stageId ] ?'COMPLETE' :'ACTIVE'
59+
60+ return < Stage stage = { stage } onContinue = { onContinue } onSave = { onSave } />
4961}
5062
5163export default StageSummaryPageContainer