From 26452c915b4dca83685df4255cf09f1c8f706879 Mon Sep 17 00:00:00 2001 From: Mohammad Luthfi Fathur Rahman Date: Thu, 6 Oct 2022 01:06:01 +0700 Subject: [PATCH 1/7] fix error link pressed callback --- src/components/Form.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/components/Form.js b/src/components/Form.js index b20ddc59c3f6..cc069d57dd14 100644 --- a/src/components/Form.js +++ b/src/components/Form.js @@ -205,7 +205,7 @@ class Form extends React.Component { isLoading={this.props.formState.isLoading} message={this.getErrorMessage()} onSubmit={this.submit} - onFixTheErrorsLinkPressed={() => { + onFixTheErrorsPressed={() => { this.inputRefs[_.first(_.keys(this.state.errors))].focus(); }} containerStyles={[styles.mh0, styles.mt5]} From 89e66a2b681067dc818d34645587904d2926c92f Mon Sep 17 00:00:00 2001 From: Mohammad Luthfi Fathur Rahman Date: Thu, 6 Oct 2022 01:06:17 +0700 Subject: [PATCH 2/7] adding option to use scrollview --- .../workspace/WorkspacePageWithSections.js | 26 ++++++++++++------- 1 file changed, 17 insertions(+), 9 deletions(-) diff --git a/src/pages/workspace/WorkspacePageWithSections.js b/src/pages/workspace/WorkspacePageWithSections.js index 7c0ecacc0d8a..2d56ae4d5a20 100644 --- a/src/pages/workspace/WorkspacePageWithSections.js +++ b/src/pages/workspace/WorkspacePageWithSections.js @@ -56,6 +56,9 @@ const propTypes = { name: PropTypes.string, }).isRequired, + /** Option to not use the default scroll view */ + shouldNotUseScrollView: PropTypes.bool, + ...withLocalizePropTypes, }; @@ -65,6 +68,7 @@ const defaultProps = { reimbursementAccount: {}, footer: null, guidesCallTaskID: '', + shouldNotUseScrollView: false, }; class WorkspacePageWithSections extends React.Component { @@ -103,15 +107,19 @@ class WorkspacePageWithSections extends React.Component { onBackButtonPress={() => Navigation.navigate(ROUTES.getWorkspaceInitialRoute(policyID))} onCloseButtonPress={() => Navigation.dismissModal()} /> - - - - {this.props.children(hasVBA, policyID, isUsingECard)} - - - + {this.props.shouldNotUseScrollView + ? this.props.children(hasVBA, policyID, isUsingECard) + : ( + + + + {this.props.children(hasVBA, policyID, isUsingECard)} + + + + )} {this.props.footer} ); From 6369026a0aa83766ea4f72c759f3ff9281a00750 Mon Sep 17 00:00:00 2001 From: Mohammad Luthfi Fathur Rahman Date: Thu, 6 Oct 2022 01:06:36 +0700 Subject: [PATCH 3/7] refactoring workspace settings form --- src/ONYXKEYS.js | 1 + src/pages/workspace/WorkspaceSettingsPage.js | 64 ++++++++------------ 2 files changed, 25 insertions(+), 40 deletions(-) diff --git a/src/ONYXKEYS.js b/src/ONYXKEYS.js index 70327599ca22..77d86426ee77 100755 --- a/src/ONYXKEYS.js +++ b/src/ONYXKEYS.js @@ -181,6 +181,7 @@ export default { ADD_DEBIT_CARD_FORM: 'addDebitCardForm', REQUEST_CALL_FORM: 'requestCallForm', REIMBURSEMENT_ACCOUNT_FORM: 'reimbursementAccount', + WORKSPACE_SETTINGS_FORM: 'workspaceSettingsForm', }, // Whether we should show the compose input or not diff --git a/src/pages/workspace/WorkspaceSettingsPage.js b/src/pages/workspace/WorkspaceSettingsPage.js index 40c370abb92b..f538d594e133 100644 --- a/src/pages/workspace/WorkspaceSettingsPage.js +++ b/src/pages/workspace/WorkspaceSettingsPage.js @@ -1,12 +1,11 @@ import React from 'react'; -import {View} from 'react-native'; +import {Keyboard, View} from 'react-native'; import {withOnyx} from 'react-native-onyx'; import _ from 'underscore'; import lodashGet from 'lodash/get'; import ONYXKEYS from '../../ONYXKEYS'; import withLocalize, {withLocalizePropTypes} from '../../components/withLocalize'; import styles from '../../styles/styles'; -import Button from '../../components/Button'; import Text from '../../components/Text'; import compose from '../../libs/compose'; import * as Policy from '../../libs/actions/Policy'; @@ -17,12 +16,12 @@ import defaultTheme from '../../styles/themes/default'; import CONST from '../../CONST'; import Picker from '../../components/Picker'; import TextInput from '../../components/TextInput'; -import FixedFooter from '../../components/FixedFooter'; import WorkspacePageWithSections from './WorkspacePageWithSections'; import withPolicy, {policyPropTypes, policyDefaultProps} from './withPolicy'; import {withNetwork} from '../../components/OnyxProvider'; import OfflineWithFeedback from '../../components/OfflineWithFeedback'; import FullPageNotFoundView from '../../components/BlockingViews/FullPageNotFoundView'; +import Form from '../../components/Form'; const propTypes = { ...policyPropTypes, @@ -37,11 +36,6 @@ class WorkspaceSettingsPage extends React.Component { constructor(props) { super(props); - this.state = { - name: props.policy.name, - currency: props.policy.outputCurrency, - }; - this.submit = this.submit.bind(this); this.getCurrencyItems = this.getCurrencyItems.bind(this); this.validate = this.validate.bind(this); @@ -58,49 +52,41 @@ class WorkspaceSettingsPage extends React.Component { })); } - submit() { - if (this.props.policy.isPolicyUpdating || !this.validate()) { + submit(values) { + if (this.props.policy.isPolicyUpdating) { return; } - const name = this.state.name.trim(); - const outputCurrency = this.state.currency; + const name = values.name.trim(); + const outputCurrency = values.currency; Policy.updateGeneralSettings(this.props.policy.id, name, outputCurrency); + Keyboard.dismiss(); } - validate() { + validate(values) { const errors = {}; - if (!this.state.name.trim().length) { - errors.nameError = true; + if (!values.name.trim().length) { + errors.name = this.props.translate('workspace.editor.nameIsRequiredError'); } - return _.size(errors) === 0; + return errors; } render() { return ( - Policy.clearWorkspaceGeneralSettingsErrors(this.props.policy.id)} - > -