Skip to content

Commit

Permalink
Merge branch 'main' of github.com:mananjadhav/App into feat/ghost-screen
Browse files Browse the repository at this point in the history
  • Loading branch information
mananjadhav committed Jul 29, 2022
2 parents 0352b63 + b7367fb commit 862557b
Show file tree
Hide file tree
Showing 7 changed files with 80 additions and 32 deletions.
1 change: 1 addition & 0 deletions src/ONYXKEYS.js
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,7 @@ export default {
REPORT_IS_COMPOSER_FULL_SIZE: 'reportIsComposerFullSize_',
IS_LOADING_INITIAL_REPORT_ACTIONS: 'isLoadingInitialReportActions_',
IS_LOADING_MORE_REPORT_ACTIONS: 'isLoadingMoreReportActions_',
POLICY_MEMBER_LIST: 'policyMemberList_',
},

// Indicates which locale should be used
Expand Down
6 changes: 5 additions & 1 deletion src/components/Composer/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,8 @@ const IMAGE_EXTENSIONS = {
'image/webp': 'webp',
};

const COPY_DROP_EFFECT = 'copy';

/**
* Enable Markdown parsing.
* On web we like to have the Text Input field always focused so the user can easily type a new chat
Expand Down Expand Up @@ -197,13 +199,15 @@ class Composer extends React.Component {
dragNDropListener(e) {
let isOriginComposer = false;
const handler = () => {
// Setting dropEffect for dragover is required for '+' icon on certain platforms/browsers (eg. Safari)
switch (e.type) {
case 'dragover':
e.preventDefault();
e.dataTransfer.dropEffect = COPY_DROP_EFFECT;
this.props.onDragOver(e, isOriginComposer);
break;
case 'dragenter':
e.dataTransfer.dropEffect = 'copy';
e.dataTransfer.dropEffect = COPY_DROP_EFFECT;
this.props.onDragEnter(e, isOriginComposer);
break;
case 'dragleave':
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,
};
56 changes: 26 additions & 30 deletions src/libs/actions/ReimbursementAccount/resetFreePlanBankAccount.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@
import Onyx from 'react-native-onyx';
import lodashGet from 'lodash/get';
import ONYXKEYS from '../../../ONYXKEYS';
import * as DeprecatedAPI from '../../deprecatedAPI';
import CONST from '../../../CONST';
import * as store from './store';
import Growl from '../../Growl';
import Navigation from '../../Navigation/Navigation';
import ROUTES from '../../../ROUTES';
import * as API from '../../API';

/**
* Reset user's reimbursement account. This will delete the bank account.
Expand All @@ -20,35 +18,33 @@ function resetFreePlanBankAccount() {
throw new Error('Missing credentials when attempting to reset free plan bank account');
}

// Create a copy of the reimbursementAccount data since we are going to optimistically wipe it so the UI changes quickly.
// If the API request fails we will set this data back into Onyx.
const previousACHData = {...store.getReimbursementAccountInSetup()};
Onyx.merge(ONYXKEYS.REIMBURSEMENT_ACCOUNT, {achData: null, shouldShowResetModal: false});
DeprecatedAPI.DeleteBankAccount({bankAccountID, ownerEmail: store.getCredentials().login})
.then((response) => {
if (response.jsonCode !== 200) {
// Unable to delete bank account so we restore the bank account details
Onyx.merge(ONYXKEYS.REIMBURSEMENT_ACCOUNT, {achData: previousACHData});
Growl.error('Sorry we were unable to delete this bank account. Please try again later');
return;
}
const achData = {
useOnfido: true,
policyID: '',
isInSetup: true,
domainLimit: 0,
currentStep: CONST.BANK_ACCOUNT.STEP.BANK_ACCOUNT,
};

// Reset reimbursement account, and clear draft user input
const achData = {
useOnfido: true,
policyID: '',
isInSetup: true,
domainLimit: 0,
currentStep: CONST.BANK_ACCOUNT.STEP.BANK_ACCOUNT,
};

Onyx.set(ONYXKEYS.REIMBURSEMENT_ACCOUNT, {achData});
Onyx.set(ONYXKEYS.REIMBURSEMENT_ACCOUNT_DRAFT, null);

// Clear the NVP for the bank account so the user can add a new one and navigate back to bank account page
DeprecatedAPI.SetNameValuePair({name: CONST.NVP.FREE_PLAN_BANK_ACCOUNT_ID, value: ''});
Navigation.navigate(ROUTES.getBankAccountRoute());
API.write('RestartBankAccountSetup',
{
bankAccountID,
ownerEmail: store.getCredentials().login,
},
{
optimisticData: [{
onyxMethod: 'merge',
key: ONYXKEYS.REIMBURSEMENT_ACCOUNT,
value: {achData, shouldShowResetModal: false},
},
{
onyxMethod: 'set',
key: ONYXKEYS.REIMBURSEMENT_ACCOUNT_DRAFT,
value: null,
}],
});

Navigation.navigate(ROUTES.getBankAccountRoute());
}

export default resetFreePlanBankAccount;
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 862557b

Please sign in to comment.