@@ -177,32 +177,34 @@ export default function patientReducer (state = initialState, action) {
177177 result = copy
178178 break
179179 case ' UPDATE_PATIENT_DATA' :
180- copy[action . payload [ 0 ]] .basic = action .payload [ 1 ]
180+ copy[copy . patientInContext ] .basic = action .payload
181181 result = copy
182182 break
183183 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+ }
186188 })
187- copy[action . payload [ 0 ]] .contacts [contactIndexForUpdation] = action .payload [ 1 ]
189+ copy[copy . patientInContext ] .contacts [contactIndexForUpdation] = action .payload
188190 result = copy
189191 break
190192 case ' START_ADDING_CONTACT' :
191- const lastContact = _ .last (copy[action . payload [ 0 ] ].contacts )
193+ const lastContact = _ .last (copy[copy . patientInContext ].contacts )
192194 let newContactId = 0
193195 if (lastContact != null && lastContact .hasOwnProperty (' id' )) {
194196 newContactId = lastContact .id + 1
195197 }
196- copy[action . payload [ 0 ] ].contacts .push ({ isNewContact: true , id: newContactId })
198+ copy[copy . patientInContext ].contacts .push ({ isNewContact: true , id: newContactId })
197199 result = copy
198200 break
199201 case ' DELETING_CONTACT' :
200- const contactIndexForDeletion = _ .findIndex (copy[action . payload [ 0 ] ].contacts , (c ) => {
202+ const contactIndexForDeletion = _ .findIndex (copy[copy . patientInContext ].contacts , (c ) => {
201203 if (c && c .hasOwnProperty (' id' )) {
202- return c .id === action .payload [ 1 ]
204+ return c .id === action .payload
203205 }
204206 })
205- delete copy[action . payload [ 0 ] ].contacts [contactIndexForDeletion]
207+ delete copy[copy . patientInContext ].contacts [contactIndexForDeletion]
206208 result = copy
207209 break
208210 default :
0 commit comments