From d2f52e2fe19023d16fe72d750c5a1fc0f1bd4992 Mon Sep 17 00:00:00 2001 From: Shravya Ramesh Date: Wed, 12 May 2021 12:49:32 -0700 Subject: fixed moment caption size --- src/components/moments/MomentPostContent.tsx | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'src/components') diff --git a/src/components/moments/MomentPostContent.tsx b/src/components/moments/MomentPostContent.tsx index 45186ba1..193bf40c 100644 --- a/src/components/moments/MomentPostContent.tsx +++ b/src/components/moments/MomentPostContent.tsx @@ -10,6 +10,7 @@ import { navigateToProfile, SCREEN_HEIGHT, SCREEN_WIDTH, + normalize, } from '../../utils'; import {mentionPartTypes, renderTextWithMentions} from '../../utils/comments'; import {CommentsCount} from '../comments'; @@ -103,6 +104,9 @@ const styles = StyleSheet.create({ marginRight: '5%', color: '#ffffff', fontWeight: '500', + fontSize: normalize(13), + lineHeight: normalize(15.51), + letterSpacing: normalize(0.6), }, }); export default MomentPostContent; -- cgit v1.2.3-70-g09d2 From 3cfad768bc7d2369ff49d1b57771ac317dbae71e Mon Sep 17 00:00:00 2001 From: George Rusu Date: Wed, 12 May 2021 18:10:08 -0700 Subject: added functionality for individual sms for invites and updated api and strings to match --- src/components/friends/InviteFriendTile.tsx | 86 +++++++++++++++++++++++++---- src/constants/api.ts | 5 +- src/constants/strings.ts | 6 ++ src/services/UserProfileService.ts | 2 +- 4 files changed, 84 insertions(+), 15 deletions(-) (limited to 'src/components') 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 = ({item}) => { const [invited, setInvited] = useState(false); + const {name} = useSelector((state: RootState) => state.user.profile); const [formatedPhoneNumber, setFormattedPhoneNumber] = useState(''); 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); } -- cgit v1.2.3-70-g09d2 From ec2654b83796df88346a96a9ddd872ac07a67901 Mon Sep 17 00:00:00 2001 From: Shravya Ramesh Date: Wed, 12 May 2021 22:21:14 -0700 Subject: Refactored mesage button code on profile screen --- src/components/messages/MessageButton.tsx | 73 +++++++++++++++++++++++++++++++ src/components/messages/index.ts | 1 + 2 files changed, 74 insertions(+) create mode 100644 src/components/messages/MessageButton.tsx (limited to 'src/components') diff --git a/src/components/messages/MessageButton.tsx b/src/components/messages/MessageButton.tsx new file mode 100644 index 00000000..5ac42c4c --- /dev/null +++ b/src/components/messages/MessageButton.tsx @@ -0,0 +1,73 @@ +import React from 'react'; +import {Fragment, useContext} from 'react'; +import {useStore} from 'react-redux'; +import {ChatContext} from '../../App'; +import {RootState} from '../../store/rootReducer'; +import {FriendshipStatusType} from '../../types'; +import {createChannel} from '../../utils'; +import {Alert, StyleProp, TextStyle, ViewStyle} from 'react-native'; +import {BasicButton} from '../common'; +import {useNavigation} from '@react-navigation/native'; +import {ERROR_UNABLE_CONNECT_CHAT} from '../../constants/strings'; + +interface MessageButtonProps { + userXId: string; + isBlocked: boolean; + friendship_status: FriendshipStatusType; + friendship_requester_id?: string; + solid?: boolean; + externalStyles?: Record>; +} + +const MessageButton: React.FC = ({ + userXId, + isBlocked, + friendship_status, + friendship_requester_id, + solid, + externalStyles, +}) => { + const navigation = useNavigation(); + const {chatClient, setChannel} = useContext(ChatContext); + + const state: RootState = useStore().getState(); + const loggedInUserId = state.user.user.userId; + + const canMessage = () => { + if ( + userXId && + !isBlocked && + (friendship_status === 'no_record' || + friendship_status === 'friends' || + (friendship_status === 'requested' && + friendship_requester_id === loggedInUserId)) + ) { + return true; + } else { + return false; + } + }; + + const onPressMessage = async () => { + if (chatClient.user && userXId) { + const channel = await createChannel(loggedInUserId, userXId, chatClient); + setChannel(channel); + navigation.navigate('Chat'); + } else { + Alert.alert(ERROR_UNABLE_CONNECT_CHAT); + } + }; + + return canMessage() ? ( + + ) : ( + + ); +}; + +export default MessageButton; diff --git a/src/components/messages/index.ts b/src/components/messages/index.ts index b19067ca..7270e2e2 100644 --- a/src/components/messages/index.ts +++ b/src/components/messages/index.ts @@ -7,3 +7,4 @@ export {default as MessageAvatar} from './MessageAvatar'; export {default as TypingIndicator} from './TypingIndicator'; export {default as MessageFooter} from './MessageFooter'; export {default as DateHeader} from './DateHeader'; +export {default as MessageButton} from './MessageButton'; -- cgit v1.2.3-70-g09d2 From 29bfc68f90d1ca82c39765dc6c84816d2733a2fa Mon Sep 17 00:00:00 2001 From: Shravya Ramesh Date: Wed, 12 May 2021 22:21:45 -0700 Subject: styles, done --- src/components/common/BasicButton.tsx | 12 +++++- src/components/notifications/Notification.tsx | 40 ++++++++++++++---- src/components/profile/ProfileBody.tsx | 58 +++++---------------------- 3 files changed, 53 insertions(+), 57 deletions(-) (limited to 'src/components') diff --git a/src/components/common/BasicButton.tsx b/src/components/common/BasicButton.tsx index 1fe29cd9..e2274dbd 100644 --- a/src/components/common/BasicButton.tsx +++ b/src/components/common/BasicButton.tsx @@ -1,5 +1,12 @@ import React from 'react'; -import {StyleProp, StyleSheet, Text, View, ViewStyle} from 'react-native'; +import { + StyleProp, + StyleSheet, + Text, + TextStyle, + View, + ViewStyle, +} from 'react-native'; import {TAGG_LIGHT_BLUE} from '../../constants'; import {TouchableOpacity} from 'react-native-gesture-handler'; import {normalize} from '../../utils'; @@ -8,7 +15,7 @@ interface BasicButtonProps { title: string; onPress: () => void; solid?: boolean; - externalStyles?: Record>; + externalStyles?: Record>; } const BasicButton: React.FC = ({ title, @@ -27,6 +34,7 @@ const BasicButton: React.FC = ({ = (props) => { const [avatar, setAvatar] = useState(undefined); const [momentURI, setMomentURI] = useState(undefined); + const notification_title = + notification_type === 'FRD_ACPT' + ? `Say Hi to ${first_name}!` + : `${first_name} ${last_name}`; useEffect(() => { (async () => { @@ -246,9 +251,7 @@ const Notification: React.FC = (props) => { {/* Text content: Actor name and verbage*/} - - {first_name} {last_name} - + {notification_title} = (props) => { /> )} + {notification_type === 'FRD_ACPT' && ( + + + + )} {/* Moment Image Preview */} {(notification_type === 'CMT' || notification_type === 'MOM_3+' || @@ -306,7 +332,7 @@ const styles = StyleSheet.create({ flex: 1, alignSelf: 'center', alignItems: 'center', - paddingHorizontal: '8%', + paddingHorizontal: '7%', }, avatarContainer: { height: 42, @@ -348,9 +374,9 @@ const styles = StyleSheet.create({ lineHeight: normalize(13.13), }, timeStampStyles: { - fontWeight: '700', - fontSize: normalize(12), - lineHeight: normalize(14.32), + fontWeight: '500', + fontSize: normalize(11), + lineHeight: normalize(13.13), marginHorizontal: 2, color: '#828282', textAlignVertical: 'center', diff --git a/src/components/profile/ProfileBody.tsx b/src/components/profile/ProfileBody.tsx index 3d654724..7557de00 100644 --- a/src/components/profile/ProfileBody.tsx +++ b/src/components/profile/ProfileBody.tsx @@ -1,17 +1,7 @@ -import {useNavigation} from '@react-navigation/core'; -import React, {useContext} from 'react'; -import { - Alert, - LayoutChangeEvent, - Linking, - StyleSheet, - Text, - View, -} from 'react-native'; +import React from 'react'; +import {LayoutChangeEvent, Linking, StyleSheet, Text, View} from 'react-native'; import {useDispatch, useSelector, useStore} from 'react-redux'; -import {ChatContext} from '../../App'; import {TAGG_DARK_BLUE, TOGGLE_BUTTON_TYPE} from '../../constants'; -import {ERROR_UNABLE_CONNECT_CHAT} from '../../constants/strings'; import { acceptFriendRequest, declineFriendRequest, @@ -22,14 +12,14 @@ import {NO_PROFILE} from '../../store/initialStates'; import {RootState} from '../../store/rootReducer'; import {ScreenType} from '../../types'; import { - createChannel, getUserAsProfilePreviewType, normalize, SCREEN_HEIGHT, SCREEN_WIDTH, } from '../../utils'; import {canViewProfile} from '../../utils/users'; -import {BasicButton, FriendsButton} from '../common'; +import {FriendsButton} from '../common'; +import {MessageButton} from '../messages'; import ToggleButton from './ToggleButton'; interface ProfileBodyProps { @@ -47,7 +37,6 @@ const ProfileBody: React.FC = ({ screenType, }) => { const dispatch = useDispatch(); - const navigation = useNavigation(); const {profile = NO_PROFILE, user} = useSelector((state: RootState) => userXId ? state.userX[screenType][userXId] : state.user, @@ -65,10 +54,7 @@ const ProfileBody: React.FC = ({ profile, ); - const {chatClient, setChannel} = useContext(ChatContext); - const state: RootState = useStore().getState(); - const loggedInUserId = state.user.user.userId; const handleAcceptRequest = async () => { await dispatch(acceptFriendRequest({id, username, first_name, last_name})); @@ -81,32 +67,6 @@ const ProfileBody: React.FC = ({ dispatch(updateUserXProfileAllScreens(id, state)); }; - const canMessage = () => { - if ( - userXId && - !isBlocked && - (friendship_status === 'no_record' || - friendship_status === 'friends' || - (friendship_status === 'requested' && - friendship_requester_id === loggedInUserId)) && - canViewProfile(state, userXId, screenType) - ) { - return true; - } else { - return false; - } - }; - - const onPressMessage = async () => { - if (chatClient.user && userXId) { - const channel = await createChannel(loggedInUserId, userXId, chatClient); - setChannel(channel); - navigation.navigate('Chat'); - } else { - Alert.alert(ERROR_UNABLE_CONNECT_CHAT); - } - }; - return ( {`@${username}`} @@ -142,10 +102,12 @@ const ProfileBody: React.FC = ({ onAcceptRequest={handleAcceptRequest} onRejectRequest={handleDeclineFriendRequest} /> - {canMessage() && ( - Date: Wed, 12 May 2021 22:35:02 -0700 Subject: button position --- src/components/notifications/Notification.tsx | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'src/components') diff --git a/src/components/notifications/Notification.tsx b/src/components/notifications/Notification.tsx index 179daa57..cb62047a 100644 --- a/src/components/notifications/Notification.tsx +++ b/src/components/notifications/Notification.tsx @@ -286,6 +286,7 @@ const Notification: React.FC = (props) => { container: { width: normalize(63), height: normalize(21), + marginTop: '7%', }, buttonTitle: { fontSize: normalize(11), @@ -332,7 +333,7 @@ const styles = StyleSheet.create({ flex: 1, alignSelf: 'center', alignItems: 'center', - paddingHorizontal: '7%', + paddingHorizontal: '6.3%', }, avatarContainer: { height: 42, -- cgit v1.2.3-70-g09d2 From 0d92d8b60550c86ce95a7f481a2599f8f9469219 Mon Sep 17 00:00:00 2001 From: Ivan Chen Date: Thu, 13 May 2021 14:57:36 -0400 Subject: removed useDerivedValue --- src/components/taggs/TaggsBar.tsx | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) (limited to 'src/components') diff --git a/src/components/taggs/TaggsBar.tsx b/src/components/taggs/TaggsBar.tsx index 4d567b25..a7e8fc7a 100644 --- a/src/components/taggs/TaggsBar.tsx +++ b/src/components/taggs/TaggsBar.tsx @@ -113,13 +113,11 @@ const TaggsBar: React.FC = ({ loadData(); } }, [taggsNeedUpdate, user]); - const paddingTopStylesProgress = useDerivedValue(() => - interpolate( - y.value, - [PROFILE_CUTOUT_BOTTOM_Y, PROFILE_CUTOUT_BOTTOM_Y + profileBodyHeight], - [0, 1], - Extrapolate.CLAMP, - ), + const paddingTopStylesProgress = interpolate( + y.value, + [PROFILE_CUTOUT_BOTTOM_Y, PROFILE_CUTOUT_BOTTOM_Y + profileBodyHeight], + [0, 1], + Extrapolate.CLAMP, ); const shadowOpacityStylesProgress = useDerivedValue(() => interpolate( @@ -134,7 +132,7 @@ const TaggsBar: React.FC = ({ ); const animatedStyles = useAnimatedStyle(() => ({ shadowOpacity: shadowOpacityStylesProgress.value / 5, - paddingTop: paddingTopStylesProgress.value * insetTop, + paddingTop: paddingTopStylesProgress + insetTop, })); return taggs.length > 0 ? ( -- cgit v1.2.3-70-g09d2 From 10c3fc8fa7e01105bcde394ef9629b40541f60ff Mon Sep 17 00:00:00 2001 From: George Rusu Date: Thu, 13 May 2021 13:46:19 -0700 Subject: simplified call to backend and refactored into service file --- src/components/friends/InviteFriendTile.tsx | 44 +++---------------- src/services/UserFriendsService.ts | 65 ++++++++++++++++++++++------- 2 files changed, 55 insertions(+), 54 deletions(-) (limited to 'src/components') diff --git a/src/components/friends/InviteFriendTile.tsx b/src/components/friends/InviteFriendTile.tsx index 9967b365..c47c8764 100644 --- a/src/components/friends/InviteFriendTile.tsx +++ b/src/components/friends/InviteFriendTile.tsx @@ -1,4 +1,3 @@ -import AsyncStorage from '@react-native-community/async-storage'; import React, {useEffect, useState} from 'react'; import { Alert, @@ -11,11 +10,7 @@ import { } from 'react-native'; import {useSelector} from 'react-redux'; import {RootState} from 'src/store/rootReducer'; -import { - CREATE_INVITE_CODE, - GET_REMAINING_INVITES, - TAGG_LIGHT_BLUE, -} from '../../constants'; +import {TAGG_LIGHT_BLUE} from '../../constants'; import { ERROR_NO_CONTACT_INVITE_LEFT, ERROR_SOMETHING_WENT_WRONG, @@ -25,7 +20,11 @@ import { SUCCESS_LAST_CONTACT_INVITE, } from '../../constants/strings'; import {InviteContactType} from '../../screens/profile/InviteFriendsScreen'; -import {inviteFriendService} from '../../services'; +import { + getRemainingInviteCount, + handleCreateInviteCode, + inviteFriendService, +} from '../../services'; import {normalize} from '../../utils'; interface InviteFriendTileProps { @@ -75,37 +74,6 @@ const InviteFriendTile: React.FC = ({item}) => { } }; - 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/services/UserFriendsService.ts b/src/services/UserFriendsService.ts index deb3ec6d..453f35a5 100644 --- a/src/services/UserFriendsService.ts +++ b/src/services/UserFriendsService.ts @@ -1,7 +1,9 @@ import AsyncStorage from '@react-native-community/async-storage'; import {Alert} from 'react-native'; import { + CREATE_INVITE_CODE, FRIENDS_ENDPOINT, + GET_REMAINING_INVITES, INVITE_FRIEND_ENDPOINT, USERS_FROM_CONTACTS_ENDPOINT, } from '../constants'; @@ -220,23 +222,54 @@ export const inviteFriendService = async ( inviteeFirstName: string, inviteeLastName: string, ) => { - const token = await AsyncStorage.getItem('token'); - const response = await fetch(INVITE_FRIEND_ENDPOINT, { - method: 'POST', - headers: { - Authorization: 'Token ' + token, - }, - body: JSON.stringify({ - invitee_phone_number: phoneNumber, - invitee_first_name: inviteeFirstName, - invitee_last_name: inviteeLastName, - }), - }); - if (response.status === 201 || response.status === 200) { + try { + const token = await AsyncStorage.getItem('token'); + const response = await fetch(INVITE_FRIEND_ENDPOINT, { + method: 'POST', + headers: { + Authorization: 'Token ' + token, + }, + body: JSON.stringify({ + invitee_phone_number: phoneNumber, + invitee_first_name: inviteeFirstName, + invitee_last_name: inviteeLastName, + }), + }); + return response.status === 201 || response.status === 200; + } catch (error) { + console.log(error); + Alert.alert(ERROR_SOMETHING_WENT_WRONG_REFRESH); + return false; + } +}; + +export const handleCreateInviteCode = async () => { + const response = await fetch(CREATE_INVITE_CODE, {method: 'POST'}); + if (response.status === 200) { const data = await response.json(); - return data.invites_left; - } else if (response.status === 400) { + return data.code; + } else if (response.status === 500) { return -1; } - return false; +}; + +export const getRemainingInviteCount = async () => { + const token = await AsyncStorage.getItem('token'); + try { + const response = await fetch(GET_REMAINING_INVITES, { + method: 'GET', + headers: { + Authorization: 'Token ' + token, + }, + }); + if (response.status === 200) { + const data = await response.json(); + return data.invites_left; + } else if (response.status === 500) { + return -1; + } + } catch (error) { + console.log(error); + Alert.alert(ERROR_SOMETHING_WENT_WRONG_REFRESH); + } }; -- cgit v1.2.3-70-g09d2 From 8db9bb83850e8e368700cb9006b8666741360653 Mon Sep 17 00:00:00 2001 From: Ivan Chen Date: Thu, 13 May 2021 17:46:39 -0400 Subject: fixed pending state bug --- src/components/friends/InviteFriendTile.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/components') diff --git a/src/components/friends/InviteFriendTile.tsx b/src/components/friends/InviteFriendTile.tsx index c47c8764..abd017d0 100644 --- a/src/components/friends/InviteFriendTile.tsx +++ b/src/components/friends/InviteFriendTile.tsx @@ -38,7 +38,6 @@ const InviteFriendTile: React.FC = ({item}) => { const handleInviteFriend = async () => { const invites_left = await getRemainingInviteCount(); if (invites_left > 0) { - setInvited(true); Alert.alert( SUCCESS_CONFIRM_INVITE_CONTACT_TITLE(invites_left), SUCCESS_CONFIRM_INVITE_CONTACT_MESSAGE, @@ -47,6 +46,7 @@ const InviteFriendTile: React.FC = ({item}) => { { text: 'Yes!', onPress: async () => { + setInvited(true); const inviteCode = await handleCreateInviteCode(); await inviteFriendService( item.phoneNumber, -- cgit v1.2.3-70-g09d2 From 1e948b556fd53c02d7462576b183cdd6c4c793bb Mon Sep 17 00:00:00 2001 From: Ivan Chen Date: Thu, 13 May 2021 17:59:29 -0400 Subject: Revert "[TMA-844] Plus sign for profile and header in profile, ability to add on the sc…" MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/assets/icons/grey-purple-plus.svg | 5 -- src/assets/icons/purple-plus.svg | 15 ----- src/components/profile/Cover.tsx | 108 +++++----------------------------- src/components/profile/TaggAvatar.tsx | 67 ++------------------- src/utils/common.ts | 17 ------ src/utils/users.ts | 82 -------------------------- 6 files changed, 18 insertions(+), 276 deletions(-) delete mode 100644 src/assets/icons/grey-purple-plus.svg delete mode 100644 src/assets/icons/purple-plus.svg (limited to 'src/components') diff --git a/src/assets/icons/grey-purple-plus.svg b/src/assets/icons/grey-purple-plus.svg deleted file mode 100644 index 2053d4a7..00000000 --- a/src/assets/icons/grey-purple-plus.svg +++ /dev/null @@ -1,5 +0,0 @@ - - - - - diff --git a/src/assets/icons/purple-plus.svg b/src/assets/icons/purple-plus.svg deleted file mode 100644 index 20949b6d..00000000 --- a/src/assets/icons/purple-plus.svg +++ /dev/null @@ -1,15 +0,0 @@ - - - - - - - - - - - - - - - diff --git a/src/components/profile/Cover.tsx b/src/components/profile/Cover.tsx index 5d5b4234..27777b64 100644 --- a/src/components/profile/Cover.tsx +++ b/src/components/profile/Cover.tsx @@ -1,93 +1,28 @@ -import React, {useState, useEffect} from 'react'; -import { - Image, - StyleSheet, - View, - TouchableOpacity, - Text, - ImageBackground, -} from 'react-native'; +import React from 'react'; +import {Image, StyleSheet, View} from 'react-native'; +import {useSelector} from 'react-redux'; import {COVER_HEIGHT, IMAGE_WIDTH} from '../../constants'; -import {ScreenType} from '../../types'; -import GreyPurplePlus from '../../assets/icons/grey-purple-plus.svg'; -import {useDispatch, useSelector} from 'react-redux'; -import {loadUserData, resetHeaderAndProfileImage} from '../../store/actions'; import {RootState} from '../../store/rootreducer'; -import {normalize, patchProfile, validateImageLink} from '../../utils'; +import {ScreenType} from '../../types'; interface CoverProps { userXId: string | undefined; screenType: ScreenType; } const Cover: React.FC = ({userXId, screenType}) => { - const dispatch = useDispatch(); - const {cover, user} = useSelector((state: RootState) => + const {cover} = useSelector((state: RootState) => userXId ? state.userX[screenType][userXId] : state.user, ); - const [needsUpdate, setNeedsUpdate] = useState(false); - const [loading, setLoading] = useState(false); - const [validImage, setValidImage] = useState(true); - - useEffect(() => { - checkAvatar(cover); - }, []); - - useEffect(() => { - if (needsUpdate) { - const userId = user.userId; - const username = user.username; - dispatch(resetHeaderAndProfileImage()); - dispatch(loadUserData({userId, username})); - } - }, [dispatch, needsUpdate]); - - const handleNewImage = async () => { - setLoading(true); - const result = await patchProfile('header', user.userId); - setLoading(true); - if (result) { - setNeedsUpdate(true); - } else { - setLoading(false); - } - }; - - const checkAvatar = async (url: string | undefined) => { - const valid = await validateImageLink(url); - if (valid !== validImage) { - setValidImage(valid); - } - }; - - if (!validImage && userXId === undefined && !loading) { - return ( - - - handleNewImage()}> - - Add Picture - - - - ); - } else { - return ( - - - - ); - } + return ( + + + + ); }; const styles = StyleSheet.create({ @@ -98,20 +33,5 @@ const styles = StyleSheet.create({ width: IMAGE_WIDTH, height: COVER_HEIGHT, }, - plus: { - position: 'absolute', - top: 75, - right: 125, - }, - text: { - color: 'white', - position: 'absolute', - fontSize: normalize(16), - top: 80, - right: 20, - }, - touch: { - flex: 1, - }, }); export default Cover; diff --git a/src/components/profile/TaggAvatar.tsx b/src/components/profile/TaggAvatar.tsx index 304b9e3a..ea0bdb65 100644 --- a/src/components/profile/TaggAvatar.tsx +++ b/src/components/profile/TaggAvatar.tsx @@ -1,12 +1,9 @@ -import React, {useState, useEffect} from 'react'; -import {StyleSheet, TouchableOpacity} from 'react-native'; +import React from 'react'; +import {StyleSheet} from 'react-native'; +import {useSelector} from 'react-redux'; import {RootState} from '../../store/rootreducer'; import {ScreenType} from '../../types'; import {Avatar} from '../common'; -import {useDispatch, useSelector} from 'react-redux'; -import {loadUserData, resetHeaderAndProfileImage} from '../../store/actions'; -import PurplePlus from '../../assets/icons/purple-plus.svg'; -import {patchProfile, validateImageLink} from '../../utils'; const PROFILE_DIM = 100; @@ -23,59 +20,8 @@ const TaggAvatar: React.FC = ({ const {avatar} = useSelector((state: RootState) => userXId ? state.userX[screenType][userXId] : state.user, ); - const dispatch = useDispatch(); - const [needsUpdate, setNeedsUpdate] = useState(false); - const [loading, setLoading] = useState(false); - const [validImage, setValidImage] = useState(true); - const {user} = useSelector((state: RootState) => - userXId ? state.userX[screenType][userXId] : state.user, - ); - - useEffect(() => { - checkAvatar(avatar); - }, []); - - useEffect(() => { - if (needsUpdate) { - const userId = user.userId; - const username = user.username; - dispatch(resetHeaderAndProfileImage()); - dispatch(loadUserData({userId, username})); - } - }, [dispatch, needsUpdate]); - const handleNewImage = async () => { - setLoading(true); - const result = await patchProfile('profile', user.userId); - if (result) { - setNeedsUpdate(true); - } else { - setLoading(false); - } - }; - - const checkAvatar = async (url: string | undefined) => { - const valid = await validateImageLink(url); - if (valid !== validImage) { - setValidImage(valid); - } - }; - - if (!validImage && userXId === undefined && !loading) { - return ( - <> - - handleNewImage()}> - - - - ); - } else { - return ; - } + return ; }; const styles = StyleSheet.create({ @@ -84,11 +30,6 @@ const styles = StyleSheet.create({ width: PROFILE_DIM, borderRadius: PROFILE_DIM / 2, }, - plus: { - position: 'absolute', - bottom: 35, - right: 0, - }, }); export default TaggAvatar; diff --git a/src/utils/common.ts b/src/utils/common.ts index 95e77f64..ce4ab7d1 100644 --- a/src/utils/common.ts +++ b/src/utils/common.ts @@ -180,20 +180,3 @@ const _crestIcon = (university: UniversityType) => { return require('../assets/images/bwbadges.png'); } }; - -export const validateImageLink = async (url: string | undefined) => { - if (!url) { - return false; - } - return fetch(url) - .then((res) => { - if (res.status === 200) { - return true; - } else { - return false; - } - }) - .catch((_) => { - return false; - }); -}; diff --git a/src/utils/users.ts b/src/utils/users.ts index 430c843f..334cb3c0 100644 --- a/src/utils/users.ts +++ b/src/utils/users.ts @@ -1,4 +1,3 @@ -import {Alert} from 'react-native'; import AsyncStorage from '@react-native-community/async-storage'; import {INTEGRATED_SOCIAL_LIST} from '../constants'; import {isUserBlocked, loadSocialPosts, removeBadgesService} from '../services'; @@ -25,8 +24,6 @@ import { UserType, UniversityBadge, } from './../types/types'; -import ImagePicker from 'react-native-image-crop-picker'; -import {patchEditProfile} from '../services'; const loadData = async (dispatch: AppDispatch, user: UserType) => { await Promise.all([ @@ -243,82 +240,3 @@ export const navigateToProfile = async ( screenType, }); }; - -export const patchProfile = async ( - title: 'profile' | 'header', - userId: string, -) => { - let imageSettings = {}; - let screenTitle: string; - let requestTitle: string; - let fileName: string; - switch (title) { - case 'header': - screenTitle = 'Select Header Picture'; - requestTitle = 'largeProfilePicture'; - fileName = 'large_profile_pic.jpg'; - imageSettings = { - smartAlbums: [ - 'Favorites', - 'RecentlyAdded', - 'SelfPortraits', - 'Screenshots', - 'UserLibrary', - ], - width: 580, - height: 580, - cropping: true, - cropperToolbarTitle: screenTitle, - mediaType: 'photo', - }; - break; - case 'profile': - screenTitle = 'Select Profile Picture'; - requestTitle = 'smallProfilePicture'; - fileName = 'small_profile_pic.jpg'; - imageSettings = { - smartAlbums: [ - 'Favorites', - 'RecentlyAdded', - 'SelfPortraits', - 'Screenshots', - 'UserLibrary', - ], - width: 580, - height: 580, - cropping: true, - cropperToolbarTitle: screenTitle, - mediaType: 'photo', - cropperCircleOverlay: true, - }; - break; - default: - screenTitle = ''; - requestTitle = ''; - fileName = ''; - } - - return await ImagePicker.openPicker(imageSettings) - .then((picture) => { - if ('path' in picture) { - const request = new FormData(); - request.append(requestTitle, { - uri: picture.path, - name: fileName, - type: 'image/jpg', - }); - - return patchEditProfile(request, userId) - .then((_) => { - return true; - }) - .catch((error) => { - Alert.alert(error); - return false; - }); - } - }) - .catch((_) => { - return false; - }); -}; -- cgit v1.2.3-70-g09d2 From 3262626f8beffaa8ee0f4a7a643bcf0c01ee694a Mon Sep 17 00:00:00 2001 From: Brian Kim Date: Thu, 13 May 2021 15:24:28 -0700 Subject: Tiny change to push not navigate, no longer goes back --- src/components/profile/FriendsCount.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/components') diff --git a/src/components/profile/FriendsCount.tsx b/src/components/profile/FriendsCount.tsx index 8252266e..a299e9a1 100644 --- a/src/components/profile/FriendsCount.tsx +++ b/src/components/profile/FriendsCount.tsx @@ -37,7 +37,7 @@ const FriendsCount: React.FC = ({ return ( - navigation.navigate('FriendsListScreen', { + navigation.push('FriendsListScreen', { userXId, screenType, }) -- cgit v1.2.3-70-g09d2