@@ -4,7 +4,9 @@ import type CONST from './CONST';
4
4
import type { IOUAction , IOUType } from './CONST' ;
5
5
import type { IOURequestType } from './libs/actions/IOU' ;
6
6
import Log from './libs/Log' ;
7
+ import type { ReportsSplitNavigatorParamList } from './libs/Navigation/types' ;
7
8
import type { ReimbursementAccountStepToOpen } from './libs/ReimbursementAccountUtils' ;
9
+ import type SCREENS from './SCREENS' ;
8
10
import type { ExitReason } from './types/form/ExitSurveyReasonForm' ;
9
11
import type { ConnectionName , SageIntacctMappingName } from './types/onyx/Policy' ;
10
12
import type { CustomFieldType } from './types/onyx/PolicyEmployee' ;
@@ -398,6 +400,14 @@ const ROUTES = {
398
400
return getUrlWithBackToParam ( `${ baseRoute } ${ queryString } ` as const , backTo ) ;
399
401
} ,
400
402
} ,
403
+ REPORT_ADD_ATTACHMENT : {
404
+ route : 'r/:reportID/attachment/add' ,
405
+ getRoute : ( reportID : string , params ?: AttachmentRouteParams ) => {
406
+ // eslint-disable-next-line @typescript-eslint/naming-convention
407
+ const { reportID : _reportIDParam , ...restParams } = params ?? { } ;
408
+ return getAttachmentRoute ( `r/${ reportID } /attachment/add` , restParams ) ;
409
+ } ,
410
+ } ,
401
411
REPORT_AVATAR : {
402
412
route : 'r/:reportID/avatar' ,
403
413
getRoute : ( reportID : string , policyID ?: string ) => {
@@ -434,29 +444,7 @@ const ROUTES = {
434
444
} ,
435
445
ATTACHMENTS : {
436
446
route : 'attachment' ,
437
- getRoute : (
438
- reportID : string | undefined ,
439
- attachmentID : string | undefined ,
440
- type : ValueOf < typeof CONST . ATTACHMENT_TYPE > ,
441
- url : string ,
442
- accountID ?: number ,
443
- isAuthTokenRequired ?: boolean ,
444
- fileName ?: string ,
445
- attachmentLink ?: string ,
446
- hashKey ?: number ,
447
- ) => {
448
- const reportParam = reportID ? `&reportID=${ reportID } ` : '' ;
449
- const accountParam = accountID ? `&accountID=${ accountID } ` : '' ;
450
- const authTokenParam = isAuthTokenRequired ? '&isAuthTokenRequired=true' : '' ;
451
- const fileNameParam = fileName ? `&fileName=${ fileName } ` : '' ;
452
- const attachmentLinkParam = attachmentLink ? `&attachmentLink=${ attachmentLink } ` : '' ;
453
- const attachmentIDParam = attachmentID ? `&attachmentID=${ attachmentID } ` : '' ;
454
- const hashKeyParam = hashKey ? `&hashKey=${ hashKey } ` : '' ;
455
-
456
- return `attachment?source=${ encodeURIComponent ( url ) } &type=${
457
- type as string
458
- } ${ reportParam } ${ attachmentIDParam } ${ accountParam } ${ authTokenParam } ${ fileNameParam } ${ attachmentLinkParam } ${ hashKeyParam } ` as const ;
459
- } ,
447
+ getRoute : ( params ?: AttachmentRouteParams ) => getAttachmentRoute ( 'attachment' , params ) ,
460
448
} ,
461
449
REPORT_PARTICIPANTS : {
462
450
route : 'r/:reportID/participants' ,
@@ -476,7 +464,7 @@ const ROUTES = {
476
464
} ,
477
465
REPORT_WITH_ID_DETAILS : {
478
466
route : 'r/:reportID/details' ,
479
- getRoute : ( reportID : string | undefined , backTo ?: string ) => {
467
+ getRoute : ( reportID : string | number | undefined , backTo ?: string ) => {
480
468
if ( ! reportID ) {
481
469
Log . warn ( 'Invalid reportID is used to build the REPORT_WITH_ID_DETAILS route' ) ;
482
470
}
@@ -2588,6 +2576,30 @@ const HYBRID_APP_ROUTES = {
2588
2576
export { HYBRID_APP_ROUTES , getUrlWithBackToParam , PUBLIC_SCREENS_ROUTES } ;
2589
2577
export default ROUTES ;
2590
2578
2579
+ type AttachmentsRoute = typeof ROUTES . ATTACHMENTS . route ;
2580
+ type ReportAddAttachmentRoute = `r/${string } /attachment/add`;
2581
+ type AttachmentRoutes = AttachmentsRoute | ReportAddAttachmentRoute ;
2582
+ type AttachmentRouteParams = ReportsSplitNavigatorParamList [ typeof SCREENS . ATTACHMENTS ] ;
2583
+
2584
+ function getAttachmentRoute ( url : AttachmentRoutes , params ?: AttachmentRouteParams ) {
2585
+ if ( ! params ?. source ) {
2586
+ return url ;
2587
+ }
2588
+
2589
+ const { source, attachmentID, type, reportID, accountID, isAuthTokenRequired, fileName, attachmentLink} = params ;
2590
+
2591
+ const sourceParam = `?source=${ encodeURIComponent ( source ) } ` ;
2592
+ const attachmentIDParam = attachmentID ? `&attachmentID=${ attachmentID } ` : '' ;
2593
+ const typeParam = type ? `&type=${ type as string } ` : '' ;
2594
+ const reportIDParam = reportID ? `&reportID=${ reportID } ` : '' ;
2595
+ const accountIDParam = accountID ? `&accountID=${ accountID } ` : '' ;
2596
+ const authTokenParam = isAuthTokenRequired ? '&isAuthTokenRequired=true' : '' ;
2597
+ const fileNameParam = fileName ? `&fileName=${ fileName } ` : '' ;
2598
+ const attachmentLinkParam = attachmentLink ? `&attachmentLink=${ attachmentLink } ` : '' ;
2599
+
2600
+ return `${ url } ${ sourceParam } ${ typeParam } ${ reportIDParam } ${ attachmentIDParam } ${ accountIDParam } ${ authTokenParam } ${ fileNameParam } ${ attachmentLinkParam } ` as const ;
2601
+ }
2602
+
2591
2603
// eslint-disable-next-line @typescript-eslint/no-explicit-any
2592
2604
type ExtractRouteName < TRoute > = TRoute extends { getRoute : ( ...args : any [ ] ) => infer TRouteName } ? TRouteName : TRoute ;
2593
2605
0 commit comments