Skip to content
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

Refactor WorkspaceInitialPage to no longer use withFullPolicy #10444

Merged
merged 3 commits into from
Aug 22, 2022
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
217 changes: 113 additions & 104 deletions src/pages/workspace/WorkspaceInitialPage.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@ import themedefault from '../../styles/themes/default';
import HeaderWithCloseButton from '../../components/HeaderWithCloseButton';
import compose from '../../libs/compose';
import Avatar from '../../components/Avatar';
import FullScreenLoadingIndicator from '../../components/FullscreenLoadingIndicator';
import withFullPolicy, {fullPolicyPropTypes, fullPolicyDefaultProps} from './withFullPolicy';
import FullPageNotFoundView from '../../components/BlockingViews/FullPageNotFoundView';
import {fullPolicyPropTypes, fullPolicyDefaultProps} from './withFullPolicy';
import * as PolicyActions from '../../libs/actions/Policy';
import CONST from '../../CONST';
import ONYXKEYS from '../../ONYXKEYS';
Expand All @@ -29,6 +29,15 @@ const propTypes = {
...fullPolicyPropTypes,
...withLocalizePropTypes,

/** URL Route params */
route: PropTypes.shape({
/** Params from the URL path */
params: PropTypes.shape({
/** policyID passed via route: /workspace/:policyID/invite */
policyID: PropTypes.string,
}),
}).isRequired,

/** The employee list of this policy (coming from Onyx) */
policyMemberList: PropTypes.objectOf(policyMemberPropType),
};
Expand Down Expand Up @@ -76,10 +85,6 @@ class WorkspaceInitialPage extends React.Component {

render() {
const policy = this.props.policy;
if (_.isEmpty(policy)) {
return <FullScreenLoadingIndicator />;
}

const hasMembersError = PolicyActions.hasPolicyMemberError(this.props.policyMemberList);
const menuItems = [
{
Expand Down Expand Up @@ -127,108 +132,110 @@ class WorkspaceInitialPage extends React.Component {

return (
<ScreenWrapper>
<HeaderWithCloseButton
title={this.props.translate('workspace.common.workspace')}
shouldShowBackButton
onBackButtonPress={() => Navigation.navigate(ROUTES.SETTINGS)}
onCloseButtonPress={() => Navigation.dismissModal()}
shouldShowThreeDotsButton
shouldShowGetAssistanceButton
guidesCallTaskID={CONST.GUIDES_CALL_TASK_IDS.WORKSPACE_INITIAL}
threeDotsMenuItems={[
{
icon: Expensicons.Plus,
text: this.props.translate('workspace.new.newWorkspace'),
onSelected: () => PolicyActions.createAndNavigate(),
}, {
icon: Expensicons.Trashcan,
text: this.props.translate('workspace.common.delete'),
onSelected: () => this.setState({isDeleteModalOpen: true}),
},
]}
threeDotsAnchorPosition={styles.threeDotsPopoverOffset}
/>
<ScrollView
contentContainerStyle={[
styles.flexGrow1,
styles.flexColumn,
styles.justifyContentBetween,
]}
>
<View style={[styles.flex1]}>
<View style={styles.pageWrapper}>
<View style={[styles.settingsPageBody, styles.alignItemsCenter]}>
<Pressable
style={[styles.pRelative, styles.avatarLarge]}
onPress={this.openEditor}
>
{this.props.policy.avatarURL
? (
<Avatar
containerStyles={styles.avatarLarge}
imageStyles={[styles.avatarLarge, styles.alignSelfCenter]}
source={this.props.policy.avatarURL}
fallbackIcon={Expensicons.FallbackWorkspaceAvatar}
size={CONST.AVATAR_SIZE.LARGE}
/>
)
: (
<Icon
src={Expensicons.Workspace}
height={80}
width={80}
fill={themedefault.iconSuccessFill}
/>
)}
</Pressable>
{!_.isEmpty(this.props.policy.name) && (
<FullPageNotFoundView shouldShow={_.isEmpty(this.props.policy)}>
<HeaderWithCloseButton
title={this.props.translate('workspace.common.workspace')}
shouldShowBackButton
onBackButtonPress={() => Navigation.navigate(ROUTES.SETTINGS)}
onCloseButtonPress={() => Navigation.dismissModal()}
shouldShowThreeDotsButton
shouldShowGetAssistanceButton
guidesCallTaskID={CONST.GUIDES_CALL_TASK_IDS.WORKSPACE_INITIAL}
threeDotsMenuItems={[
{
icon: Expensicons.Plus,
text: this.props.translate('workspace.new.newWorkspace'),
onSelected: () => PolicyActions.createAndNavigate(),
}, {
icon: Expensicons.Trashcan,
text: this.props.translate('workspace.common.delete'),
onSelected: () => this.setState({isDeleteModalOpen: true}),
},
]}
threeDotsAnchorPosition={styles.threeDotsPopoverOffset}
/>
<ScrollView
contentContainerStyle={[
styles.flexGrow1,
styles.flexColumn,
styles.justifyContentBetween,
]}
>
<View style={[styles.flex1]}>
<View style={styles.pageWrapper}>
<View style={[styles.settingsPageBody, styles.alignItemsCenter]}>
<Pressable
style={[
styles.alignSelfCenter,
styles.mt4,
styles.mb6,
styles.w100,
]}
style={[styles.pRelative, styles.avatarLarge]}
onPress={this.openEditor}
>
<Tooltip text={this.props.policy.name}>
<Text
numberOfLines={1}
style={[
styles.displayName,
styles.alignSelfCenter,
]}
>
{this.props.policy.name}
</Text>
</Tooltip>
{this.props.policy.avatarURL
? (
<Avatar
containerStyles={styles.avatarLarge}
imageStyles={[styles.avatarLarge, styles.alignSelfCenter]}
source={this.props.policy.avatarURL}
fallbackIcon={Expensicons.FallbackWorkspaceAvatar}
size={CONST.AVATAR_SIZE.LARGE}
/>
)
: (
<Icon
src={Expensicons.Workspace}
height={80}
width={80}
fill={themedefault.iconSuccessFill}
/>
)}
</Pressable>
)}
{!_.isEmpty(this.props.policy.name) && (
<Pressable
style={[
styles.alignSelfCenter,
styles.mt4,
styles.mb6,
styles.w100,
]}
onPress={this.openEditor}
>
<Tooltip text={this.props.policy.name}>
<Text
numberOfLines={1}
style={[
styles.displayName,
styles.alignSelfCenter,
]}
>
{this.props.policy.name}
</Text>
</Tooltip>
</Pressable>
)}
</View>
</View>
{_.map(menuItems, item => (
<MenuItem
key={item.translationKey}
title={this.props.translate(item.translationKey)}
icon={item.icon}
iconRight={item.iconRight}
onPress={() => item.action()}
shouldShowRightIcon
brickRoadIndicator={item.error ? 'error' : null}
/>
))}
</View>
{_.map(menuItems, item => (
<MenuItem
key={item.translationKey}
title={this.props.translate(item.translationKey)}
icon={item.icon}
iconRight={item.iconRight}
onPress={() => item.action()}
shouldShowRightIcon
brickRoadIndicator={item.error ? 'error' : null}
/>
))}
</View>
</ScrollView>
<ConfirmModal
title={this.props.translate('workspace.common.delete')}
isVisible={this.state.isDeleteModalOpen}
onConfirm={this.confirmDeleteAndHideModal}
onCancel={() => this.toggleDeleteModal(false)}
prompt={this.props.translate('workspace.common.deleteConfirmation')}
confirmText={this.props.translate('common.delete')}
cancelText={this.props.translate('common.cancel')}
danger
/>
</ScrollView>
<ConfirmModal
title={this.props.translate('workspace.common.delete')}
isVisible={this.state.isDeleteModalOpen}
onConfirm={this.confirmDeleteAndHideModal}
onCancel={() => this.toggleDeleteModal(false)}
prompt={this.props.translate('workspace.common.deleteConfirmation')}
confirmText={this.props.translate('common.delete')}
cancelText={this.props.translate('common.cancel')}
danger
/>
</FullPageNotFoundView>
</ScreenWrapper>
);
}
Expand All @@ -240,10 +247,12 @@ WorkspaceInitialPage.displayName = 'WorkspaceInitialPage';

export default compose(
withLocalize,
withFullPolicy,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry for the confusion, but we're no longer looking to remove withFullPolicy completely. Instead, we'll just be updating it to not fetch policy data so you can keep it here

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmmm... Yes, I am confused 😅 . Do we need withFullPolicy here - why keep it? Also, the withFullPolicy code is still loading the full policy - when are we removing that?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So withFullPolicy also tracks the last visited workspace/policy so we shouldn't remove that functionality.

We'll remove the policy loading with this GH but this is only safe to do once all the other refactors are done (if we do it before, these pages will have no data).

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Okay great - makes sense thanks for clarifying!

withOnyx({
policyMemberList: {
key: ({policy}) => `${ONYXKEYS.COLLECTION.POLICY_MEMBER_LIST}${policy.id}`,
key: ({route}) => `${ONYXKEYS.COLLECTION.POLICY_MEMBER_LIST}${route.params.policyID}`,
},
policy: {
key: ({route}) => `${ONYXKEYS.COLLECTION.POLICY}${route.params.policyID}`,
},
}),
)(WorkspaceInitialPage);