Skip to content

Commit fc47eff

Browse files
committed
attachment modal migration
1 parent 8bd6478 commit fc47eff

File tree

91 files changed

+1936
-1460
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

91 files changed

+1936
-1460
lines changed

src/App.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ import Expensify from './Expensify';
4040
import {CurrentReportIDContextProvider} from './hooks/useCurrentReportID';
4141
import useDefaultDragAndDrop from './hooks/useDefaultDragAndDrop';
4242
import OnyxUpdateManager from './libs/actions/OnyxUpdateManager';
43-
import {ReportAttachmentsProvider} from './pages/home/report/ReportAttachmentsContext';
43+
import {AttachmentModalContextProvider} from './pages/media/AttachmentModalScreen/AttachmentModalContext';
4444
import type {Route} from './ROUTES';
4545
import './setup/backgroundTask';
4646
import {SplashScreenStateContextProvider} from './SplashScreenStateContext';
@@ -98,7 +98,7 @@ function App({url, hybridAppSettings, timestamp}: AppProps) {
9898
PopoverContextProvider,
9999
CurrentReportIDContextProvider,
100100
ScrollOffsetContextProvider,
101-
ReportAttachmentsProvider,
101+
AttachmentModalContextProvider,
102102
PickerStateProvider,
103103
EnvironmentProvider,
104104
CustomStatusBarAndBackgroundContextProvider,

src/ROUTES.ts

Lines changed: 36 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,9 @@ import type CONST from './CONST';
44
import type {IOUAction, IOUType} from './CONST';
55
import type {IOURequestType} from './libs/actions/IOU';
66
import Log from './libs/Log';
7+
import type {ReportsSplitNavigatorParamList} from './libs/Navigation/types';
78
import type {ReimbursementAccountStepToOpen} from './libs/ReimbursementAccountUtils';
9+
import type SCREENS from './SCREENS';
810
import type {ExitReason} from './types/form/ExitSurveyReasonForm';
911
import type {ConnectionName, SageIntacctMappingName} from './types/onyx/Policy';
1012
import type {CustomFieldType} from './types/onyx/PolicyEmployee';
@@ -398,6 +400,14 @@ const ROUTES = {
398400
return getUrlWithBackToParam(`${baseRoute}${queryString}` as const, backTo);
399401
},
400402
},
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+
},
401411
REPORT_AVATAR: {
402412
route: 'r/:reportID/avatar',
403413
getRoute: (reportID: string, policyID?: string) => {
@@ -434,29 +444,7 @@ const ROUTES = {
434444
},
435445
ATTACHMENTS: {
436446
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),
460448
},
461449
REPORT_PARTICIPANTS: {
462450
route: 'r/:reportID/participants',
@@ -476,7 +464,7 @@ const ROUTES = {
476464
},
477465
REPORT_WITH_ID_DETAILS: {
478466
route: 'r/:reportID/details',
479-
getRoute: (reportID: string | undefined, backTo?: string) => {
467+
getRoute: (reportID: string | number | undefined, backTo?: string) => {
480468
if (!reportID) {
481469
Log.warn('Invalid reportID is used to build the REPORT_WITH_ID_DETAILS route');
482470
}
@@ -2588,6 +2576,30 @@ const HYBRID_APP_ROUTES = {
25882576
export {HYBRID_APP_ROUTES, getUrlWithBackToParam, PUBLIC_SCREENS_ROUTES};
25892577
export default ROUTES;
25902578

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+
25912603
// eslint-disable-next-line @typescript-eslint/no-explicit-any
25922604
type ExtractRouteName<TRoute> = TRoute extends {getRoute: (...args: any[]) => infer TRouteName} ? TRouteName : TRoute;
25932605

0 commit comments

Comments
 (0)