-
Notifications
You must be signed in to change notification settings - Fork 3.2k
[VIP][Travel] View trip details and authenticate to travelDot #43081
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
Changes from all commits
03af563
5b0fd92
b2d1aa3
d2f6dad
2851353
c4f4512
a408b66
fb7fdec
68ba31d
09af194
69cf344
d0bc4fe
8f8029d
b0bd79d
a6bc038
61e22e0
750856b
8ad2e06
407b93a
53e65c9
05a9cc6
c095083
5ee49dd
25400ac
0f17458
17fba2d
deb01aa
57da999
9956900
997fb34
e15858e
a6d48f2
f0d4fd8
dae0dd4
938b60e
6895d38
2e9d622
bcde944
d80564d
e48fc99
9033b4e
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
type GenerateSpotnanaTokenParams = { | ||
policyID: string; | ||
}; | ||
|
||
export default GenerateSpotnanaTokenParams; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,7 @@ | ||
import Onyx from 'react-native-onyx'; | ||
import type {OnyxEntry} from 'react-native-onyx'; | ||
import * as API from '@libs/API'; | ||
import type {GenerateSpotnanaTokenParams} from '@libs/API/parameters'; | ||
import {SIDE_EFFECT_REQUEST_COMMANDS} from '@libs/API/types'; | ||
import asyncOpenURL from '@libs/asyncOpenURL'; | ||
import * as Environment from '@libs/Environment/Environment'; | ||
|
@@ -64,6 +66,40 @@ function openOldDotLink(url: string) { | |
); | ||
} | ||
|
||
function buildTravelDotURL(spotnanaToken?: string, postLoginPath?: string): Promise<string> { | ||
return Promise.all([Environment.getTravelDotEnvironmentURL(), Environment.getSpotnanaEnvironmentTMCID()]).then(([environmentURL, tmcID]) => { | ||
const authCode = spotnanaToken ? `authCode=${spotnanaToken}` : ''; | ||
const redirectURL = postLoginPath ? `redirectUrl=${Url.addLeadingForwardSlash(postLoginPath)}` : ''; | ||
const tmcIDParam = `tmcId=${tmcID}`; | ||
|
||
const paramsArray = [authCode, tmcIDParam, redirectURL]; | ||
const params = paramsArray.filter(Boolean).join('&'); | ||
const travelDotDomain = Url.addTrailingForwardSlash(environmentURL); | ||
return `${travelDotDomain}auth/code?${params}`; | ||
}); | ||
} | ||
|
||
/** | ||
* @param postLoginPath When provided, we will redirect the user to this path post login on travelDot. eg: 'trips/:tripID' | ||
*/ | ||
function openTravelDotLink(policyID: OnyxEntry<string>, postLoginPath?: string) { | ||
if (policyID === null || policyID === undefined) { | ||
return; | ||
} | ||
|
||
const parameters: GenerateSpotnanaTokenParams = { | ||
policyID, | ||
}; | ||
|
||
asyncOpenURL( | ||
// eslint-disable-next-line rulesdir/no-api-side-effects-method | ||
API.makeRequestWithSideEffects(SIDE_EFFECT_REQUEST_COMMANDS.GENERATE_SPOTNANA_TOKEN, parameters, {}) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @rushatgabhane Have you confirmed if this is the right way as this kind of pattern in API is discouraged? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
you can refer the docs for its intended use. we're calling a third party and we have to wait for the response because it contains the auth token that we'll use for navigating There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. So in this case, we are actually not calling a third party, this is a token generated by our server. That being said we do need to wait for the response before we can take any actions in the app, so I believe that the usage is still correct (since we are redirecting the user) |
||
.then((response) => (response?.spotnanaToken ? buildTravelDotURL(response.spotnanaToken, postLoginPath) : buildTravelDotURL())) | ||
.catch(() => buildTravelDotURL()), | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think that we need to throw some sort of error here (and line 97) if we don't get the token. Otherwise it will just error out on Spotnana's side right? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @stitesExpensify yes that's a good point 👍 I'm not sure where would be a good place to show the error. This method can be called from any component. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If we throw an error here, we'll have to add try catch everywhere this navigation function is called. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I wasn't thinking an actual throw, but more like a red brick road notification. Maybe for now it's okay to just let Spotnana show an error? I'm not sure that the user would know what to do next though.. cc @twisterdotcom There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think it's fine to leave it as the Spotnana error for now. Can we log it at least? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think a small pre-design would be nice. I created an issue to handle errors - #43780 |
||
(travelDotURL) => travelDotURL, | ||
); | ||
} | ||
|
||
function getInternalNewExpensifyPath(href: string) { | ||
const attrPath = Url.getPathFromURL(href); | ||
return (Url.hasSameExpensifyOrigin(href, CONST.NEW_EXPENSIFY_URL) || Url.hasSameExpensifyOrigin(href, CONST.STAGING_NEW_EXPENSIFY_URL) || href.startsWith(CONST.DEV_NEW_EXPENSIFY_URL)) && | ||
|
@@ -121,4 +157,4 @@ function openLink(href: string, environmentURL: string, isAttachment = false) { | |
openExternalLink(href); | ||
} | ||
|
||
export {buildOldDotURL, openOldDotLink, openExternalLink, openLink, getInternalNewExpensifyPath, getInternalExpensifyPath}; | ||
export {buildOldDotURL, openOldDotLink, openExternalLink, openLink, getInternalNewExpensifyPath, getInternalExpensifyPath, openTravelDotLink}; |
Uh oh!
There was an error while loading. Please reload this page.