diff --git a/src/pages/iou/request/IOURequestStartPage.tsx b/src/pages/iou/request/IOURequestStartPage.tsx index 17592b879fc9..6b5a591d03df 100644 --- a/src/pages/iou/request/IOURequestStartPage.tsx +++ b/src/pages/iou/request/IOURequestStartPage.tsx @@ -69,7 +69,9 @@ function IOURequestStartPage({ const [report] = useOnyx(`${ONYXKEYS.COLLECTION.REPORT}${reportID}`, {canBeMissing: true}); const [parentReport] = useOnyx(`${ONYXKEYS.COLLECTION.REPORT}${report?.parentReportID}`, {canBeMissing: true}); const policy = usePolicy(report?.policyID); - const [selectedTab, selectedTabResult] = useOnyx(`${ONYXKEYS.COLLECTION.SELECTED_TAB}${CONST.TAB.IOU_REQUEST_TYPE}`, {canBeMissing: true}); + const [lastSelectedTab, selectedTabResult] = useOnyx(`${ONYXKEYS.COLLECTION.SELECTED_TAB}${CONST.TAB.IOU_REQUEST_TYPE}`, {canBeMissing: true}); + const [selectedTab, setSelectedTab] = useState(lastSelectedTab); + const isLoadingSelectedTab = shouldUseTab ? isLoadingOnyxValue(selectedTabResult) : false; const [transaction, transactionResult] = useOnyx(`${ONYXKEYS.COLLECTION.TRANSACTION_DRAFT}${getNonEmptyStringOnyxID(route?.params.transactionID)}`, {canBeMissing: true}); const isLoadingTransaction = isLoadingOnyxValue(transactionResult); @@ -192,6 +194,14 @@ function IOURequestStartPage({ ], ); + const onTabSelected = useCallback( + (newIouType: IOURequestType) => { + setSelectedTab(newIouType); + resetIOUTypeIfChanged(newIouType); + }, + [resetIOUTypeIfChanged], + ); + // Clear out the temporary expense if the reportID in the URL has changed from the transaction's reportID. useFocusEffect( useCallback(() => { @@ -272,7 +282,7 @@ function IOURequestStartPage({