-
Notifications
You must be signed in to change notification settings - Fork 3k
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 #42683 from MrMuzyk/feat/payment-card-subscription…
…-size-screen feat: Payment card subscription size screen UI
- Loading branch information
Showing
16 changed files
with
285 additions
and
1 deletion.
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
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
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
66 changes: 66 additions & 0 deletions
66
src/pages/settings/Subscription/SubscriptionSize/SubscriptionSizePage.tsx
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,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 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 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 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 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 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