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

[Payment card / Subscription] Implement “Your plan” section (UI) #42690

Merged
merged 16 commits into from
Jun 4, 2024
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
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
6 changes: 6 additions & 0 deletions src/CONST.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1890,6 +1890,12 @@ const CONST = {
COMPACT: 'compact',
DEFAULT: 'default',
},
SUBSCRIPTION: {
TYPE: {
ANNUAL: 'yearly2018',
PAYPERUSE: 'monthly2018',
JKobrynski marked this conversation as resolved.
Show resolved Hide resolved
},
},
REGEX: {
SPECIAL_CHARS_WITHOUT_NEWLINE: /((?!\n)[()-\s\t])/g,
DIGITS_AND_PLUS: /^\+?[0-9]*$/,
Expand Down
4 changes: 4 additions & 0 deletions src/ONYXKEYS.ts
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,9 @@ const ONYXKEYS = {
/** Whether the user has been shown the hold educational interstitial yet */
NVP_HOLD_USE_EXPLAINED: 'holdUseExplained',

/** Store the state of the subscription */
NVP_PRIVATE_SUBSCRIPTION: 'nvp_private_subscription',

/** Store preferred skintone for emoji */
PREFERRED_EMOJI_SKIN_TONE: 'nvp_expensify_preferredEmojiSkinTone',

Expand Down Expand Up @@ -633,6 +636,7 @@ type OnyxValuesMapping = {
[ONYXKEYS.NVP_ACTIVE_POLICY_ID]: string;
[ONYXKEYS.NVP_DISMISSED_REFERRAL_BANNERS]: OnyxTypes.DismissedReferralBanners;
[ONYXKEYS.NVP_HAS_SEEN_TRACK_TRAINING]: boolean;
[ONYXKEYS.NVP_PRIVATE_SUBSCRIPTION]: OnyxTypes.PrivateSubscription;
[ONYXKEYS.USER_WALLET]: OnyxTypes.UserWallet;
[ONYXKEYS.WALLET_ONFIDO]: OnyxTypes.WalletOnfido;
[ONYXKEYS.WALLET_ADDITIONAL_DETAILS]: OnyxTypes.WalletAdditionalDetails;
Expand Down
18 changes: 7 additions & 11 deletions src/hooks/useSubscriptionPlan.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,24 +8,20 @@ function useSubscriptionPlan() {
const [policies] = useOnyx(ONYXKEYS.COLLECTION.POLICY);

// Filter workspaces in which user is the admin and the type is either corporate (control) or team (collect)
JKobrynski marked this conversation as resolved.
Show resolved Hide resolved
const adminPolicies = useMemo(() => {
if (!policies) {
return {};
}

return Object.fromEntries(
Object.entries(policies).filter(
([, policy]) => policy?.role === CONST.POLICY.ROLE.ADMIN && (CONST.POLICY.TYPE.CORPORATE === policy?.type || CONST.POLICY.TYPE.TEAM === policy?.type),
const adminPolicies = useMemo(
() =>
Object.values(policies ?? {}).filter(
(policy) => policy?.role === CONST.POLICY.ROLE.ADMIN && (CONST.POLICY.TYPE.CORPORATE === policy?.type || CONST.POLICY.TYPE.TEAM === policy?.type),
),
);
}, [policies]);
[policies],
);

if (isEmptyObject(adminPolicies)) {
return null;
}

// Check if user has corporate (control) workspace
const hasControlWorkspace = Object.entries(adminPolicies).some(([, policy]) => policy?.type === CONST.POLICY.TYPE.CORPORATE);
const hasControlWorkspace = adminPolicies.some((policy) => policy?.type === CONST.POLICY.TYPE.CORPORATE);

// Corporate (control) workspace is supposed to be the higher priority
return hasControlWorkspace ? CONST.POLICY.TYPE.CORPORATE : CONST.POLICY.TYPE.TEAM;
Expand Down
2 changes: 2 additions & 0 deletions src/libs/API/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -480,6 +480,7 @@ const READ_COMMANDS = {
OPEN_POLICY_MORE_FEATURES_PAGE: 'OpenPolicyMoreFeaturesPage',
OPEN_POLICY_ACCOUNTING_PAGE: 'OpenPolicyAccountingPage',
SEARCH: 'Search',
OPEN_SUBSCRIPTION_PAGE: 'OpenSubscriptionPage',
} as const;

type ReadCommand = ValueOf<typeof READ_COMMANDS>;
Expand Down Expand Up @@ -526,6 +527,7 @@ type ReadCommandParameters = {
[READ_COMMANDS.OPEN_POLICY_MORE_FEATURES_PAGE]: Parameters.OpenPolicyMoreFeaturesPageParams;
[READ_COMMANDS.OPEN_POLICY_ACCOUNTING_PAGE]: Parameters.OpenPolicyAccountingPageParams;
[READ_COMMANDS.SEARCH]: Parameters.SearchParams;
[READ_COMMANDS.OPEN_SUBSCRIPTION_PAGE]: EmptyObject;
};

const SIDE_EFFECT_REQUEST_COMMANDS = {
Expand Down
14 changes: 14 additions & 0 deletions src/libs/actions/Subscription.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import * as API from '@libs/API';
import {READ_COMMANDS} from '@libs/API/types';

/**
* Fetches data when the user opens the SubscriptionSettingsPage
*/
function openSubscriptionPage() {
API.read(READ_COMMANDS.OPEN_SUBSCRIPTION_PAGE, {});
}

export {
// eslint-disable-next-line import/prefer-default-export
openSubscriptionPage,
};
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
/** Return null because this button is not supposed to be rendered in the native apps */
function SaveWithExpensifyButton() {
Copy link
Contributor

Choose a reason for hiding this comment

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

Maybe let's add a comment to the top of the file explaining why it returns just null?

return null;
}
Expand Down
21 changes: 11 additions & 10 deletions src/pages/settings/Subscription/SubscriptionPlan.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import React from 'react';
import {View} from 'react-native';
import {useOnyx} from 'react-native-onyx';
import Icon from '@components/Icon';
import * as Expensicons from '@components/Icon/Expensicons';
import * as Illustrations from '@components/Icon/Illustrations';
Expand All @@ -11,6 +12,7 @@ import useTheme from '@hooks/useTheme';
import useThemeStyles from '@hooks/useThemeStyles';
import variables from '@styles/variables';
import CONST from '@src/CONST';
import ONYXKEYS from '@src/ONYXKEYS';
import SaveWithExpensifyButton from './SaveWithExpensifyButton';

function SubscriptionPlan() {
Expand All @@ -19,10 +21,10 @@ function SubscriptionPlan() {
const theme = useTheme();

const subscriptionPlan = useSubscriptionPlan();
const [privateSubscription] = useOnyx(ONYXKEYS.NVP_PRIVATE_SUBSCRIPTION);

const isCollect = subscriptionPlan === CONST.POLICY.TYPE.TEAM;
// TODO: replace this with a real value once OpenSubscriptionPage API command is implemented
const isAnnual = true;
const isAnnual = privateSubscription?.type === CONST.SUBSCRIPTION.TYPE.ANNUAL;

const benefitsList = isCollect
JKobrynski marked this conversation as resolved.
Show resolved Hide resolved
? [
Expand All @@ -47,19 +49,18 @@ function SubscriptionPlan() {
<Section
title={translate('subscription.yourPlan.title')}
isCentralPane
titleStyles={styles.subscriptionSettingsSectionTitle}
titleStyles={styles.textStrong}
>
<View style={[styles.subscriptionSettingsBorderWrapper, styles.mt5, styles.p5]}>
<View style={[styles.borderedContentCard, styles.mt5, styles.p5]}>
<Icon
src={isCollect ? Illustrations.Mailbox : Illustrations.ShieldYellow}
width={variables.iconHeader}
height={variables.iconHeader}
/>
<Text style={[styles.yourPlanTitle, styles.mt2]}>{translate(`subscription.yourPlan.${isCollect ? 'collect' : 'control'}.title`)}</Text>
<Text style={[styles.yourPlanSubtitle, styles.mb2]}>
<Text style={[styles.headerText, styles.mt2]}>{translate(`subscription.yourPlan.${isCollect ? 'collect' : 'control'}.title`)}</Text>
<Text style={[styles.textLabelSupporting, styles.mb2]}>
{translate(`subscription.yourPlan.${isCollect ? 'collect' : 'control'}.${isAnnual ? 'priceAnnual' : 'pricePayPerUse'}`)}
JKobrynski marked this conversation as resolved.
Show resolved Hide resolved
</Text>
;
{benefitsList.map((benefit) => (
<View
style={[styles.flexRow, styles.alignItemsCenter, styles.mt2]}
Expand All @@ -69,7 +70,7 @@ function SubscriptionPlan() {
src={Expensicons.Checkmark}
fill={theme.iconSuccessFill}
/>
<Text style={[styles.yourPlanBenefit, styles.ml2]}>{benefit}</Text>
<Text style={[styles.textMicroSupporting, styles.ml2]}>{benefit}</Text>
</View>
))}
</View>
Expand All @@ -81,8 +82,8 @@ function SubscriptionPlan() {
additionalStyles={styles.mr2}
/>
<View style={[styles.flexColumn, styles.justifyContentCenter, styles.flex1, styles.mr2]}>
<Text style={[styles.yourPlanTitle, styles.mt2]}>{translate('subscription.yourPlan.saveWithExpensifyTitle')}</Text>
<Text style={[styles.yourPlanSubtitle, styles.mb2]}>{translate('subscription.yourPlan.saveWithExpensifyDescription')}</Text>
<Text style={[styles.headerText, styles.mt2]}>{translate('subscription.yourPlan.saveWithExpensifyTitle')}</Text>
<Text style={[styles.textLabelSupporting, styles.mb2]}>{translate('subscription.yourPlan.saveWithExpensifyDescription')}</Text>
</View>
<SaveWithExpensifyButton />
</View>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,16 +1,21 @@
import React from 'react';
import React, {useEffect} from 'react';
import HeaderWithBackButton from '@components/HeaderWithBackButton';
import * as Illustrations from '@components/Icon/Illustrations';
import ScreenWrapper from '@components/ScreenWrapper';
import useLocalize from '@hooks/useLocalize';
import useWindowDimensions from '@hooks/useWindowDimensions';
import Navigation from '@libs/Navigation/Navigation';
import * as Subscription from '@userActions/Subscription';
import SubscriptionPlan from './SubscriptionPlan';

function SubscriptionSettingsPage() {
const {isSmallScreenWidth} = useWindowDimensions();
const {translate} = useLocalize();
JKobrynski marked this conversation as resolved.
Show resolved Hide resolved

useEffect(() => {
Subscription.openSubscriptionPage();
}, []);

return (
<ScreenWrapper testID={SubscriptionSettingsPage.displayName}>
<HeaderWithBackButton
JKobrynski marked this conversation as resolved.
Show resolved Hide resolved
Expand Down
31 changes: 2 additions & 29 deletions src/styles/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2794,39 +2794,12 @@ const styles = (theme: ThemeColors) =>
fontWeight: FontUtils.fontWeight.bold,
},

subscriptionSettingsSectionTitle: {
fontFamily: FontUtils.fontFamily.platform.EXP_NEUE_BOLD,
fontWeight: FontUtils.fontWeight.bold,
},

subscriptionSettingsBorderWrapper: {
borderedContentCard: {
borderWidth: 1,
borderColor: colors.productDark400,
borderColor: theme.border,
borderRadius: variables.componentBorderRadiusMedium,
},

yourPlanTitle: {
fontFamily: FontUtils.fontFamily.platform.EXP_NEUE_BOLD,
fontWeight: FontUtils.fontWeight.bold,
fontSize: variables.fontSizeNormal,
lineHeight: variables.lineHeightXLarge,
},

yourPlanSubtitle: {
fontFamily: FontUtils.fontFamily.platform.EXP_NEUE,
fontWeight: FontUtils.fontWeight.normal,
fontSize: variables.fontSizeLabel,
lineHeight: variables.lineHeightNormal,
color: colors.productDark800,
},

yourPlanBenefit: {
fontFamily: FontUtils.fontFamily.platform.EXP_NEUE,
fontSize: variables.fontSizeSmall,
lineHeight: variables.lineHeightSmall,
color: colors.productDark800,
},

sectionMenuItem: {
borderRadius: 8,
paddingHorizontal: 8,
Expand Down
30 changes: 30 additions & 0 deletions src/types/onyx/PrivateSubscription.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
import type {ValueOf} from 'type-fest';
import type CONST from '@src/CONST';

type PrivateSubscription = {
/** "auto increase annual seats" setting */
addNewUsersAutomatically: boolean;

/** "auto renew" setting */
autoRenew: boolean;

/** The date "auto renew" was last edited */
autoRenewLastChangedDate: string;

/** "corporate karma" setting */
donateToExpensifyOrg?: true;

/** Subscription end date */
endDate: string;

/** Subscription start date */
startDate: string;

/** Subscription variant. "yearly2018" - annual, "monthly2018" - pay-per-use */
type: ValueOf<typeof CONST.SUBSCRIPTION.TYPE>;

/** Subscription size */
userCount?: 8;
JKobrynski marked this conversation as resolved.
Show resolved Hide resolved
};

export default PrivateSubscription;
2 changes: 2 additions & 0 deletions src/types/onyx/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ import type {PolicyTag, PolicyTagList, PolicyTags} from './PolicyTag';
import type PreferredTheme from './PreferredTheme';
import type PriorityMode from './PriorityMode';
import type PrivatePersonalDetails from './PrivatePersonalDetails';
import type PrivateSubscription from './PrivateSubscription';
import type QuickAction from './QuickAction';
import type RecentlyUsedCategories from './RecentlyUsedCategories';
import type RecentlyUsedReportFields from './RecentlyUsedReportFields';
Expand Down Expand Up @@ -181,4 +182,5 @@ export type {
PolicyJoinMember,
CapturedLogs,
SearchResults,
PrivateSubscription,
};
Loading