-
Notifications
You must be signed in to change notification settings - Fork 2.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #15039 from Expensify/beaman-newContactMethodsPage
New Contact methods page linked from Profile page
- Loading branch information
Showing
10 changed files
with
265 additions
and
195 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
138 changes: 138 additions & 0 deletions
138
src/pages/settings/Profile/Contacts/ContactMethodsPage.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,138 @@ | ||
import Str from 'expensify-common/lib/str'; | ||
import lodashGet from 'lodash/get'; | ||
import PropTypes from 'prop-types'; | ||
import React, {Component} from 'react'; | ||
import {ScrollView} from 'react-native-gesture-handler'; | ||
import {withOnyx} from 'react-native-onyx'; | ||
import _ from 'underscore'; | ||
import HeaderWithCloseButton from '../../../../components/HeaderWithCloseButton'; | ||
import ScreenWrapper from '../../../../components/ScreenWrapper'; | ||
import withCurrentUserPersonalDetails, {withCurrentUserPersonalDetailsDefaultProps, withCurrentUserPersonalDetailsPropTypes} from '../../../../components/withCurrentUserPersonalDetails'; | ||
import withLocalize, {withLocalizePropTypes} from '../../../../components/withLocalize'; | ||
import CONST from '../../../../CONST'; | ||
import compose from '../../../../libs/compose'; | ||
import Navigation from '../../../../libs/Navigation/Navigation'; | ||
import ONYXKEYS from '../../../../ONYXKEYS'; | ||
import ROUTES from '../../../../ROUTES'; | ||
import LoginField from './LoginField'; | ||
|
||
const propTypes = { | ||
/* Onyx Props */ | ||
|
||
/** Login list for the user that is signed in */ | ||
loginList: PropTypes.shape({ | ||
/** Value of partner name */ | ||
partnerName: PropTypes.string, | ||
|
||
/** Phone/Email associated with user */ | ||
partnerUserID: PropTypes.string, | ||
|
||
/** Date of when login was validated */ | ||
validatedDate: PropTypes.string, | ||
}), | ||
|
||
...withLocalizePropTypes, | ||
...withCurrentUserPersonalDetailsPropTypes, | ||
}; | ||
|
||
const defaultProps = { | ||
loginList: {}, | ||
...withCurrentUserPersonalDetailsDefaultProps, | ||
}; | ||
|
||
class ContactMethodsPage extends Component { | ||
constructor(props) { | ||
super(props); | ||
|
||
this.state = { | ||
logins: this.getLogins(), | ||
}; | ||
|
||
this.getLogins = this.getLogins.bind(this); | ||
} | ||
|
||
componentDidUpdate(prevProps) { | ||
let stateToUpdate = {}; | ||
|
||
// Recalculate logins if loginList has changed | ||
if (_.keys(this.props.loginList).length !== _.keys(prevProps.loginList).length) { | ||
stateToUpdate = {logins: this.getLogins()}; | ||
} | ||
|
||
if (_.isEmpty(stateToUpdate)) { | ||
return; | ||
} | ||
|
||
// eslint-disable-next-line react/no-did-update-set-state | ||
this.setState(stateToUpdate); | ||
} | ||
|
||
/** | ||
* Get the most validated login of each type | ||
* | ||
* @returns {Object} | ||
*/ | ||
getLogins() { | ||
return _.reduce(_.values(this.props.loginList), (logins, currentLogin) => { | ||
const type = Str.isSMSLogin(currentLogin.partnerUserID) ? CONST.LOGIN_TYPE.PHONE : CONST.LOGIN_TYPE.EMAIL; | ||
const login = Str.removeSMSDomain(currentLogin.partnerUserID); | ||
|
||
// If there's already a login type that's validated and/or currentLogin isn't valid then return early | ||
if ((login !== lodashGet(this.props.currentUserPersonalDetails, 'login')) && !_.isEmpty(logins[type]) | ||
&& (logins[type].validatedDate || !currentLogin.validatedDate)) { | ||
return logins; | ||
} | ||
return { | ||
...logins, | ||
[type]: { | ||
...currentLogin, | ||
type, | ||
partnerUserID: Str.removeSMSDomain(currentLogin.partnerUserID), | ||
}, | ||
}; | ||
}, { | ||
phone: {}, | ||
email: {}, | ||
}); | ||
} | ||
|
||
render() { | ||
return ( | ||
<ScreenWrapper> | ||
<HeaderWithCloseButton | ||
title={this.props.translate('contacts.contactMethods')} | ||
shouldShowBackButton | ||
onBackButtonPress={() => Navigation.navigate(ROUTES.SETTINGS_PROFILE)} | ||
onCloseButtonPress={() => Navigation.dismissModal(true)} | ||
/> | ||
<ScrollView> | ||
<LoginField | ||
label={this.props.translate('profilePage.emailAddress')} | ||
type="email" | ||
login={this.state.logins.email} | ||
defaultValue={this.state.logins.email} | ||
/> | ||
<LoginField | ||
label={this.props.translate('common.phoneNumber')} | ||
type="phone" | ||
login={this.state.logins.phone} | ||
defaultValue={this.state.logins.phone} | ||
/> | ||
</ScrollView> | ||
</ScreenWrapper> | ||
); | ||
} | ||
} | ||
|
||
ContactMethodsPage.propTypes = propTypes; | ||
ContactMethodsPage.defaultProps = defaultProps; | ||
|
||
export default compose( | ||
withLocalize, | ||
withCurrentUserPersonalDetails, | ||
withOnyx({ | ||
loginList: { | ||
key: ONYXKEYS.LOGIN_LIST, | ||
}, | ||
}), | ||
)(ContactMethodsPage); |
24 changes: 12 additions & 12 deletions
24
src/pages/settings/Profile/LoginField.js → ...s/settings/Profile/Contacts/LoginField.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.