-
Notifications
You must be signed in to change notification settings - Fork 2.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #45603 from nyomanjyotisa/track-expense-and-submit…
…-expense-deep-links track-expense and submit-expense deep links
- Loading branch information
Showing
9 changed files
with
162 additions
and
0 deletions.
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
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
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
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
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,56 @@ | ||
import {useFocusEffect} from '@react-navigation/native'; | ||
import React, {useEffect, useRef} from 'react'; | ||
import {View} from 'react-native'; | ||
import ReportActionsSkeletonView from '@components/ReportActionsSkeletonView'; | ||
import ReportHeaderSkeletonView from '@components/ReportHeaderSkeletonView'; | ||
import ScreenWrapper from '@components/ScreenWrapper'; | ||
import useThemeStyles from '@hooks/useThemeStyles'; | ||
import interceptAnonymousUser from '@libs/interceptAnonymousUser'; | ||
import Navigation from '@libs/Navigation/Navigation'; | ||
import * as ReportUtils from '@libs/ReportUtils'; | ||
import * as App from '@userActions/App'; | ||
import * as IOU from '@userActions/IOU'; | ||
import CONST from '@src/CONST'; | ||
|
||
/* | ||
* This is a "utility page", that does this: | ||
* - If the user is authenticated, start Submit Expense | ||
* - Else re-route to the login page | ||
*/ | ||
function SubmitExpensePage() { | ||
const styles = useThemeStyles(); | ||
const isUnmounted = useRef(false); | ||
|
||
useFocusEffect(() => { | ||
interceptAnonymousUser(() => { | ||
App.confirmReadyToOpenApp(); | ||
Navigation.isNavigationReady().then(() => { | ||
if (isUnmounted.current) { | ||
return; | ||
} | ||
Navigation.goBack(); | ||
IOU.startMoneyRequest(CONST.IOU.TYPE.SUBMIT, ReportUtils.generateReportID()); | ||
}); | ||
}); | ||
}); | ||
|
||
useEffect( | ||
() => () => { | ||
isUnmounted.current = true; | ||
}, | ||
[], | ||
); | ||
|
||
return ( | ||
<ScreenWrapper testID={SubmitExpensePage.displayName}> | ||
<View style={[styles.borderBottom]}> | ||
<ReportHeaderSkeletonView onBackButtonPress={Navigation.goBack} /> | ||
</View> | ||
<ReportActionsSkeletonView /> | ||
</ScreenWrapper> | ||
); | ||
} | ||
|
||
SubmitExpensePage.displayName = 'SubmitExpensePage'; | ||
|
||
export default SubmitExpensePage; |
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,74 @@ | ||
import {useFocusEffect} from '@react-navigation/native'; | ||
import React, {useEffect, useRef} from 'react'; | ||
import {View} from 'react-native'; | ||
import {useOnyx} from 'react-native-onyx'; | ||
import ReportActionsSkeletonView from '@components/ReportActionsSkeletonView'; | ||
import ReportHeaderSkeletonView from '@components/ReportHeaderSkeletonView'; | ||
import ScreenWrapper from '@components/ScreenWrapper'; | ||
import useNetwork from '@hooks/useNetwork'; | ||
import useThemeStyles from '@hooks/useThemeStyles'; | ||
import interceptAnonymousUser from '@libs/interceptAnonymousUser'; | ||
import Navigation from '@libs/Navigation/Navigation'; | ||
import * as ReportUtils from '@libs/ReportUtils'; | ||
import * as App from '@userActions/App'; | ||
import * as IOU from '@userActions/IOU'; | ||
import CONST from '@src/CONST'; | ||
import ONYXKEYS from '@src/ONYXKEYS'; | ||
import ROUTES from '@src/ROUTES'; | ||
import isLoadingOnyxValue from '@src/types/utils/isLoadingOnyxValue'; | ||
|
||
/* | ||
* This is a "utility page", that does this: | ||
* - If the user is authenticated, find their self DM and and start a Track Expense | ||
* - Else re-route to the login page | ||
*/ | ||
function TrackExpensePage() { | ||
const styles = useThemeStyles(); | ||
const isUnmounted = useRef(false); | ||
const {isOffline} = useNetwork(); | ||
const [hasSeenTrackTraining, hasSeenTrackTrainingResult] = useOnyx(ONYXKEYS.NVP_HAS_SEEN_TRACK_TRAINING); | ||
const isLoadingHasSeenTrackTraining = isLoadingOnyxValue(hasSeenTrackTrainingResult); | ||
|
||
useFocusEffect(() => { | ||
interceptAnonymousUser(() => { | ||
App.confirmReadyToOpenApp(); | ||
Navigation.isNavigationReady().then(() => { | ||
if (isUnmounted.current || isLoadingHasSeenTrackTraining) { | ||
return; | ||
} | ||
Navigation.goBack(); | ||
IOU.startMoneyRequest( | ||
CONST.IOU.TYPE.TRACK, | ||
// eslint-disable-next-line @typescript-eslint/prefer-nullish-coalescing | ||
ReportUtils.findSelfDMReportID() || ReportUtils.generateReportID(), | ||
); | ||
|
||
if (!hasSeenTrackTraining && !isOffline) { | ||
setTimeout(() => { | ||
Navigation.navigate(ROUTES.TRACK_TRAINING_MODAL); | ||
}, CONST.ANIMATED_TRANSITION); | ||
} | ||
}); | ||
}); | ||
}); | ||
|
||
useEffect( | ||
() => () => { | ||
isUnmounted.current = true; | ||
}, | ||
[], | ||
); | ||
|
||
return ( | ||
<ScreenWrapper testID={TrackExpensePage.displayName}> | ||
<View style={[styles.borderBottom]}> | ||
<ReportHeaderSkeletonView onBackButtonPress={Navigation.goBack} /> | ||
</View> | ||
<ReportActionsSkeletonView /> | ||
</ScreenWrapper> | ||
); | ||
} | ||
|
||
TrackExpensePage.displayName = 'TrackExpensePage'; | ||
|
||
export default TrackExpensePage; |