Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[User Settings] Add new Profile view #1767

Merged
merged 23 commits into from
Mar 23, 2021
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
46 changes: 46 additions & 0 deletions src/components/Checkbox.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
import React from 'react';
import {View, Pressable, Text} from 'react-native';
import PropTypes from 'prop-types';
import styles from '../styles/styles';
import Icon from './Icon';
import {Checkmark} from './Icon/Expensicons';

const propTypes = {
// Whether checkbox is checked
isChecked: PropTypes.bool.isRequired,

// A function that is called when the box/label is clicked on
onClick: PropTypes.func.isRequired,
Maftalion marked this conversation as resolved.
Show resolved Hide resolved

// Text that appears next to check box
label: PropTypes.string,
};

const defaultProps = {
label: '',
};

const Checkbox = ({
isChecked, onClick, label,
Maftalion marked this conversation as resolved.
Show resolved Hide resolved
}) => (
<View style={styles.flexRow}>
<Pressable onPress={() => onClick(!isChecked)}>
<View style={[styles.checkboxContainer, isChecked && styles.checkedContainer]}>
<Icon src={Checkmark} fill="white" height={14} width={14} />
</View>
</Pressable>
{label ? (
<Pressable onPress={() => onClick(!isChecked)}>
<Text style={[styles.ml2, styles.textP]}>
{label}
</Text>
</Pressable>
) : null}
Maftalion marked this conversation as resolved.
Show resolved Hide resolved
</View>
);


Maftalion marked this conversation as resolved.
Show resolved Hide resolved
Checkbox.defaultProps = defaultProps;
Checkbox.propTypes = propTypes;

export default Checkbox;
244 changes: 228 additions & 16 deletions src/pages/settings/ProfilePage.js
Original file line number Diff line number Diff line change
@@ -1,24 +1,236 @@
import React from 'react';
import React, {Component} from 'react';
import {withOnyx} from 'react-native-onyx';
import PropTypes from 'prop-types';
import {
View,
TextInput,
} from 'react-native';
import RNPickerSelect from 'react-native-picker-select';
import Str from 'expensify-common/lib/str';
import moment from 'moment-timezone';

Maftalion marked this conversation as resolved.
Show resolved Hide resolved
import HeaderWithCloseButton from '../../components/HeaderWithCloseButton';
import Navigation from '../../libs/Navigation/Navigation';
import ScreenWrapper from '../../components/ScreenWrapper';
import {setPersonalDetails} from '../../libs/actions/PersonalDetails';
import ROUTES from '../../ROUTES';
import ONYXKEYS from '../../ONYXKEYS';
import CONST from '../../CONST';
import Avatar from '../../components/Avatar';
import styles from '../../styles/styles';
import Text from '../../components/Text';
import {DownArrow} from '../../components/Icon/Expensicons';
import Icon from '../../components/Icon';
import Checkbox from '../../components/Checkbox';
import ButtonWithLoader from '../../components/ButtonWithLoader';

const propTypes = {
/* Onyx Props */
// The personal details of the person who is logged in
myPersonalDetails: PropTypes.shape({
// Email/Phone login of the current user from their personal details
login: PropTypes.string,

// Display first name of the current user from their personal details
firstName: PropTypes.string,

// Display last name of the current user from their personal details
lastName: PropTypes.string,

// Avatar URL of the current user from their personal details
avatarURL: PropTypes.string,
Maftalion marked this conversation as resolved.
Show resolved Hide resolved

// Pronouns of the current user from their personal details
pronouns: PropTypes.string,

// timezone of the current user from their personal details
timezone: PropTypes.shape({

// Value of selected timezone
selected: PropTypes.string,

// Whether timezone is automatically set
automatic: PropTypes.bool,
}),
}),
};

const defaultProps = {
myPersonalDetails: {},
};

const pronounsMap = {
theyThemTheirs: 'They/them/theirs',
sheHerHers: 'She/her/hers',
heHimHis: 'He/him/his',
zeHirHirs: 'Ze/hir/hirs',
selfSelect: 'Self-select',
callMeByMyName: 'Call me by my name',
};
Maftalion marked this conversation as resolved.
Show resolved Hide resolved

const timezones = moment.tz.names()
.map(timezone => ({
value: timezone,
label: timezone,
}));

class ProfilePage extends Component {
constructor(props) {
super(props);

const {
firstName, lastName, pronouns, timezone = {},
} = props.myPersonalDetails;
Maftalion marked this conversation as resolved.
Show resolved Hide resolved

this.state = {
firstName,
lastName,
pronouns,
selfSelectedPronouns: '',
nickmurray47 marked this conversation as resolved.
Show resolved Hide resolved
selectedTimezone: timezone.selected ?? CONST.DEFAULT_TIME_ZONE.selected,
Maftalion marked this conversation as resolved.
Show resolved Hide resolved
isAutomaticTimezone: timezone.automatic ?? CONST.DEFAULT_TIME_ZONE.automatic,
};

this.pronounDropdownValues = Object.values(pronounsMap).map(pronoun => ({value: pronoun, label: pronoun}));
this.updatePersonalDetails = this.updatePersonalDetails.bind(this);
}

updatePersonalDetails() {
const {
firstName, lastName, pronouns, selfSelectedPronouns, selectedTimezone, isAutomaticTimezone,
} = this.state;
Maftalion marked this conversation as resolved.
Show resolved Hide resolved

setPersonalDetails({
firstName,
lastName,
pronouns: pronouns === pronounsMap.selfSelect ? selfSelectedPronouns : pronouns,
timezone: {
automatic: isAutomaticTimezone,
selected: selectedTimezone,
},
});
}

render() {
return (
<ScreenWrapper>
{() => (
<>
<HeaderWithCloseButton
title="Profile"
shouldShowBackButton
onBackButtonPress={() => Navigation.navigate(ROUTES.SETTINGS)}
onCloseButtonPress={Navigation.dismissModal}
/>
<View style={styles.p5}>
<Avatar
style={[styles.avatarLarge, styles.alignSelfCenter]}
source={this.props.myPersonalDetails.avatarURL}
/>
<Text style={[styles.mt6, styles.mb6, styles.textP]}>
Tell us about yourself, we would love to get to know you!
</Text>
<View style={[styles.flexRow, styles.mb6]}>
<View style={styles.flex1}>
<Text style={[styles.mb1, styles.formLabel]}>First Name</Text>
<TextInput
style={styles.textInput}
value={this.state.firstName}
onChangeText={firstName => this.setState({firstName})}
placeholder="John"
Maftalion marked this conversation as resolved.
Show resolved Hide resolved
/>
</View>
<View style={[styles.flex1, styles.ml2]}>
<Text style={[styles.mb1, styles.formLabel]}>Last Name</Text>
<TextInput
style={styles.textInput}
value={this.state.lastName}
onChangeText={lastName => this.setState({lastName})}
placeholder="Doe"
/>
</View>
</View>
<View style={styles.mb6}>
<Text style={[styles.mb1, styles.formLabel]}>Preferred Pronouns</Text>
<View style={styles.mb1}>
<RNPickerSelect
onValueChange={pronouns => this.setState({pronouns, selfSelectedPronouns: ''})}
items={this.pronounDropdownValues}
style={styles.picker}
useNativeAndroidPickerStyle={false}
placeholder={{
value: '',
label: 'Select your pronouns',
}}
value={this.state.pronouns}
Icon={() => <Icon src={DownArrow} />}
/>
</View>
{this.state.pronouns === pronounsMap.selfSelect ? (
<TextInput
style={styles.textInput}
value={this.state.selfSelectedPronouns}
onChangeText={selfSelectedPronouns => this.setState({selfSelectedPronouns})}
placeholder="Self-select your pronoun"
/>
) : null}
Maftalion marked this conversation as resolved.
Show resolved Hide resolved
</View>
<View style={styles.mb6}>
<Text style={[styles.mb1, styles.formLabel]}>
{Str.isSMSLogin(this.props.myPersonalDetails.login)
? 'Phone Number' : 'Email Address'}
</Text>
<TextInput
style={[styles.textInput, styles.disabledTextInput]}
value={this.props.myPersonalDetails.login}
Maftalion marked this conversation as resolved.
Show resolved Hide resolved
editable={false}
/>
</View>
<View style={styles.mb2}>
<Text style={[styles.mb1, styles.formLabel]}>Timezone</Text>
<RNPickerSelect
onValueChange={selectedTimezone => this.setState({selectedTimezone})}
items={timezones}
style={this.state.isAutomaticTimezone ? {
...styles.picker,
inputIOS: [styles.picker.inputIOS, styles.textInput, styles.disabledTextInput],
inputAndroid: [
styles.picker.inputAndroid, styles.textInput, styles.disabledTextInput,
],
inputWeb: [styles.picker.inputWeb, styles.textInput, styles.disabledTextInput],
} : styles.picker}
useNativeAndroidPickerStyle={false}
value={this.state.selectedTimezone}
Icon={() => <Icon src={DownArrow} />}
disabled={this.state.isAutomaticTimezone}
Maftalion marked this conversation as resolved.
Show resolved Hide resolved
/>
</View>
<Checkbox
Maftalion marked this conversation as resolved.
Show resolved Hide resolved
label="Set my timezone automatically"
Maftalion marked this conversation as resolved.
Show resolved Hide resolved
isChecked={this.state.isAutomaticTimezone}
onClick={isAutomaticTimezone => this.setState({isAutomaticTimezone})}
/>
</View>
<View style={styles.fixedBottomButton}>
<ButtonWithLoader
text="Save"
onClick={this.updatePersonalDetails}
/>
</View>
</>
)}
</ScreenWrapper>
);
}
}

const ProfilePage = () => (
<ScreenWrapper>
{() => (
<>
<HeaderWithCloseButton
title="Profile"
shouldShowBackButton
onBackButtonPress={() => Navigation.navigate(ROUTES.SETTINGS)}
onCloseButtonPress={() => Navigation.dismissModal()}
/>
</>
)}
</ScreenWrapper>
);

Maftalion marked this conversation as resolved.
Show resolved Hide resolved
ProfilePage.propTypes = propTypes;
ProfilePage.defaultProps = defaultProps;
ProfilePage.displayName = 'ProfilePage';

export default ProfilePage;
export default withOnyx({
myPersonalDetails: {
key: ONYXKEYS.MY_PERSONAL_DETAILS,
},
})(ProfilePage);
Loading