Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
addContact () {
let newContact = {
givenName: PREFIX + Math.floor(Math.random()*99999999),
familyName: PREFIX + Math.floor(Math.random()*99999999),
emailAddresses: [
{email: 'fromRNContacts1@example.com', type: 'work'},
{email: 'fromRNContacts2@example.com', type: 'personal'}
]
}
Contacts.addContact(newContact, (err, data) => {
Contacts.getAll((err, records) => {
let contact = _.find(records, {givenName: newContact.givenName})
console.log('attempted to add:', newContact)
console.log('after add:', contact)
_.each(newContact, (value, key) => {
if (Array.isArray(newContact[key])) {
invariant(
contact[key].length === newContact[key].length,
'contact values !isEqual for ' + key
)
} else {
invariant(
_.isEqual(contact[key], newContact[key]),
'contact values !isEqual for ' + key
)
}
handleDone(validationCondition){
const {firstName, lastName, mobileNumber} = this.state;
if(validationCondition){
RNContacts.addContact({
givenName: firstName + " " + lastName,
phoneNumbers: [
{
label: "mobile",
number: mobileNumber
}
]
},(err)=>{
if(!err){
this.props.navigator.pop();
}
})
}
}