forked from Expensify/App
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request Expensify#43128 from JKobrynski/integrateYourPlanS…
…ectionWithBackend [Payment card / Subscription] Integrate “Your plan” section with backend data and related screens
- Loading branch information
Showing
10 changed files
with
176 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
import {useMemo} from 'react'; | ||
import {useOnyx} from 'react-native-onyx'; | ||
import type {ValueOf} from 'type-fest'; | ||
import CONST from '@src/CONST'; | ||
import ONYXKEYS from '@src/ONYXKEYS'; | ||
|
||
type PreferredCurrency = ValueOf<typeof CONST.PAYMENT_CARD_CURRENCY>; | ||
|
||
/** | ||
* Get user's preferred currency in the following order: | ||
* | ||
* 1. Payment card currency | ||
* 2. User's local currency (if it's a valid payment card currency) | ||
* 3. USD (default currency) | ||
* | ||
*/ | ||
function usePreferredCurrency(): PreferredCurrency { | ||
const [personalDetails] = useOnyx(ONYXKEYS.PERSONAL_DETAILS_LIST); | ||
const [session] = useOnyx(ONYXKEYS.SESSION); | ||
const [fundList] = useOnyx(ONYXKEYS.FUND_LIST); | ||
|
||
const paymentCardCurrency = useMemo(() => Object.values(fundList ?? {}).find((card) => card.accountData?.additionalData?.isBillingCard)?.accountData?.currency, [fundList]); | ||
|
||
if (paymentCardCurrency) { | ||
return paymentCardCurrency; | ||
} | ||
|
||
const currentUserLocalCurrency = (personalDetails?.[session?.accountID ?? '-1']?.localCurrencyCode ?? CONST.PAYMENT_CARD_CURRENCY.USD) as PreferredCurrency; | ||
|
||
return Object.values(CONST.PAYMENT_CARD_CURRENCY).includes(currentUserLocalCurrency) ? currentUserLocalCurrency : CONST.PAYMENT_CARD_CURRENCY.USD; | ||
} | ||
|
||
export default usePreferredCurrency; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
import {useOnyx} from 'react-native-onyx'; | ||
import CONST from '@src/CONST'; | ||
import ONYXKEYS from '@src/ONYXKEYS'; | ||
import usePreferredCurrency from './usePreferredCurrency'; | ||
import useSubscriptionPlan from './useSubscriptionPlan'; | ||
|
||
const SUBSCRIPTION_PRICES = { | ||
[CONST.PAYMENT_CARD_CURRENCY.USD]: { | ||
[CONST.POLICY.TYPE.CORPORATE]: { | ||
[CONST.SUBSCRIPTION.TYPE.ANNUAL]: 900, | ||
[CONST.SUBSCRIPTION.TYPE.PAYPERUSE]: 1800, | ||
}, | ||
[CONST.POLICY.TYPE.TEAM]: { | ||
[CONST.SUBSCRIPTION.TYPE.ANNUAL]: 500, | ||
[CONST.SUBSCRIPTION.TYPE.PAYPERUSE]: 1000, | ||
}, | ||
}, | ||
[CONST.PAYMENT_CARD_CURRENCY.AUD]: { | ||
[CONST.POLICY.TYPE.CORPORATE]: { | ||
[CONST.SUBSCRIPTION.TYPE.ANNUAL]: 1500, | ||
[CONST.SUBSCRIPTION.TYPE.PAYPERUSE]: 3000, | ||
}, | ||
[CONST.POLICY.TYPE.TEAM]: { | ||
[CONST.SUBSCRIPTION.TYPE.ANNUAL]: 700, | ||
[CONST.SUBSCRIPTION.TYPE.PAYPERUSE]: 1400, | ||
}, | ||
}, | ||
[CONST.PAYMENT_CARD_CURRENCY.GBP]: { | ||
[CONST.POLICY.TYPE.CORPORATE]: { | ||
[CONST.SUBSCRIPTION.TYPE.ANNUAL]: 700, | ||
[CONST.SUBSCRIPTION.TYPE.PAYPERUSE]: 1400, | ||
}, | ||
[CONST.POLICY.TYPE.TEAM]: { | ||
[CONST.SUBSCRIPTION.TYPE.ANNUAL]: 400, | ||
[CONST.SUBSCRIPTION.TYPE.PAYPERUSE]: 800, | ||
}, | ||
}, | ||
[CONST.PAYMENT_CARD_CURRENCY.NZD]: { | ||
[CONST.POLICY.TYPE.CORPORATE]: { | ||
[CONST.SUBSCRIPTION.TYPE.ANNUAL]: 1600, | ||
[CONST.SUBSCRIPTION.TYPE.PAYPERUSE]: 3200, | ||
}, | ||
[CONST.POLICY.TYPE.TEAM]: { | ||
[CONST.SUBSCRIPTION.TYPE.ANNUAL]: 800, | ||
[CONST.SUBSCRIPTION.TYPE.PAYPERUSE]: 1600, | ||
}, | ||
}, | ||
} as const; | ||
|
||
function useSubscriptionPrice(): number { | ||
const preferredCurrency = usePreferredCurrency(); | ||
const subscriptionPlan = useSubscriptionPlan(); | ||
const [privateSubscription] = useOnyx(ONYXKEYS.NVP_PRIVATE_SUBSCRIPTION); | ||
|
||
if (!subscriptionPlan || !privateSubscription?.type) { | ||
return 0; | ||
} | ||
|
||
return SUBSCRIPTION_PRICES[preferredCurrency][subscriptionPlan][privateSubscription.type]; | ||
} | ||
|
||
export default useSubscriptionPrice; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters