-
Notifications
You must be signed in to change notification settings - Fork 3k
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
Add currency selector to settings page #5713
Changes from 2 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,13 +5,10 @@ import PropTypes from 'prop-types'; | |
import lodashGet from 'lodash/get'; | ||
import _ from 'underscore'; | ||
import ONYXKEYS from '../../ONYXKEYS'; | ||
import HeaderWithCloseButton from '../../components/HeaderWithCloseButton'; | ||
import ScreenWrapper from '../../components/ScreenWrapper'; | ||
import withLocalize, {withLocalizePropTypes} from '../../components/withLocalize'; | ||
import Navigation from '../../libs/Navigation/Navigation'; | ||
import Permissions from '../../libs/Permissions'; | ||
import styles from '../../styles/styles'; | ||
import TextInputWithLabel from '../../components/TextInputWithLabel'; | ||
import Button from '../../components/Button'; | ||
import Text from '../../components/Text'; | ||
import compose from '../../libs/compose'; | ||
|
@@ -24,6 +21,11 @@ import AvatarWithImagePicker from '../../components/AvatarWithImagePicker'; | |
import defaultTheme from '../../styles/themes/default'; | ||
import Growl from '../../libs/Growl'; | ||
import CONST from '../../CONST'; | ||
import ExpensiPicker from '../../components/ExpensiPicker'; | ||
import {getCurrencyList} from '../../libs/actions/PersonalDetails'; | ||
import ExpensiTextInput from '../../components/ExpensiTextInput/index'; | ||
import FixedFooter from '../../components/FixedFooter'; | ||
import WorkspacePageWithSections from './WorkspacePageWithSections'; | ||
|
||
const propTypes = { | ||
/** List of betas */ | ||
|
@@ -43,14 +45,20 @@ class WorkspaceSettingsPage extends React.Component { | |
name: props.policy.name, | ||
avatarURL: props.policy.avatarURL, | ||
previewAvatarURL: props.policy.avatarURL, | ||
currency: props.policy.outputCurrency, | ||
}; | ||
|
||
this.submit = this.submit.bind(this); | ||
this.onImageSelected = this.onImageSelected.bind(this); | ||
this.onImageRemoved = this.onImageRemoved.bind(this); | ||
this.getCurrencyItems = this.getCurrencyItems.bind(this); | ||
this.uploadAvatarPromise = Promise.resolve(); | ||
} | ||
|
||
componentDidMount() { | ||
getCurrencyList(); | ||
} | ||
|
||
onImageSelected(image) { | ||
updateLocalPolicyValues(this.props.policy.id, {isAvatarUploading: true}); | ||
this.setState({previewAvatarURL: image.uri}); | ||
|
@@ -67,6 +75,19 @@ class WorkspaceSettingsPage extends React.Component { | |
this.setState({previewAvatarURL: '', avatarURL: ''}); | ||
} | ||
|
||
/** | ||
* | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Remove extra line |
||
* @returns {Object[]} | ||
*/ | ||
getCurrencyItems() { | ||
const currencyListKeys = _.keys(this.props.currencyList); | ||
const a = _.map(currencyListKeys, currencyCode => ({ | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Don't use a short variable and just use There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Oh I was debugging this and added it for easy inspection, removing it |
||
value: currencyCode, | ||
label: `${currencyCode} - ${this.props.currencyList[currencyCode].symbol}`, | ||
})); | ||
return a; | ||
} | ||
|
||
submit() { | ||
updateLocalPolicyValues(this.props.policy.id, {isPolicyUpdating: true}); | ||
|
||
|
@@ -75,8 +96,9 @@ class WorkspaceSettingsPage extends React.Component { | |
const name = this.state.name.trim(); | ||
const avatarURL = this.state.avatarURL; | ||
const policyID = this.props.policy.id; | ||
const currency = this.state.currency; | ||
|
||
update(policyID, {name, avatarURL}); | ||
update(policyID, {name, avatarURL, outputCurrency: currency}); | ||
}).catch(() => { | ||
updateLocalPolicyValues(this.props.policy.id, {isPolicyUpdating: false}); | ||
}); | ||
|
@@ -98,55 +120,69 @@ class WorkspaceSettingsPage extends React.Component { | |
|| (this.state.avatarURL === this.props.policy.avatarURL | ||
&& this.state.name === this.props.policy.name); | ||
return ( | ||
<ScreenWrapper> | ||
<HeaderWithCloseButton | ||
title={this.props.translate('workspace.common.edit')} | ||
onCloseButtonPress={Navigation.dismissModal} | ||
/> | ||
|
||
<View style={[styles.pageWrapper, styles.flex1, styles.pRelative]}> | ||
<View style={[styles.w100, styles.flex1]}> | ||
<AvatarWithImagePicker | ||
isUploading={policy.isAvatarUploading} | ||
avatarURL={this.state.previewAvatarURL} | ||
size={CONST.AVATAR_SIZE.LARGE} | ||
DefaultAvatar={() => ( | ||
<Icon | ||
src={Workspace} | ||
height={80} | ||
width={80} | ||
fill={defaultTheme.iconSuccessFill} | ||
<WorkspacePageWithSections | ||
headerText={this.props.translate('workspace.common.edit')} | ||
route={this.props.route} | ||
> | ||
{(hasVBA) => ( | ||
<> | ||
<View style={[styles.pageWrapper, styles.flex1, styles.pRelative]}> | ||
<View style={[styles.w100, styles.flex1]}> | ||
<AvatarWithImagePicker | ||
isUploading={policy.isAvatarUploading} | ||
avatarURL={this.state.previewAvatarURL} | ||
size={CONST.AVATAR_SIZE.LARGE} | ||
DefaultAvatar={() => ( | ||
<Icon | ||
src={Workspace} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think this is supposed to be |
||
height={80} | ||
width={80} | ||
fill={defaultTheme.iconSuccessFill} | ||
/> | ||
)} | ||
style={[styles.mb3]} | ||
anchorPosition={{top: 172, right: 18}} | ||
isUsingDefaultAvatar={!this.state.previewAvatarURL} | ||
onImageSelected={this.onImageSelected} | ||
onImageRemoved={this.onImageRemoved} | ||
/> | ||
|
||
<ExpensiTextInput | ||
label={this.props.translate('workspace.editor.nameInputLabel')} | ||
containerStyles={[styles.mt4]} | ||
onChangeText={name => this.setState({name})} | ||
value={this.state.name} | ||
hasError={!this.state.name.trim().length} | ||
errorText={this.state.name.trim().length ? '' : this.props.translate('workspace.editor.nameIsRequiredError')} | ||
/> | ||
|
||
<ExpensiPicker | ||
label={this.props.translate('workspace.editor.currencyInputLabel')} | ||
onChange={currency => this.setState({currency})} | ||
items={this.getCurrencyItems()} | ||
value={this.state.currency} | ||
style={[styles.mt4]} | ||
isDisabled={hasVBA} | ||
/> | ||
<Text style={[styles.mt2, styles.formHint]}> | ||
{this.props.translate('workspace.editor.currencyInputHelpText')} | ||
</Text> | ||
</View> | ||
|
||
<FixedFooter style={[styles.w100]}> | ||
<Button | ||
success | ||
isLoading={policy.isPolicyUpdating} | ||
isDisabled={isButtonDisabled} | ||
text={this.props.translate('workspace.editor.save')} | ||
onPress={this.submit} | ||
pressOnEnter | ||
/> | ||
)} | ||
style={[styles.mb3]} | ||
anchorPosition={{top: 172, right: 18}} | ||
isUsingDefaultAvatar={!this.state.previewAvatarURL} | ||
onImageSelected={this.onImageSelected} | ||
onImageRemoved={this.onImageRemoved} | ||
/> | ||
|
||
<TextInputWithLabel | ||
label={this.props.translate('workspace.editor.nameInputLabel')} | ||
value={this.state.name} | ||
onChangeText={name => this.setState({name})} | ||
onSubmitEditting={this.submit} | ||
/> | ||
<Text style={[styles.mt2, styles.formHint]}> | ||
{this.props.translate('workspace.editor.nameInputHelpText')} | ||
</Text> | ||
</View> | ||
|
||
<Button | ||
success | ||
isLoading={policy.isPolicyUpdating} | ||
isDisabled={isButtonDisabled} | ||
style={[styles.w100]} | ||
text={this.props.translate('workspace.editor.save')} | ||
onPress={this.submit} | ||
pressOnEnter | ||
/> | ||
</View> | ||
</ScreenWrapper> | ||
</FixedFooter> | ||
</View> | ||
</> | ||
)} | ||
</WorkspacePageWithSections> | ||
); | ||
} | ||
} | ||
|
@@ -167,6 +203,7 @@ export default compose( | |
return `${ONYXKEYS.COLLECTION.POLICY}${policyID}`; | ||
}, | ||
}, | ||
currencyList: {key: ONYXKEYS.CURRENCY_LIST}, | ||
}), | ||
withLocalize, | ||
)(WorkspaceSettingsPage); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
props.policy
is missing from thepropTypes
. Can you please add it?