From f81a4e1a05ca3fa66c2798b047d4bfd6995f462d Mon Sep 17 00:00:00 2001 From: Shravya Ramesh Date: Thu, 18 Mar 2021 13:44:19 -0700 Subject: Support modified endpoints + refactoring --- src/utils/common.ts | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) (limited to 'src/utils/common.ts') diff --git a/src/utils/common.ts b/src/utils/common.ts index c1049c42..5f0e26ba 100644 --- a/src/utils/common.ts +++ b/src/utils/common.ts @@ -1,8 +1,9 @@ -import {NotificationType} from './../types/types'; +import {ContactType, NotificationType} from './../types/types'; import moment from 'moment'; import {Linking} from 'react-native'; import {BROWSABLE_SOCIAL_URLS, TOGGLE_BUTTON_TYPE} from '../constants'; import AsyncStorage from '@react-native-community/async-storage'; +import {getAll} from 'react-native-contacts'; export const getToggleButtonText: ( buttonType: string, @@ -115,3 +116,21 @@ export const shuffle = (array: any[]) => { return array; }; + +export const extractContacts = async () => { + let retrievedContacts: Array = []; + await getAll().then((contacts) => { + contacts.map((contact) => { + let obj: ContactType = { + first_name: contact.givenName, + last_name: contact.familyName, + }; + contact.phoneNumbers.map(async (phoneNumber) => { + obj.phone_number = phoneNumber.number; + retrievedContacts.push(obj); + console.log('contact: ', obj); + }); + }); + }); + return retrievedContacts; +}; -- cgit v1.2.3-70-g09d2 From 5bb8376cd6f3c87af8011c6d523c5a32813970fb Mon Sep 17 00:00:00 2001 From: Shravya Ramesh Date: Thu, 18 Mar 2021 16:33:22 -0700 Subject: fix --- src/utils/common.ts | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) (limited to 'src/utils/common.ts') diff --git a/src/utils/common.ts b/src/utils/common.ts index 5f0e26ba..0a76ec08 100644 --- a/src/utils/common.ts +++ b/src/utils/common.ts @@ -121,14 +121,12 @@ export const extractContacts = async () => { let retrievedContacts: Array = []; await getAll().then((contacts) => { contacts.map((contact) => { - let obj: ContactType = { - first_name: contact.givenName, - last_name: contact.familyName, - }; - contact.phoneNumbers.map(async (phoneNumber) => { - obj.phone_number = phoneNumber.number; - retrievedContacts.push(obj); - console.log('contact: ', obj); + contact.phoneNumbers.map((phoneNumber) => { + retrievedContacts.push({ + first_name: contact.givenName, + last_name: contact.familyName, + phone_number: phoneNumber.number, + }); }); }); }); -- cgit v1.2.3-70-g09d2