@@ -90,7 +90,7 @@ export const updatePatientData = (data) => {
90
90
console . debug ( `updating basic patient data for ${ getState ( ) . patient . patientInContext } ` )
91
91
dispatch ( {
92
92
type : 'UPDATE_PATIENT_DATA' ,
93
- payload : [ getState ( ) . patient . patientInContext , data ]
93
+ payload : data
94
94
} )
95
95
resolve ( )
96
96
} )
@@ -103,7 +103,7 @@ export const updateContactData = (data) => {
103
103
console . debug ( `updating contact data for ${ getState ( ) . patient . patientInContext } ` )
104
104
dispatch ( {
105
105
type : 'UPDATE_CONTACT_DATA' ,
106
- payload : [ getState ( ) . patient . patientInContext , data ]
106
+ payload : data
107
107
} )
108
108
resolve ( )
109
109
} )
@@ -116,7 +116,7 @@ export const deleteContact = (data) => {
116
116
console . debug ( `deleting contact data for ${ getState ( ) . patient . patientInContext } ` )
117
117
dispatch ( {
118
118
type : 'DELETING_CONTACT' ,
119
- payload : [ getState ( ) . patient . patientInContext , data ]
119
+ payload : data
120
120
} )
121
121
resolve ( )
122
122
} )
@@ -129,7 +129,7 @@ export const startAddingNewContact = (data) => {
129
129
console . debug ( `starting to add contact data for ${ getState ( ) . patient . patientInContext } ` )
130
130
dispatch ( {
131
131
type : 'START_ADDING_CONTACT' ,
132
- payload : [ getState ( ) . patient . patientInContext , data ]
132
+ payload : data
133
133
} )
134
134
resolve ( )
135
135
} )
@@ -149,32 +149,34 @@ export default function patientReducer (state = initialState, action) {
149
149
result = copy
150
150
break
151
151
case 'UPDATE_PATIENT_DATA' :
152
- copy [ action . payload [ 0 ] ] . basic = action . payload [ 1 ]
152
+ copy [ copy . patientInContext ] . basic = action . payload
153
153
result = copy
154
154
break
155
155
case 'UPDATE_CONTACT_DATA' :
156
- const contactIndexForUpdation = _ . findIndex ( copy [ action . payload [ 0 ] ] . contacts , ( c ) => {
157
- return c . id === action . payload [ 1 ] . id
156
+ const contactIndexForUpdation = _ . findIndex ( copy [ copy . patientInContext ] . contacts , ( c ) => {
157
+ if ( c && c . hasOwnProperty ( 'id' ) ) {
158
+ return c . id === action . payload . id
159
+ }
158
160
} )
159
- copy [ action . payload [ 0 ] ] . contacts [ contactIndexForUpdation ] = action . payload [ 1 ]
161
+ copy [ copy . patientInContext ] . contacts [ contactIndexForUpdation ] = action . payload
160
162
result = copy
161
163
break
162
164
case 'START_ADDING_CONTACT' :
163
- const lastContact = _ . last ( copy [ action . payload [ 0 ] ] . contacts )
165
+ const lastContact = _ . last ( copy [ copy . patientInContext ] . contacts )
164
166
let newContactId = 0
165
167
if ( lastContact != null && lastContact . hasOwnProperty ( 'id' ) ) {
166
168
newContactId = lastContact . id + 1
167
169
}
168
- copy [ action . payload [ 0 ] ] . contacts . push ( { isNewContact : true , id : newContactId } )
170
+ copy [ copy . patientInContext ] . contacts . push ( { isNewContact : true , id : newContactId } )
169
171
result = copy
170
172
break
171
173
case 'DELETING_CONTACT' :
172
- const contactIndexForDeletion = _ . findIndex ( copy [ action . payload [ 0 ] ] . contacts , ( c ) => {
174
+ const contactIndexForDeletion = _ . findIndex ( copy [ copy . patientInContext ] . contacts , ( c ) => {
173
175
if ( c && c . hasOwnProperty ( 'id' ) ) {
174
- return c . id === action . payload [ 1 ]
176
+ return c . id === action . payload
175
177
}
176
178
} )
177
- delete copy [ action . payload [ 0 ] ] . contacts [ contactIndexForDeletion ]
179
+ delete copy [ copy . patientInContext ] . contacts [ contactIndexForDeletion ]
178
180
result = copy
179
181
break
180
182
default :
0 commit comments