@@ -3,18 +3,20 @@ import moment from 'moment';
3
3
import { connect } from 'react-redux' ;
4
4
import { cloneDeep } from 'lodash' ;
5
5
6
+ import BlockList from './BlockList' ;
7
+ import CommitBlock from './CommitBlock' ;
8
+ import Flex from './Flex' ;
9
+ import LoadingDots from './Loading' ;
6
10
import ScheduleHeader from './ScheduleHeader' ;
7
11
import SideBar from './SideBar' ;
8
- import Flex from './Flex' ;
9
- import SetBlock from './SetBlock' ;
10
12
import Text from './Text' ;
11
- import LoadingDots from './Loading' ;
12
- import CommitBlock from './CommitBlock' ;
13
- import { DEFAULT_SETBLOCKS } from '../constants/index' ;
13
+
14
+ import { DEFAULT_SETBLOCKS } from '../constants' ;
14
15
15
16
import {
16
17
fetchCurrentTeamMemberById ,
17
18
setEditModeSchedule ,
19
+ setEnableSubmit ,
18
20
setSelectedDay ,
19
21
updateUnsavedSetblocks
20
22
} from '../reducers/environment' ;
@@ -23,7 +25,6 @@ import {
23
25
class SchedulePage extends React . Component {
24
26
state = {
25
27
daysOfWeek : [ ] ,
26
- enableSubmit : false ,
27
28
}
28
29
29
30
componentDidMount ( ) {
@@ -69,7 +70,7 @@ class SchedulePage extends React.Component {
69
70
// This only take effect if change the currentTeamMember
70
71
if ( ( editModeSchedule && currentTeamMember !== nextProps . currentTeamMember ) || selectedDay !== nextProps . selectedDay ) {
71
72
this . makeSetBlocksForEdit ( nextProps . currentWeeklySetblocks ) ;
72
- this . setState ( { enableSubmit : false } )
73
+ this . props . setEnableSubmit ( false )
73
74
}
74
75
}
75
76
@@ -86,61 +87,21 @@ class SchedulePage extends React.Component {
86
87
let replacedBlocks = 0 ;
87
88
setBlocks = _ . orderBy ( setBlocks , [ 'blockTime' ] , [ 'asc' ] ) ; // Use Lodash to sort array by 'name'
88
89
setBlocks = _ . uniqBy ( setBlocks , 'blockTime' ) ; // Use Lodash to delete repeated blockTimes
89
- defaultSetBlocks . forEach ( ( setBlock , index , theArray ) => {
90
- if ( setBlocks && replacedBlocks < setBlocks . length && setBlock . blockTime === setBlocks [ replacedBlocks ] . blockTime ) {
91
- theArray [ index ] = setBlocks [ replacedBlocks ] ;
92
- replacedBlocks ++ ;
93
- }
94
- } ) ;
95
- return defaultSetBlocks
96
- }
97
-
98
- updateUnsavedSetBlock ( selectedDay , index , editedSetBlock ) {
99
- const { unsavedSetBlocks } = this . props
100
- let dayEdited = unsavedSetBlocks [ selectedDay ] ;
101
- dayEdited [ index ] = editedSetBlock ; // index 0 = SetBlock with blockTime 1
102
- this . props . updateUnsavedSetblocks ( {
103
- ...unsavedSetBlocks ,
104
- [ selectedDay ] : dayEdited
105
- } )
106
- this . setState ( { enableSubmit : true } )
107
- }
108
-
109
- renderSetBlocks = ( selectedDay ) => {
110
- const { editModeSchedule, currentWeeklySetblocks, unsavedSetBlocks } = this . props ;
111
- selectedDay = moment ( selectedDay ) . format ( 'YYYY-MM-DD' )
112
- const setBlocksByDate = _ . groupBy ( currentWeeklySetblocks , 'date' )
113
- let setBlocks = setBlocksByDate [ selectedDay ] ;
114
-
115
- if ( editModeSchedule && unsavedSetBlocks ) {
116
- // If the match.params don't have a teamMemberId are u seeing your schedule
117
- // As it is your schedule, you can see the empty blocks, to complete then, that's why it is completed with the missing ones
118
- return this . completeWithEmptySetBlocks ( setBlocks ) . map ( ( setBlock , index ) => {
119
- return (
120
- < SetBlock
121
- data = { setBlock }
122
- key = { setBlock . id || ( index + selectedDay ) }
123
- editMode = { editModeSchedule }
124
- updateSetBlock = { ( editedSetBlock ) => this . updateUnsavedSetBlock ( selectedDay , index , editedSetBlock ) }
125
- />
126
- )
127
- } )
128
- } else if ( ! editModeSchedule && setBlocks ) {
129
- return setBlocks . map ( ( setBlock , index ) => {
130
- return < SetBlock data = { setBlock } key = { setBlock . id || index } />
131
- } )
132
- } else {
133
- return (
134
- < Text weight = '600' align = 'center' > This user hasn't committed any Setblocks for this day </ Text >
135
- )
90
+ if ( setBlocks && setBlocks . length > 0 ) { // To avoid iterate if the array is empty, return default
91
+ defaultSetBlocks . forEach ( ( setBlock , index , theArray ) => {
92
+ if ( setBlocks && replacedBlocks < setBlocks . length && setBlock . blockTime === setBlocks [ replacedBlocks ] . blockTime ) {
93
+ theArray [ index ] = setBlocks [ replacedBlocks ] ;
94
+ replacedBlocks ++ ;
95
+ }
96
+ } ) ;
136
97
}
98
+ return defaultSetBlocks
137
99
}
138
100
139
101
renderIfItReady ( ) {
140
102
const {
141
- match, currentTeamMember, fetchingData, selectedDay , editModeSchedule
103
+ match, currentTeamMember, fetchingData, editModeSchedule , enableSubmit
142
104
} = this . props
143
- const { enableSubmit } = this . state
144
105
145
106
if ( fetchingData ) {
146
107
return ( // If you are waiting for the API to respond, render a loading
@@ -161,7 +122,7 @@ class SchedulePage extends React.Component {
161
122
{ match . params . teamMemberId ? currentTeamMember . name : 'Your' }
162
123
{ ' Schedule\'s Page' }
163
124
</ Text >
164
- { this . renderSetBlocks ( selectedDay ) }
125
+ < BlockList />
165
126
{ editModeSchedule && ( < CommitBlock enableSubmit = { enableSubmit } /> ) }
166
127
</ Flex >
167
128
)
@@ -212,6 +173,7 @@ const mapDispatchToProps = (dispatch) => {
212
173
fetchCurrentTeamMemberById : ( params ) => dispatch ( fetchCurrentTeamMemberById ( params ) ) ,
213
174
setSelectedDay : ( selectedDay ) => dispatch ( setSelectedDay ( selectedDay ) ) ,
214
175
setEditModeSchedule : ( editMode ) => dispatch ( setEditModeSchedule ( editMode ) ) ,
176
+ setEnableSubmit : ( enableSubmit ) => dispatch ( setEnableSubmit ( enableSubmit ) ) ,
215
177
updateUnsavedSetblocks : ( unsavedSetBlocks ) => dispatch ( updateUnsavedSetblocks ( unsavedSetBlocks ) )
216
178
} ;
217
179
} ;
0 commit comments