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#46813 from rezkiy37/feature/45179-invoic…
…e-balance-section Invoicing balance section
- Loading branch information
Showing
6 changed files
with
73 additions
and
19 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
import React from 'react'; | ||
import type {StyleProp, TextStyle} from 'react-native'; | ||
import useThemeStyles from '@hooks/useThemeStyles'; | ||
import * as CurrencyUtils from '@libs/CurrencyUtils'; | ||
import Text from './Text'; | ||
|
||
type BalanceProps = { | ||
textStyles?: StyleProp<TextStyle>; | ||
balance: number; | ||
}; | ||
|
||
function Balance({textStyles, balance}: BalanceProps) { | ||
const styles = useThemeStyles(); | ||
const formattedBalance = CurrencyUtils.convertToDisplayString(balance); | ||
|
||
return <Text style={[styles.textHeadline, styles.textXXXLarge, textStyles]}>{formattedBalance}</Text>; | ||
} | ||
|
||
Balance.displayName = 'Balance'; | ||
|
||
export default Balance; |
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 |
---|---|---|
@@ -1,32 +1,26 @@ | ||
import React from 'react'; | ||
import type {StyleProp, TextStyle} from 'react-native'; | ||
import type {OnyxEntry} from 'react-native-onyx'; | ||
import {withOnyx} from 'react-native-onyx'; | ||
import {useOnyx} from 'react-native-onyx'; | ||
import useThemeStyles from '@hooks/useThemeStyles'; | ||
import * as CurrencyUtils from '@libs/CurrencyUtils'; | ||
import ONYXKEYS from '@src/ONYXKEYS'; | ||
import type UserWallet from '@src/types/onyx/UserWallet'; | ||
import Text from './Text'; | ||
import Balance from './Balance'; | ||
|
||
type CurrentWalletBalanceOnyxProps = { | ||
/** The user's wallet account */ | ||
userWallet: OnyxEntry<UserWallet>; | ||
}; | ||
|
||
type CurrentWalletBalanceProps = CurrentWalletBalanceOnyxProps & { | ||
type CurrentWalletBalanceProps = { | ||
balanceStyles?: StyleProp<TextStyle>; | ||
}; | ||
|
||
function CurrentWalletBalance({userWallet, balanceStyles}: CurrentWalletBalanceProps) { | ||
function CurrentWalletBalance({balanceStyles}: CurrentWalletBalanceProps) { | ||
const styles = useThemeStyles(); | ||
const formattedBalance = CurrencyUtils.convertToDisplayString(userWallet?.currentBalance ?? 0); | ||
return <Text style={[styles.pv5, styles.alignSelfCenter, styles.textHeadline, styles.textXXXLarge, balanceStyles]}>{formattedBalance}</Text>; | ||
const [userWallet] = useOnyx(ONYXKEYS.USER_WALLET); | ||
|
||
return ( | ||
<Balance | ||
textStyles={[styles.pv5, styles.alignSelfCenter, balanceStyles]} | ||
balance={userWallet?.currentBalance ?? 0} | ||
/> | ||
); | ||
} | ||
|
||
CurrentWalletBalance.displayName = 'CurrentWalletBalance'; | ||
|
||
export default withOnyx<CurrentWalletBalanceProps, CurrentWalletBalanceOnyxProps>({ | ||
userWallet: { | ||
key: ONYXKEYS.USER_WALLET, | ||
}, | ||
})(CurrentWalletBalance); | ||
export default CurrentWalletBalance; |
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
33 changes: 33 additions & 0 deletions
33
src/pages/workspace/invoices/WorkspaceInvoiceBalanceSection.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,33 @@ | ||
import React from 'react'; | ||
import {useOnyx} from 'react-native-onyx'; | ||
import Balance from '@components/Balance'; | ||
import Section from '@components/Section'; | ||
import useLocalize from '@hooks/useLocalize'; | ||
import useThemeStyles from '@hooks/useThemeStyles'; | ||
import ONYXKEYS from '@src/ONYXKEYS'; | ||
|
||
type WorkspaceInvoiceBalanceSectionProps = { | ||
/** The policy ID currently being configured */ | ||
policyID: string; | ||
}; | ||
|
||
function WorkspaceInvoiceBalanceSection({policyID}: WorkspaceInvoiceBalanceSectionProps) { | ||
const styles = useThemeStyles(); | ||
const {translate} = useLocalize(); | ||
const [policy] = useOnyx(`${ONYXKEYS.COLLECTION.POLICY}${policyID}`); | ||
|
||
return ( | ||
<Section | ||
title={translate('workspace.invoices.invoiceBalance')} | ||
subtitle={translate('workspace.invoices.invoiceBalanceSubtitle')} | ||
isCentralPane | ||
titleStyles={styles.textStrong} | ||
childrenStyles={styles.pt5} | ||
subtitleMuted | ||
> | ||
<Balance balance={policy?.invoice?.bankAccount?.stripeConnectAccountBalance ?? 0} /> | ||
</Section> | ||
); | ||
} | ||
|
||
export default WorkspaceInvoiceBalanceSection; |
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