aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/components/friends/InviteFriendTile.tsx2
-rw-r--r--src/components/profile/Friends.tsx23
-rw-r--r--src/screens/profile/InviteFriendsScreen.tsx32
-rw-r--r--src/services/UserFriendsService.ts10
-rw-r--r--src/utils/common.ts21
5 files changed, 44 insertions, 44 deletions
diff --git a/src/components/friends/InviteFriendTile.tsx b/src/components/friends/InviteFriendTile.tsx
index c49792f9..f56d3514 100644
--- a/src/components/friends/InviteFriendTile.tsx
+++ b/src/components/friends/InviteFriendTile.tsx
@@ -19,13 +19,11 @@ interface InviteFriendTileProps {
const InviteFriendTile: React.FC<InviteFriendTileProps> = ({item}) => {
const [invited, setInvited] = useState<boolean>(false);
const [formatedPhoneNumber, setFormattedPhoneNumber] = useState<string>('');
- const {profile} = useSelector((state: RootState) => state.user);
const handleInviteFriend = async () => {
const response = await inviteFriendService(
item.phoneNumber,
item.firstName,
item.lastName,
- profile.name,
);
if (response) {
setInvited(response);
diff --git a/src/components/profile/Friends.tsx b/src/components/profile/Friends.tsx
index 36e0ef8a..7d57177c 100644
--- a/src/components/profile/Friends.tsx
+++ b/src/components/profile/Friends.tsx
@@ -9,7 +9,12 @@ import {usersFromContactsService} from '../../services';
import {NO_USER} from '../../store/initialStates';
import {RootState} from '../../store/rootReducer';
import {ProfilePreviewType, ScreenType} from '../../types';
-import {normalize, SCREEN_HEIGHT, SCREEN_WIDTH} from '../../utils';
+import {
+ extractContacts,
+ normalize,
+ SCREEN_HEIGHT,
+ SCREEN_WIDTH,
+} from '../../utils';
import {handleAddFriend, handleUnfriend} from '../../utils/friends';
import {ProfilePreview} from '../profile';
import FindFriendsBlueIcon from '../../assets/icons/findFriends/find-friends-blue-icon.svg';
@@ -31,24 +36,12 @@ const Friends: React.FC<FriendsProps> = ({result, screenType, userId}) => {
ProfilePreviewType[]
>([]);
- const extractPhoneNumbers = async () => {
- let phoneNumbers: Array<string> = [];
- await getAll().then((contacts) => {
- contacts.map((contact) => {
- contact.phoneNumbers.map(async (phoneNumber) => {
- phoneNumbers.push(await phoneNumber.number);
- });
- });
- });
- return phoneNumbers;
- };
-
useEffect(() => {
const handleFindFriends = () => {
- extractPhoneNumbers().then(async (phoneNumbers) => {
+ extractContacts().then(async (contacts) => {
const permission = await checkPermission();
if (permission === 'authorized') {
- let response = await usersFromContactsService(phoneNumbers);
+ let response = await usersFromContactsService(contacts);
await setUsersFromContacts(response.existing_tagg_users);
usersFromContacts.map((user) => console.log('user: ', user.username));
} else if (permission === 'undefined') {
diff --git a/src/screens/profile/InviteFriendsScreen.tsx b/src/screens/profile/InviteFriendsScreen.tsx
index 1a5de1ce..53215d8a 100644
--- a/src/screens/profile/InviteFriendsScreen.tsx
+++ b/src/screens/profile/InviteFriendsScreen.tsx
@@ -15,6 +15,7 @@ import {
import {useDispatch, useStore} from 'react-redux';
import {ContactType, ProfilePreviewType, ScreenType} from '../../types';
import {
+ extractContacts,
handleAddFriend,
HeaderHeight,
normalize,
@@ -53,24 +54,6 @@ const InviteFriendsScreen: React.FC<InviteFriendsScreenProps> = ({
});
const [query, setQuery] = useState('');
- const extractContacts = async () => {
- let retrievedContacts: Array<ContactType> = [];
- 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;
- };
-
useEffect(() => {
const handleFindFriends = () => {
extractContacts().then(async (retrievedContacts) => {
@@ -190,7 +173,13 @@ const InviteFriendsScreen: React.FC<InviteFriendsScreenProps> = ({
<SafeAreaView>
<StatusBar barStyle="dark-content" />
<View style={styles.body}>
- <View style={{width: 319, height: 42, alignSelf: 'center', marginBottom: '2%',}}>
+ <View
+ style={{
+ width: 319,
+ height: 42,
+ alignSelf: 'center',
+ marginBottom: '2%',
+ }}>
<Text style={[styles.subheaderText, {textAlign: 'center'}]}>
Sharing is caring, invite friends, and create moments together!
</Text>
@@ -224,9 +213,7 @@ const InviteFriendsScreen: React.FC<InviteFriendsScreenProps> = ({
</Animated.View>
</View>
<View style={styles.subheader}>
- <Text style={[styles.subheaderText, {marginBottom: '5%'}]}>
- Add Friends
- </Text>
+ <Text style={styles.subheaderText}>Add Friends</Text>
<UsersFromContacts />
</View>
<View style={styles.subheader}>
@@ -257,6 +244,7 @@ const styles = StyleSheet.create({
fontSize: normalize(12),
fontWeight: '600',
lineHeight: normalize(14.32),
+ marginBottom: '5%',
},
container: {
alignSelf: 'center',
diff --git a/src/services/UserFriendsService.ts b/src/services/UserFriendsService.ts
index 86339868..c6679bef 100644
--- a/src/services/UserFriendsService.ts
+++ b/src/services/UserFriendsService.ts
@@ -8,7 +8,10 @@ import {
INVITE_FRIEND_ENDPOINT,
USERS_FROM_CONTACTS_ENDPOINT,
} from '../constants';
-import {ERROR_SOMETHING_WENT_WRONG_REFRESH} from '../constants/strings';
+import {
+ ERROR_SOMETHING_WENT_WRONG,
+ ERROR_SOMETHING_WENT_WRONG_REFRESH,
+} from '../constants/strings';
export const loadFriends = async (userId: string, token: string) => {
try {
@@ -223,7 +226,6 @@ export const inviteFriendService = async (
phoneNumber: string,
inviteeFirstName: string,
inviteeLastName: string,
- inviterFullName: string,
) => {
const token = await AsyncStorage.getItem('token');
const response = await fetch(INVITE_FRIEND_ENDPOINT, {
@@ -232,15 +234,15 @@ export const inviteFriendService = async (
Authorization: 'Token ' + token,
},
body: JSON.stringify({
- phone_number: phoneNumber,
+ invitee_phone_number: phoneNumber,
invitee_first_name: inviteeFirstName,
invitee_last_name: inviteeLastName,
- inviter_full_name: inviterFullName,
}),
});
if (response.status === 201) {
const response_body = await response.json();
return response_body;
}
+ Alert.alert(ERROR_SOMETHING_WENT_WRONG);
return false;
};
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<ContactType> = [];
+ 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;
+};