-
Notifications
You must be signed in to change notification settings - Fork 2.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add a route for easy redirects to the start request flow #33303
Merged
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
eade946
Add a route for easy redirects to the start request flow
tgolen 8a751af
Merge branch 'main' into tgolen-scan-landingpage
tgolen a203ca1
Dismiss modal before redirecting
tgolen aa5b2ea
Do navigation once component has mounted
tgolen c744ec1
Check for valid iou types and show not found if invalid
tgolen 9d960f3
Add screenwrapper
tgolen File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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; |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We prefer lodash to underscore.
Btw not blocker since both will be deprecated during TS migration