aboutsummaryrefslogtreecommitdiff
path: root/src/screens/onboarding/Profile.tsx
diff options
context:
space:
mode:
authorLeon Jiang <35908040+leonyjiang@users.noreply.github.com>2020-07-20 16:27:45 -0700
committerGitHub <noreply@github.com>2020-07-20 19:27:45 -0400
commite87d4f2b10cff8cf5f31784cfddb22727a94f373 (patch)
treedd454883f3f4054e895c7ce80f2845d68ba31364 /src/screens/onboarding/Profile.tsx
parentc38291fb50e30af0739f17de42f3b8bb51cca73e (diff)
[TMA-134] Profile Picture Upload (#22)
* Fix styling, remove unnecessary state * Change large profile to square crop, restyle * Disable gestures on Verification and Profile screens * Forward username and ID to Profile screen * Add API request upon submit & filler components * Restore gestures to Verification and Profile * Rewrite network failure error message * Update profile request form keys
Diffstat (limited to 'src/screens/onboarding/Profile.tsx')
-rw-r--r--src/screens/onboarding/Profile.tsx265
1 files changed, 151 insertions, 114 deletions
diff --git a/src/screens/onboarding/Profile.tsx b/src/screens/onboarding/Profile.tsx
index cb4a2728..d42b1185 100644
--- a/src/screens/onboarding/Profile.tsx
+++ b/src/screens/onboarding/Profile.tsx
@@ -2,16 +2,18 @@ import React from 'react';
import {RouteProp} from '@react-navigation/native';
import {StackNavigationProp} from '@react-navigation/stack';
import {
- View,
Text,
StatusBar,
StyleSheet,
Image,
TouchableOpacity,
+ Alert,
+ View,
} from 'react-native';
import {RootStackParamList} from '../../routes';
import {Background} from '../../components';
import ImagePicker from 'react-native-image-crop-picker';
+import {REGISTER_ENDPOINT} from '../../constants';
type ProfileScreenRouteProp = RouteProp<RootStackParamList, 'Profile'>;
type ProfileScreenNavigationProp = StackNavigationProp<
@@ -24,75 +26,53 @@ interface ProfileProps {
}
/**
- * Create Profile screen for onboarding.
- * @param navigation react-navigation navigation object.
+ * Create profile screen for onboarding.
+ * @param navigation react-navigation navigation object
*/
-const Profile: React.FC<ProfileProps> = ({}) => {
- const [largePicture, setLargePicture] = React.useState({
- path: '',
- height: 0,
- width: 0,
- });
- const [smallPicture, setSmallPicture] = React.useState({
- path: '',
- height: 0,
- width: 0,
- });
- const [showLargeText, setShowLargeText] = React.useState(true);
- const [showSmallText, setShowSmallText] = React.useState(true);
+const Profile: React.FC<ProfileProps> = ({route}) => {
+ const {userId, username} = route.params;
+ const [largePic, setLargePic] = React.useState('');
+ const [smallPic, setSmallPic] = React.useState('');
/**
* Profile screen "Add Large Profile Pic Here" button
*/
const LargeProfilePic = () => (
- <View style={styles.container}>
- <View style={styles.largeButton}>
- <TouchableOpacity
- accessible={true}
- accessibilityLabel="ADD LARGE PROFILE PIC HERE"
- onPress={goToGalleryLargePic}
- style={styles.largeButtonContainer}>
- {showLargeText ? (
- <Text style={styles.addLargeProfilePicText}>
- ADD LARGE PROFILE PIC HERE
- </Text>
- ) : null}
-
- {largePicture.path !== '' && (
- <Image
- source={{uri: largePicture.path}}
- style={styles.largeProfilePic}
- />
- )}
- </TouchableOpacity>
- </View>
- </View>
+ <TouchableOpacity
+ accessible={true}
+ accessibilityLabel="ADD LARGE PROFILE PIC HERE"
+ onPress={goToGalleryLargePic}
+ style={styles.largeProfile}>
+ {largePic ? (
+ <Image
+ source={{uri: largePic}}
+ style={[styles.largeProfile, styles.profilePic]}
+ />
+ ) : (
+ <Text style={styles.largeProfileText}>ADD LARGE PROFILE PIC HERE</Text>
+ )}
+ </TouchableOpacity>
);
/**
* Profile screen "Add Smaller Profile Pic Here" button
*/
const SmallProfilePic = () => (
- <View style={styles.container}>
- <View style={styles.smallButton}>
- <TouchableOpacity
- accessible={true}
- accessibilityLabel="ADD SMALLER PIC"
- onPress={goToGallerySmallPic}>
- {showSmallText ? (
- <Text style={styles.addSmallProfilePicText}>ADD SMALLER PIC</Text>
- ) : null}
-
- {smallPicture.path !== '' && (
- <Image
- source={{uri: smallPicture.path}}
- style={styles.smallProfilePic}
- />
- )}
- </TouchableOpacity>
- </View>
- </View>
+ <TouchableOpacity
+ accessible={true}
+ accessibilityLabel="ADD SMALLER PIC"
+ onPress={goToGallerySmallPic}
+ style={styles.smallProfile}>
+ {smallPic ? (
+ <Image
+ source={{uri: smallPic}}
+ style={[styles.smallProfile, styles.profilePic]}
+ />
+ ) : (
+ <Text style={styles.smallProfileText}>ADD SMALLER PIC</Text>
+ )}
+ </TouchableOpacity>
);
/*
@@ -104,16 +84,12 @@ const Profile: React.FC<ProfileProps> = ({}) => {
width: 580,
height: 580,
cropping: true,
- cropperCircleOverlay: true,
+ cropperToolbarTitle: 'Large profile picture',
+ mediaType: 'photo',
})
.then((picture) => {
if ('path' in picture) {
- setLargePicture({
- path: picture.path,
- height: picture.height,
- width: picture.width,
- });
- setShowLargeText(false);
+ setLargePic(picture.path);
}
})
.catch(() => {});
@@ -128,88 +104,149 @@ const Profile: React.FC<ProfileProps> = ({}) => {
width: 580,
height: 580,
cropping: true,
+ cropperToolbarTitle: 'Small profile picture',
+ mediaType: 'photo',
cropperCircleOverlay: true,
})
.then((picture) => {
if ('path' in picture) {
- setSmallPicture({
- path: picture.path,
- height: picture.height,
- width: picture.width,
- });
- setShowSmallText(false);
+ setSmallPic(picture.path);
}
})
.catch(() => {});
};
+ const handleSubmit = async () => {
+ const form = new FormData();
+ if (largePic) {
+ form.append('largeProfilePicture', {
+ uri: largePic,
+ name: 'large_profile_pic.jpg',
+ type: 'image/jpg',
+ });
+ }
+ if (smallPic) {
+ form.append('smallProfilePicture', {
+ uri: smallPic,
+ name: 'small_profile_pic.jpg',
+ type: 'image/jpg',
+ });
+ }
+ const endpoint = REGISTER_ENDPOINT + `${userId}/`;
+ try {
+ let response = await fetch(endpoint, {
+ method: 'PATCH',
+ headers: {
+ 'Content-Type': 'multipart/form-data',
+ },
+ body: form,
+ });
+ let data = await response.json();
+ let statusCode = response.status;
+ if (statusCode === 200) {
+ Alert.alert(
+ 'Profile successfully created! 🥳',
+ `Welcome to Tagg, ${username}!`,
+ );
+ } else if (statusCode === 400) {
+ Alert.alert('Profile update failed. 😔', `${data}`);
+ } else {
+ Alert.alert(
+ 'Something went wrong! 😭',
+ "Would you believe me if I told you that I don't know what happened?",
+ );
+ }
+ } catch (error) {
+ Alert.alert(
+ 'Profile creation failed 😓',
+ 'Please double-check your network connection and retry.',
+ );
+ return {
+ name: 'Profile creation error',
+ description: error,
+ };
+ }
+ };
+
return (
- <Background>
+ <Background centered>
<StatusBar barStyle="light-content" />
<LargeProfilePic />
<SmallProfilePic />
+ <View style={styles.dummyField}>
+ <Text>DUMMY WEBSITE</Text>
+ </View>
+ <View style={styles.dummyField}>
+ <Text>DUMMY BIO</Text>
+ </View>
+ <TouchableOpacity onPress={handleSubmit} style={styles.submitBtn}>
+ <Text style={styles.submitBtnLabel}>Let's start!</Text>
+ </TouchableOpacity>
</Background>
);
};
const styles = StyleSheet.create({
- container: {
- flex: 1,
- flexDirection: 'row',
+ largeProfile: {
justifyContent: 'center',
alignItems: 'center',
- },
- largeButtonContainer: {
- flex: 1,
- justifyContent: 'center',
- },
- largeButton: {
- padding: 5,
- height: 180,
- width: 180,
- borderRadius: 400,
+ padding: 15,
+ height: 230,
+ width: 230,
+ borderRadius: 23,
backgroundColor: '#fff',
- alignItems: 'center',
- marginTop: '100%',
- marginRight: '12%',
- zIndex: 2,
+ marginRight: '6%',
},
- addLargeProfilePicText: {
+ largeProfileText: {
+ textAlign: 'center',
+ fontSize: 14,
fontWeight: 'bold',
- padding: 22,
- fontSize: 12,
color: '#863FF9',
- textAlign: 'center',
},
- largeProfilePic: {
- height: 180,
- width: 180,
- borderRadius: 400,
- },
- smallButton: {
- position: 'relative',
- padding: 5,
+ smallProfile: {
+ justifyContent: 'center',
+ alignItems: 'center',
+ padding: 20,
height: 110,
width: 110,
- borderRadius: 400,
+ borderRadius: 55,
backgroundColor: '#E1F0FF',
- justifyContent: 'center',
- alignItems: 'center',
- zIndex: 1,
- marginTop: '128%',
- marginLeft: '30%',
+ marginLeft: '45%',
+ bottom: '7%',
},
- addSmallProfilePicText: {
+ smallProfileText: {
+ textAlign: 'center',
+ fontSize: 14,
fontWeight: 'bold',
- padding: 10,
- fontSize: 12,
color: '#806DF4',
- textAlign: 'center',
},
- smallProfilePic: {
- height: 110,
- width: 110,
- borderRadius: 400,
+ profilePic: {
+ marginRight: 0,
+ marginLeft: 0,
+ bottom: 0,
+ },
+ dummyField: {
+ height: '10%',
+ width: '80%',
+ justifyContent: 'center',
+ alignItems: 'center',
+ borderColor: '#fff',
+ borderWidth: 1,
+ borderRadius: 8,
+ marginBottom: '10%',
+ },
+ submitBtn: {
+ backgroundColor: '#8F01FF',
+ justifyContent: 'center',
+ alignItems: 'center',
+ width: 150,
+ height: 40,
+ borderRadius: 5,
+ },
+ submitBtnLabel: {
+ fontSize: 16,
+ fontWeight: '500',
+ color: '#fff',
},
});