Skip to content

Commit

Permalink
Sprint 33 (#538)
Browse files Browse the repository at this point in the history
* Resolves #516
  • Loading branch information
raschdiaz authored Jan 7, 2021
1 parent 2c022b0 commit 4238859
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 21 deletions.
32 changes: 23 additions & 9 deletions screens/Contact/ContactDetailScreen.js
Original file line number Diff line number Diff line change
Expand Up @@ -1466,11 +1466,23 @@ class ContactDetailScreen extends React.Component {
if (users !== null) {
newState = {
...newState,
users: JSON.parse(users).map((user) => ({
key: user.ID,
label: user.name,
contactID: parseInt(user.contact_id),
})),
users: JSON.parse(users).map((user) => {
let newUser = {
key: user.ID,
label: user.name,
};
// Prevent 'null' values
if (
Object.prototype.hasOwnProperty.call(user, 'contact_id') &&
sharedTools.isNumeric(user.contact_id)
) {
newUser = {
...newUser,
contactID: parseInt(user.contact_id),
};
}
return newUser;
}),
};
}

Expand Down Expand Up @@ -2902,10 +2914,12 @@ class ContactDetailScreen extends React.Component {
items={[
...this.state.subAssignedContacts,
...this.state.usersContacts,
...this.state.users.map((user) => ({
name: user.label,
value: user.key.toString(),
})),
...this.state.users
.filter((user) => Object.prototype.hasOwnProperty.call(user, 'contactID'))
.map((user) => ({
name: user.label,
value: user.contactID.toString(),
})),
]}
selectedItems={this.getSelectizeItems(this.state.contact.subassigned, [
...this.state.subAssignedContacts,
Expand Down
16 changes: 4 additions & 12 deletions shared/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -512,30 +512,22 @@ const groupsByFilter = (groupsList, query) => {
const getSelectizeValuesToSave = (dbData, selectedValues) => {
const dbItems = [...dbData];
const localItems = [];

// Map selectize value to get selected options
Object.keys(selectedValues.entities.item).forEach((itemValue) => {
const item = selectedValues.entities.item[itemValue];
localItems.push(item);
});

const itemsToSave = localItems
.filter((localItem) => {
const foundLocalInDatabase = dbItems.find((dbItem) => dbItem.value === localItem.value);
return foundLocalInDatabase === undefined;
})
.map((localItem) => ({ value: localItem.value }));

// Remove of D.B items that were removed of the field
dbItems.forEach((dbItem) => {
const foundDatabaseInLocal = localItems.find((localItem) => dbItem.value === localItem.value);
if (!foundDatabaseInLocal) {
itemsToSave.push({
localItems.push({
...dbItem,
delete: true,
});
}
});

return itemsToSave;
return localItems;
};

const mapContacts = (contacts, entities) => {
Expand Down

0 comments on commit 4238859

Please sign in to comment.