Skip to content

Commit

Permalink
Merge branch 'main' into pac-guerreiro/feature/50335-add-transaction-…
Browse files Browse the repository at this point in the history
…and-violation-data-to-debug-mode
  • Loading branch information
pac-guerreiro committed Nov 18, 2024
2 parents 05c55c2 + 6ac7513 commit 6bfa9a9
Show file tree
Hide file tree
Showing 9 changed files with 82 additions and 90 deletions.
1 change: 0 additions & 1 deletion src/components/AddPaymentMethodMenu.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,6 @@ function AddPaymentMethodMenu({
text: translate('common.businessBankAccount'),
icon: Expensicons.Building,
onSelected: () => {
completePaymentOnboarding(CONST.PAYMENT_SELECTED.BBA);
onItemSelected(CONST.PAYMENT_METHODS.BUSINESS_BANK_ACCOUNT);
},
},
Expand Down
4 changes: 3 additions & 1 deletion src/components/KYCWall/BaseKYCWall.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import type {EmitterSubscription, GestureResponderEvent, View} from 'react-nativ
import {useOnyx} from 'react-native-onyx';
import AddPaymentMethodMenu from '@components/AddPaymentMethodMenu';
import * as BankAccounts from '@libs/actions/BankAccounts';
import {completePaymentOnboarding} from '@libs/actions/IOU';
import getClickedTargetLocation from '@libs/getClickedTargetLocation';
import Log from '@libs/Log';
import Navigation from '@libs/Navigation/Navigation';
Expand Down Expand Up @@ -108,7 +109,8 @@ function KYCWall({
Navigation.navigate(addDebitCardRoute);
} else if (paymentMethod === CONST.PAYMENT_METHODS.BUSINESS_BANK_ACCOUNT) {
if (iouReport && ReportUtils.isIOUReport(iouReport)) {
const {policyID, workspaceChatReportID, reportPreviewReportActionID} = Policy.createWorkspaceFromIOUPayment(iouReport) ?? {};
const {policyID, workspaceChatReportID, reportPreviewReportActionID, adminsChatReportID} = Policy.createWorkspaceFromIOUPayment(iouReport) ?? {};
completePaymentOnboarding(CONST.PAYMENT_SELECTED.BBA, adminsChatReportID, policyID);
if (workspaceChatReportID) {
Navigation.navigate(ROUTES.REPORT_WITH_ID.getRoute(workspaceChatReportID, reportPreviewReportActionID));
}
Expand Down
9 changes: 9 additions & 0 deletions src/libs/PolicyUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1108,6 +1108,14 @@ function isPolicyAccessible(policy: OnyxEntry<Policy>): boolean {
return !isEmptyObject(policy) && (Object.keys(policy).length !== 1 || isEmptyObject(policy.errors)) && !!policy?.id;
}

function areAllGroupPoliciesExpenseChatDisabled(policies = allPolicies) {
const groupPolicies = Object.values(policies ?? {}).filter((policy) => isPaidGroupPolicy(policy));
if (groupPolicies.length === 0) {
return false;
}
return !groupPolicies.some((policy) => !!policy?.isPolicyExpenseChatEnabled);
}

export {
canEditTaxRate,
extractPolicyIDFromPath,
Expand Down Expand Up @@ -1228,6 +1236,7 @@ export {
getAllPoliciesLength,
getActivePolicy,
isPolicyAccessible,
areAllGroupPoliciesExpenseChatDisabled,
};

export type {MemberEmailsToAccountIDs};
7 changes: 3 additions & 4 deletions src/libs/actions/IOU.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7364,7 +7364,7 @@ function cancelPayment(expenseReport: OnyxEntry<OnyxTypes.Report>, chatReport: O
*
* @param paymentSelected based on which we choose the onboarding choice and concierge message
*/
function completePaymentOnboarding(paymentSelected: ValueOf<typeof CONST.PAYMENT_SELECTED>) {
function completePaymentOnboarding(paymentSelected: ValueOf<typeof CONST.PAYMENT_SELECTED>, adminsChatReportID?: string, onboardingPolicyID?: string) {
const isInviteOnboardingComplete = introSelected?.isInviteOnboardingComplete ?? false;

if (isInviteOnboardingComplete || !introSelected?.choice || !introSelected?.inviteType) {
Expand All @@ -7390,15 +7390,14 @@ function completePaymentOnboarding(paymentSelected: ValueOf<typeof CONST.PAYMENT
CONST.ONBOARDING_MESSAGES[onboardingPurpose],
personalDetails?.firstName ?? '',
personalDetails?.lastName ?? '',
undefined,
undefined,
adminsChatReportID,
onboardingPolicyID,
paymentSelected,
undefined,
undefined,
true,
);
}

function payMoneyRequest(paymentType: PaymentMethodType, chatReport: OnyxTypes.Report, iouReport: OnyxEntry<OnyxTypes.Report>, full = true) {
if (chatReport.policyID && SubscriptionUtils.shouldRestrictUserBillableActions(chatReport.policyID)) {
Navigation.navigate(ROUTES.RESTRICTED_ACTION.getRoute(chatReport.policyID));
Expand Down
3 changes: 2 additions & 1 deletion src/libs/actions/Policy/Policy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,7 @@ type WorkspaceFromIOUCreationData = {
policyID: string;
workspaceChatReportID: string;
reportPreviewReportActionID?: string;
adminsChatReportID: string;
};

const allPolicies: OnyxCollection<Policy> = {};
Expand Down Expand Up @@ -2563,7 +2564,7 @@ function createWorkspaceFromIOUPayment(iouReport: OnyxEntry<Report>): WorkspaceF

API.write(WRITE_COMMANDS.CREATE_WORKSPACE_FROM_IOU_PAYMENT, params, {optimisticData, successData, failureData});

return {policyID, workspaceChatReportID: memberData.workspaceChatReportID, reportPreviewReportActionID: reportPreview?.reportActionID};
return {policyID, workspaceChatReportID: memberData.workspaceChatReportID, reportPreviewReportActionID: reportPreview?.reportActionID, adminsChatReportID};
}

function enablePolicyConnections(policyID: string, enabled: boolean) {
Expand Down
70 changes: 56 additions & 14 deletions src/pages/Search/EmptySearchView.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import React, {useMemo, useState} from 'react';
import {Linking, View} from 'react-native';
import {useOnyx} from 'react-native-onyx';
import type {OnyxCollection} from 'react-native-onyx';
import ConfirmModal from '@components/ConfirmModal';
import DotIndicatorMessage from '@components/DotIndicatorMessage';
import EmptyStateComponent from '@components/EmptyStateComponent';
import type {FeatureListItem} from '@components/FeatureList';
Expand All @@ -16,6 +18,7 @@ import useStyleUtils from '@hooks/useStyleUtils';
import useTheme from '@hooks/useTheme';
import useThemeStyles from '@hooks/useThemeStyles';
import interceptAnonymousUser from '@libs/interceptAnonymousUser';
import * as PolicyUtils from '@libs/PolicyUtils';
import * as ReportUtils from '@libs/ReportUtils';
import {getNavatticURL} from '@libs/TourUtils';
import * as TripsResevationUtils from '@libs/TripReservationUtils';
Expand All @@ -24,6 +27,7 @@ import * as IOU from '@userActions/IOU';
import * as Link from '@userActions/Link';
import CONST from '@src/CONST';
import ONYXKEYS from '@src/ONYXKEYS';
import type * as OnyxTypes from '@src/types/onyx';
import type {SearchDataTypes} from '@src/types/onyx/SearchResults';

type EmptySearchViewProps = {
Expand All @@ -46,6 +50,11 @@ function EmptySearchView({type}: EmptySearchViewProps) {
const StyleUtils = useStyleUtils();
const {translate} = useLocalize();
const styles = useThemeStyles();
const [modalVisible, setModalVisible] = useState(false);
const [allPolicies] = useOnyx(ONYXKEYS.COLLECTION.POLICY);
const shouldRedirectToExpensifyClassic = useMemo(() => {
return PolicyUtils.areAllGroupPoliciesExpenseChatDisabled((allPolicies as OnyxCollection<OnyxTypes.Policy>) ?? {});
}, [allPolicies]);

const [ctaErrorMessage, setCtaErrorMessage] = useState('');

Expand Down Expand Up @@ -126,7 +135,14 @@ function EmptySearchView({type}: EmptySearchViewProps) {
{buttonText: translate('emptySearchView.takeATour'), buttonAction: () => Link.openExternalLink(navatticURL)},
{
buttonText: translate('iou.createExpense'),
buttonAction: () => interceptAnonymousUser(() => IOU.startMoneyRequest(CONST.IOU.TYPE.CREATE, ReportUtils.generateReportID())),
buttonAction: () =>
interceptAnonymousUser(() => {
if (shouldRedirectToExpensifyClassic) {
setModalVisible(true);
return;
}
IOU.startMoneyRequest(CONST.IOU.TYPE.CREATE, ReportUtils.generateReportID());
}),
success: true,
},
],
Expand All @@ -143,21 +159,47 @@ function EmptySearchView({type}: EmptySearchViewProps) {
headerContentStyles: styles.emptyStateFolderWebStyles,
};
}
}, [type, StyleUtils, translate, theme, styles, subtitleComponent, ctaErrorMessage, navatticURL]);
}, [
type,
StyleUtils,
theme.travelBG,
theme.emptyFolderBG,
translate,
styles.textAlignLeft,
styles.emptyStateFolderWebStyles,
subtitleComponent,
ctaErrorMessage,
navatticURL,
shouldRedirectToExpensifyClassic,
]);

return (
<EmptyStateComponent
SkeletonComponent={SearchRowSkeleton}
headerMediaType={CONST.EMPTY_STATE_MEDIA.ANIMATION}
headerMedia={content.headerMedia}
headerStyles={[content.headerStyles, styles.emptyStateCardIllustrationContainer]}
title={content.title}
titleStyles={content.titleStyles}
subtitle={content.subtitle}
buttons={content.buttons}
headerContentStyles={[styles.h100, styles.w100, content.headerContentStyles]}
lottieWebViewStyles={styles.emptyStateFolderWebStyles}
/>
<>
<EmptyStateComponent
SkeletonComponent={SearchRowSkeleton}
headerMediaType={CONST.EMPTY_STATE_MEDIA.ANIMATION}
headerMedia={content.headerMedia}
headerStyles={[content.headerStyles, styles.emptyStateCardIllustrationContainer]}
title={content.title}
titleStyles={content.titleStyles}
subtitle={content.subtitle}
buttons={content.buttons}
headerContentStyles={[styles.h100, styles.w100, content.headerContentStyles]}
lottieWebViewStyles={styles.emptyStateFolderWebStyles}
/>
<ConfirmModal
prompt={translate('sidebarScreen.redirectToExpensifyClassicModal.description')}
isVisible={modalVisible}
onConfirm={() => {
setModalVisible(false);
Link.openOldDotLink(CONST.OLDDOT_URLS.INBOX);
}}
onCancel={() => setModalVisible(false)}
title={translate('sidebarScreen.redirectToExpensifyClassicModal.title')}
confirmText={translate('exitSurvey.goToExpensifyClassic')}
cancelText={translate('common.cancel')}
/>
</>
);
}

Expand Down
62 changes: 0 additions & 62 deletions src/pages/WorkspaceSwitcherPage/WorkspacesSectionHeader.tsx

This file was deleted.

10 changes: 8 additions & 2 deletions src/pages/WorkspaceSwitcherPage/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ import CONST from '@src/CONST';
import ONYXKEYS from '@src/ONYXKEYS';
import {isEmptyObject} from '@src/types/utils/EmptyObject';
import WorkspaceCardCreateAWorkspace from './WorkspaceCardCreateAWorkspace';
import WorkspacesSectionHeader from './WorkspacesSectionHeader';

type WorkspaceListItem = {
text: string;
Expand Down Expand Up @@ -183,7 +182,14 @@ function WorkspaceSwitcherPage() {
pressableStyle={styles.flexRow}
shouldSyncFocus={false}
/>
<WorkspacesSectionHeader shouldShowCreateWorkspaceIcon={!shouldShowCreateWorkspace} />
<View style={[styles.ph5, styles.mv2]}>
<Text
style={styles.label}
color={theme.textSupporting}
>
{translate('common.workspaces')}
</Text>
</View>
<SelectionList<WorkspaceListItem>
ListItem={UserListItem}
sections={sections}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -191,11 +191,7 @@ function FloatingActionButtonAndPopover({onHideCreateMenu, onShowCreateMenu}: Fl
* 2. none of the group policies they are a member of have isPolicyExpenseChatEnabled=true
*/
const shouldRedirectToExpensifyClassic = useMemo(() => {
const groupPolicies = Object.values(allPolicies ?? {}).filter((policy) => ReportUtils.isGroupPolicy(policy?.type ?? ''));
if (groupPolicies.length === 0) {
return false;
}
return !groupPolicies.some((policy) => !!policy?.isPolicyExpenseChatEnabled);
return PolicyUtils.areAllGroupPoliciesExpenseChatDisabled((allPolicies as OnyxCollection<OnyxTypes.Policy>) ?? {});
}, [allPolicies]);

const shouldShowNewWorkspaceButton = Object.values(allPolicies ?? {}).every(
Expand Down

0 comments on commit 6bfa9a9

Please sign in to comment.