diff options
author | Ivan Chen <ivan@tagg.id> | 2021-04-21 13:56:54 -0400 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-04-21 13:56:54 -0400 |
commit | b556f97a7eae3f9d9fce2d9c5c25f419ba77fa14 (patch) | |
tree | 495c7e7567e9d528b9d8171395a1793ae9cc8aab | |
parent | 45c0935d4c18ca7bd18ba56aa5ae37f4c40dc9f2 (diff) | |
parent | 2ee4ffc4c99f794941e9d3e2c7e47a145d89d83d (diff) |
Merge pull request #373 from IvanIFChen/tma792-5-invite-limit
[TMA-792] 5 invite limits
-rw-r--r-- | src/components/friends/InviteFriendTile.tsx | 22 | ||||
-rw-r--r-- | src/constants/strings.ts | 3 | ||||
-rw-r--r-- | src/screens/profile/InviteFriendsScreen.tsx | 17 | ||||
-rw-r--r-- | src/services/UserFriendsService.ts | 5 |
4 files changed, 36 insertions, 11 deletions
diff --git a/src/components/friends/InviteFriendTile.tsx b/src/components/friends/InviteFriendTile.tsx index 95ebf16a..5237389a 100644 --- a/src/components/friends/InviteFriendTile.tsx +++ b/src/components/friends/InviteFriendTile.tsx @@ -8,25 +8,37 @@ import { View, } from 'react-native'; import {TAGG_LIGHT_BLUE} from '../../constants'; -import {ERROR_SOMETHING_WENT_WRONG} from '../../constants/strings'; +import { + ERROR_NO_CONTACT_INVITE_LEFT, + ERROR_SOMETHING_WENT_WRONG, + SUCCESS_INVITE_CONTACT, + SUCCESS_LAST_CONTACT_INVITE, +} from '../../constants/strings'; +import {InviteContactType} from '../../screens/profile/InviteFriendsScreen'; import {inviteFriendService} from '../../services'; import {normalize} from '../../utils'; interface InviteFriendTileProps { - item: Object; + item: InviteContactType; } const InviteFriendTile: React.FC<InviteFriendTileProps> = ({item}) => { const [invited, setInvited] = useState<boolean>(false); const [formatedPhoneNumber, setFormattedPhoneNumber] = useState<string>(''); const handleInviteFriend = async () => { - const response = await inviteFriendService( + const invites_left = await inviteFriendService( item.phoneNumber, item.firstName, item.lastName, ); - if (response) { - setInvited(response); + 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(ERROR_NO_CONTACT_INVITE_LEFT); } else { Alert.alert(ERROR_SOMETHING_WENT_WRONG); } diff --git a/src/constants/strings.ts b/src/constants/strings.ts index bdb94fba..50e4518b 100644 --- a/src/constants/strings.ts +++ b/src/constants/strings.ts @@ -30,6 +30,7 @@ export const ERROR_LINK = (str: string) => `Unable to link with ${str}, Please c export const ERROR_LOGIN = 'There was a problem logging you in, please refresh and try again'; export const ERROR_LOGIN_FAILED = 'Login failed. Check your username and password, and try again'; export const ERROR_NEXT_PAGE = 'There was a problem while loading the next page 😓, try again in a couple minutes'; +export const ERROR_NO_CONTACT_INVITE_LEFT = 'You have no more invites left!' export const ERROR_NOT_ONBOARDED = 'You are now on waitlist, please enter your invitation code if you have one'; export const ERROR_PHONE_IN_USE = 'Phone already in use, please try another one'; export const ERROR_PROFILE_CREATION_SHORT = 'Profile creation failed 😓'; @@ -62,7 +63,9 @@ export const NO_RESULTS_FOUND = 'No Results Found!'; export const PRIVATE_ACCOUNT = 'This account is private'; 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_LAST_CONTACT_INVITE = 'Done! That was your last invite, hope you used it wisely!'; 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_LINK = (str: string) => `Successfully linked ${str} 🎉`; export const SUCCESS_PIC_UPLOAD = 'Beautiful, the picture was uploaded successfully!'; export const SUCCESS_PWD_RESET = 'Your password was reset successfully!'; diff --git a/src/screens/profile/InviteFriendsScreen.tsx b/src/screens/profile/InviteFriendsScreen.tsx index ad9e382e..e1f739c5 100644 --- a/src/screens/profile/InviteFriendsScreen.tsx +++ b/src/screens/profile/InviteFriendsScreen.tsx @@ -36,6 +36,17 @@ import {MainStackParams} from '../../routes'; import {RouteProp} from '@react-navigation/native'; const AnimatedIcon = Animated.createAnimatedComponent(Icon); +export type InviteContactType = { + firstName: string; + lastName: string; + phoneNumber: string; +}; + +type SearchResultType = { + usersFromContacts: ProfilePreviewType[]; + nonUsersFromContacts: InviteContactType[]; +}; + type InviteFriendsScreenRouteProp = RouteProp< MainStackParams, 'InviteFriendsScreen' @@ -53,10 +64,6 @@ const InviteFriendsScreen: React.FC<InviteFriendsScreenProps> = ({route}) => { ProfilePreviewType[] >([]); const [nonUsersFromContacts, setNonUsersFromContacts] = useState<[]>([]); - type SearchResultType = { - usersFromContacts: ProfilePreviewType[]; - nonUsersFromContacts: []; - }; const [results, setResults] = useState<SearchResultType>({ usersFromContacts: usersFromContacts, nonUsersFromContacts: nonUsersFromContacts, @@ -98,7 +105,7 @@ const InviteFriendsScreen: React.FC<InviteFriendsScreenProps> = ({route}) => { item.last_name.toLowerCase().startsWith(query), ); const searchResultsNonUsers = nonUsersFromContacts.filter( - (item) => + (item: InviteContactType) => (item.firstName + ' ' + item.lastName) .toLowerCase() .startsWith(query) || diff --git a/src/services/UserFriendsService.ts b/src/services/UserFriendsService.ts index 5c41e988..deb3ec6d 100644 --- a/src/services/UserFriendsService.ts +++ b/src/services/UserFriendsService.ts @@ -233,7 +233,10 @@ export const inviteFriendService = async ( }), }); if (response.status === 201 || response.status === 200) { - return await response.json(); + const data = await response.json(); + return data.invites_left; + } else if (response.status === 400) { + return -1; } return false; }; |