aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/components/friends/InviteFriendTile.tsx86
-rw-r--r--src/constants/api.ts5
-rw-r--r--src/constants/strings.ts6
-rw-r--r--src/services/UserProfileService.ts2
4 files changed, 84 insertions, 15 deletions
diff --git a/src/components/friends/InviteFriendTile.tsx b/src/components/friends/InviteFriendTile.tsx
index 5237389a..9967b365 100644
--- a/src/components/friends/InviteFriendTile.tsx
+++ b/src/components/friends/InviteFriendTile.tsx
@@ -1,17 +1,27 @@
+import AsyncStorage from '@react-native-community/async-storage';
import React, {useEffect, useState} from 'react';
import {
Alert,
+ Linking,
StyleSheet,
Text,
TouchableOpacity,
TouchableWithoutFeedback,
View,
} from 'react-native';
-import {TAGG_LIGHT_BLUE} from '../../constants';
+import {useSelector} from 'react-redux';
+import {RootState} from 'src/store/rootReducer';
+import {
+ CREATE_INVITE_CODE,
+ GET_REMAINING_INVITES,
+ TAGG_LIGHT_BLUE,
+} from '../../constants';
import {
ERROR_NO_CONTACT_INVITE_LEFT,
ERROR_SOMETHING_WENT_WRONG,
- SUCCESS_INVITE_CONTACT,
+ INVITE_USER_SMS_BODY,
+ SUCCESS_CONFIRM_INVITE_CONTACT_MESSAGE,
+ SUCCESS_CONFIRM_INVITE_CONTACT_TITLE,
SUCCESS_LAST_CONTACT_INVITE,
} from '../../constants/strings';
import {InviteContactType} from '../../screens/profile/InviteFriendsScreen';
@@ -24,26 +34,78 @@ interface InviteFriendTileProps {
const InviteFriendTile: React.FC<InviteFriendTileProps> = ({item}) => {
const [invited, setInvited] = useState<boolean>(false);
+ const {name} = useSelector((state: RootState) => state.user.profile);
const [formatedPhoneNumber, setFormattedPhoneNumber] = useState<string>('');
const handleInviteFriend = async () => {
- const invites_left = await inviteFriendService(
- item.phoneNumber,
- item.firstName,
- item.lastName,
- );
+ const invites_left = await getRemainingInviteCount();
if (invites_left > 0) {
setInvited(true);
- Alert.alert(SUCCESS_INVITE_CONTACT(invites_left));
- } else if (invites_left === 0) {
- setInvited(true);
- Alert.alert(SUCCESS_LAST_CONTACT_INVITE);
- } else if (invites_left === -1) {
+ Alert.alert(
+ SUCCESS_CONFIRM_INVITE_CONTACT_TITLE(invites_left),
+ SUCCESS_CONFIRM_INVITE_CONTACT_MESSAGE,
+ [
+ {text: 'No!', style: 'cancel'},
+ {
+ text: 'Yes!',
+ onPress: async () => {
+ const inviteCode = await handleCreateInviteCode();
+ await inviteFriendService(
+ item.phoneNumber,
+ item.firstName,
+ item.lastName,
+ );
+ Linking.openURL(
+ `sms:${item.phoneNumber}&body=${INVITE_USER_SMS_BODY(
+ item.firstName,
+ name,
+ inviteCode,
+ )}`,
+ );
+ if (invites_left === 1) {
+ Alert.alert(SUCCESS_LAST_CONTACT_INVITE);
+ }
+ },
+ },
+ ],
+ );
+ } else if (invites_left === -1 || invites_left === 0) {
Alert.alert(ERROR_NO_CONTACT_INVITE_LEFT);
} else {
Alert.alert(ERROR_SOMETHING_WENT_WRONG);
}
};
+ const getRemainingInviteCount = async () => {
+ const firstName = name.split(' ')[0];
+ const lastName = name.split(' ')[1];
+ const token = await AsyncStorage.getItem('token');
+ const response = await fetch(GET_REMAINING_INVITES, {
+ method: 'POST',
+ headers: {
+ Authorization: 'Token ' + token,
+ },
+ body: JSON.stringify({
+ invitee_first_name: firstName,
+ invitee_last_name: lastName,
+ }),
+ });
+ if (response.status === 200) {
+ const data = await response.json();
+ return data.invites_left;
+ } else if (response.status === 500) {
+ return -1;
+ }
+ };
+
+ const handleCreateInviteCode = async () => {
+ const response = await fetch(CREATE_INVITE_CODE, {method: 'POST'});
+ if (response.status === 200) {
+ const data = await response.json();
+ return data.code;
+ } else if (response.status === 500) {
+ return -1;
+ }
+ };
useEffect(() => {
const formatPhoneNumer = () => {
const unformatted_number: string = item.phoneNumber;
diff --git a/src/constants/api.ts b/src/constants/api.ts
index e5ce9e77..41c54d6f 100644
--- a/src/constants/api.ts
+++ b/src/constants/api.ts
@@ -49,7 +49,8 @@ export const USERS_FROM_CONTACTS_ENDPOINT: string =
API_URL + 'user_contacts/find_friends/';
export const INVITE_FRIEND_ENDPOINT: string =
API_URL + 'user_contacts/invite_friend/';
-
+export const CREATE_INVITE_CODE = API_URL + 'create-code/';
+export const GET_REMAINING_INVITES = API_URL + 'user_contacts/check_invite_count/'
// Suggested People
export const SP_USERS_ENDPOINT: string = API_URL + 'suggested_people/';
export const SP_UPDATE_PICTURE_ENDPOINT: string =
@@ -59,7 +60,7 @@ export const SP_MUTUAL_BADGE_HOLDERS_ENDPOINT: string =
export const ADD_BADGES_ENDPOINT: string = SP_USERS_ENDPOINT + 'add_badges/';
export const UPDATE_BADGES_ENDPOINT: string =
SP_USERS_ENDPOINT + 'update_badges/';
- export const REMOVE_BADGES_ENDPOINT: string =
+export const REMOVE_BADGES_ENDPOINT: string =
SP_USERS_ENDPOINT + 'remove_badges/';
export const GET_USER_BADGES_ENDPOINT: string = SP_USERS_ENDPOINT + 'get_badges/';
diff --git a/src/constants/strings.ts b/src/constants/strings.ts
index 56d54d39..2ce64aed 100644
--- a/src/constants/strings.ts
+++ b/src/constants/strings.ts
@@ -2,6 +2,7 @@
// Below is the regex to convert this into a csv for the Google Sheet
// export const (.*) = .*?(['|"|`])(.*)\2;
// replace with: $1\t$3
+export const APP_STORE_LINK = 'https://apps.apple.com/us/app/tagg-discover-your-community/id1537853613'
export const ADD_COMMENT_TEXT = (username?: string) => username ? `Reply to ${username}` : 'Add a comment...'
export const COMING_SOON_MSG = 'Creating more fun things for you, surprises coming soon 😉';
export const ERROR_ATTEMPT_EDIT_SP = 'Can\'t let you do that yet! Please onboard Suggested People first!';
@@ -68,6 +69,11 @@ export const SUCCESS_BADGES_UPDATE = 'Badges updated successfully!'
export const SUCCESS_CATEGORY_DELETE = 'Category successfully deleted, but its memory will live on';
export const SUCCESS_INVITATION_CODE = 'Welcome to Tagg!';
export const SUCCESS_INVITE_CONTACT = (str: string) => `Success! You now have ${str} invites left!`;
+export const SUCCESS_CONFIRM_INVITE_CONTACT_TITLE = (str: string) => `You have ${str} invites left!`;
+export const SUCCESS_CONFIRM_INVITE_CONTACT_MESSAGE = 'Use one now?';
+export const INVITE_USER_SMS_BODY = (invitedUserName: string, invitee: string, inviteCode: string) => `Hey ${invitedUserName}!\n
+You've been tagged by ${invitee}. Follow the instructions below to skip the line and join them on Tagg!\n
+Sign up and use this code to get in: ${inviteCode}\n ${APP_STORE_LINK}`;
export const SUCCESS_LAST_CONTACT_INVITE = 'Done! That was your last invite, hope you used it wisely!';
export const SUCCESS_LINK = (str: string) => `Successfully linked ${str} 🎉`;
export const SUCCESS_PIC_UPLOAD = 'Beautiful, the picture was uploaded successfully!';
diff --git a/src/services/UserProfileService.ts b/src/services/UserProfileService.ts
index 8b7b78e1..624f0e2a 100644
--- a/src/services/UserProfileService.ts
+++ b/src/services/UserProfileService.ts
@@ -442,7 +442,7 @@ export const verifyExistingInformation = async (
const form = new FormData();
if (email) {
form.append('email', email);
- }
+ }
if (username) {
form.append('username', username);
}