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
105 changes: 62 additions & 43 deletions src/pages/AddUnreportedExpense.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import React, {useCallback, useEffect, useMemo, useRef, useState} from 'react';
import {InteractionManager} from 'react-native';
import type {OnyxCollection} from 'react-native-onyx';
import Button from '@components/Button';
import EmptyStateComponent from '@components/EmptyStateComponent';
import FormHelpMessage from '@components/FormHelpMessage';
import HeaderWithBackButton from '@components/HeaderWithBackButton';
Expand Down Expand Up @@ -110,8 +111,13 @@ function AddUnreportedExpense({route}: AddUnreportedExpensePageType) {

const styles = useThemeStyles();
const selectionListRef = useRef<SelectionListHandle>(null);

const shouldShowTextInput = useMemo(() => {
return transactions.length >= CONST.SEARCH_ITEM_LIMIT;
}, [transactions.length]);

const filteredTransactions = useMemo(() => {
if (!debouncedSearchValue.trim()) {
if (!debouncedSearchValue.trim() || !shouldShowTextInput) {

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is to fix the empty list issue

return transactions;
}

Expand All @@ -135,13 +141,58 @@ function AddUnreportedExpense({route}: AddUnreportedExpensePageType) {

return searchableFields;
});
}, [transactions, debouncedSearchValue]);
}, [debouncedSearchValue, shouldShowTextInput, transactions]);

const sections: Array<SectionListDataType<Transaction & ListItem>> = useMemo(() => createUnreportedExpenseSections(filteredTransactions), [filteredTransactions]);

const shouldShowTextInput = useMemo(() => {
return transactions.length >= CONST.SEARCH_ITEM_LIMIT;
}, [transactions.length]);
const handleConfirm = useCallback(() => {
if (selectedIds.size === 0) {
setErrorMessage(translate('iou.selectUnreportedExpense'));
return;
}
Navigation.dismissModal();
// eslint-disable-next-line deprecation/deprecation
InteractionManager.runAfterInteractions(() => {
if (report && isIOUReport(report)) {
convertBulkTrackedExpensesToIOU([...selectedIds], report.reportID);
} else {
changeTransactionsReport(
[...selectedIds],
report?.reportID ?? CONST.REPORT.UNREPORTED_REPORT_ID,
isASAPSubmitBetaEnabled,
session?.accountID ?? CONST.DEFAULT_NUMBER_ID,
session?.email ?? '',
policy,
reportNextStep,
policyCategories,
);
}
});
setErrorMessage('');
}, [selectedIds, translate, report, isASAPSubmitBetaEnabled, session?.accountID, session?.email, policy, reportNextStep, policyCategories]);

const footerContent = useMemo(() => {

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is to fix the error message not showing issue

return (
<>
{!!errorMessage && (
<FormHelpMessage
style={[styles.ph1, styles.mb2]}
isError
message={errorMessage}
/>
)}
<Button
success

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@lorretheboy, to clarify, why did we create this button, instead of using the ScreenWrapper one as before? Thank you.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@brunovjk if so there is no error message on empty state. This is also one of the current pattern in codebase

const footerContent = useMemo(() => {

large
style={[styles.w100, styles.justifyContentCenter]}
text={translate('iou.addUnreportedExpenseConfirm')}
onPress={handleConfirm}
pressOnEnter
enterKeyEventListenerPriority={1}
/>
</>
);
}, [errorMessage, styles, translate, handleConfirm]);

const headerMessage = useMemo(() => {
if (debouncedSearchValue.trim() && sections.at(0)?.data.length === 0) {
Expand Down Expand Up @@ -217,9 +268,11 @@ function AddUnreportedExpense({route}: AddUnreportedExpensePageType) {

return (
<ScreenWrapper
shouldEnableKeyboardAvoidingView={false}
shouldEnableKeyboardAvoidingView
includeSafeAreaPaddingBottom
shouldEnablePickerAvoiding={false}
shouldEnableMaxHeight
enableEdgeToEdgeBottomSafeAreaPadding

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is to fix the button is hidden by keyboard issue

testID={NewChatSelectorPage.displayName}
focusTrapSettings={{active: false}}
>
Expand Down Expand Up @@ -253,46 +306,12 @@ function AddUnreportedExpense({route}: AddUnreportedExpensePageType) {
canSelectMultiple
sections={sections}
ListItem={UnreportedExpenseListItem}
confirmButtonStyles={[styles.justifyContentCenter]}
showConfirmButton
confirmButtonText={translate('iou.addUnreportedExpenseConfirm')}
onConfirm={() => {
if (selectedIds.size === 0) {
setErrorMessage(translate('iou.selectUnreportedExpense'));
return;
}
Navigation.dismissModal();
// eslint-disable-next-line deprecation/deprecation
InteractionManager.runAfterInteractions(() => {
if (report && isIOUReport(report)) {
convertBulkTrackedExpensesToIOU([...selectedIds], report.reportID);
} else {
changeTransactionsReport(
[...selectedIds],
report?.reportID ?? CONST.REPORT.UNREPORTED_REPORT_ID,
isASAPSubmitBetaEnabled,
session?.accountID ?? CONST.DEFAULT_NUMBER_ID,
session?.email ?? '',
policy,
reportNextStep,
policyCategories,
);
}
});
setErrorMessage('');
}}
onEndReached={fetchMoreUnreportedTransactions}
onEndReachedThreshold={0.75}
addBottomSafeAreaPadding
listFooterContent={shouldShowUnreportedTransactionsSkeletons ? <UnreportedExpensesSkeleton fixedNumberOfItems={3} /> : undefined}
>
{!!errorMessage && (
<FormHelpMessage
style={[styles.mb2, styles.ph4]}
isError
message={errorMessage}
/>
)}
</SelectionList>
footerContent={footerContent}
/>
</ScreenWrapper>
);
}
Expand Down
Loading