From 5165662941f0cbf69627007759bd6cb325b3c4c7 Mon Sep 17 00:00:00 2001 From: Fedi Rajhi Date: Mon, 19 Dec 2022 01:24:05 +0100 Subject: [PATCH 01/22] [Fix] Allow Form component to detect children that are Class components --- src/components/Form.js | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/src/components/Form.js b/src/components/Form.js index a6320fe04b74..25db26e182f5 100644 --- a/src/components/Form.js +++ b/src/components/Form.js @@ -174,15 +174,19 @@ class Form extends React.Component { // Look for any inputs nested in a custom component, e.g AddressForm or IdentityForm if (_.isFunction(child.type)) { - const nestedChildren = new child.type(child.props); + const childNode = new child.type(child.props); - if (!React.isValidElement(nestedChildren) || !lodashGet(nestedChildren, 'props.children')) { - return child; + // If the custom component has a render method, use it to get the nested children + const nestedChildren = _.isFunction(childNode.render) ? childNode.render() : childNode; + + // Render the custom component if it's a valid React element + // If the custom component has nested children, Loop over them and supply From props + if (React.isValidElement(nestedChildren) || lodashGet(nestedChildren, 'props.children')) { + return this.childrenWrapperWithProps(nestedChildren); } - return React.cloneElement(nestedChildren, { - children: this.childrenWrapperWithProps(lodashGet(nestedChildren, 'props.children')), - }); + // Just render the child if it's custom component not a valid React element, or if it hasn't children + return child; } // We check if the child has the inputID prop. From 2c6a4b4eb7bf5651d46df17989ba7e6c85b05431 Mon Sep 17 00:00:00 2001 From: Fedi Rajhi Date: Mon, 19 Dec 2022 01:34:09 +0100 Subject: [PATCH 02/22] [Refactor] Add Form component to new room page --- src/ONYXKEYS.js | 1 + src/pages/workspace/WorkspaceNewRoomPage.js | 25 +++++++++------------ 2 files changed, 12 insertions(+), 14 deletions(-) diff --git a/src/ONYXKEYS.js b/src/ONYXKEYS.js index 60a686195dcd..5f338cf5c6cf 100755 --- a/src/ONYXKEYS.js +++ b/src/ONYXKEYS.js @@ -172,6 +172,7 @@ export default { CLOSE_ACCOUNT_FORM: 'closeAccount', PROFILE_SETTINGS_FORM: 'profileSettingsForm', DISPLAY_NAME_FORM: 'displayNameForm', + NEW_ROOM_FORM: 'newRoomForm', }, // Whether we should show the compose input or not diff --git a/src/pages/workspace/WorkspaceNewRoomPage.js b/src/pages/workspace/WorkspaceNewRoomPage.js index 654e2ce8cc0f..48d12697fae5 100644 --- a/src/pages/workspace/WorkspaceNewRoomPage.js +++ b/src/pages/workspace/WorkspaceNewRoomPage.js @@ -1,5 +1,5 @@ import React from 'react'; -import {ScrollView, View} from 'react-native'; +import {View} from 'react-native'; import _ from 'underscore'; import {withOnyx} from 'react-native-onyx'; import PropTypes from 'prop-types'; @@ -15,11 +15,10 @@ import Picker from '../../components/Picker'; import ONYXKEYS from '../../ONYXKEYS'; import CONST from '../../CONST'; import Text from '../../components/Text'; -import Button from '../../components/Button'; -import FixedFooter from '../../components/FixedFooter'; import Permissions from '../../libs/Permissions'; import Log from '../../libs/Log'; import * as ValidationUtils from '../../libs/ValidationUtils'; +import Form from '../../components/Form'; const propTypes = { /** All reports shared with the user */ @@ -155,7 +154,14 @@ class WorkspaceNewRoomPage extends React.Component { title={this.props.translate('newRoomPage.newRoom')} onCloseButtonPress={() => Navigation.dismissModal()} /> - +
this.roomNameInputRef = el} @@ -186,16 +192,7 @@ class WorkspaceNewRoomPage extends React.Component { {_.find(visibilityOptions, option => option.value === this.state.visibility).description} - - -