@@ -177,32 +177,34 @@ export default function patientReducer (state = initialState, action) {
177
177
result = copy
178
178
break
179
179
case ' UPDATE_PATIENT_DATA' :
180
- copy[action . payload [ 0 ]] .basic = action .payload [ 1 ]
180
+ copy[copy . patientInContext ] .basic = action .payload
181
181
result = copy
182
182
break
183
183
case ' UPDATE_CONTACT_DATA' :
184
- const contactIndexForUpdation = _ .findIndex (copy[action .payload [0 ]].contacts , (c ) => {
185
- return c .id === action .payload [1 ].id
184
+ const contactIndexForUpdation = _ .findIndex (copy[copy .patientInContext ].contacts , (c ) => {
185
+ if (c && c .hasOwnProperty (' id' )) {
186
+ return c .id === action .payload .id
187
+ }
186
188
})
187
- copy[action . payload [ 0 ]] .contacts [contactIndexForUpdation] = action .payload [ 1 ]
189
+ copy[copy . patientInContext ] .contacts [contactIndexForUpdation] = action .payload
188
190
result = copy
189
191
break
190
192
case ' START_ADDING_CONTACT' :
191
- const lastContact = _ .last (copy[action . payload [ 0 ] ].contacts )
193
+ const lastContact = _ .last (copy[copy . patientInContext ].contacts )
192
194
let newContactId = 0
193
195
if (lastContact != null && lastContact .hasOwnProperty (' id' )) {
194
196
newContactId = lastContact .id + 1
195
197
}
196
- copy[action . payload [ 0 ] ].contacts .push ({ isNewContact: true , id: newContactId })
198
+ copy[copy . patientInContext ].contacts .push ({ isNewContact: true , id: newContactId })
197
199
result = copy
198
200
break
199
201
case ' DELETING_CONTACT' :
200
- const contactIndexForDeletion = _ .findIndex (copy[action . payload [ 0 ] ].contacts , (c ) => {
202
+ const contactIndexForDeletion = _ .findIndex (copy[copy . patientInContext ].contacts , (c ) => {
201
203
if (c && c .hasOwnProperty (' id' )) {
202
- return c .id === action .payload [ 1 ]
204
+ return c .id === action .payload
203
205
}
204
206
})
205
- delete copy[action . payload [ 0 ] ].contacts [contactIndexForDeletion]
207
+ delete copy[copy . patientInContext ].contacts [contactIndexForDeletion]
206
208
result = copy
207
209
break
208
210
default :
0 commit comments