Skip to content

Commit

Permalink
Merge pull request #3547 from Expensify/horus-modal-screen-new-workspace
Browse files Browse the repository at this point in the history
Add a modal screen for creating a new workspace
  • Loading branch information
marcaaron authored Jun 14, 2021
2 parents 85b22bf + 9872661 commit bdf2144
Show file tree
Hide file tree
Showing 10 changed files with 235 additions and 3 deletions.
1 change: 1 addition & 0 deletions assets/images/workspace-default-avatar.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions src/ROUTES.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ export default {
VALIDATE_LOGIN: 'v',
VALIDATE_LOGIN_WITH_VALIDATE_CODE: 'v/:accountID/:validateCode',
ENABLE_PAYMENTS: 'enable-payments',
WORKSPACE_NEW: 'workspace/new',

/**
* @param {String} route
Expand Down
11 changes: 11 additions & 0 deletions src/languages/en.js
Original file line number Diff line number Diff line change
Expand Up @@ -335,4 +335,15 @@ export default {
session: {
offlineMessage: 'Looks like you\'re not connected to internet. Can you check your connection and try again?',
},
workspace: {
new: {
welcome: 'Welcome',
chooseAName: 'Choose a name',
helpText: 'Need help getting setup? Request a call below and we’ll have someone reach out to you.',
getStarted: 'Get started!',
editPhoto: 'Edit Photo',
uploadPhoto: 'Upload Photo',
requestCall: 'Request a call',
},
},
};
11 changes: 11 additions & 0 deletions src/languages/es.js
Original file line number Diff line number Diff line change
Expand Up @@ -289,4 +289,15 @@ export default {
session: {
offlineMessage: 'Parece que no estás conectado a internet. Comprueba tu conexión e inténtalo de nuevo.',
},
workspace: {
new: {
welcome: 'Bienvenido/a',
chooseAName: 'Elige un nombre',
helpText: '¿Necesitas ayuda con la configuración? Pídenos una llamada y una persona de nuestro equipo te ayudará.',
getStarted: '¡Empezar!',
uploadPhoto: 'Subir Foto',
editPhoto: 'Editar Foto',
requestCall: 'Concertar una llamada',
},
},
};
6 changes: 6 additions & 0 deletions src/libs/Navigation/AppNavigator/AuthScreens.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ import {
EnablePaymentsStackNavigator,
BusinessBankAccountModalStackNavigator,
AddPersonalBankAccountModalStackNavigator,
NewWorkspaceStackNavigator,
} from './ModalStackNavigators';
import SCREENS from '../../../SCREENS';
import Timers from '../../Timers';
Expand Down Expand Up @@ -276,6 +277,11 @@ class AuthScreens extends React.Component {
component={AddPersonalBankAccountModalStackNavigator}
listeners={modalScreenListeners}
/>
<RootStack.Screen
name="NewWorkspace"
options={modalScreenOptions}
component={NewWorkspaceStackNavigator}
/>
<RootStack.Screen
name="BusinessBankAccount"
options={modalScreenOptions}
Expand Down
7 changes: 7 additions & 0 deletions src/libs/Navigation/AppNavigator/ModalStackNavigators.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import ReportParticipantsPage from '../../../pages/ReportParticipantsPage';
import EnablePaymentsPage from '../../../pages/EnablePayments';
import BusinessBankAccountNewPage from '../../../pages/BusinessBankAccount/NewPage';
import AddPersonalBankAccountPage from '../../../pages/AddPersonalBankAccountPage';
import NewWorkspacePage from '../../../pages/workspace/NewWorkspacePage';

const defaultSubRouteOptions = {
cardStyle: styles.navigationScreenCardStyle,
Expand Down Expand Up @@ -153,6 +154,11 @@ const AddPersonalBankAccountModalStackNavigator = createModalStackNavigator([{
name: 'AddPersonalBankAccount_Root',
}]);

const NewWorkspaceStackNavigator = createModalStackNavigator([{
Component: NewWorkspacePage,
name: 'NewWorkspace_Root',
}]);

const BusinessBankAccountModalStackNavigator = createModalStackNavigator([
{
Component: BusinessBankAccountNewPage,
Expand All @@ -173,4 +179,5 @@ export {
EnablePaymentsStackNavigator,
BusinessBankAccountModalStackNavigator,
AddPersonalBankAccountModalStackNavigator,
NewWorkspaceStackNavigator,
};
31 changes: 30 additions & 1 deletion src/libs/Navigation/Navigation.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import _ from 'underscore';
import React from 'react';
import {StackActions, DrawerActions} from '@react-navigation/native';

import PropTypes from 'prop-types';
import Onyx from 'react-native-onyx';
import linkTo from './linkTo';
import ROUTES from '../../ROUTES';
Expand Down Expand Up @@ -98,8 +98,37 @@ function dismissModal(shouldOpenDrawer = false) {
openDrawer();
}

/**
* Alternative to the `Navigation.dismissModal()` function that we can use inside
* the render function of other components to avoid breaking React rules about side-effects.
*
* Example:
* ```jsx
* if (!Permissions.canUseFreePlan(this.props.betas)) {
* return <Navigation.DismissModal />;
* }
* ```
*/
class DismissModal extends React.Component {
componentDidMount() {
dismissModal(this.props.shouldOpenDrawer);
}

render() {
return null;
}
}

DismissModal.propTypes = {
shouldOpenDrawer: PropTypes.bool,
};
DismissModal.defaultProps = {
shouldOpenDrawer: false,
};

export default {
navigate,
dismissModal,
goBack,
DismissModal,
};
5 changes: 5 additions & 0 deletions src/libs/Navigation/linkingConfig.js
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,11 @@ export default {
EnablePayments_Root: ROUTES.ENABLE_PAYMENTS,
},
},
NewWorkspace: {
screens: {
NewWorkspace_Root: ROUTES.WORKSPACE_NEW,
},
},
},
},
};
3 changes: 1 addition & 2 deletions src/pages/BusinessBankAccount/NewPage.js
Original file line number Diff line number Diff line change
Expand Up @@ -71,8 +71,7 @@ class BusinessBankAccountNewPage extends React.Component {
render() {
if (!Permissions.canUseFreePlan(this.props.betas)) {
console.debug('Not showing new bank account page because user is not on free plan beta');
Navigation.dismissModal();
return null;
return <Navigation.DismissModal />;
}

return (
Expand Down
162 changes: 162 additions & 0 deletions src/pages/workspace/NewWorkspacePage.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,162 @@
import React from 'react';
import {View, Text} from 'react-native';
import {withOnyx} from 'react-native-onyx';
import PropTypes from 'prop-types';
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 WorkspaceDefaultAvatar from '../../../assets/images/workspace-default-avatar.svg';
import TextInputWithLabel from '../../components/TextInputWithLabel';
import Button from '../../components/Button';
import AttachmentPicker from '../../components/AttachmentPicker';
import Icon from '../../components/Icon';
import {DownArrow, Upload} from '../../components/Icon/Expensicons';
import CreateMenu from '../../components/CreateMenu';
import Switch from '../../components/Switch';
import compose from '../../libs/compose';


const propTypes = {
/** List of betas */
betas: PropTypes.arrayOf(PropTypes.string).isRequired,

...withLocalizePropTypes,
};

class NewWorkspacePage extends React.Component {
constructor(props) {
super(props);

this.state = {
isEditPhotoMenuVisible: false,
name: '',
requestCall: false,
};

this.createMenuItems = this.createMenuItems.bind(this);
}

/**
* Create menu items list for avatar menu
*
* @param {Function} openPicker
* @returns {Array}
*/
createMenuItems(openPicker) {
const menuItems = [
{
icon: Upload,
text: this.props.translate('workspace.new.uploadPhoto'),
onSelected: () => {
openPicker({
onPicked: () => {
// TODO: connect with setWorkspaceAvatar function
},
});
},
},
];

// TODO: Add option to remove avatar if the user doesn't like the one they chose.

return menuItems;
}

render() {
if (!Permissions.canUseFreePlan(this.props.betas)) {
console.debug('Not showing new workspace page because user is not on free plan beta');
return <Navigation.DismissModal />;
}

return (
<ScreenWrapper>
<HeaderWithCloseButton
title={this.props.translate('workspace.new.welcome')}
onCloseButtonPress={Navigation.dismissModal}
/>

<View style={[styles.pageWrapper, styles.flex1]}>
{/* TODO: replace this with the Avatar component once we connect it with the backend */}
<WorkspaceDefaultAvatar height={100} width={100} />

<AttachmentPicker>
{({openPicker}) => (
<>
<Button
style={[styles.alignSelfCenter, styles.mt3]}
onPress={() => this.setState({isEditPhotoMenuVisible: true})}
ContentComponent={() => (
<View style={[styles.flexRow]}>
<Icon src={DownArrow} />
<View style={styles.justifyContentCenter}>
<Text style={[styles.headerText, styles.ml2]}>
{this.props.translate('workspace.new.editPhoto')}
</Text>
</View>
</View>
)}
/>
<CreateMenu
isVisible={this.state.isEditPhotoMenuVisible}
onClose={() => this.setState({isEditPhotoMenuVisible: false})}
onItemSelected={() => this.setState({isEditPhotoMenuVisible: false})}
menuItems={this.createMenuItems(openPicker)}
anchorPosition={styles.createMenuPositionProfile}
animationIn="fadeInRight"
animationOut="fadeOutRight"
/>
</>
)}
</AttachmentPicker>

<View style={[styles.mt6, styles.w100, styles.flex1]}>
<TextInputWithLabel
label={this.props.translate('workspace.new.chooseAName')}
value={this.state.name}
onChangeText={name => this.setState({name})}
/>
<Text style={[styles.mt6, styles.textP]}>{this.props.translate('workspace.new.helpText')}</Text>
<View
style={[
styles.mt3,
styles.flexRow,
styles.mb6,
styles.justifyContentBetween,
styles.alignItemsCenter,
]}
>
<View style={styles.flex4}>
<Text style={styles.textMicro}>
{this.props.translate('workspace.new.requestCall')}
</Text>
</View>
<View style={[styles.flex1, styles.alignItemsEnd]}>
<Switch
isOn={this.state.requestCall}
onToggle={requestCall => this.setState({requestCall})}
/>
</View>
</View>
</View>

<Button success style={[styles.w100]} text={this.props.translate('workspace.new.getStarted')} />
</View>
</ScreenWrapper>
);
}
}

NewWorkspacePage.propTypes = propTypes;

export default compose(
withOnyx({
betas: {
key: ONYXKEYS.BETAS,
},
}),
withLocalize,
)(NewWorkspacePage);

0 comments on commit bdf2144

Please sign in to comment.