-
Notifications
You must be signed in to change notification settings - Fork 3.6k
Refactor subscription size page to use useSubPage hook #82340
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
base: main
Are you sure you want to change the base?
Changes from all commits
b5fe5dc
b941b0b
2699bc9
7eff636
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -3,48 +3,27 @@ import {View} from 'react-native'; | |
| import Button from '@components/Button'; | ||
| import FixedFooter from '@components/FixedFooter'; | ||
| import MenuItemWithTopDescription from '@components/MenuItemWithTopDescription'; | ||
| import SubscriptionPlanDowngradeBlocked from '@components/SubscriptionPlanDowngradeBlocked'; | ||
| import Text from '@components/Text'; | ||
| import useLocalize from '@hooks/useLocalize'; | ||
| import useOnyx from '@hooks/useOnyx'; | ||
| import usePrivateSubscription from '@hooks/usePrivateSubscription'; | ||
| import type {SubStepProps} from '@hooks/useSubStep/types'; | ||
| import useThemeStyles from '@hooks/useThemeStyles'; | ||
| import Navigation from '@navigation/Navigation'; | ||
| import {formatSubscriptionEndDate, getNewSubscriptionRenewalDate} from '@pages/settings/Subscription/utils'; | ||
| import {getNewSubscriptionRenewalDate} from '@pages/settings/Subscription/utils'; | ||
| import ONYXKEYS from '@src/ONYXKEYS'; | ||
| import INPUT_IDS from '@src/types/form/SubscriptionSizeForm'; | ||
|
|
||
| type ConfirmationProps = SubStepProps; | ||
|
|
||
| function Confirmation({onNext, isEditing}: ConfirmationProps) { | ||
| function Confirmation({onNext}: ConfirmationProps) { | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Removing Useful? React with 👍 / 👎. |
||
| const {translate} = useLocalize(); | ||
| const styles = useThemeStyles(); | ||
| const [account] = useOnyx(ONYXKEYS.ACCOUNT, {canBeMissing: false}); | ||
| const privateSubscription = usePrivateSubscription(); | ||
| const [subscriptionSizeFormDraft] = useOnyx(ONYXKEYS.FORMS.SUBSCRIPTION_SIZE_FORM_DRAFT, {canBeMissing: true}); | ||
| const subscriptionRenewalDate = getNewSubscriptionRenewalDate(); | ||
| const subscriptionSizeDraft = subscriptionSizeFormDraft ? Number(subscriptionSizeFormDraft[INPUT_IDS.SUBSCRIPTION_SIZE]) : 0; | ||
| const subscriptionSize = subscriptionSizeDraft || (privateSubscription?.userCount ?? 0); | ||
|
|
||
| const isTryingToIncreaseSubscriptionSize = subscriptionSizeDraft > (privateSubscription?.userCount ?? 0); | ||
| const canChangeSubscriptionSize = (account?.canDowngrade ?? false) || (isTryingToIncreaseSubscriptionSize && isEditing); | ||
| const formattedSubscriptionEndDate = formatSubscriptionEndDate(privateSubscription?.endDate); | ||
|
|
||
| const onClosePress = () => { | ||
| Navigation.goBack(); | ||
| }; | ||
|
|
||
| if (!canChangeSubscriptionSize) { | ||
| return ( | ||
| <SubscriptionPlanDowngradeBlocked | ||
| privateSubscription={privateSubscription} | ||
| formattedSubscriptionEndDate={formattedSubscriptionEndDate} | ||
| onClosePress={onClosePress} | ||
| /> | ||
| ); | ||
| } | ||
|
|
||
| return ( | ||
| <View style={[styles.flexGrow1]}> | ||
| <Text style={[styles.ph5, styles.pb3]}>{translate('subscription.subscriptionSize.confirmDetails')}</Text> | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The canChangeSize param is used to show the downgrade blocked view when trying to downgrade from an annual to a pay-per-use plan, so instead of conditionally rendering it based on the params that can be easily changed by the user, I navigate to the already existing downgrade blocked page.