-
Notifications
You must be signed in to change notification settings - Fork 3.9k
feat: Payment card subscription size screen UI #42683
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
Merged
amyevans
merged 11 commits into
Expensify:main
from
MrMuzyk:feat/payment-card-subscription-size-screen
Jun 3, 2024
Merged
Changes from all commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
aa73006
feat: Subscription size screen UI
MrMuzyk 9c5ad15
fix: adjust type
MrMuzyk 9ecf73c
fix: back button fix
MrMuzyk b4b8e46
fix: cr fixes
MrMuzyk 4dcce10
fix: typo
MrMuzyk 89d3c47
fix: spanish error translation
MrMuzyk 8838d6f
fix: nest translations one level deeper
MrMuzyk 7b5e8b8
fix: route typo
MrMuzyk c637d92
Merge branch 'main' of https://github.com/Expensify/App into feat/pay…
MrMuzyk 5b13859
fix: changed validation and renewal date
MrMuzyk 0b0fd42
fix: adjusted styles
MrMuzyk File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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
66 changes: 66 additions & 0 deletions
66
src/pages/settings/Subscription/SubscriptionSize/SubscriptionSizePage.tsx
This file contains hidden or 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,66 @@ | ||
| import React from 'react'; | ||
| import {useOnyx} from 'react-native-onyx'; | ||
| import HeaderWithBackButton from '@components/HeaderWithBackButton'; | ||
| import ScreenWrapper from '@components/ScreenWrapper'; | ||
| import useLocalize from '@hooks/useLocalize'; | ||
| import useSubStep from '@hooks/useSubStep'; | ||
| import type {SubStepProps} from '@hooks/useSubStep/types'; | ||
| import Navigation from '@libs/Navigation/Navigation'; | ||
| import ONYXKEYS from '@src/ONYXKEYS'; | ||
| import Confirmation from './substeps/Confirmation'; | ||
| import Size from './substeps/Size'; | ||
|
|
||
| const bodyContent: Array<React.ComponentType<SubStepProps>> = [Size, Confirmation]; | ||
|
|
||
| function SubscriptionSizePage() { | ||
| const [subscriptionSizeFormDraft] = useOnyx(ONYXKEYS.FORMS.SUBSCRIPTION_SIZE_FORM_DRAFT); | ||
| const {translate} = useLocalize(); | ||
| // TODO startFrom variable will get it's value based on ONYX data, it will be implemented in next phase (account?.canDowngrade field) | ||
| const CAN_DOWNGRADE = true; | ||
| const startFrom = CAN_DOWNGRADE ? 0 : 1; | ||
|
|
||
| const onFinished = () => { | ||
| if (CAN_DOWNGRADE) { | ||
| // TODO this is temporary solution for the time being, API call will be implemented in next phase | ||
| // eslint-disable-next-line no-console | ||
| console.log(subscriptionSizeFormDraft); | ||
| return; | ||
| } | ||
|
|
||
| Navigation.goBack(); | ||
| }; | ||
|
|
||
| const {componentToRender: SubStep, isEditing, screenIndex, nextScreen, prevScreen, moveTo} = useSubStep({bodyContent, startFrom, onFinished}); | ||
|
|
||
| const onBackButtonPress = () => { | ||
| if (screenIndex !== 0 && startFrom === 0) { | ||
| prevScreen(); | ||
| return; | ||
| } | ||
|
|
||
| Navigation.goBack(); | ||
| }; | ||
|
|
||
| return ( | ||
| <ScreenWrapper | ||
| testID={SubscriptionSizePage.displayName} | ||
| includeSafeAreaPaddingBottom={false} | ||
| shouldEnablePickerAvoiding={false} | ||
| shouldEnableMaxHeight | ||
| > | ||
| <HeaderWithBackButton | ||
| title={translate('subscription.subscriptionSize.title')} | ||
| onBackButtonPress={onBackButtonPress} | ||
| /> | ||
| <SubStep | ||
| isEditing={isEditing} | ||
| onNext={nextScreen} | ||
| onMove={moveTo} | ||
| /> | ||
| </ScreenWrapper> | ||
| ); | ||
| } | ||
|
|
||
| SubscriptionSizePage.displayName = 'SubscriptionSizePage'; | ||
|
|
||
| export default SubscriptionSizePage; |
73 changes: 73 additions & 0 deletions
73
src/pages/settings/Subscription/SubscriptionSize/substeps/Confirmation.tsx
This file contains hidden or 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,73 @@ | ||
| import React from 'react'; | ||
| import {View} from 'react-native'; | ||
| import {useOnyx} from 'react-native-onyx'; | ||
| import Button from '@components/Button'; | ||
| import FixedFooter from '@components/FixedFooter'; | ||
| import MenuItemWithTopDescription from '@components/MenuItemWithTopDescription'; | ||
| import Text from '@components/Text'; | ||
| import useLocalize from '@hooks/useLocalize'; | ||
| import useNetwork from '@hooks/useNetwork'; | ||
| import type {SubStepProps} from '@hooks/useSubStep/types'; | ||
| import useThemeStyles from '@hooks/useThemeStyles'; | ||
| import {getNewSubscriptionRenewalDate} from '@pages/settings/Subscription/SubscriptionSize/utils'; | ||
| import ONYXKEYS from '@src/ONYXKEYS'; | ||
| import INPUT_IDS from '@src/types/form/SubscriptionSizeForm'; | ||
|
|
||
| type ConfirmationProps = SubStepProps; | ||
|
|
||
| function Confirmation({onNext}: ConfirmationProps) { | ||
| const {translate} = useLocalize(); | ||
| const styles = useThemeStyles(); | ||
| const {isOffline} = useNetwork(); | ||
| const [subscriptionSizeFormDraft] = useOnyx(ONYXKEYS.FORMS.SUBSCRIPTION_SIZE_FORM_DRAFT); | ||
| const subscriptionRenewalDate = getNewSubscriptionRenewalDate(); | ||
|
|
||
| // TODO this is temporary and will be replaced in next phase once data in ONYX is ready | ||
| // we will have to check if the amount of active members is less than the current amount of active members and if account?.canDowngrade is true - if so then we can't downgrade | ||
| const CAN_DOWNGRADE = true; | ||
| // TODO this is temporary and will be replaced in next phase once data in ONYX is ready | ||
| const SUBSCRIPTION_UNTIL = subscriptionRenewalDate; | ||
|
|
||
| return ( | ||
| <View style={[styles.flexGrow1]}> | ||
| {CAN_DOWNGRADE ? ( | ||
| <> | ||
| <Text style={[styles.ph5, styles.pb3]}>{translate('subscription.subscriptionSize.confirmDetails')}</Text> | ||
| <MenuItemWithTopDescription | ||
| interactive={false} | ||
| description={translate('subscription.subscriptionSize.subscriptionSize')} | ||
| title={translate('subscription.subscriptionSize.activeMembers', {size: subscriptionSizeFormDraft ? subscriptionSizeFormDraft[INPUT_IDS.SUBSCRIPTION_SIZE] : 0})} | ||
| /> | ||
| <MenuItemWithTopDescription | ||
| interactive={false} | ||
| description={translate('subscription.subscriptionSize.subscriptionRenews')} | ||
| title={subscriptionRenewalDate} | ||
| /> | ||
| </> | ||
| ) : ( | ||
| <> | ||
| <Text style={[styles.ph5, styles.pb5, styles.textNormalThemeText]}>{translate('subscription.subscriptionSize.youCantDowngrade')}</Text> | ||
| <Text style={[styles.ph5, styles.textNormalThemeText]}> | ||
| {translate('subscription.subscriptionSize.youAlreadyCommitted', { | ||
| size: subscriptionSizeFormDraft ? subscriptionSizeFormDraft[INPUT_IDS.SUBSCRIPTION_SIZE] : 0, | ||
| date: SUBSCRIPTION_UNTIL, | ||
| })} | ||
| </Text> | ||
| </> | ||
| )} | ||
| <FixedFooter style={[styles.mtAuto]}> | ||
| <Button | ||
| isDisabled={isOffline} | ||
| success | ||
| large | ||
| onPress={onNext} | ||
| text={translate(CAN_DOWNGRADE ? 'common.save' : 'common.close')} | ||
| /> | ||
| </FixedFooter> | ||
| </View> | ||
| ); | ||
| } | ||
|
|
||
| Confirmation.displayName = 'ConfirmationStep'; | ||
|
|
||
| export default Confirmation; |
54 changes: 54 additions & 0 deletions
54
src/pages/settings/Subscription/SubscriptionSize/substeps/Size.tsx
This file contains hidden or 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,54 @@ | ||
| import React from 'react'; | ||
| import {View} from 'react-native'; | ||
| import FormProvider from '@components/Form/FormProvider'; | ||
| import InputWrapper from '@components/Form/InputWrapper'; | ||
| import Text from '@components/Text'; | ||
| import TextInput from '@components/TextInput'; | ||
| import useLocalize from '@hooks/useLocalize'; | ||
| import type {SubStepProps} from '@hooks/useSubStep/types'; | ||
| import useThemeStyles from '@hooks/useThemeStyles'; | ||
| import {validate} from '@pages/settings/Subscription/SubscriptionSize/utils'; | ||
| import CONST from '@src/CONST'; | ||
| import ONYXKEYS from '@src/ONYXKEYS'; | ||
| import INPUT_IDS from '@src/types/form/SubscriptionSizeForm'; | ||
|
|
||
| type SizeProps = SubStepProps; | ||
|
|
||
| function Size({onNext}: SizeProps) { | ||
| const {translate} = useLocalize(); | ||
| const styles = useThemeStyles(); | ||
|
|
||
| const defaultValues = { | ||
| // TODO this is temporary and default value will be replaced in next phase once data in ONYX is ready | ||
| [INPUT_IDS.SUBSCRIPTION_SIZE]: '0', | ||
| }; | ||
|
|
||
| return ( | ||
| <FormProvider | ||
| formID={ONYXKEYS.FORMS.SUBSCRIPTION_SIZE_FORM} | ||
| submitButtonText={translate('common.next')} | ||
| onSubmit={onNext} | ||
| validate={validate} | ||
| style={[styles.mh5, styles.flexGrow1]} | ||
| > | ||
| <View> | ||
| <Text style={[styles.textNormalThemeText, styles.mb5]}>{translate('subscription.subscriptionSize.yourSize')}</Text> | ||
| <InputWrapper | ||
| InputComponent={TextInput} | ||
| inputID={INPUT_IDS.SUBSCRIPTION_SIZE} | ||
| label={translate('subscription.subscriptionSize.subscriptionSize')} | ||
| aria-label={translate('subscription.subscriptionSize.subscriptionSize')} | ||
| role={CONST.ROLE.PRESENTATION} | ||
| defaultValue={defaultValues[INPUT_IDS.SUBSCRIPTION_SIZE]} | ||
| shouldSaveDraft | ||
| /> | ||
| <Text style={[styles.formHelp, styles.mt2]}>{translate('subscription.subscriptionSize.eachMonth')}</Text> | ||
| <Text style={[styles.formHelp, styles.mt2]}>{translate('subscription.subscriptionSize.note')}</Text> | ||
| </View> | ||
| </FormProvider> | ||
| ); | ||
| } | ||
|
|
||
| Size.displayName = 'SizeStep'; | ||
|
|
||
| export default Size; | ||
This file contains hidden or 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,19 @@ | ||
| import {addMonths, format, startOfMonth} from 'date-fns'; | ||
| import type {FormInputErrors, FormOnyxValues} from '@components/Form/types'; | ||
| import * as ValidationUtils from '@libs/ValidationUtils'; | ||
| import CONST from '@src/CONST'; | ||
| import type ONYXKEYS from '@src/ONYXKEYS'; | ||
| import INPUT_IDS from '@src/types/form/SubscriptionSizeForm'; | ||
|
|
||
| const validate = (values: FormOnyxValues<typeof ONYXKEYS.FORMS.SUBSCRIPTION_SIZE_FORM>): FormInputErrors<typeof ONYXKEYS.FORMS.SUBSCRIPTION_SIZE_FORM> => { | ||
| const errors = ValidationUtils.getFieldRequiredErrors(values, [INPUT_IDS.SUBSCRIPTION_SIZE]); | ||
| if (values[INPUT_IDS.SUBSCRIPTION_SIZE] && !ValidationUtils.isValidSubscriptionSize(values[INPUT_IDS.SUBSCRIPTION_SIZE])) { | ||
| errors.subscriptionSize = 'subscription.subscriptionSize.error.size'; | ||
| } | ||
|
|
||
| return errors; | ||
| }; | ||
|
|
||
| const getNewSubscriptionRenewalDate = (): string => format(startOfMonth(addMonths(new Date(), 12)), CONST.DATE.MONTH_DAY_YEAR_ABBR_FORMAT); | ||
|
|
||
| export {validate, getNewSubscriptionRenewalDate}; |
This file contains hidden or 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,13 @@ | ||
| import type {ValueOf} from 'type-fest'; | ||
| import type Form from './Form'; | ||
|
|
||
| const INPUT_IDS = { | ||
| SUBSCRIPTION_SIZE: 'subscriptionSize', | ||
| } as const; | ||
|
|
||
| type InputID = ValueOf<typeof INPUT_IDS>; | ||
|
|
||
| type SubscriptionSizeForm = Form<InputID, {[INPUT_IDS.SUBSCRIPTION_SIZE]: string}>; | ||
|
|
||
| export type {SubscriptionSizeForm}; | ||
| export default INPUT_IDS; |
This file contains hidden or 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
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
coming from #69011, for better UX, we add
inputMode={CONST.INPUT_MODE.NUMERIC}to this input to open the correct keyboard type.