diff options
Diffstat (limited to 'src/components')
-rw-r--r-- | src/components/friends/InviteFriendTile.tsx | 25 |
1 files changed, 16 insertions, 9 deletions
diff --git a/src/components/friends/InviteFriendTile.tsx b/src/components/friends/InviteFriendTile.tsx index 48f65a94..d384ed27 100644 --- a/src/components/friends/InviteFriendTile.tsx +++ b/src/components/friends/InviteFriendTile.tsx @@ -1,3 +1,4 @@ +import {useNavigation} from '@react-navigation/core'; import React, {useEffect, useState} from 'react'; import { Alert, @@ -9,11 +10,10 @@ import { View, } from 'react-native'; import {useSelector} from 'react-redux'; -import {RootState} from 'src/store/rootReducer'; import {TAGG_LIGHT_BLUE} from '../../constants'; import { + ERROR_FAILED_TO_INVITE_CONTACT, ERROR_NO_CONTACT_INVITE_LEFT, - ERROR_SOMETHING_WENT_WRONG, INVITE_USER_SMS_BODY, SUCCESS_CONFIRM_INVITE_CONTACT_MESSAGE, SUCCESS_CONFIRM_INVITE_CONTACT_TITLE, @@ -23,7 +23,8 @@ import { InviteContactType, SearchResultType, } from '../../screens/profile/InviteFriendsScreen'; -import {getRemainingInviteCount, inviteFriendService} from '../../services'; +import {inviteFriendService} from '../../services'; +import {RootState} from '../../store/rootReducer'; import {normalize} from '../../utils'; interface InviteFriendTileProps { @@ -31,18 +32,22 @@ interface InviteFriendTileProps { remind: boolean; results: SearchResultType; setResults: Function; + invitesLeft: number; + setInvitesLeft: (updateInvites: number) => void; } const InviteFriendTile: React.FC<InviteFriendTileProps> = ({ item, + invitesLeft, + setInvitesLeft, remind, results, setResults, }) => { + const navigation = useNavigation(); const [invited, setInvited] = useState<boolean>(remind); const {name} = useSelector((state: RootState) => state.user.profile); const [formatedPhoneNumber, setFormattedPhoneNumber] = useState<string>(''); - const handleInviteFriend = async () => { // If user has been invited already, don't show alerts and change invite count if (invited) { @@ -54,6 +59,7 @@ const InviteFriendTile: React.FC<InviteFriendTileProps> = ({ ); const inviteCode = response?.invite_code; if (inviteCode) { + // Open iMessage Linking.openURL( `sms:${item.phoneNumber}&body=${INVITE_USER_SMS_BODY( item.firstName, @@ -63,12 +69,11 @@ const InviteFriendTile: React.FC<InviteFriendTileProps> = ({ ); } } else { - const invites_left = await getRemainingInviteCount(); - if (invites_left < 1) { + if (invitesLeft < 1) { Alert.alert(ERROR_NO_CONTACT_INVITE_LEFT); } Alert.alert( - SUCCESS_CONFIRM_INVITE_CONTACT_TITLE(invites_left), + SUCCESS_CONFIRM_INVITE_CONTACT_TITLE(String(invitesLeft)), SUCCESS_CONFIRM_INVITE_CONTACT_MESSAGE, [ {text: 'No!', style: 'cancel'}, @@ -83,7 +88,8 @@ const InviteFriendTile: React.FC<InviteFriendTileProps> = ({ ); const inviteCode = response?.invite_code; if (!inviteCode) { - Alert.alert(ERROR_SOMETHING_WENT_WRONG); + setInvited(false); + Alert.alert(ERROR_FAILED_TO_INVITE_CONTACT); } // Add user to Pending Users list const newPendingUser: InviteContactType = { @@ -110,6 +116,7 @@ const InviteFriendTile: React.FC<InviteFriendTileProps> = ({ // Update results after navigating out of the app setTimeout(() => { setInvited(true); + setInvitesLeft(invitesLeft - 1); setResults({ ...results, pendingUsers: [...results.pendingUsers, newPendingUser], @@ -117,7 +124,7 @@ const InviteFriendTile: React.FC<InviteFriendTileProps> = ({ }); }, 500); - if (invites_left === 1) { + if (invitesLeft === 1) { Alert.alert(SUCCESS_LAST_CONTACT_INVITE); } }, |