aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/components/common/Avatar.tsx12
-rw-r--r--src/components/friends/InviteFriendTile.tsx23
-rw-r--r--src/constants/strings.ts1
-rw-r--r--src/routes/main/MainStackNavigator.tsx4
-rw-r--r--src/screens/profile/InviteFriendsScreen.tsx43
5 files changed, 55 insertions, 28 deletions
diff --git a/src/components/common/Avatar.tsx b/src/components/common/Avatar.tsx
index 4d9aec41..29197d6e 100644
--- a/src/components/common/Avatar.tsx
+++ b/src/components/common/Avatar.tsx
@@ -4,8 +4,8 @@ import {Image, ImageStyle, StyleProp, ImageBackground} from 'react-native';
type AvatarProps = {
style: StyleProp<ImageStyle>;
uri: string | undefined;
- loading: boolean;
- loadingStyle: StyleProp<ImageStyle> | undefined;
+ loading?: boolean;
+ loadingStyle?: StyleProp<ImageStyle> | undefined;
};
const Avatar: FC<AvatarProps> = ({
style,
@@ -13,7 +13,7 @@ const Avatar: FC<AvatarProps> = ({
loading = false,
loadingStyle,
}) => {
- return (
+ return loading ? (
<ImageBackground
style={style}
imageStyle={style}
@@ -26,6 +26,12 @@ const Avatar: FC<AvatarProps> = ({
/>
)}
</ImageBackground>
+ ) : (
+ <Image
+ defaultSource={require('../../assets/images/avatar-placeholder.png')}
+ source={{uri, cache: 'reload'}}
+ style={style}
+ />
);
};
diff --git a/src/components/friends/InviteFriendTile.tsx b/src/components/friends/InviteFriendTile.tsx
index 48f65a94..f990df6a 100644
--- a/src/components/friends/InviteFriendTile.tsx
+++ b/src/components/friends/InviteFriendTile.tsx
@@ -9,11 +9,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 +22,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,10 +31,14 @@ 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,
@@ -42,7 +46,6 @@ const InviteFriendTile: React.FC<InviteFriendTileProps> = ({
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 +57,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 +67,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 +86,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 +114,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 +122,7 @@ const InviteFriendTile: React.FC<InviteFriendTileProps> = ({
});
}, 500);
- if (invites_left === 1) {
+ if (invitesLeft === 1) {
Alert.alert(SUCCESS_LAST_CONTACT_INVITE);
}
},
diff --git a/src/constants/strings.ts b/src/constants/strings.ts
index 2ce64aed..a1064f49 100644
--- a/src/constants/strings.ts
+++ b/src/constants/strings.ts
@@ -21,6 +21,7 @@ export const ERROR_FAILED_LOGIN_INFO = 'Login failed, please try re-entering you
export const ERROR_FAILED_TO_COMMENT = 'Unable to post comment, refresh and try again!';
export const ERROR_FAILED_TO_CREATE_CHANNEL = 'Failed to create a channel, Please try again!';
export const ERROR_FAILED_TO_DELETE_COMMENT = 'Unable to delete comment, refresh and try again!';
+export const ERROR_FAILED_TO_INVITE_CONTACT = `Unable to invite contact, refresh and try again!`;
export const ERROR_INVALID_INVITATION_CODE = 'Invitation code invalid, try again or talk to the friend that sent it 😬';
export const ERROR_INVALID_LOGIN = 'Invalid login, Please login again';
export const ERROR_INVALID_PWD_CODE = 'Looks like you have entered the wrong code, please try again';
diff --git a/src/routes/main/MainStackNavigator.tsx b/src/routes/main/MainStackNavigator.tsx
index a8da3030..054fb643 100644
--- a/src/routes/main/MainStackNavigator.tsx
+++ b/src/routes/main/MainStackNavigator.tsx
@@ -94,9 +94,7 @@ export type MainStackParams = {
badge_title: string;
badge_img: string;
};
- InviteFriendsScreen: {
- screenType: ScreenType;
- };
+ InviteFriendsScreen: undefined;
SPWelcomeScreen: {};
ChatList: undefined;
Chat: undefined;
diff --git a/src/screens/profile/InviteFriendsScreen.tsx b/src/screens/profile/InviteFriendsScreen.tsx
index d6effe02..89f2e62f 100644
--- a/src/screens/profile/InviteFriendsScreen.tsx
+++ b/src/screens/profile/InviteFriendsScreen.tsx
@@ -1,4 +1,4 @@
-import {RouteProp} from '@react-navigation/native';
+import {useNavigation} from '@react-navigation/native';
import React, {useEffect, useMemo, useState} from 'react';
import {
FlatList,
@@ -16,8 +16,11 @@ import {checkPermission} from 'react-native-contacts';
import {TAGG_LIGHT_BLUE} from '../../constants';
import {SearchBar, TabsGradient} from '../../components';
import {InviteFriendTile} from '../../components/friends';
-import {MainStackParams} from '../../routes';
-import {usersFromContactsService} from '../../services/UserFriendsService';
+import {headerBarOptions} from '../../routes';
+import {
+ getRemainingInviteCount,
+ usersFromContactsService,
+} from '../../services/UserFriendsService';
import {ProfilePreviewType} from '../../types';
import {
extractContacts,
@@ -40,16 +43,8 @@ export type SearchResultType = {
pendingUsers: InviteContactType[];
};
-type InviteFriendsScreenRouteProp = RouteProp<
- MainStackParams,
- 'InviteFriendsScreen'
->;
-
-interface InviteFriendsScreenProps {
- route: InviteFriendsScreenRouteProp;
-}
-
-const InviteFriendsScreen: React.FC<InviteFriendsScreenProps> = ({}) => {
+const InviteFriendsScreen: React.FC = () => {
+ const navigation = useNavigation();
const [usersFromContacts, setUsersFromContacts] = useState<
ProfilePreviewType[]
>([]);
@@ -60,6 +55,24 @@ const InviteFriendsScreen: React.FC<InviteFriendsScreenProps> = ({}) => {
pendingUsers: pendingUsers,
});
const [query, setQuery] = useState('');
+ const [invitesLeft, setInvitesLeft] = useState(0);
+
+ useEffect(() => {
+ // Get number of invites from the backend and set the state
+ const getInitialInvitesCount = async () => {
+ const intialInvites = await getRemainingInviteCount();
+ setInvitesLeft(intialInvites);
+ };
+ getInitialInvitesCount();
+ }, []);
+
+ useEffect(
+ () =>
+ navigation.setOptions({
+ ...headerBarOptions('black', `You have ${invitesLeft} Invites`),
+ }),
+ [invitesLeft],
+ );
useEffect(() => {
const handleFindFriends = () => {
@@ -129,6 +142,8 @@ const InviteFriendsScreen: React.FC<InviteFriendsScreenProps> = ({}) => {
<InviteFriendTile
item={item}
remind={true}
+ invitesLeft={invitesLeft}
+ setInvitesLeft={setInvitesLeft}
results={results}
setResults={setResults}
/>
@@ -150,6 +165,8 @@ const InviteFriendsScreen: React.FC<InviteFriendsScreenProps> = ({}) => {
<InviteFriendTile
item={item}
remind={false}
+ invitesLeft={invitesLeft}
+ setInvitesLeft={setInvitesLeft}
results={results}
setResults={setResults}
/>