-
Notifications
You must be signed in to change notification settings - Fork 4k
[Internal QA] Expensify Card feed selector #59887
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
Changes from all commits
7517dbc
5b36e01
b7217c8
4ea87c4
1b065bc
5f5771f
adc5267
7aeac08
c2533e5
d9eedab
ef99915
c374673
c95ff9c
bce3979
90a8a4b
58e7543
61a4859
6cd3129
b92f9cc
980bc83
aca943d
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 |
|---|---|---|
| @@ -0,0 +1,67 @@ | ||
| import React from 'react'; | ||
| import {View} from 'react-native'; | ||
| import useTheme from '@hooks/useTheme'; | ||
| import useThemeStyles from '@hooks/useThemeStyles'; | ||
| import variables from '@styles/variables'; | ||
| import type IconAsset from '@src/types/utils/IconAsset'; | ||
| import CaretWrapper from './CaretWrapper'; | ||
| import Icon from './Icon'; | ||
| import * as Expensicons from './Icon/Expensicons'; | ||
| import {PressableWithFeedback} from './Pressable'; | ||
| import Text from './Text'; | ||
|
|
||
| type Props = { | ||
| /** Function to call when the feed is selected */ | ||
| onFeedSelect: () => void; | ||
|
|
||
| /** Icon for the card */ | ||
| cardIcon: IconAsset; | ||
|
|
||
| /** Whether to show assign card button */ | ||
| shouldChangeLayout?: boolean; | ||
|
|
||
| /** Feed name */ | ||
| feedName?: string; | ||
|
|
||
| /** Supporting text */ | ||
| supportingText?: string; | ||
|
|
||
| /** Whether the RBR indicator should be shown */ | ||
| shouldShowRBR?: boolean; | ||
| }; | ||
|
|
||
| function FeedSelector({onFeedSelect, cardIcon, shouldChangeLayout, feedName, supportingText, shouldShowRBR = false}: Props) { | ||
| const styles = useThemeStyles(); | ||
| const theme = useTheme(); | ||
|
|
||
| return ( | ||
| <PressableWithFeedback | ||
| onPress={onFeedSelect} | ||
| style={[styles.flexRow, styles.alignItemsCenter, styles.gap3, shouldChangeLayout && styles.mb3]} | ||
| accessibilityLabel={feedName ?? ''} | ||
| > | ||
| <Icon | ||
| src={cardIcon} | ||
| height={variables.cardIconHeight} | ||
| width={variables.cardIconWidth} | ||
| additionalStyles={styles.cardIcon} | ||
| /> | ||
| <View style={styles.flex1}> | ||
| <View style={[styles.flexRow, styles.gap1]}> | ||
| <CaretWrapper style={styles.flex1}> | ||
| <Text style={[styles.textStrong, styles.flexShrink1]}>{feedName}</Text> | ||
| </CaretWrapper> | ||
| {shouldShowRBR && ( | ||
| <Icon | ||
| src={Expensicons.DotIndicator} | ||
| fill={theme.danger} | ||
| /> | ||
| )} | ||
| </View> | ||
| <Text style={styles.textLabelSupporting}>{supportingText}</Text> | ||
| </View> | ||
| </PressableWithFeedback> | ||
| ); | ||
| } | ||
|
|
||
| export default FeedSelector; | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,37 @@ | ||
| import {useOnyx} from 'react-native-onyx'; | ||
| import {getFundIdFromSettingsKey} from '@libs/CardUtils'; | ||
| import CONST from '@src/CONST'; | ||
| import ONYXKEYS from '@src/ONYXKEYS'; | ||
| import useWorkspaceAccountID from './useWorkspaceAccountID'; | ||
|
|
||
| /** | ||
| * Hook to get the default fundID for a given policyID. This is used to get the settings and cards for each of the feeds. | ||
| * It will always return lastSelectedExpensifyCardFeed if it exists or fallback to the workspaceAccountID or domainFundID. | ||
| */ | ||
| function useDefaultFundID(policyID: string | undefined) { | ||
|
puneetlath marked this conversation as resolved.
|
||
| const workspaceAccountID = useWorkspaceAccountID(policyID); | ||
| const [lastSelectedExpensifyCardFeed] = useOnyx(`${ONYXKEYS.COLLECTION.LAST_SELECTED_EXPENSIFY_CARD_FEED}${policyID}`); | ||
|
|
||
| const [domainFundID] = useOnyx(ONYXKEYS.COLLECTION.PRIVATE_EXPENSIFY_CARD_SETTINGS, { | ||
| selector: (cardSettings) => { | ||
| const matchingKey = Object.entries(cardSettings ?? {}).find( | ||
| // eslint-disable-next-line @typescript-eslint/no-unused-vars | ||
| ([key, settings]) => settings?.preferredPolicy && settings.preferredPolicy === policyID && !key.includes(workspaceAccountID.toString()), | ||
| ); | ||
|
|
||
| return getFundIdFromSettingsKey(matchingKey?.[0] ?? ''); | ||
| }, | ||
| }); | ||
|
|
||
| if (lastSelectedExpensifyCardFeed) { | ||
|
Contributor
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. I think we should also consider |
||
| return lastSelectedExpensifyCardFeed; | ||
| } | ||
|
|
||
| if (workspaceAccountID) { | ||
| return workspaceAccountID; | ||
| } | ||
|
|
||
| return domainFundID ?? CONST.DEFAULT_NUMBER_ID; | ||
| } | ||
|
|
||
| export default useDefaultFundID; | ||
This file was deleted.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,19 @@ | ||
| import {useOnyx} from 'react-native-onyx'; | ||
| import ONYXKEYS from '@src/ONYXKEYS'; | ||
|
|
||
| function useExpensifyCardFeeds(policyID: string | undefined) { | ||
| const [allExpensifyCardFeeds] = useOnyx(ONYXKEYS.COLLECTION.PRIVATE_EXPENSIFY_CARD_SETTINGS, { | ||
| selector: (cardSettings) => { | ||
| const matchingEntries = Object.entries(cardSettings ?? {}).filter( | ||
| // eslint-disable-next-line @typescript-eslint/no-unused-vars | ||
| ([_, settings]) => settings?.preferredPolicy && settings.preferredPolicy === policyID, | ||
| ); | ||
|
|
||
| return Object.fromEntries(matchingEntries); | ||
| }, | ||
| }); | ||
|
|
||
| return allExpensifyCardFeeds; | ||
| } | ||
|
|
||
| export default useExpensifyCardFeeds; |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -334,11 +334,10 @@ function updateSettlementFrequency(workspaceAccountID: number, settlementFrequen | |
| API.write(WRITE_COMMANDS.UPDATE_CARD_SETTLEMENT_FREQUENCY, parameters, {optimisticData, successData, failureData}); | ||
| } | ||
|
|
||
| function updateSettlementAccount(workspaceAccountID: number, policyID: string, settlementBankAccountID?: number, currentSettlementBankAccountID?: number) { | ||
| function updateSettlementAccount(domainName: string, workspaceAccountID: number, policyID: string, settlementBankAccountID?: number, currentSettlementBankAccountID?: number) { | ||
|
Contributor
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. Why do we need to change this function?
Contributor
Author
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. |
||
| if (!settlementBankAccountID) { | ||
| return; | ||
| } | ||
| const domainName = PolicyUtils.getDomainNameForPolicy(policyID); | ||
|
|
||
| const optimisticData: OnyxUpdate[] = [ | ||
| { | ||
|
|
@@ -390,7 +389,12 @@ function getCardDefaultName(userName?: string) { | |
| } | ||
|
|
||
| function setIssueNewCardStepAndData({data, isEditing, step, policyID}: IssueNewCardFlowData) { | ||
| Onyx.merge(`${ONYXKEYS.COLLECTION.ISSUE_NEW_EXPENSIFY_CARD}${policyID}`, {data, isEditing, currentStep: step, errors: null}); | ||
| Onyx.merge(`${ONYXKEYS.COLLECTION.ISSUE_NEW_EXPENSIFY_CARD}${policyID}`, { | ||
| data, | ||
| isEditing, | ||
| currentStep: step, | ||
| errors: null, | ||
| }); | ||
| } | ||
|
|
||
| function clearIssueNewCardFlow(policyID: string | undefined) { | ||
|
|
@@ -918,6 +922,20 @@ function updateSelectedFeed(feed: CompanyCardFeed, policyID: string | undefined) | |
| ]); | ||
| } | ||
|
|
||
| function updateSelectedExpensifyCardFeed(feed: number, policyID: string | undefined) { | ||
| if (!policyID) { | ||
| return; | ||
| } | ||
|
|
||
| Onyx.update([ | ||
| { | ||
| onyxMethod: Onyx.METHOD.MERGE, | ||
| key: `${ONYXKEYS.COLLECTION.LAST_SELECTED_EXPENSIFY_CARD_FEED}${policyID}`, | ||
| value: feed, | ||
| }, | ||
| ]); | ||
| } | ||
|
|
||
| function queueExpensifyCardForBilling(feedCountry: string, domainAccountID: number) { | ||
| const parameters = { | ||
| feedCountry, | ||
|
|
@@ -948,6 +966,7 @@ export { | |
| toggleContinuousReconciliation, | ||
| updateExpensifyCardLimitType, | ||
| updateSelectedFeed, | ||
| updateSelectedExpensifyCardFeed, | ||
| deactivateCard, | ||
| getCardDefaultName, | ||
| queueExpensifyCardForBilling, | ||
|
|
||

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.
Came from this issue
We had an issue where the Card feed name is displayed partially with a blank space on Android 16
More context here