Skip to content

Commit

Permalink
Merge pull request #10873 from Expensify/arosiclair-update-with-policy
Browse files Browse the repository at this point in the history
Refactor withFullPolicy
  • Loading branch information
grgia authored Sep 13, 2022
2 parents d312075 + c17f149 commit dc0a249
Show file tree
Hide file tree
Showing 12 changed files with 43 additions and 88 deletions.
4 changes: 2 additions & 2 deletions src/components/AvatarWithIndicator.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import policyMemberPropType from '../pages/policyMemberPropType';
import bankAccountPropTypes from './bankAccountPropTypes';
import cardPropTypes from './cardPropTypes';
import userWalletPropTypes from '../pages/EnablePayments/userWalletPropTypes';
import {fullPolicyPropTypes} from '../pages/workspace/withFullPolicy';
import {policyPropTypes} from '../pages/workspace/withPolicy';
import walletTermsPropTypes from '../pages/EnablePayments/walletTermsPropTypes';
import * as PolicyUtils from '../libs/PolicyUtils';
import * as PaymentMethods from '../libs/actions/PaymentMethods';
Expand All @@ -30,7 +30,7 @@ const propTypes = {
policiesMemberList: PropTypes.objectOf(policyMemberPropType),

/** All the user's policies (from Onyx via withFullPolicy) */
policies: PropTypes.objectOf(fullPolicyPropTypes.policy),
policies: PropTypes.objectOf(policyPropTypes.policy),

/** List of bank accounts */
bankAccountList: PropTypes.objectOf(bankAccountPropTypes),
Expand Down
4 changes: 0 additions & 4 deletions src/components/RoomNameInput.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import CONST from '../CONST';
import ONYXKEYS from '../ONYXKEYS';
import compose from '../libs/compose';
import withLocalize, {withLocalizePropTypes} from './withLocalize';
import withFullPolicy, {fullPolicyDefaultProps, fullPolicyPropTypes} from '../pages/workspace/withFullPolicy';
import TextInput from './TextInput';

const propTypes = {
Expand All @@ -22,7 +21,6 @@ const propTypes = {
errorText: PropTypes.string,

...withLocalizePropTypes,
...fullPolicyPropTypes,

/* Onyx Props */

Expand Down Expand Up @@ -53,7 +51,6 @@ const defaultProps = {
initialValue: '',
disabled: false,
errorText: '',
...fullPolicyDefaultProps,
forwardedRef: () => {},
};

Expand Down Expand Up @@ -114,7 +111,6 @@ RoomNameInput.defaultProps = defaultProps;

export default compose(
withLocalize,
withFullPolicy,
withOnyx({
reports: {
key: ONYXKEYS.COLLECTION.REPORT,
Expand Down
15 changes: 0 additions & 15 deletions src/pages/ReportSettingsPage.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ import Text from '../components/Text';
import Button from '../components/Button';
import RoomNameInput from '../components/RoomNameInput';
import Picker from '../components/Picker';
import withFullPolicy, {fullPolicyDefaultProps, fullPolicyPropTypes} from './workspace/withFullPolicy';
import * as ValidationUtils from '../libs/ValidationUtils';
import OfflineWithFeedback from '../components/OfflineWithFeedback';

Expand All @@ -31,7 +30,6 @@ const propTypes = {
}),
}).isRequired,

...fullPolicyPropTypes,
...withLocalizePropTypes,

/* Onyx Props */
Expand Down Expand Up @@ -79,17 +77,6 @@ const propTypes = {
}).isRequired,
};

const defaultProps = {
...fullPolicyDefaultProps,
report: {
reportID: 0,
reportName: '',
policyID: '',
notificationPreference: '',
visibility: '',
},
};

class ReportSettingsPage extends Component {
constructor(props) {
super(props);
Expand Down Expand Up @@ -287,11 +274,9 @@ class ReportSettingsPage extends Component {
}

ReportSettingsPage.propTypes = propTypes;
ReportSettingsPage.defaultProps = defaultProps;

export default compose(
withLocalize,
withFullPolicy,
withOnyx({
report: {
key: ({route}) => `${ONYXKEYS.COLLECTION.REPORT}${route.params.reportID}`,
Expand Down
4 changes: 2 additions & 2 deletions src/pages/workspace/WorkspaceBankAccountPage.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import Section from '../../components/Section';
import WorkspaceResetBankAccountModal from './WorkspaceResetBankAccountModal';
import styles from '../../styles/styles';
import CONST from '../../CONST';
import withFullPolicy from './withFullPolicy';
import withPolicy from './withPolicy';
import Button from '../../components/Button';
import MenuItem from '../../components/MenuItem';
import FullPageNotFoundView from '../../components/BlockingViews/FullPageNotFoundView';
Expand Down Expand Up @@ -131,5 +131,5 @@ export default compose(
key: ONYXKEYS.REIMBURSEMENT_ACCOUNT,
},
}),
withFullPolicy,
withPolicy,
)(WorkspaceBankAccountPage);
8 changes: 4 additions & 4 deletions src/pages/workspace/WorkspaceInitialPage.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import HeaderWithCloseButton from '../../components/HeaderWithCloseButton';
import compose from '../../libs/compose';
import Avatar from '../../components/Avatar';
import FullPageNotFoundView from '../../components/BlockingViews/FullPageNotFoundView';
import withFullPolicy, {fullPolicyPropTypes, fullPolicyDefaultProps} from './withFullPolicy';
import withPolicy, {policyPropTypes, policyDefaultProps} from './withPolicy';
import * as Policy from '../../libs/actions/Policy';
import * as PolicyUtils from '../../libs/PolicyUtils';
import CONST from '../../CONST';
Expand All @@ -30,15 +30,15 @@ import policyMemberPropType from '../policyMemberPropType';
import OfflineWithFeedback from '../../components/OfflineWithFeedback';

const propTypes = {
...fullPolicyPropTypes,
...policyPropTypes,
...withLocalizePropTypes,

/** The employee list of this policy (coming from Onyx) */
policyMemberList: PropTypes.objectOf(policyMemberPropType),
};

const defaultProps = {
...fullPolicyDefaultProps,
...policyDefaultProps,
policyMemberList: {},
};

Expand Down Expand Up @@ -248,7 +248,7 @@ WorkspaceInitialPage.defaultProps = defaultProps;

export default compose(
withLocalize,
withFullPolicy,
withPolicy,
withOnyx({
policyMemberList: {
key: ({policy}) => `${ONYXKEYS.COLLECTION.POLICY_MEMBER_LIST}${policy.id}`,
Expand Down
8 changes: 4 additions & 4 deletions src/pages/workspace/WorkspaceInvitePage.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import CONST from '../../CONST';
import FullScreenLoadingIndicator from '../../components/FullscreenLoadingIndicator';
import * as Link from '../../libs/actions/Link';
import Text from '../../components/Text';
import withFullPolicy, {fullPolicyPropTypes, fullPolicyDefaultProps} from './withFullPolicy';
import withPolicy, {policyPropTypes, policyDefaultProps} from './withPolicy';
import {withNetwork} from '../../components/OnyxProvider';
import FullPageNotFoundView from '../../components/BlockingViews/FullPageNotFoundView';
import networkPropTypes from '../../components/networkPropTypes';
Expand Down Expand Up @@ -53,12 +53,12 @@ const propTypes = {
}),
}).isRequired,

...fullPolicyPropTypes,
...policyPropTypes,
...withLocalizePropTypes,
...networkPropTypes,
};

const defaultProps = fullPolicyDefaultProps;
const defaultProps = policyDefaultProps;

class WorkspaceInvitePage extends React.Component {
constructor(props) {
Expand Down Expand Up @@ -352,7 +352,7 @@ WorkspaceInvitePage.defaultProps = defaultProps;

export default compose(
withLocalize,
withFullPolicy,
withPolicy,
withNetwork(),
withOnyx({
personalDetails: {
Expand Down
8 changes: 4 additions & 4 deletions src/pages/workspace/WorkspaceMembersPage.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ import withWindowDimensions, {windowDimensionsPropTypes} from '../../components/
import OptionRow from '../../components/OptionRow';
import CheckboxWithTooltip from '../../components/CheckboxWithTooltip';
import Hoverable from '../../components/Hoverable';
import withFullPolicy, {fullPolicyPropTypes, fullPolicyDefaultProps} from './withFullPolicy';
import withPolicy, {policyPropTypes, policyDefaultProps} from './withPolicy';
import CONST from '../../CONST';
import OfflineWithFeedback from '../../components/OfflineWithFeedback';
import {withNetwork} from '../../components/OnyxProvider';
Expand All @@ -45,13 +45,13 @@ const propTypes = {
}),
}).isRequired,

...fullPolicyPropTypes,
...policyPropTypes,
...withLocalizePropTypes,
...windowDimensionsPropTypes,
...networkPropTypes,
};

const defaultProps = fullPolicyDefaultProps;
const defaultProps = policyDefaultProps;

class WorkspaceMembersPage extends React.Component {
constructor(props) {
Expand Down Expand Up @@ -367,7 +367,7 @@ WorkspaceMembersPage.defaultProps = defaultProps;
export default compose(
withLocalize,
withWindowDimensions,
withFullPolicy,
withPolicy,
withNetwork(),
withOnyx({
personalDetails: {
Expand Down
8 changes: 3 additions & 5 deletions src/pages/workspace/WorkspaceNewRoomPage.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ import {ScrollView, View} from 'react-native';
import _ from 'underscore';
import {withOnyx} from 'react-native-onyx';
import PropTypes from 'prop-types';
import withFullPolicy, {fullPolicyDefaultProps, fullPolicyPropTypes} from './withFullPolicy';
import * as Report from '../../libs/actions/Report';
import withLocalize, {withLocalizePropTypes} from '../../components/withLocalize';
import compose from '../../libs/compose';
Expand Down Expand Up @@ -35,17 +34,17 @@ const propTypes = {
policyID: PropTypes.string,
}).isRequired,

/** List of betas available to current user */
betas: PropTypes.arrayOf(PropTypes.string),

/** Are we loading the createPolicyRoom command */
isLoadingCreatePolicyRoom: PropTypes.bool,

...fullPolicyPropTypes,

...withLocalizePropTypes,
};
const defaultProps = {
betas: [],
isLoadingCreatePolicyRoom: false,
...fullPolicyDefaultProps,
};

class WorkspaceNewRoomPage extends React.Component {
Expand Down Expand Up @@ -203,7 +202,6 @@ WorkspaceNewRoomPage.propTypes = propTypes;
WorkspaceNewRoomPage.defaultProps = defaultProps;

export default compose(
withFullPolicy,
withOnyx({
betas: {
key: ONYXKEYS.BETAS,
Expand Down
4 changes: 2 additions & 2 deletions src/pages/workspace/WorkspacePageWithSections.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import * as BankAccounts from '../../libs/actions/BankAccounts';
import BankAccount from '../../libs/models/BankAccount';
import reimbursementAccountPropTypes from '../ReimbursementAccount/reimbursementAccountPropTypes';
import userPropTypes from '../settings/userPropTypes';
import withFullPolicy from './withFullPolicy';
import withPolicy from './withPolicy';
import {withNetwork} from '../../components/OnyxProvider';
import networkPropTypes from '../../components/networkPropTypes';

Expand Down Expand Up @@ -131,6 +131,6 @@ export default compose(
key: ONYXKEYS.REIMBURSEMENT_ACCOUNT,
},
}),
withFullPolicy,
withPolicy,
withNetwork(),
)(WorkspacePageWithSections);
8 changes: 4 additions & 4 deletions src/pages/workspace/WorkspaceSettingsPage.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,18 +19,18 @@ import Picker from '../../components/Picker';
import TextInput from '../../components/TextInput';
import FixedFooter from '../../components/FixedFooter';
import WorkspacePageWithSections from './WorkspacePageWithSections';
import withFullPolicy, {fullPolicyPropTypes, fullPolicyDefaultProps} from './withFullPolicy';
import withPolicy, {policyPropTypes, policyDefaultProps} from './withPolicy';
import {withNetwork} from '../../components/OnyxProvider';
import OfflineWithFeedback from '../../components/OfflineWithFeedback';
import FullPageNotFoundView from '../../components/BlockingViews/FullPageNotFoundView';

const propTypes = {
...fullPolicyPropTypes,
...policyPropTypes,
...withLocalizePropTypes,
};

const defaultProps = {
...fullPolicyDefaultProps,
...policyDefaultProps,
};

class WorkspaceSettingsPage extends React.Component {
Expand Down Expand Up @@ -162,7 +162,7 @@ WorkspaceSettingsPage.propTypes = propTypes;
WorkspaceSettingsPage.defaultProps = defaultProps;

export default compose(
withFullPolicy,
withPolicy,
withOnyx({
currencyList: {key: ONYXKEYS.CURRENCY_LIST},
}),
Expand Down
4 changes: 2 additions & 2 deletions src/pages/workspace/reimburse/WorkspaceReimburseView.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import * as Link from '../../../libs/actions/Link';
import compose from '../../../libs/compose';
import ONYXKEYS from '../../../ONYXKEYS';
import * as Policy from '../../../libs/actions/Policy';
import withFullPolicy from '../withFullPolicy';
import withPolicy from '../withPolicy';
import CONST from '../../../CONST';
import Button from '../../../components/Button';
import {withNetwork} from '../../../components/OnyxProvider';
Expand Down Expand Up @@ -302,7 +302,7 @@ class WorkspaceReimburseView extends React.Component {
WorkspaceReimburseView.propTypes = propTypes;

export default compose(
withFullPolicy,
withPolicy,
withLocalize,
withNetwork(),
withOnyx({
Expand Down
Loading

0 comments on commit dc0a249

Please sign in to comment.