Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ import React, {useMemo} from 'react';
import HeaderWithBackButton from '@components/HeaderWithBackButton';
import Modal from '@components/Modal';
import ScreenWrapper from '@components/ScreenWrapper';
import SelectionList from '@components/SelectionListWithSections';
import RadioListItem from '@components/SelectionListWithSections/RadioListItem';
import SelectionList from '@components/SelectionList';
import RadioListItem from '@components/SelectionList/ListItem/RadioListItem';
import useDebouncedState from '@hooks/useDebouncedState';
import useLocalize from '@hooks/useLocalize';
import type {CustomListSelectorType} from '@pages/workspace/accounting/netsuite/types';
Expand Down Expand Up @@ -37,8 +37,10 @@ function NetSuiteCustomListSelectorModal({isVisible, currentCustomListValue, onC
const {translate} = useLocalize();
const [searchValue, debouncedSearchValue, setSearchValue] = useDebouncedState('');

const {sections, headerMessage, showTextInput} = useMemo(() => {
const customLists = policy?.connections?.netsuite?.options?.data?.customLists ?? [];
const rawCustomLists = policy?.connections?.netsuite?.options?.data?.customLists;

const {options, showTextInput} = useMemo(() => {
const customLists = rawCustomLists ?? [];
const customListData = customLists.map((customListRecord) => ({
text: customListRecord.name,
value: customListRecord.name,
Expand All @@ -52,17 +54,20 @@ function NetSuiteCustomListSelectorModal({isVisible, currentCustomListValue, onC
const isEmpty = debouncedSearchValue.trim() && !filteredCustomLists.length;

return {
sections: isEmpty
? []
: [
{
data: filteredCustomLists,
},
],
headerMessage: isEmpty ? translate('common.noResultsFound') : '',
options: isEmpty ? [] : filteredCustomLists,
showTextInput: customListData.length > CONST.STANDARD_LIST_ITEM_LIMIT,
};
}, [debouncedSearchValue, policy?.connections?.netsuite?.options?.data?.customLists, translate, currentCustomListValue]);
}, [debouncedSearchValue, rawCustomLists, currentCustomListValue]);

const textInputOptions = useMemo(
() => ({
value: searchValue,
label: showTextInput ? translate('common.search') : undefined,
onChangeText: setSearchValue,
headerMessage: debouncedSearchValue.trim() && options.length === 0 ? translate('common.noResultsFound') : '',
}),
[searchValue, showTextInput, translate, setSearchValue, debouncedSearchValue, options.length],
);

return (
<Modal
Expand All @@ -84,17 +89,13 @@ function NetSuiteCustomListSelectorModal({isVisible, currentCustomListValue, onC
onBackButtonPress={onClose}
/>
<SelectionList
sections={sections}
textInputValue={searchValue}
textInputLabel={showTextInput ? translate('common.search') : undefined}
onChangeText={setSearchValue}
data={options}
textInputOptions={textInputOptions}
onSelectRow={onCustomListSelected}
headerMessage={headerMessage}
ListItem={RadioListItem}
initiallyFocusedOptionKey={currentCustomListValue}
initiallyFocusedItemKey={currentCustomListValue}
shouldSingleExecuteRowSelect
shouldStopPropagation
shouldUseDynamicMaxToRenderPerBatch
addBottomSafeAreaPadding
/>
</ScreenWrapper>
Expand Down
Loading