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] Allow users to add secondary logins (followup) #2251

Merged
Merged
Show file tree
Hide file tree
Changes from all 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
11 changes: 10 additions & 1 deletion src/pages/settings/AddSecondaryLoginPage.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,9 @@ const propTypes = {

// Route object from navigation
route: PropTypes.shape({
// Params that are passed into the route
params: PropTypes.shape({
// The type of secondary login to be added (email|phone)
type: PropTypes.string,
}),
}),
Expand Down Expand Up @@ -69,6 +71,9 @@ class AddSecondaryLoginPage extends Component {
Onyx.merge(ONYXKEYS.USER, {error: ''});
}

/**
* Add a secondary login to a user's account
*/
submitForm() {
setSecondaryLogin(this.state.login, this.state.password)
.then((response) => {
Expand All @@ -78,7 +83,11 @@ class AddSecondaryLoginPage extends Component {
});
}

// Determines whether form is valid
/**
* Determine whether the form is valid
*
* @returns {Boolean}
*/
validateForm() {
const validationMethod = this.formType === CONST.LOGIN_TYPE.PHONE ? Str.isValidPhone : Str.isValidEmail;
return !this.state.password || !validationMethod(this.state.login);
Expand Down
6 changes: 6 additions & 0 deletions src/pages/settings/ProfilePage/LoginField.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,10 @@ const propTypes = {

// Login associated with the user
login: PropTypes.shape({
// Phone/Email associated with user
partnerUserID: PropTypes.string,

// Date of when login was validated
validatedDate: PropTypes.string,
}).isRequired,
};
Expand All @@ -35,6 +38,9 @@ export default class LoginField extends Component {
this.onResendClicked = this.onResendClicked.bind(this);
}

/**
* Resend validation code and show the checkmark icon
*/
onResendClicked() {
resendValidateCode(this.props.login.partnerUserID);
this.setState({showCheckmarkIcon: true});
Expand Down
25 changes: 23 additions & 2 deletions src/pages/settings/ProfilePage/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,9 @@ const propTypes = {

const defaultProps = {
myPersonalDetails: {},
user: {},
user: {
loginList: [],
},
};

const timezones = moment.tz.names()
Expand Down Expand Up @@ -134,14 +136,24 @@ class ProfilePage extends Component {
}
}

/**
* Set the form to use automatic timezone
*
* @param {Boolean} isAutomaticTimezone
*/
setAutomaticTimezone(isAutomaticTimezone) {
this.setState(({selectedTimezone}) => ({
isAutomaticTimezone,
selectedTimezone: isAutomaticTimezone ? moment.tz.guess() : selectedTimezone,
}));
}

// Get the most validated login of each type
/**
* Get the most validated login of each type
*
* @param {Array} loginList
* @returns {Object}
*/
getLogins(loginList) {
return loginList.reduce((logins, currentLogin) => {
const type = Str.isSMSLogin(currentLogin.partnerUserID) ? CONST.LOGIN_TYPE.PHONE : CONST.LOGIN_TYPE.EMAIL;
Expand All @@ -166,6 +178,9 @@ class ProfilePage extends Component {
});
}

/**
* Submit form to update personal details
*/
updatePersonalDetails() {
const {
firstName,
Expand All @@ -187,6 +202,12 @@ class ProfilePage extends Component {
});
}

/**
* Create menu items list for avatar menu
*
* @param {Function} openPicker
* @returns {Array}
*/
createMenuItems(openPicker) {
const menuItems = [
{
Expand Down