Skip to content

Commit

Permalink
From previous commit to issue SHPEUCF#136 did some clean up and code …
Browse files Browse the repository at this point in the history
…style to profile.js. Added the functions to OtherProfile.js to handle app linking there. In FormData.js jus did code clean up to the element added earlier in edit regular profile. ** in profile in form component in the values parameter I erase function that was formating the this.props.activeuser since it was creating a type missmatch in Form.js. the parameter values is expecting an object but was receiving an array. this cause the app to crash when onsubmit was called.**
  • Loading branch information
Sergio Perez-Aponte authored and Sergio Perez-Aponte committed May 22, 2020
1 parent f5a75f9 commit 1344ba0
Show file tree
Hide file tree
Showing 3 changed files with 89 additions and 29 deletions.
3 changes: 1 addition & 2 deletions src/data/FormData.js
Original file line number Diff line number Diff line change
Expand Up @@ -161,11 +161,10 @@ const editProfileFormDataRegular = [
}
},
{
placeholder: "LinkedIn Profile",
placeholder: "LinkedIn Profile (after the in/)",
camelCaseName: "linkedin",
type: "Input",
isRequired: false

}
];

Expand Down
60 changes: 51 additions & 9 deletions src/screens/User/OtherProfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { Alert, ButtonLayout, NavBar } from "../../components";
import { Avatar } from "react-native-elements";
import Flag from "react-native-flags";
import { verifiedCheckMark } from "../../utils/render";
import { Text, View, TouchableOpacity, Dimensions, SafeAreaView } from "react-native";
import { Text, View, TouchableOpacity, Dimensions, SafeAreaView, Linking } from "react-native";

const dimension = Dimensions.get("window");

Expand Down Expand Up @@ -122,8 +122,8 @@ class OtherProfile extends Component {
}

renderFlag() {

let flag = null;

if (this.props.flag !== "" && this.props.flag) {
flag = <Flag
type = "flat"
Expand All @@ -147,15 +147,20 @@ class OtherProfile extends Component {
socialmediarow
} = styles;

const {
firstName,
email,
linkedin
} = this.props;

return (
<View style = {{ flex: 0.2 }}>
<View style = {{ flex: 0.03 }}></View>
<View style = { socialmediarow }>
<View style = { [LogoContainer, { backgroundColor: this.props.color, flex: 1 }] }>
<TouchableOpacity
onPress = { () => {
Alert.alert("Coming Soon");
// Actions.PostShow({ title: 'Linkedin', uri: 'https://www.linkedin.com/'})
this.openApp(linkedin, firstName);
} }>
<Ionicons name = "logo-linkedin" size = { dimension.height * 0.045 } color = 'white' />
</TouchableOpacity>
Expand All @@ -164,8 +169,7 @@ class OtherProfile extends Component {
<View style = { [LogoContainer, { backgroundColor: this.props.color, flex: 1 }] }>
<TouchableOpacity
onPress = { () => {
Alert.alert("Coming Soon");
// Actions.PostShow({ title: 'Github', uri: 'https://www.github.com/'})
this.openEmail(email, firstName);
} } >
<Ionicons name = "ios-mail" size = { dimension.height * 0.045 } color = 'white' />
</TouchableOpacity>
Expand All @@ -174,6 +178,42 @@ class OtherProfile extends Component {
</View>
);
}

async openApp(profile, name) {
if (!profile) {
Alert.alert(`${ name } has not added his LinkedIn profile yet.`);
}
else {
let url = `linkedin://in/${ profile }`;

console.log(`URL: ${ profile }`);
// then have to check if the link can be handle
const canOpenLink = await Linking.canOpenURL(url);

if (canOpenLink)
await Linking.openURL(url);
else
await Linking.openURL(`https://linkedin.com/in/${ profile }`);
}
}

async openEmail(to, name) {
if (!to) {
Alert.alert(`No email for ${ name } has been found.`);
}
else {
let url = `mailto:${ to }`;
const canOpenEmail = await Linking.canOpenURL(url);

if (canOpenEmail) {
await Linking.openURL(url);
}
else {
Alert.alert(`Oops! Somenthing went wrong.\\n
If problem persists contact support.`);
}
}
}
}

const styles = {
Expand Down Expand Up @@ -259,7 +299,8 @@ const mapStateToProps = ({ members, general, user }) => {
quote,
color,
flag,
paidMember
paidMember,
linkedin
} = members;
const {
loading
Expand All @@ -280,10 +321,11 @@ const mapStateToProps = ({ members, general, user }) => {
activeUser,
color,
flag,
paidMember
paidMember,
linkedin
};
};

const mapDispatchToProps = {};

export default connect(mapStateToProps, mapDispatchToProps)(OtherProfile);
export default connect(mapStateToProps, mapDispatchToProps)(OtherProfile);
55 changes: 37 additions & 18 deletions src/screens/User/Profile.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,10 @@ class Profile extends Component {
render() {
return this.renderContent();
}

/*
* using convertObjectToInitialValues() to pass the value back to values break the app due to parameter
* miss match. Form expected an object but receives an array.
*/
renderContent() {
const { email, major, points, privilege } = this.props.activeUser;
const { bioContainer, fieldContainerStyle, itemLabelText, itemValueText, textColor } = styles;
Expand All @@ -38,12 +41,12 @@ class Profile extends Component {
<SafeAreaView style = {{ flex: 1, backgroundColor: "#0c0b0b" }}>
<Form
elements = { privilege.eboard ? editProfileFormDataPrivileged : editProfileFormDataRegular }
values = { convertObjectToInitialValues(this.props.activeUser) }
values = { this.props.activeUser }
title = "Edit Profile"
visible = { this.state.editProfileFormVisibility }
changeVisibility = { (visible) => this.setState({ editProfileFormVisibility: visible }) }
onSubmit = { ({ gender, major, country, birthday }) =>
editUser({ gender, major, country, birthday }) }
onSubmit = { ({ gender, major, country, birthday, linkedin }) =>
editUser({ gender, major, country, birthday, linkedin }) }
/>
<View style = {{ flex: 1, backgroundColor: "black" }}>
{ this.renderPicture() }
Expand Down Expand Up @@ -159,7 +162,7 @@ class Profile extends Component {
</View>
<View style = {{ flex: 0.01 }} />
<View style = { [logoContainer, { backgroundColor: color, flex: 1 }] }>
<TouchableOpacity onPress = { () => Linking.openURL(`mailto:${email}`) }>
<TouchableOpacity onPress = { () => this.openEmail(email) }>
<Ionicons name = "ios-mail" size = { height * 0.045 } color = "white" />
</TouchableOpacity>
</View>
Expand All @@ -168,23 +171,39 @@ class Profile extends Component {
);
}

async openApp(profile){
if(profile === "")
{
Alert.alert("No profile have been added.");
async openApp(profile) {
if (!profile) {
Alert.alert(`No profile have been added.\nTo add your profile click on Edit Profile.`);
}
let url = `linkedin://in/${profile}`;
else {
let url = `linkedin://in/${profile}`;

// then have to check if the link can be handle
const canOpenLink = await Linking.canOpenURL(url);
console.log(`URL: ${profile}`);
// then have to check if the link can be handle
const canOpenLink = await Linking.canOpenURL(url);

if(canOpenLink)
{
await Linking.openURL(url);
if (canOpenLink)
await Linking.openURL(url);
else
await Linking.openURL(`https://linkedin.com/in/${profile}`);
}
else
{
await Linking.openURL(`https://linkedin.com/in/${profile}`);
}

async openEmail(to) {
if (!to) {
Alert.alert("No email was found.\nTry again again.");
}
else {
let url = `mailto:${to}`;
const canOpenEmail = await Linking.canOpenURL(url);

if (canOpenEmail) {
await Linking.openURL(url);
}
else {
Alert.alert(`Oops! Somenthing went wrong.\n
If problem persists contact support.`);
}
}
}
}
Expand Down

0 comments on commit 1344ba0

Please sign in to comment.