-
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 #33303 from Expensify/tgolen-scan-landingpage
Add a route for easy redirects to the start request flow
- Loading branch information
Showing
5 changed files
with
78 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
import PropTypes from 'prop-types'; | ||
import React, {useEffect} from 'react'; | ||
import _ from 'underscore'; | ||
import FullPageNotFoundView from '@components/BlockingViews/FullPageNotFoundView'; | ||
import ScreenWrapper from '@components/ScreenWrapper'; | ||
import Navigation from '@libs/Navigation/Navigation'; | ||
import * as ReportUtils from '@libs/ReportUtils'; | ||
import CONST from '@src/CONST'; | ||
import ROUTES from '@src/ROUTES'; | ||
|
||
const propTypes = { | ||
/** Navigation route context info provided by react navigation */ | ||
route: PropTypes.shape({ | ||
/** Route specific parameters used on this screen */ | ||
params: PropTypes.shape({ | ||
/** The type of IOU report, i.e. bill, request, send */ | ||
iouType: PropTypes.oneOf(_.values(CONST.IOU.TYPE)).isRequired, | ||
|
||
/** The type of IOU Request, i.e. manual, scan, distance */ | ||
iouRequestType: PropTypes.oneOf(_.values(CONST.IOU.REQUEST_TYPE)).isRequired, | ||
}), | ||
}).isRequired, | ||
}; | ||
|
||
function IOURequestRedirectToStartPage({ | ||
route: { | ||
params: {iouType, iouRequestType}, | ||
}, | ||
}) { | ||
const isIouTypeValid = _.values(CONST.IOU.TYPE).includes(iouType); | ||
const isIouRequestTypeValid = _.values(CONST.IOU.REQUEST_TYPE).includes(iouRequestType); | ||
|
||
useEffect(() => { | ||
if (!isIouTypeValid || !isIouRequestTypeValid) { | ||
return; | ||
} | ||
|
||
// Dismiss this modal because the redirects below will open a new modal and there shouldn't be two modals stacked on top of each other. | ||
Navigation.dismissModal(); | ||
|
||
// Redirect the person to the right start page using a rendom reportID | ||
const optimisticReportID = ReportUtils.generateReportID(); | ||
if (iouRequestType === CONST.IOU.REQUEST_TYPE.DISTANCE) { | ||
Navigation.navigate(ROUTES.MONEY_REQUEST_CREATE_TAB_DISTANCE.getRoute(iouType, CONST.IOU.OPTIMISTIC_TRANSACTION_ID, optimisticReportID)); | ||
} else if (iouRequestType === CONST.IOU.REQUEST_TYPE.MANUAL) { | ||
Navigation.navigate(ROUTES.MONEY_REQUEST_CREATE_TAB_MANUAL.getRoute(iouType, CONST.IOU.OPTIMISTIC_TRANSACTION_ID, optimisticReportID)); | ||
} else if (iouRequestType === CONST.IOU.REQUEST_TYPE.SCAN) { | ||
Navigation.navigate(ROUTES.MONEY_REQUEST_CREATE_TAB_SCAN.getRoute(iouType, CONST.IOU.OPTIMISTIC_TRANSACTION_ID, optimisticReportID)); | ||
} | ||
|
||
// This useEffect should only run on mount which is why there are no dependencies being passed in the second parameter | ||
// eslint-disable-next-line react-hooks/exhaustive-deps | ||
}, []); | ||
|
||
if (!isIouTypeValid || !isIouRequestTypeValid) { | ||
return ( | ||
<ScreenWrapper testID={IOURequestRedirectToStartPage.displayName}> | ||
<FullPageNotFoundView shouldShow /> | ||
</ScreenWrapper> | ||
); | ||
} | ||
|
||
return null; | ||
} | ||
|
||
IOURequestRedirectToStartPage.displayName = 'IOURequestRedirectToStartPage'; | ||
IOURequestRedirectToStartPage.propTypes = propTypes; | ||
|
||
export default IOURequestRedirectToStartPage; |