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

[Free trial] Implement and show Trial Ended banner, Expensify DM GBR and custom Expensify DM chat item in the App after Free Trial ends #44483

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
20 commits
Select commit Hold shift + click to select a range
1c35f4d
feat: add trial ended banner and update related UI
pac-guerreiro Jun 26, 2024
d6e2f36
refactor: remove unnecessary text wrapper
pac-guerreiro Jun 26, 2024
8fc1eba
Merge branch 'pac-guerreiro/feature/43672-implement-and-show-free-tri…
pac-guerreiro Jun 27, 2024
ace1c18
Merge branch 'pac-guerreiro/feature/43672-implement-and-show-free-tri…
pac-guerreiro Jun 27, 2024
978af7e
Merge branch 'pac-guerreiro/feature/43672-implement-and-show-free-tri…
pac-guerreiro Jun 28, 2024
d3dc428
Merge branch 'pac-guerreiro/feature/43672-implement-and-show-free-tri…
pac-guerreiro Jul 1, 2024
a2f0e84
refactor: apply suggestions
pac-guerreiro Jul 2, 2024
21554b9
Merge branch 'pac-guerreiro/feature/43672-implement-and-show-free-tri…
pac-guerreiro Jul 2, 2024
5e8e967
Merge branch 'main' into pac-guerreiro/feature/43671-trial-ended-bann…
pac-guerreiro Jul 3, 2024
222e524
Merge branch 'main' into pac-guerreiro/feature/43671-trial-ended-bann…
pac-guerreiro Jul 4, 2024
a36a47c
Merge branch 'main' into pac-guerreiro/feature/43671-trial-ended-bann…
pac-guerreiro Jul 4, 2024
bc13f9a
fix: free trial ended not showing as report last message in LHN
pac-guerreiro Jul 4, 2024
38a11b6
fix: GBR not showing in concierge chat option in LHN
pac-guerreiro Jul 4, 2024
174c48b
Merge branch 'main' into pac-guerreiro/feature/43671-trial-ended-bann…
pac-guerreiro Jul 8, 2024
bc06a92
Merge branch 'main' into pac-guerreiro/feature/43671-trial-ended-bann…
pac-guerreiro Jul 10, 2024
3e1992a
Merge branch 'main' into pac-guerreiro/feature/43671-trial-ended-bann…
pac-guerreiro Jul 11, 2024
16dd7a2
Merge branch 'main' into pac-guerreiro/feature/43671-trial-ended-bann…
pac-guerreiro Jul 11, 2024
79b3671
refactor: add isConciergeChat property to OptionData and check for it
pac-guerreiro Jul 11, 2024
cfb59ee
Merge branch 'main' into pac-guerreiro/feature/43671-trial-ended-bann…
pac-guerreiro Jul 11, 2024
531e0be
chore: fix linter issue
pac-guerreiro Jul 11, 2024
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
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions src/CONST.ts
Original file line number Diff line number Diff line change
Expand Up @@ -668,6 +668,7 @@ const CONST = {
LIMIT: 50,
// OldDot Actions render getMessage from Web-Expensify/lib/Report/Action PHP files via getMessageOfOldDotReportAction in ReportActionsUtils.ts
TYPE: {
ACTIONABLE_ADD_PAYMENT_CARD: 'ACTIONABLEADDPAYMENTCARD',
ACTIONABLE_JOIN_REQUEST: 'ACTIONABLEJOINREQUEST',
ACTIONABLE_MENTION_WHISPER: 'ACTIONABLEMENTIONWHISPER',
ACTIONABLE_REPORT_MENTION_WHISPER: 'ACTIONABLEREPORTMENTIONWHISPER',
Expand Down
2 changes: 2 additions & 0 deletions src/components/Icon/Illustrations.ts
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,7 @@ import SubscriptionPPU from '@assets/images/simple-illustrations/simple-illustra
import Tag from '@assets/images/simple-illustrations/simple-illustration__tag.svg';
import TeachersUnite from '@assets/images/simple-illustrations/simple-illustration__teachers-unite.svg';
import ThumbsUpStars from '@assets/images/simple-illustrations/simple-illustration__thumbsupstars.svg';
import Tire from '@assets/images/simple-illustrations/simple-illustration__tire.svg';
import TrackShoe from '@assets/images/simple-illustrations/simple-illustration__track-shoe.svg';
import TrashCan from '@assets/images/simple-illustrations/simple-illustration__trashcan.svg';
import TreasureChest from '@assets/images/simple-illustrations/simple-illustration__treasurechest.svg';
Expand Down Expand Up @@ -204,4 +205,5 @@ export {
EmptyState,
FolderWithPapers,
VirtualCard,
Tire,
};
4 changes: 4 additions & 0 deletions src/languages/en.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3985,6 +3985,10 @@ export default {
title: ({numOfDays}) => `Free trial: ${numOfDays} ${numOfDays === 1 ? 'day' : 'days'} left!`,
subtitle: 'Add a payment card to continue using all of your favorite features.',
},
trialEnded: {
title: 'Your free trial has ended',
subtitle: 'Add a payment card to continue using all of your favorite features.',
},
},
cardSection: {
title: 'Payment',
Expand Down
4 changes: 4 additions & 0 deletions src/languages/es.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4502,6 +4502,10 @@ export default {
title: ({numOfDays}) => `Prueba gratuita: ¡${numOfDays === 1 ? `queda 1 día` : `quedan ${numOfDays} días`}!`,
subtitle: 'Añade una tarjeta de pago para seguir utilizando tus funciones favoritas.',
},
trialEnded: {
title: 'Tu prueba gratuita ha terminado',
subtitle: 'Añade una tarjeta de pago para seguir utilizando tus funciones favoritas.',
},
},
cardSection: {
title: 'Pago',
Expand Down
2 changes: 2 additions & 0 deletions src/libs/OptionsListUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -725,6 +725,8 @@ function getLastMessageTextForReport(report: OnyxEntry<Report>, lastActorDetails
lastMessageTextFromReport = ReportUtils.getIOUSubmittedMessage(reportID);
} else if (lastReportAction?.actionName === CONST.REPORT.ACTIONS.TYPE.APPROVED) {
lastMessageTextFromReport = ReportUtils.getIOUApprovedMessage(reportID);
} else if (ReportActionUtils.isActionableAddPaymentCard(lastReportAction)) {
lastMessageTextFromReport = ReportActionUtils.getReportActionMessageText(lastReportAction);
}

return lastMessageTextFromReport || (report?.lastMessageText ?? '');
Expand Down
9 changes: 9 additions & 0 deletions src/libs/ReportActionsUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1408,6 +1408,14 @@ function getTrackExpenseActionableWhisper(transactionID: string, chatReportID: s
return Object.values(chatReportActions).find((action: ReportAction) => isActionableTrackExpense(action) && getOriginalMessage(action)?.transactionID === transactionID);
}

/**
* Checks if a given report action corresponds to a add payment card action.
* @param reportAction
*/
function isActionableAddPaymentCard(reportAction: OnyxEntry<ReportAction>): reportAction is ReportAction<typeof CONST.REPORT.ACTIONS.TYPE.ACTIONABLE_ADD_PAYMENT_CARD> {
Copy link
Contributor

Choose a reason for hiding this comment

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

Why is the return type ReportAction here? Shouldn't it be boolean?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@rojiphil

We're applying a type predicate - https://www.typescriptlang.org/docs/handbook/2/narrowing.html#using-type-predicates

Not only does this function return a boolean, it also tells the compiler that the argument we passed to it is a specific subtype of ReportAction, which allows us developers to easily access it's properties without the need to do manual assertions.

I hope this answers your requestion 😄

Copy link
Contributor

Choose a reason for hiding this comment

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

Got it. That's cool. Thanks.

return reportAction?.actionName === CONST.REPORT.ACTIONS.TYPE.ACTIONABLE_ADD_PAYMENT_CARD;
}

export {
extractLinksFromMessageHtml,
getDismissedViolationMessageText,
Expand Down Expand Up @@ -1494,6 +1502,7 @@ export {
isTripPreview,
getIOUActionForReportID,
getFilteredForOneTransactionView,
isActionableAddPaymentCard,
};

export type {LastVisibleMessage};
7 changes: 5 additions & 2 deletions src/libs/ReportUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -438,6 +438,7 @@ type OptionData = {
shouldShowAmountInput?: boolean;
amountInputProps?: MoneyRequestAmountInputProps;
tabIndex?: 0 | -1;
isConciergeChat?: boolean;
} & Report;

type OnyxDataTaskAssigneeChat = {
Expand Down Expand Up @@ -7079,8 +7080,10 @@ function shouldShowMerchantColumn(transactions: Transaction[]) {
/**
* Whether the report is a system chat or concierge chat, depending on the user's account ID (used for A/B testing purposes).
*/
function isChatUsedForOnboarding(report: OnyxEntry<Report>): boolean {
return AccountUtils.isAccountIDOddNumber(currentUserAccountID ?? -1) ? isSystemChat(report) : isConciergeChatReport(report);
function isChatUsedForOnboarding(optionOrReport: OnyxEntry<Report> | OptionData): boolean {
return AccountUtils.isAccountIDOddNumber(currentUserAccountID ?? -1)
? isSystemChat(optionOrReport)
: (optionOrReport as OptionData).isConciergeChat ?? isConciergeChatReport(optionOrReport);
Copy link
Contributor

Choose a reason for hiding this comment

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

We should had used optional chaining here, this caused the app to crash and caused the issue #45492

}

/**
Expand Down
2 changes: 2 additions & 0 deletions src/libs/SidebarUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -260,6 +260,7 @@ function getOptionData({
isWaitingOnBankAccount: false,
isAllowedToComment: true,
isDeletedParentAction: false,
isConciergeChat: false,
};

const participantAccountIDs = ReportUtils.getParticipantsAccountIDsForDisplay(report);
Expand Down Expand Up @@ -305,6 +306,7 @@ function getOptionData({
result.tooltipText = ReportUtils.getReportParticipantsTitle(visibleParticipantAccountIDs);
result.hasOutstandingChildTask = report.hasOutstandingChildTask;
result.hasParentAccess = report.hasParentAccess;
result.isConciergeChat = ReportUtils.isConciergeChatReport(report);

const hasMultipleParticipants = participantPersonalDetailList.length > 1 || result.isChatRoom || result.isPolicyExpenseChat || ReportUtils.isExpenseReport(report);
const subtitle = ReportUtils.getChatRoomSubtitle(report);
Expand Down
5 changes: 5 additions & 0 deletions src/libs/shouldRenderAppPaymentCard/index.native.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import type ShouldRenderAddPaymentCard from './types';

const shouldRenderAddPaymentCard: ShouldRenderAddPaymentCard = () => false;

export default shouldRenderAddPaymentCard;
5 changes: 5 additions & 0 deletions src/libs/shouldRenderAppPaymentCard/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import type ShouldRenderAddPaymentCard from './types';

const shouldRenderAddPaymentCard: ShouldRenderAddPaymentCard = () => true;

export default shouldRenderAddPaymentCard;
3 changes: 3 additions & 0 deletions src/libs/shouldRenderAppPaymentCard/types.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
type ShouldRenderAddPaymentCard = () => boolean;

export default ShouldRenderAddPaymentCard;
15 changes: 15 additions & 0 deletions src/pages/home/report/ReportActionItem.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ import * as PolicyUtils from '@libs/PolicyUtils';
import * as ReportActionsUtils from '@libs/ReportActionsUtils';
import * as ReportUtils from '@libs/ReportUtils';
import SelectionScraper from '@libs/SelectionScraper';
import shouldRenderAddPaymentCard from '@libs/shouldRenderAppPaymentCard';
import {ReactionListContext} from '@pages/home/ReportScreenContext';
import * as BankAccounts from '@userActions/BankAccounts';
import * as EmojiPickerAction from '@userActions/EmojiPickerAction';
Expand Down Expand Up @@ -398,6 +399,20 @@ function ReportActionItem({
const attachmentContextValue = useMemo(() => ({reportID: report.reportID, type: CONST.ATTACHMENT_TYPE.REPORT}), [report.reportID]);

const actionableItemButtons: ActionableItem[] = useMemo(() => {
if (ReportActionsUtils.isActionableAddPaymentCard(action) && shouldRenderAddPaymentCard()) {
pac-guerreiro marked this conversation as resolved.
Show resolved Hide resolved
return [
{
text: 'subscription.cardSection.addCardButton',
key: `${action.reportActionID}-actionableAddPaymentCard-submit`,
onPress: () => {
Navigation.navigate(ROUTES.SETTINGS_SUBSCRIPTION);
},
isMediumSized: true,
isPrimary: true,
},
];
}

if (!isActionableWhisper && (!ReportActionsUtils.isActionableJoinRequest(action) || ReportActionsUtils.getOriginalMessage(action)?.choice !== ('' as JoinWorkspaceResolution))) {
return [];
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import React from 'react';
import * as Illustrations from '@components/Icon/Illustrations';
import useLocalize from '@hooks/useLocalize';
import BillingBanner from './BillingBanner';

function TrialEndedBillingBanner() {
const {translate} = useLocalize();

return (
<BillingBanner
title={translate('subscription.billingBanner.trialEnded.title')}
subtitle={translate('subscription.billingBanner.trialEnded.subtitle')}
icon={Illustrations.Tire}
/>
);
}

TrialEndedBillingBanner.displayName = 'TrialEndedBillingBanner';

export default TrialEndedBillingBanner;
3 changes: 3 additions & 0 deletions src/pages/settings/Subscription/CardSection/CardSection.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import ROUTES from '@src/ROUTES';
import {isEmptyObject} from '@src/types/utils/EmptyObject';
import PreTrialBillingBanner from './BillingBanner/PreTrialBillingBanner';
import SubscriptionBillingBanner from './BillingBanner/SubscriptionBillingBanner';
import TrialEndedBillingBanner from './BillingBanner/TrialEndedBillingBanner';
import TrialStartedBillingBanner from './BillingBanner/TrialStartedBillingBanner';
import CardSectionActions from './CardSectionActions';
import CardSectionDataEmpty from './CardSectionDataEmpty';
Expand Down Expand Up @@ -76,6 +77,8 @@ function CardSection() {
BillingBanner = <PreTrialBillingBanner />;
} else if (SubscriptionUtils.isUserOnFreeTrial()) {
BillingBanner = <TrialStartedBillingBanner />;
} else if (SubscriptionUtils.hasUserFreeTrialEnded()) {
BillingBanner = <TrialEndedBillingBanner />;
} else if (billingStatus) {
BillingBanner = (
<SubscriptionBillingBanner
Expand Down
7 changes: 7 additions & 0 deletions src/types/onyx/OriginalMessage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -414,8 +414,15 @@ type OriginalMessageUnapproved = {
expenseReportID: string;
};

/**
* Model of `Add payment card` report action
*/
type OriginalMessageAddPaymentCard = Record<string, never>;

/** The map type of original message */
type OriginalMessageMap = {
/** */
[CONST.REPORT.ACTIONS.TYPE.ACTIONABLE_ADD_PAYMENT_CARD]: OriginalMessageAddPaymentCard;
/** */
[CONST.REPORT.ACTIONS.TYPE.ACTIONABLE_JOIN_REQUEST]: OriginalMessageJoinPolicyChangeLog;
/** */
Expand Down
Loading