-
Notifications
You must be signed in to change notification settings - Fork 3.7k
feat: implement card section for subscription #42787
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
Merged
Changes from all commits
Commits
Show all changes
17 commits
Select commit
Hold shift + click to select a range
183e74e
feat: implement card section for subscription
pasyukevich c1eda1b
fix comments
pasyukevich bbb16bc
update comments
pasyukevich 48c09d7
fix button width
pasyukevich a4ef5b4
Merge branch 'main' into feature/card-section
pasyukevich 2f10793
fix ui
pasyukevich 4b14b2d
Merge branch 'main' into feature/card-section
pasyukevich ca63fa4
fix button size
pasyukevich 39f5947
fix text, icon color
pasyukevich 477157a
rename function, fix ui
pasyukevich 1dd9cd8
Merge branch 'main' into feature/card-section
pasyukevich 1f54598
fix prettier
pasyukevich cf233c0
fix card offset
pasyukevich 23152b5
fix month format
pasyukevich 15109cd
fix comments
pasyukevich 138a897
fix billing card
pasyukevich ec88580
revert default card
pasyukevich 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
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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
67 changes: 67 additions & 0 deletions
67
src/pages/settings/Subscription/CardSection/CardSection.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,67 @@ | ||
| import React, {useMemo} 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 Section from '@components/Section'; | ||
| import Text from '@components/Text'; | ||
| import useLocalize from '@hooks/useLocalize'; | ||
| import useTheme from '@hooks/useTheme'; | ||
| import useThemeStyles from '@hooks/useThemeStyles'; | ||
| import DateUtils from '@libs/DateUtils'; | ||
| import ONYXKEYS from '@src/ONYXKEYS'; | ||
| import {isEmptyObject} from '@src/types/utils/EmptyObject'; | ||
| import CardSectionActions from './CardSectionActions'; | ||
| import CardSectionDataEmpty from './CardSectionDataEmpty'; | ||
|
|
||
| function CardSection() { | ||
| const {translate, preferredLocale} = useLocalize(); | ||
| const styles = useThemeStyles(); | ||
| const theme = useTheme(); | ||
| const [fundList] = useOnyx(ONYXKEYS.FUND_LIST); | ||
|
|
||
| const defaultCard = useMemo(() => Object.values(fundList ?? {}).find((card) => card.isDefault), [fundList]); | ||
|
|
||
| const cardMonth = useMemo(() => DateUtils.getMonthNames(preferredLocale)[(defaultCard?.accountData?.cardMonth ?? 1) - 1], [defaultCard?.accountData?.cardMonth, preferredLocale]); | ||
|
|
||
| return ( | ||
| <Section | ||
| title={translate('subscription.cardSection.title')} | ||
| subtitle={translate('subscription.cardSection.subtitle')} | ||
| isCentralPane | ||
| titleStyles={styles.textStrong} | ||
| subtitleMuted | ||
| > | ||
| <View style={[styles.mt8, styles.mb3, styles.flexRow]}> | ||
| {!isEmptyObject(defaultCard?.accountData) && ( | ||
| <> | ||
| <View style={[styles.flexRow, styles.flex1, styles.gap3]}> | ||
| <Icon | ||
| src={Expensicons.CreditCard} | ||
| additionalStyles={styles.subscriptionAddedCardIcon} | ||
| fill={theme.text} | ||
| medium | ||
| /> | ||
| <View style={styles.flex1}> | ||
| <Text style={styles.textStrong}>{translate('subscription.cardSection.cardEnding', {cardNumber: defaultCard?.accountData?.cardNumber})}</Text> | ||
| <Text style={styles.mutedNormalTextLabel}> | ||
| {translate('subscription.cardSection.cardInfo', { | ||
| name: defaultCard?.accountData?.addressName, | ||
| expiration: `${cardMonth} ${defaultCard?.accountData?.cardYear}`, | ||
| currency: defaultCard?.accountData?.currency, | ||
| })} | ||
| </Text> | ||
| </View> | ||
| </View> | ||
| <CardSectionActions /> | ||
| </> | ||
| )} | ||
| {isEmptyObject(defaultCard?.accountData) && <CardSectionDataEmpty />} | ||
| </View> | ||
| </Section> | ||
| ); | ||
| } | ||
|
|
||
| CardSection.displayName = 'CardSection'; | ||
|
|
||
| export default CardSection; | ||
7 changes: 7 additions & 0 deletions
7
src/pages/settings/Subscription/CardSection/CardSectionActions/index.native.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,7 @@ | ||
| function CardSectionActions() { | ||
pasyukevich marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| return null; // We need to disable actions on mobile | ||
| } | ||
|
|
||
| CardSectionActions.displayName = 'CardSectionActions'; | ||
|
|
||
| export default CardSectionActions; | ||
pasyukevich marked this conversation as resolved.
Show resolved
Hide resolved
|
||
65 changes: 65 additions & 0 deletions
65
src/pages/settings/Subscription/CardSection/CardSectionActions/index.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,65 @@ | ||
| import React, {useCallback, useMemo, useRef, useState} from 'react'; | ||
| import {View} from 'react-native'; | ||
| import * as Expensicons from '@components/Icon/Expensicons'; | ||
| import ThreeDotsMenu from '@components/ThreeDotsMenu'; | ||
| import type ThreeDotsMenuProps from '@components/ThreeDotsMenu/types'; | ||
| import useLocalize from '@hooks/useLocalize'; | ||
| import useWindowDimensions from '@hooks/useWindowDimensions'; | ||
| import type {AnchorPosition} from '@styles/index'; | ||
| import CONST from '@src/CONST'; | ||
|
|
||
| const anchorAlignment = { | ||
| horizontal: CONST.MODAL.ANCHOR_ORIGIN_HORIZONTAL.RIGHT, | ||
| vertical: CONST.MODAL.ANCHOR_ORIGIN_VERTICAL.TOP, | ||
| }; | ||
|
|
||
| function CardSectionActions() { | ||
| const {isSmallScreenWidth} = useWindowDimensions(); | ||
| const {translate} = useLocalize(); | ||
| const [threeDotsMenuPosition, setThreeDotsMenuPosition] = useState<AnchorPosition>({horizontal: 0, vertical: 0}); | ||
| const threeDotsMenuContainerRef = useRef<View>(null); | ||
|
|
||
| const overflowMenu: ThreeDotsMenuProps['menuItems'] = useMemo( | ||
| () => [ | ||
| { | ||
| icon: Expensicons.CreditCard, | ||
| text: translate('subscription.cardSection.changeCard'), | ||
| onSelected: () => {}, // TODO: update with navigation to "add card" screen (https://github.com/Expensify/App/issues/38621) | ||
| }, | ||
| { | ||
| icon: Expensicons.MoneyCircle, | ||
| text: translate('subscription.cardSection.changeCurrency'), | ||
| onSelected: () => {}, // TODO: update with navigation to "change currency" screen (https://github.com/Expensify/App/issues/38621) | ||
| }, | ||
| ], | ||
| [translate], | ||
| ); | ||
|
|
||
| const calculateAndSetThreeDotsMenuPosition = useCallback(() => { | ||
| if (isSmallScreenWidth) { | ||
| return; | ||
| } | ||
| threeDotsMenuContainerRef.current?.measureInWindow((x, y, width, height) => { | ||
| setThreeDotsMenuPosition({ | ||
| horizontal: x + width, | ||
| vertical: y + height, | ||
| }); | ||
| }); | ||
| }, [isSmallScreenWidth]); | ||
|
|
||
| return ( | ||
| <View ref={threeDotsMenuContainerRef}> | ||
| <ThreeDotsMenu | ||
| onIconPress={calculateAndSetThreeDotsMenuPosition} | ||
| menuItems={overflowMenu} | ||
| anchorPosition={threeDotsMenuPosition} | ||
| anchorAlignment={anchorAlignment} | ||
| shouldOverlay | ||
| /> | ||
| </View> | ||
| ); | ||
| } | ||
|
|
||
| CardSectionActions.displayName = 'CardSectionActions'; | ||
|
|
||
| export default CardSectionActions; | ||
pasyukevich marked this conversation as resolved.
Show resolved
Hide resolved
|
||
30 changes: 30 additions & 0 deletions
30
src/pages/settings/Subscription/CardSection/CardSectionDataEmpty/index.native.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,30 @@ | ||
| import React from 'react'; | ||
| import {View} from 'react-native'; | ||
| import Icon from '@components/Icon'; | ||
| import * as Expensicons from '@components/Icon/Expensicons'; | ||
| import Text from '@components/Text'; | ||
| import useLocalize from '@hooks/useLocalize'; | ||
| import useTheme from '@hooks/useTheme'; | ||
| import useThemeStyles from '@hooks/useThemeStyles'; | ||
|
|
||
| function CardSectionDataEmpty() { | ||
| const {translate} = useLocalize(); | ||
| const styles = useThemeStyles(); | ||
| const theme = useTheme(); | ||
|
|
||
| return ( | ||
| <View style={[styles.flexRow, styles.alignItemsCenter, styles.gap3]}> | ||
| <Icon | ||
| src={Expensicons.CreditCardExclamation} | ||
| additionalStyles={styles.subscriptionCardIcon} | ||
| fill={theme.icon} | ||
| medium | ||
| /> | ||
| <Text style={[styles.mutedNormalTextLabel, styles.textStrong]}>{translate('subscription.cardSection.cardNotFound')}</Text> | ||
| </View> | ||
| ); | ||
| } | ||
|
|
||
| CardSectionDataEmpty.displayName = 'CardSectionDataEmpty'; | ||
|
|
||
| export default CardSectionDataEmpty; | ||
pasyukevich marked this conversation as resolved.
Show resolved
Hide resolved
|
||
23 changes: 23 additions & 0 deletions
23
src/pages/settings/Subscription/CardSection/CardSectionDataEmpty/index.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,23 @@ | ||
| import React from 'react'; | ||
| import Button from '@components/Button'; | ||
| import useLocalize from '@hooks/useLocalize'; | ||
| import useThemeStyles from '@hooks/useThemeStyles'; | ||
|
|
||
| function CardSectionDataEmpty() { | ||
| const {translate} = useLocalize(); | ||
| const styles = useThemeStyles(); | ||
|
|
||
| return ( | ||
| <Button | ||
| text={translate('subscription.cardSection.addCardButton')} | ||
| onPress={() => {}} // TODO: update with navigation to "add card" screen (https://github.com/Expensify/App/issues/38621) | ||
| style={styles.w100} | ||
| success | ||
| large | ||
| /> | ||
| ); | ||
| } | ||
|
|
||
| CardSectionDataEmpty.displayName = 'CardSectionDataEmpty'; | ||
|
|
||
| export default CardSectionDataEmpty; | ||
pasyukevich marked this conversation as resolved.
Show resolved
Hide resolved
|
||
14 changes: 14 additions & 0 deletions
14
src/pages/settings/Subscription/ReducedFunctionalityMessage/index.native.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,14 @@ | ||
| import Text from '@components/Text'; | ||
| import useLocalize from '@hooks/useLocalize'; | ||
| import useThemeStyles from '@hooks/useThemeStyles'; | ||
|
|
||
| function ReducedFunctionalityMessage() { | ||
| const styles = useThemeStyles(); | ||
| const {translate} = useLocalize(); | ||
|
|
||
| return <Text style={[styles.ph5, styles.pb5, styles.textSupporting]}>{translate('subscription.mobileReducedFunctionalityMessage')}</Text>; | ||
| } | ||
|
|
||
| ReducedFunctionalityMessage.displayName = 'ReducedFunctionalityMessage'; | ||
|
|
||
| export default ReducedFunctionalityMessage; | ||
pasyukevich marked this conversation as resolved.
Show resolved
Hide resolved
|
||
7 changes: 7 additions & 0 deletions
7
src/pages/settings/Subscription/ReducedFunctionalityMessage/index.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,7 @@ | ||
| function ReducedFunctionalityMessage() { | ||
pasyukevich marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| return null; // We do not need to show this message on web and desktop | ||
| } | ||
|
|
||
| ReducedFunctionalityMessage.displayName = 'ReducedFunctionalityMessage'; | ||
|
|
||
| export default ReducedFunctionalityMessage; | ||
pasyukevich marked this conversation as resolved.
Show resolved
Hide resolved
|
||
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
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.
Uh oh!
There was an error while loading. Please reload this page.