diff --git a/screens/Contact/ContactDetailScreen.js b/screens/Contact/ContactDetailScreen.js index f0cf17ae..25c3a193 100644 --- a/screens/Contact/ContactDetailScreen.js +++ b/screens/Contact/ContactDetailScreen.js @@ -365,8 +365,22 @@ const initialState = { sources: [], nonExistingSources: [], unmodifiedSources: [], - nonExistingSubassigned: [], - unmodifiedSubassigned: [], + subAssignedContacts: [], + unmodifiedSubAssignedContacts: [], + relationContacts: [], + unmodifiedRelationContacts: [], + baptizedByContacts: [], + unmodifiedBaptizedByContacts: [], + baptizedContacts: [], + unmodifiedBaptizedContacts: [], + coachedByContacts: [], + unmodifiedCoachedByContacts: [], + coachedContacts: [], + unmodifiedCoachedContacts: [], + connectionGroups: [], + unmodifiedConnectionGroups: [], + assignedToContacts: [], + unmodifedAssignedToContacts: [] }; const safeFind = (found, prop) => { @@ -649,37 +663,266 @@ class ContactDetailScreen extends React.Component { }); } if (newState.contact.subassigned) { - console.log(newState.contact.subassigned); + + // Clear collection + newState = { + ...newState, + subAssignedContacts: [] + }; + newState.contact.subassigned.values.forEach((subassignedContact) => { const foundSubassigned = newState.usersContacts.find((user) => user.value === subassignedContact.value); if (!foundSubassigned) { // Add non existent contact subassigned in subassigned list (user does not have access permission to this contacts) newState = { ...newState, - usersContacts: [ - ...newState.usersContacts, + subAssignedContacts: [ + ...newState.subAssignedContacts, { name: subassignedContact.name, value: subassignedContact.value } ], - nonExistingSubassigned: [ - ...newState.nonExistingSubassigned, + unmodifiedSubAssignedContacts: [ + ...newState.unmodifiedSubAssignedContacts, { name: subassignedContact.name, - value: subassignedContact.value, - }, + value: subassignedContact.value + } + ] + }; + } + }); + + } + if (newState.contact.relation) { + + // Clear collection + newState = { + ...newState, + relationContacts: [] + }; + + newState.contact.relation.values.forEach((relationContact) => { + const foundRelation = newState.usersContacts.find((user) => user.value === relationContact.value); + if (!foundRelation) { + // Add non existent contact relation in relation list (user does not have access permission to this contacts) + newState = { + ...newState, + relationContacts: [ + ...newState.relationContacts, + { + name: relationContact.name, + value: relationContact.value + } ], - unmodifiedSubassigned: [ - ...newState.unmodifiedSubassigned, + unmodifiedRelationContacts: [ + ...newState.unmodifiedRelationContacts, { - name: subassignedContact.name, - value: subassignedContact.value, - }, + name: relationContact.name, + value: relationContact.value + } + ] + }; + } + }); + + } + if (newState.contact.baptized_by) { + + // Clear collection + newState = { + ...newState, + baptizedByContacts: [] + }; + + newState.contact.baptized_by.values.forEach((baptizedByContact) => { + const foundBaptized = newState.usersContacts.find((user) => user.value === baptizedByContact.value); + if (!foundBaptized) { + // Add non existent contact relation in relation list (user does not have access permission to this contacts) + newState = { + ...newState, + baptizedByContacts: [ + ...newState.baptizedByContacts, + { + name: baptizedByContact.name, + value: baptizedByContact.value + } ], - } + unmodifiedBaptizedByContacts: [ + ...newState.unmodifiedBaptizedByContacts, + { + name: baptizedByContact.name, + value: baptizedByContact.value + } + ] + }; + } + }); + + } + if (newState.contact.baptized) { + + // Clear collection + newState = { + ...newState, + baptizedContacts: [] + }; + + newState.contact.baptized.values.forEach((baptizedContact) => { + const foundBaptized = newState.usersContacts.find((user) => user.value === baptizedContact.value); + if (!foundBaptized) { + // Add non existent contact baptized to list (user does not have access permission to this contacts) + newState = { + ...newState, + baptizedContacts: [ + ...newState.baptizedContacts, + { + name: baptizedContact.name, + value: baptizedContact.value + } + ], + unmodifiedBaptizedContacts: [ + ...newState.unmodifiedBaptizedContacts, + { + name: baptizedContact.name, + value: baptizedContact.value + } + ] + }; } }); + + } + if (newState.contact.coached_by) { + + // Clear collection + newState = { + ...newState, + coachedByContacts: [] + }; + + newState.contact.coached_by.values.forEach((coachedByContact) => { + const foundcoachedBy = newState.usersContacts.find((user) => user.value === coachedByContact.value); + if (!foundcoachedBy) { + // Add non existent contact coachedBy to list (user does not have access permission to this contacts) + newState = { + ...newState, + coachedByContacts: [ + ...newState.coachedByContacts, + { + name: coachedByContact.name, + value: coachedByContact.value + } + ], + unmodifiedCoachedByContacts: [ + ...newState.unmodifiedCoachedByContacts, + { + name: coachedByContact.name, + value: coachedByContact.value + } + ] + }; + } + }); + + } + if (newState.contact.coaching) { + + // Clear collection + newState = { + ...newState, + coachedContacts: [] + }; + + newState.contact.coaching.values.forEach((coachedContact) => { + const foundCoached = newState.usersContacts.find((user) => user.value === coachedContact.value); + if (!foundCoached) { + // Add non existent contact coached to list (user does not have access permission to this contacts) + newState = { + ...newState, + coachedContacts: [ + ...newState.coachedContacts, + { + name: coachedContact.name, + value: coachedContact.value + } + ], + unmodifiedCoachedContacts: [ + ...newState.unmodifiedCoachedContacts, + { + name: coachedContact.name, + value: coachedContact.value + } + ] + }; + } + }); + + } + if (newState.contact.groups) { + + // Clear collection + newState = { + ...newState, + connectionGroups: [] + }; + + newState.contact.groups.values.forEach((groupConnection) => { + const foundGroup = newState.groups.find((group) => group.value === groupConnection.value); + if (!foundGroup) { + // Add non existent group to list (user does not have access permission to this groups) + newState = { + ...newState, + connectionGroups: [ + ...newState.connectionGroups, + { + name: groupConnection.name, + value: groupConnection.value + } + ], + unmodifiedConnectionGroups: [ + ...newState.unmodifiedConnectionGroups, + { + name: groupConnection.name, + value: groupConnection.value + } + ] + }; + } + }); + + } + if (newState.contact.assigned_to) { + + // Clear collection + newState = { + ...newState, + assignedToContacts: [] + }; + + let foundAssigned = newState.users.find((user) => user.key === newState.contact.assigned_to.key); + if (!foundAssigned) { + // Add non existent group to list (user does not have access permission to this groups) + newState = { + ...newState, + assignedToContacts: [ + ...newState.assignedToContacts, + { + label: foundAssigned.label, + key: foundAssigned.key + } + ], + unmodifedAssignedToContacts: [ + ...newState.unmodifedAssignedToContacts, + { + label: foundAssigned.label, + key: foundAssigned.key + } + ] + }; + } + } } @@ -1003,8 +1246,7 @@ class ContactDetailScreen extends React.Component { })), loadedLocal: true, sources: [...sourcesList], - unmodifiedSources: [...sourcesList], - unmodifiedSubassigned: [...userContactsList] + unmodifiedSources: [...sourcesList] }; this.setState(newState, () => { @@ -1072,7 +1314,17 @@ class ContactDetailScreen extends React.Component { }; onDisableEdit = () => { - const { unmodifiedContact, unmodifiedSources, unmodifiedSubassigned } = this.state; + const { unmodifiedContact, + unmodifiedSources, + unmodifiedSubAssignedContacts, + unmodifiedRelationContacts, + unmodifiedBaptizedByContacts, + unmodifiedBaptizedContacts, + unmodifiedCoachedByContacts, + unmodifiedCoachedContacts, + unmodifiedConnectionGroups, + unmodifedAssignedToContacts + } = this.state; this.setState((state) => { const indexFix = state.tabViewConfig.index > 1 ? state.tabViewConfig.index + 1 : state.tabViewConfig.index; @@ -1090,7 +1342,14 @@ class ContactDetailScreen extends React.Component { routes: [...tabViewRoutes], }, sources: [...unmodifiedSources], - usersContacts: [...unmodifiedSubassigned] + subAssignedContacts: [...unmodifiedSubAssignedContacts], + relationContacts: [...unmodifiedRelationContacts], + baptizedByContacts: [...unmodifiedBaptizedByContacts], + baptizedContacts: [...unmodifiedBaptizedContacts], + coachedByContacts: [...unmodifiedCoachedByContacts], + coachedContacts: [...unmodifiedCoachedContacts], + connectionGroups: [...unmodifiedConnectionGroups], + assignedToContacts: [...unmodifedAssignedToContacts] }; }); this.props.navigation.setParams({ hideTabBar: false, onlyView: true }); @@ -1269,6 +1528,12 @@ class ContactDetailScreen extends React.Component { ID: this.state.contact.ID, }; } + if(contactToSave.assigned_to) { + contactToSave = { + ...contactToSave, + assigned_to: `user-${contactToSave.assigned_to.key}`, + }; + } this.props.saveContact( this.props.userData.domain, this.props.userData.token, @@ -1558,7 +1823,7 @@ class ContactDetailScreen extends React.Component { - {this.showAssignedUser()} + {(this.state.contact.assigned_to) ? this.showAssignedUser() : null}