Skip to content
Merged
Show file tree
Hide file tree
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
2 changes: 2 additions & 0 deletions src/components/SelectionList/BaseSelectionList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ function BaseSelectionList<TItem extends ListItem>({
onEndReached,
onEndReachedThreshold,
confirmButtonOptions,
children,
customListHeader,
customListHeaderContent,
footerContent,
Expand Down Expand Up @@ -445,6 +446,7 @@ function BaseSelectionList<TItem extends ListItem>({
</>
}
/>
{children}
</>
)}

Expand Down
3 changes: 2 additions & 1 deletion src/components/SelectionList/types.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
import type {ReactElement, RefObject} from 'react';
import type {GestureResponderEvent, InputModeOptions, StyleProp, TextStyle, ViewStyle} from 'react-native';
import type {BaseTextInputRef} from '@components/TextInput/BaseTextInput/types';
import type ChildrenProps from '@src/types/utils/ChildrenProps';
import type {ListItem, ValidListItem} from './ListItem/types';

type SelectionListProps<TItem extends ListItem> = {
type SelectionListProps<TItem extends ListItem> = Partial<ChildrenProps> & {
/** Array of items to display in the list */
data: TItem[];

Expand Down
38 changes: 22 additions & 16 deletions src/pages/workspace/companyCards/addNew/AmexCustomFeed.tsx
Original file line number Diff line number Diff line change
@@ -1,47 +1,47 @@
import React, {useEffect, useState} from 'react';
import React, {useCallback, useEffect, useMemo, useState} from 'react';
import {View} from 'react-native';
import type {ValueOf} from 'type-fest';
import FormHelpMessage from '@components/FormHelpMessage';
import HeaderWithBackButton from '@components/HeaderWithBackButton';
import RenderHTML from '@components/RenderHTML';
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 Text from '@components/Text';
import useLocalize from '@hooks/useLocalize';
import useOnyx from '@hooks/useOnyx';
import useThemeStyles from '@hooks/useThemeStyles';
import * as CompanyCards from '@userActions/CompanyCards';
import {setAddNewCompanyCardStepAndData} from '@userActions/CompanyCards';
import CONST from '@src/CONST';
import ONYXKEYS from '@src/ONYXKEYS';

function AmexCustomFeed() {
const {translate} = useLocalize();
const styles = useThemeStyles();
const [addNewCard] = useOnyx(ONYXKEYS.ADD_NEW_COMPANY_CARD);
const [addNewCard] = useOnyx(ONYXKEYS.ADD_NEW_COMPANY_CARD, {canBeMissing: true});
const [typeSelected, setTypeSelected] = useState<ValueOf<typeof CONST.COMPANY_CARDS.AMEX_CUSTOM_FEED>>();
const [hasError, setHasError] = useState(false);

const submit = () => {
const submit = useCallback(() => {
if (!typeSelected) {
setHasError(true);
return;
}
CompanyCards.setAddNewCompanyCardStepAndData({
setAddNewCompanyCardStepAndData({
step: typeSelected === CONST.COMPANY_CARDS.AMEX_CUSTOM_FEED.CORPORATE ? CONST.COMPANY_CARDS.STEP.CARD_INSTRUCTIONS : CONST.COMPANY_CARDS.STEP.BANK_CONNECTION,
data: {
feedType: CONST.COMPANY_CARD.FEED_BANK_NAME.AMEX,
selectedAmexCustomFeed: typeSelected,
},
});
};
}, [typeSelected]);

useEffect(() => {
setTypeSelected(addNewCard?.data.selectedAmexCustomFeed);
}, [addNewCard?.data.selectedAmexCustomFeed]);
Comment thread
zfurtak marked this conversation as resolved.

const handleBackButtonPress = () => {
Comment thread
zfurtak marked this conversation as resolved.
CompanyCards.setAddNewCompanyCardStepAndData({step: CONST.COMPANY_CARDS.STEP.SELECT_BANK});
setAddNewCompanyCardStepAndData({step: CONST.COMPANY_CARDS.STEP.SELECT_BANK});
};

const data = [
Expand All @@ -68,6 +68,15 @@ function AmexCustomFeed() {
},
];
Comment thread
zfurtak marked this conversation as resolved.

const confirmButtonOptions = useMemo(
() => ({
showButton: true,
text: translate('common.next'),
onConfirm: submit,
}),
[submit, translate],
);

return (
<ScreenWrapper
testID={AmexCustomFeed.displayName}
Expand All @@ -86,20 +95,17 @@ function AmexCustomFeed() {
</View>

<SelectionList
data={data}
ListItem={RadioListItem}
onSelectRow={({value}) => {
Comment thread
zfurtak marked this conversation as resolved.
setTypeSelected(value);
setHasError(false);
}}
sections={[{data}]}
confirmButtonOptions={confirmButtonOptions}
shouldSingleExecuteRowSelect
isAlternateTextMultilineSupported
alternateTextNumberOfLines={3}
initiallyFocusedOptionKey={addNewCard?.data.selectedAmexCustomFeed}
alternateNumberOfSupportedLines={3}
initiallyFocusedItemKey={addNewCard?.data.selectedAmexCustomFeed ?? undefined}
shouldUpdateFocusedIndex
showConfirmButton
confirmButtonText={translate('common.next')}
onConfirm={submit}
addBottomSafeAreaPadding
>
{hasError && (
Expand Down
Loading