Skip to content

Commit

Permalink
Merge pull request #10080 from Expensify/jack-settingsredbrick
Browse files Browse the repository at this point in the history
Brick Road Indicator For Settings Page
  • Loading branch information
iwiznia authored Jul 28, 2022
2 parents 53bff65 + 3913b00 commit 1857e44
Show file tree
Hide file tree
Showing 5 changed files with 49 additions and 1 deletion.
1 change: 1 addition & 0 deletions src/ONYXKEYS.js
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,7 @@ export default {
REPORTS_WITH_DRAFT: 'reportWithDraft_',
REPORT_IS_COMPOSER_FULL_SIZE: 'reportIsComposerFullSize_',
IS_LOADING_REPORT_ACTIONS: 'isLoadingReportActions_',
POLICY_MEMBER_LIST: 'policyMemberList_',
},

// Indicates which locale should be used
Expand Down
14 changes: 13 additions & 1 deletion src/components/MenuItem.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ import Badge from './Badge';
import CONST from '../CONST';
import menuItemPropTypes from './menuItemPropTypes';
import SelectCircle from './SelectCircle';
import colors from '../styles/colors';
import variables from '../styles/variables';

const propTypes = {
...menuItemPropTypes,
Expand All @@ -40,6 +42,7 @@ const defaultProps = {
onPress: () => {},
interactive: true,
fallbackIcon: Expensicons.FallbackAvatar,
brickRoadIndicator: undefined,
};

const MenuItem = props => (
Expand Down Expand Up @@ -119,7 +122,6 @@ const MenuItem = props => (
</View>
<View style={[styles.flexRow, styles.menuItemTextContainer, styles.pointerEventsNone]}>
{props.badgeText && <Badge text={props.badgeText} badgeStyles={[styles.alignSelfCenter]} />}

{/* Since subtitle can be of type number, we should allow 0 to be shown */}
{(props.subtitle || props.subtitle === 0) && (
<View style={[styles.justifyContentCenter, styles.mr1]}>
Expand All @@ -130,6 +132,16 @@ const MenuItem = props => (
</Text>
</View>
)}
{props.brickRoadIndicator && (
<View style={[[styles.alignItemsCenter, styles.justifyContentCenter]]}>
<Icon
src={Expensicons.DotIndicator}
fill={props.brickRoadIndicator === 'error' ? colors.red : colors.green}
height={variables.iconSizeSmall}
width={variables.iconSizeSmall}
/>
</View>
)}
{props.shouldShowRightIcon && (
<View style={styles.popoverMenuIcon}>
<Icon
Expand Down
11 changes: 11 additions & 0 deletions src/libs/actions/Policy.js
Original file line number Diff line number Diff line change
Expand Up @@ -539,6 +539,16 @@ function subscribeToPolicyEvents() {
});
}

/**
* Checks if we have any errors stored within the POLICY_MEMBER_LIST. Determines whether we should show a red brick road error or not
* Data structure: {email: {role:'bla', errors: []}, email2: {role:'bla', errors: [{1231312313: 'Unable to do X'}]}, ...}
* @param {Object} policyMemberList
* @returns {Boolean}
*/
function hasPolicyMemberError(policyMemberList) {
return _.some(policyMemberList, member => !_.isEmpty(member.errors));
}

export {
getPolicyList,
loadFullPolicy,
Expand All @@ -557,4 +567,5 @@ export {
setCustomUnitRate,
updateLastAccessedWorkspace,
subscribeToPolicyEvents,
hasPolicyMemberError,
};
12 changes: 12 additions & 0 deletions src/pages/policyMemberPropType.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import PropTypes from 'prop-types';

export default PropTypes.shape({
/** Role of the user in the policy */
role: PropTypes.string,

/**
* Errors from api calls on the specific user
* {<timestamp>: 'error message', <timestamp2>: 'error message 2'}
*/
errors: PropTypes.objectOf(PropTypes.string),
});
12 changes: 12 additions & 0 deletions src/pages/settings/InitialSettingsPage.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import React from 'react';
import {View, ScrollView, Pressable} from 'react-native';
import PropTypes from 'prop-types';
import _ from 'underscore';
import lodashGet from 'lodash/get';
import {withOnyx} from 'react-native-onyx';
import Str from 'expensify-common/lib/str';
import styles from '../../styles/styles';
Expand All @@ -24,6 +25,8 @@ import Permissions from '../../libs/Permissions';
import networkPropTypes from '../../components/networkPropTypes';
import {withNetwork} from '../../components/OnyxProvider';
import withCurrentUserPersonalDetails, {withCurrentUserPersonalDetailsPropTypes, withCurrentUserPersonalDetailsDefaultProps} from '../../components/withCurrentUserPersonalDetails';
import * as Policy from '../../libs/actions/Policy';
import policyMemberPropType from '../policyMemberPropType';

const propTypes = {
/* Onyx Props */
Expand Down Expand Up @@ -52,6 +55,9 @@ const propTypes = {
role: PropTypes.string,
})),

/** List of policy members */
policyMembers: PropTypes.objectOf(policyMemberPropType),

/** The user's wallet account */
userWallet: PropTypes.shape({
/** The user's current wallet balance */
Expand All @@ -72,6 +78,7 @@ const defaultProps = {
currentBalance: 0,
},
betas: [],
policyMembers: {},
...withCurrentUserPersonalDetailsDefaultProps,
};

Expand Down Expand Up @@ -135,6 +142,7 @@ const InitialSettingsPage = (props) => {
iconStyles: policy.avatarURL ? [] : [styles.popoverMenuIconEmphasized],
iconFill: themeColors.iconReversed,
fallbackIcon: Expensicons.FallbackWorkspaceAvatar,
brickRoadIndicator: Policy.hasPolicyMemberError(lodashGet(props.policyMembers, `${ONYXKEYS.COLLECTION.POLICY_MEMBER_LIST}${policy.id}`, {})) ? 'error' : null,
}))
.value();
menuItems.push(...defaultMenuItems);
Expand Down Expand Up @@ -190,6 +198,7 @@ const InitialSettingsPage = (props) => {
shouldShowRightIcon
badgeText={(isPaymentItem && Permissions.canUseWallet(props.betas)) ? walletBalance : undefined}
fallbackIcon={item.fallbackIcon}
brickRoadIndicator={item.brickRoadIndicator}
/>
);
})}
Expand All @@ -214,6 +223,9 @@ export default compose(
policies: {
key: ONYXKEYS.COLLECTION.POLICY,
},
policyMembers: {
key: ONYXKEYS.COLLECTION.POLICY_MEMBER_LIST,
},
userWallet: {
key: ONYXKEYS.USER_WALLET,
},
Expand Down

0 comments on commit 1857e44

Please sign in to comment.