-
Notifications
You must be signed in to change notification settings - Fork 3.1k
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
Add CurrencySelectionList component and use it in IOU and WS currency settings #30889
Merged
Merged
Changes from 14 commits
Commits
Show all changes
17 commits
Select commit
Hold shift + click to select a range
84eab1a
Add CurrencySelectionList component and use it in IOU and WS currency…
tsa321 6264025
Merge main and resolve conflict
tsa321 87c644c
Add currency url parameter for WorkspaceSettingsCurrencyPage
tsa321 1e508c1
Don't automatically save ws default currency when selecting currency …
tsa321 760a3d0
Merge main and resolve conflict
tsa321 81dc4ec
Fix adding currency parameter to worksapace_settings get route calls
tsa321 6c4c5b0
Change display text format of currency selection list
tsa321 bb7982c
Merge main and resolve conflict
tsa321 c0d111d
Merge branch 'main' into curr-slist
tsa321 4bbe617
Merge main and resolve conflict
tsa321 3cc506d
revert ROUTES
tsa321 6f1b234
merge main and resolve IOURequestStepCurrency
tsa321 15554f2
Change display text format of currency selection list and pretify a file
tsa321 47ca679
Merge branch 'main' into curr-slist
tsa321 3b80099
Merge main and resolve conflict
tsa321 dd2b879
Modify textInputLabel property name into searchInputLabel
tsa321 4a9648c
Merge main and resolve conflict
tsa321 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 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,64 @@ | ||
import Str from 'expensify-common/lib/str'; | ||
import React, {useMemo, useState} from 'react'; | ||
import {withOnyx} from 'react-native-onyx'; | ||
import SelectionList from '@components/SelectionList'; | ||
import RadioListItem from '@components/SelectionList/RadioListItem'; | ||
import useLocalize from '@hooks/useLocalize'; | ||
import * as CurrencyUtils from '@libs/CurrencyUtils'; | ||
import ONYXKEYS from '@src/ONYXKEYS'; | ||
import type {CurrencyListItem, CurrencySelectionListOnyxProps, CurrencySelectionListProps} from './types'; | ||
|
||
function CurrencySelectionList({textInputLabel, initiallySelectedCurrencyCode, onSelect, currencyList}: CurrencySelectionListProps) { | ||
const [searchValue, setSearchValue] = useState(''); | ||
const {translate} = useLocalize(); | ||
|
||
const {sections, headerMessage} = useMemo(() => { | ||
const currencyOptions: CurrencyListItem[] = Object.entries(currencyList ?? {}).map(([currencyCode, currencyInfo]) => { | ||
const isSelectedCurrency = currencyCode === initiallySelectedCurrencyCode; | ||
return { | ||
currencyName: currencyInfo?.name ?? '', | ||
text: `${currencyCode} - ${CurrencyUtils.getCurrencySymbol(currencyCode)}`, | ||
currencyCode, | ||
keyForList: currencyCode, | ||
isSelected: isSelectedCurrency, | ||
}; | ||
}); | ||
|
||
const searchRegex = new RegExp(Str.escapeForRegExp(searchValue.trim()), 'i'); | ||
const filteredCurrencies = currencyOptions.filter((currencyOption) => searchRegex.test(currencyOption.text ?? '') || searchRegex.test(currencyOption.currencyName)); | ||
const isEmpty = searchValue.trim() && !filteredCurrencies.length; | ||
|
||
return { | ||
sections: isEmpty | ||
? [] | ||
: [ | ||
{ | ||
data: filteredCurrencies, | ||
}, | ||
], | ||
headerMessage: isEmpty ? translate('common.noResultsFound') : '', | ||
}; | ||
}, [currencyList, searchValue, translate, initiallySelectedCurrencyCode]); | ||
|
||
return ( | ||
<SelectionList | ||
sections={sections} | ||
ListItem={RadioListItem} | ||
textInputLabel={textInputLabel} | ||
textInputValue={searchValue} | ||
onChangeText={setSearchValue} | ||
onSelectRow={onSelect} | ||
headerMessage={headerMessage} | ||
initiallyFocusedOptionKey={initiallySelectedCurrencyCode} | ||
showScrollIndicator | ||
/> | ||
); | ||
} | ||
|
||
CurrencySelectionList.displayName = 'CurrencySelectionList'; | ||
|
||
const CurrencySelectionListWithOnyx = withOnyx<CurrencySelectionListProps, CurrencySelectionListOnyxProps>({ | ||
currencyList: {key: ONYXKEYS.CURRENCY_LIST}, | ||
})(CurrencySelectionList); | ||
|
||
export default CurrencySelectionListWithOnyx; |
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,26 @@ | ||||||
import type {OnyxEntry} from 'react-native-onyx'; | ||||||
import type {ListItem} from '@components/SelectionList/types'; | ||||||
import type {CurrencyList} from '@src/types/onyx'; | ||||||
|
||||||
type CurrencyListItem = ListItem & { | ||||||
currencyName: string; | ||||||
currencyCode: string; | ||||||
}; | ||||||
|
||||||
type CurrencySelectionListOnyxProps = { | ||||||
/** Constant, list of available currencies */ | ||||||
currencyList: OnyxEntry<CurrencyList>; | ||||||
}; | ||||||
|
||||||
type CurrencySelectionListProps = CurrencySelectionListOnyxProps & { | ||||||
/** Label for the search text input */ | ||||||
textInputLabel: string; | ||||||
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. NAB
Suggested change
|
||||||
|
||||||
/** Currency item to be selected initially */ | ||||||
initiallySelectedCurrencyCode?: string; | ||||||
|
||||||
/** Callback to fire when a currency is selected */ | ||||||
onSelect: (item: CurrencyListItem) => void; | ||||||
}; | ||||||
|
||||||
export type {CurrencyListItem, CurrencySelectionListProps, CurrencySelectionListOnyxProps}; |
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
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
@@ -1,72 +1,24 @@ | ||||||
import React, {useState} from 'react'; | ||||||
import type {OnyxEntry} from 'react-native-onyx'; | ||||||
import {withOnyx} from 'react-native-onyx'; | ||||||
import React from 'react'; | ||||||
import FullPageNotFoundView from '@components/BlockingViews/FullPageNotFoundView'; | ||||||
import CurrencySelectionList from '@components/CurrencySelectionList'; | ||||||
import type {CurrencyListItem} from '@components/CurrencySelectionList/types'; | ||||||
import HeaderWithBackButton from '@components/HeaderWithBackButton'; | ||||||
import ScreenWrapper from '@components/ScreenWrapper'; | ||||||
import SelectionList from '@components/SelectionList'; | ||||||
import RadioListItem from '@components/SelectionList/RadioListItem'; | ||||||
import useLocalize from '@hooks/useLocalize'; | ||||||
import Navigation from '@libs/Navigation/Navigation'; | ||||||
import * as PolicyUtils from '@libs/PolicyUtils'; | ||||||
import * as Policy from '@userActions/Policy'; | ||||||
import ONYXKEYS from '@src/ONYXKEYS'; | ||||||
import type {CurrencyList} from '@src/types/onyx'; | ||||||
import {isEmptyObject} from '@src/types/utils/EmptyObject'; | ||||||
import type {WithPolicyAndFullscreenLoadingProps} from './withPolicyAndFullscreenLoading'; | ||||||
import withPolicyAndFullscreenLoading from './withPolicyAndFullscreenLoading'; | ||||||
|
||||||
type WorkspaceProfileCurrentPageOnyxProps = { | ||||||
/** Constant, list of available currencies */ | ||||||
currencyList: OnyxEntry<CurrencyList>; | ||||||
}; | ||||||
type WorkspaceProfileCurrentPageProps = WithPolicyAndFullscreenLoadingProps; | ||||||
|
||||||
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.
Suggested change
|
||||||
type WorkspaceProfileCurrentPageProps = WithPolicyAndFullscreenLoadingProps & WorkspaceProfileCurrentPageOnyxProps; | ||||||
|
||||||
type WorkspaceProfileCurrencyPageSectionItem = { | ||||||
text: string; | ||||||
keyForList: string; | ||||||
isSelected: boolean; | ||||||
}; | ||||||
|
||||||
const getDisplayText = (currencyCode: string, currencySymbol: string) => `${currencyCode} - ${currencySymbol}`; | ||||||
|
||||||
function WorkspaceProfileCurrencyPage({currencyList = {}, policy, isLoadingReportData = true}: WorkspaceProfileCurrentPageProps) { | ||||||
function WorkspaceProfileCurrencyPage({policy, isLoadingReportData = true}: WorkspaceProfileCurrentPageProps) { | ||||||
const {translate} = useLocalize(); | ||||||
const [searchText, setSearchText] = useState(''); | ||||||
const trimmedText = searchText.trim().toLowerCase(); | ||||||
const currencyListKeys = Object.keys(currencyList ?? {}); | ||||||
|
||||||
const filteredItems = currencyListKeys.filter((currencyCode: string) => { | ||||||
const currency = currencyList?.[currencyCode]; | ||||||
return getDisplayText(currencyCode, currency?.symbol ?? '') | ||||||
.toLowerCase() | ||||||
.includes(trimmedText); | ||||||
}); | ||||||
|
||||||
let initiallyFocusedOptionKey; | ||||||
|
||||||
const currencyItems: WorkspaceProfileCurrencyPageSectionItem[] = filteredItems.map((currencyCode: string) => { | ||||||
const currency = currencyList?.[currencyCode]; | ||||||
const isSelected = policy?.outputCurrency === currencyCode; | ||||||
|
||||||
if (isSelected) { | ||||||
initiallyFocusedOptionKey = currencyCode; | ||||||
} | ||||||
|
||||||
return { | ||||||
text: getDisplayText(currencyCode, currency?.symbol ?? ''), | ||||||
keyForList: currencyCode, | ||||||
isSelected, | ||||||
}; | ||||||
}); | ||||||
|
||||||
const sections = [{data: currencyItems}]; | ||||||
|
||||||
const headerMessage = searchText.trim() && !currencyItems.length ? translate('common.noResultsFound') : ''; | ||||||
|
||||||
const onSelectCurrency = (item: WorkspaceProfileCurrencyPageSectionItem) => { | ||||||
Policy.updateGeneralSettings(policy?.id ?? '', policy?.name ?? '', item.keyForList); | ||||||
const onSelectCurrency = (item: CurrencyListItem) => { | ||||||
Policy.updateGeneralSettings(policy?.id ?? '', policy?.name ?? '', item.currencyCode); | ||||||
Navigation.goBack(); | ||||||
}; | ||||||
|
||||||
|
@@ -86,16 +38,10 @@ function WorkspaceProfileCurrencyPage({currencyList = {}, policy, isLoadingRepor | |||||
onBackButtonPress={() => Navigation.goBack()} | ||||||
/> | ||||||
|
||||||
<SelectionList | ||||||
sections={sections} | ||||||
ListItem={RadioListItem} | ||||||
<CurrencySelectionList | ||||||
textInputLabel={translate('workspace.editor.currencyInputLabel')} | ||||||
textInputValue={searchText} | ||||||
onChangeText={setSearchText} | ||||||
onSelectRow={onSelectCurrency} | ||||||
headerMessage={headerMessage} | ||||||
initiallyFocusedOptionKey={initiallyFocusedOptionKey} | ||||||
showScrollIndicator | ||||||
onSelect={onSelectCurrency} | ||||||
initiallySelectedCurrencyCode={policy?.outputCurrency} | ||||||
/> | ||||||
</FullPageNotFoundView> | ||||||
</ScreenWrapper> | ||||||
|
@@ -104,8 +50,4 @@ function WorkspaceProfileCurrencyPage({currencyList = {}, policy, isLoadingRepor | |||||
|
||||||
WorkspaceProfileCurrencyPage.displayName = 'WorkspaceProfileCurrencyPage'; | ||||||
|
||||||
export default withPolicyAndFullscreenLoading( | ||||||
withOnyx<WorkspaceProfileCurrentPageProps, WorkspaceProfileCurrentPageOnyxProps>({ | ||||||
currencyList: {key: ONYXKEYS.CURRENCY_LIST}, | ||||||
})(WorkspaceProfileCurrencyPage), | ||||||
); | ||||||
export default withPolicyAndFullscreenLoading(WorkspaceProfileCurrencyPage); |
Oops, something went wrong.
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.