Skip to content

Commit

Permalink
chore: address pr comments
Browse files Browse the repository at this point in the history
  • Loading branch information
thiagobrez committed Sep 20, 2023
1 parent f7ca607 commit 5539242
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 34 deletions.
2 changes: 1 addition & 1 deletion src/pages/workspace/WorkspaceSettingsCurrencyPage.js
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ function WorkspaceSettingsCurrencyPage({currencyList, policy}) {

const sections = [{data: currencyItems, indexOffset: 0}];

const headerMessage = searchText.trim() && !sections[0].data.length ? translate('common.noResultsFound') : '';
const headerMessage = searchText.trim() && !currencyItems.length ? translate('common.noResultsFound') : '';

const onBackButtonPress = useCallback(() => Navigation.goBack(ROUTES.getWorkspaceSettingsRoute(policy.id)), [policy.id]);

Expand Down
77 changes: 44 additions & 33 deletions src/pages/workspace/WorkspaceSettingsPage.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import {withOnyx} from 'react-native-onyx';
import PropTypes from 'prop-types';
import lodashGet from 'lodash/get';
import ONYXKEYS from '../../ONYXKEYS';
import withLocalize, {withLocalizePropTypes} from '../../components/withLocalize';
import styles from '../../styles/styles';
import compose from '../../libs/compose';
import * as Policy from '../../libs/actions/Policy';
Expand All @@ -25,6 +24,7 @@ import ROUTES from '../../ROUTES';
import withWindowDimensions, {windowDimensionsPropTypes} from '../../components/withWindowDimensions';
import MenuItemWithTopDescription from '../../components/MenuItemWithTopDescription';
import Text from '../../components/Text';
import useLocalize from '../../hooks/useLocalize';

const propTypes = {
/** Constant, list of available currencies */
Expand All @@ -34,8 +34,17 @@ const propTypes = {
symbol: PropTypes.string.isRequired,
}),
),

/** The route object passed to this page from the navigator */
route: PropTypes.shape({
/** Each parameter passed via the URL */
params: PropTypes.shape({
/** The policyID that is being configured */
policyID: PropTypes.string.isRequired,
}).isRequired,
}).isRequired,

...policyPropTypes,
...withLocalizePropTypes,
...windowDimensionsPropTypes,
};

Expand All @@ -44,20 +53,21 @@ const defaultProps = {
...policyDefaultProps,
};

function WorkspaceSettingsPage(props) {
const formattedCurrency = props.policy ? `${props.policy.outputCurrency} - ${props.currencyList[props.policy.outputCurrency].symbol}` : '';
function WorkspaceSettingsPage({policy, currencyList, windowWidth, route}) {
const {translate} = useLocalize();
const formattedCurrency = policy ? `${policy.outputCurrency} - ${currencyList[policy.outputCurrency].symbol}` : '';

const submit = useCallback(
(values) => {
if (props.policy.isPolicyUpdating) {
if (policy.isPolicyUpdating) {
return;
}

Policy.updateGeneralSettings(props.policy.id, values.name.trim(), props.policy.outputCurrency);
Policy.updateGeneralSettings(policy.id, values.name.trim(), policy.outputCurrency);
Keyboard.dismiss();
Navigation.goBack(ROUTES.getWorkspaceInitialRoute(props.policy.id));
Navigation.goBack(ROUTES.getWorkspaceInitialRoute(policy.id));
},
[props.policy.id, props.policy.isPolicyUpdating, props.policy.outputCurrency],
[policy.id, policy.isPolicyUpdating, policy.outputCurrency],
);

const validate = useCallback((values) => {
Expand All @@ -75,33 +85,35 @@ function WorkspaceSettingsPage(props) {
return errors;
}, []);

const policyName = lodashGet(props.policy, 'name', '');
const onPressCurrency = useCallback(() => Navigation.navigate(ROUTES.getWorkspaceSettingsCurrencyRoute(policy.id)), [policy.id]);

const policyName = lodashGet(policy, 'name', '');

return (
<WorkspacePageWithSections
headerText={props.translate('workspace.common.settings')}
route={props.route}
headerText={translate('workspace.common.settings')}
route={route}
guidesCallTaskID={CONST.GUIDES_CALL_TASK_IDS.WORKSPACE_SETTINGS}
>
{(hasVBA) => (
<Form
formID={ONYXKEYS.FORMS.WORKSPACE_SETTINGS_FORM}
submitButtonText={props.translate('workspace.editor.save')}
submitButtonText={translate('workspace.editor.save')}
style={styles.flexGrow1}
scrollContextEnabled
validate={validate}
onSubmit={submit}
enabledWhenOffline
>
<AvatarWithImagePicker
isUploading={props.policy.isAvatarUploading}
source={lodashGet(props.policy, 'avatar')}
isUploading={policy.isAvatarUploading}
source={lodashGet(policy, 'avatar')}
size={CONST.AVATAR_SIZE.LARGE}
DefaultAvatar={() => (
<Avatar
containerStyles={styles.avatarLarge}
imageStyles={[styles.avatarLarge, styles.alignSelfCenter]}
source={props.policy.avatar ? props.policy.avatar : ReportUtils.getDefaultWorkspaceAvatar(policyName)}
source={policy.avatar ? policy.avatar : ReportUtils.getDefaultWorkspaceAvatar(policyName)}
fallbackIcon={Expensicons.FallbackWorkspaceAvatar}
size={CONST.AVATAR_SIZE.LARGE}
name={policyName}
Expand All @@ -111,40 +123,40 @@ function WorkspaceSettingsPage(props) {
type={CONST.ICON_TYPE_WORKSPACE}
fallbackIcon={Expensicons.FallbackWorkspaceAvatar}
style={[styles.mb3]}
anchorPosition={styles.createMenuPositionProfile(props.windowWidth)}
anchorPosition={styles.createMenuPositionProfile(windowWidth)}
anchorAlignment={{horizontal: CONST.MODAL.ANCHOR_ORIGIN_HORIZONTAL.LEFT, vertical: CONST.MODAL.ANCHOR_ORIGIN_VERTICAL.TOP}}
isUsingDefaultAvatar={!lodashGet(props.policy, 'avatar', null)}
onImageSelected={(file) => Policy.updateWorkspaceAvatar(lodashGet(props.policy, 'id', ''), file)}
onImageRemoved={() => Policy.deleteWorkspaceAvatar(lodashGet(props.policy, 'id', ''))}
isUsingDefaultAvatar={!lodashGet(policy, 'avatar', null)}
onImageSelected={(file) => Policy.updateWorkspaceAvatar(lodashGet(policy, 'id', ''), file)}
onImageRemoved={() => Policy.deleteWorkspaceAvatar(lodashGet(policy, 'id', ''))}
editorMaskImage={Expensicons.ImageCropSquareMask}
pendingAction={lodashGet(props.policy, 'pendingFields.avatar', null)}
errors={lodashGet(props.policy, 'errorFields.avatar', null)}
onErrorClose={() => Policy.clearAvatarErrors(props.policy.id)}
previewSource={UserUtils.getFullSizeAvatar(props.policy.avatar, '')}
headerTitle={props.translate('workspace.common.workspaceAvatar')}
originalFileName={props.policy.originalFileName}
pendingAction={lodashGet(policy, 'pendingFields.avatar', null)}
errors={lodashGet(policy, 'errorFields.avatar', null)}
onErrorClose={() => Policy.clearAvatarErrors(policy.id)}
previewSource={UserUtils.getFullSizeAvatar(policy.avatar, '')}
headerTitle={translate('workspace.common.workspaceAvatar')}
originalFileName={policy.originalFileName}
/>
<OfflineWithFeedback pendingAction={lodashGet(props.policy, 'pendingFields.generalSettings')}>
<OfflineWithFeedback pendingAction={lodashGet(policy, 'pendingFields.generalSettings')}>
<TextInput
accessibilityRole={CONST.ACCESSIBILITY_ROLE.TEXT}
inputID="name"
label={props.translate('workspace.editor.nameInputLabel')}
accessibilityLabel={props.translate('workspace.editor.nameInputLabel')}
label={translate('workspace.editor.nameInputLabel')}
accessibilityLabel={translate('workspace.editor.nameInputLabel')}
containerStyles={[styles.mt4, styles.mh5]}
defaultValue={props.policy.name}
defaultValue={policy.name}
maxLength={CONST.WORKSPACE_NAME_CHARACTER_LIMIT}
spellCheck={false}
/>
<View style={[styles.mt4]}>
<MenuItemWithTopDescription
title={formattedCurrency}
description={props.translate('workspace.editor.currencyInputLabel')}
description={translate('workspace.editor.currencyInputLabel')}
shouldShowRightIcon
disabled={hasVBA}
onPress={() => Navigation.navigate(ROUTES.getWorkspaceSettingsCurrencyRoute(props.policy.id))}
onPress={onPressCurrency}
/>
<Text style={[styles.textLabel, styles.colorMuted, styles.mt2, styles.mh5]}>
{hasVBA ? props.translate('workspace.editor.currencyInputDisabledText') : props.translate('workspace.editor.currencyInputHelpText')}
{hasVBA ? translate('workspace.editor.currencyInputDisabledText') : translate('workspace.editor.currencyInputHelpText')}
</Text>
</View>
</OfflineWithFeedback>
Expand All @@ -164,6 +176,5 @@ export default compose(
withOnyx({
currencyList: {key: ONYXKEYS.CURRENCY_LIST},
}),
withLocalize,
withNetwork(),
)(WorkspaceSettingsPage);

0 comments on commit 5539242

Please sign in to comment.