Skip to content

Commit

Permalink
Merge pull request #35566 from VickyStash/ts-migration/report-page
Browse files Browse the repository at this point in the history
[TS migration] Migrate 'Report' page to TypeScript
  • Loading branch information
puneetlath authored Mar 11, 2024
2 parents fb6e050 + ecb3f58 commit 59ac113
Show file tree
Hide file tree
Showing 30 changed files with 697 additions and 870 deletions.
2 changes: 1 addition & 1 deletion src/components/DragAndDrop/Provider/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ type DragAndDropProviderProps = {
isDisabled?: boolean;

/** Indicate that users are dragging file or not */
setIsDraggingOver: (value: boolean) => void;
setIsDraggingOver?: (value: boolean) => void;
};

type SetOnDropHandlerCallback = (event: DragEvent) => void;
Expand Down
6 changes: 3 additions & 3 deletions src/components/MoneyReportHeader.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ type MoneyReportHeaderProps = MoneyReportHeaderOnyxProps & {
report: OnyxTypes.Report;

/** The policy tied to the money request report */
policy: OnyxTypes.Policy;
policy: OnyxEntry<OnyxTypes.Policy>;
};

function MoneyReportHeader({session, policy, chatReport, nextStep, report: moneyRequestReport}: MoneyReportHeaderProps) {
Expand Down Expand Up @@ -79,8 +79,8 @@ function MoneyReportHeader({session, policy, chatReport, nextStep, report: money

// The submit button should be success green colour only if the user is submitter and the policy does not have Scheduled Submit turned on
const isWaitingForSubmissionFromCurrentUser = useMemo(
() => chatReport?.isOwnPolicyExpenseChat && !policy.harvesting?.enabled,
[chatReport?.isOwnPolicyExpenseChat, policy.harvesting?.enabled],
() => chatReport?.isOwnPolicyExpenseChat && !policy?.harvesting?.enabled,
[chatReport?.isOwnPolicyExpenseChat, policy?.harvesting?.enabled],
);

const threeDotsMenuItems = [HeaderUtils.getPinMenuItem(moneyRequestReport)];
Expand Down
16 changes: 11 additions & 5 deletions src/components/MoneyRequestHeader.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -46,10 +46,10 @@ type MoneyRequestHeaderProps = MoneyRequestHeaderOnyxProps & {
report: Report;

/** The policy which the report is tied to */
policy: Policy;
policy: OnyxEntry<Policy>;

/** The report action the transaction is tied to from the parent report */
parentReportAction: ReportAction & OriginalMessageIOU;
parentReportAction: OnyxEntry<ReportAction>;
};

function MoneyRequestHeader({session, parentReport, report, parentReportAction, transaction, shownHoldUseExplanation = false, policy}: MoneyRequestHeaderProps) {
Expand All @@ -69,7 +69,11 @@ function MoneyRequestHeader({session, parentReport, report, parentReportAction,
const isApprover = ReportUtils.isMoneyRequestReport(moneyRequestReport) && (session?.accountID ?? null) === moneyRequestReport?.managerID;

const deleteTransaction = useCallback(() => {
IOU.deleteMoneyRequest(parentReportAction?.originalMessage?.IOUTransactionID ?? '', parentReportAction, true);
if (parentReportAction) {
const iouTransactionID = parentReportAction.actionName === CONST.REPORT.ACTIONS.TYPE.IOU ? parentReportAction.originalMessage?.IOUTransactionID ?? '' : '';
IOU.deleteMoneyRequest(iouTransactionID, parentReportAction, true);
}

setIsDeleteModalVisible(false);
}, [parentReportAction, setIsDeleteModalVisible]);

Expand All @@ -83,11 +87,13 @@ function MoneyRequestHeader({session, parentReport, report, parentReportAction,
const canDeleteRequest = isActionOwner && ReportUtils.canAddOrDeleteTransactions(moneyRequestReport) && !isDeletedParentAction;

const changeMoneyRequestStatus = () => {
const iouTransactionID = parentReportAction?.actionName === CONST.REPORT.ACTIONS.TYPE.IOU ? parentReportAction.originalMessage?.IOUTransactionID ?? '' : '';

if (isOnHold) {
IOU.unholdRequest(parentReportAction?.originalMessage?.IOUTransactionID ?? '', report?.reportID);
IOU.unholdRequest(iouTransactionID, report?.reportID);
} else {
const activeRoute = encodeURIComponent(Navigation.getActiveRouteWithoutParams());
Navigation.navigate(ROUTES.MONEY_REQUEST_HOLD_REASON.getRoute(policy?.type, parentReportAction?.originalMessage?.IOUTransactionID ?? '', report?.reportID, activeRoute));
Navigation.navigate(ROUTES.MONEY_REQUEST_HOLD_REASON.getRoute(policy?.type ?? '', iouTransactionID, report?.reportID, activeRoute));
}
};

Expand Down
4 changes: 2 additions & 2 deletions src/components/ScreenWrapper.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import useTackInputFocus from '@hooks/useTackInputFocus';
import useThemeStyles from '@hooks/useThemeStyles';
import useWindowDimensions from '@hooks/useWindowDimensions';
import * as Browser from '@libs/Browser';
import type {RootStackParamList} from '@libs/Navigation/types';
import type {CentralPaneNavigatorParamList, RootStackParamList} from '@libs/Navigation/types';
import toggleTestToolsModal from '@userActions/TestTool';
import CONST from '@src/CONST';
import CustomDevMenu from './CustomDevMenu';
Expand Down Expand Up @@ -92,7 +92,7 @@ type ScreenWrapperProps = {
*
* This is required because transitionEnd event doesn't trigger in the testing environment.
*/
navigation?: StackNavigationProp<RootStackParamList>;
navigation?: StackNavigationProp<RootStackParamList> | StackNavigationProp<CentralPaneNavigatorParamList>;

/** Whether to show offline indicator on wide screens */
shouldShowOfflineIndicatorInWideScreen?: boolean;
Expand Down
2 changes: 2 additions & 0 deletions src/components/withViewportOffsetTop.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -40,3 +40,5 @@ export default function withViewportOffsetTop<TProps extends ViewportOffsetTopPr

return forwardRef(WithViewportOffsetTop);
}

export type {ViewportOffsetTopProps};
1 change: 0 additions & 1 deletion src/libs/Navigation/AppNavigator/ReportScreenWrapper.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ function ReportScreenWrapper({route, navigation}: ReportScreenWrapperProps) {
return (
<>
<ReportScreen
// @ts-expect-error Error will be resolved after ReportScreen migration to TypeScript
route={route}
navigation={navigation}
/>
Expand Down
8 changes: 6 additions & 2 deletions src/libs/OnyxSelectors/reportWithoutHasDraftSelector.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,14 @@
import type {OnyxEntry} from 'react-native-onyx';
import type {Report} from '@src/types/onyx';

export default function reportWithoutHasDraftSelector(report: OnyxEntry<Report>) {
type ReportWithoutHasDraft = Omit<Report, 'hasDraft'>;

export default function reportWithoutHasDraftSelector(report: OnyxEntry<Report>): OnyxEntry<ReportWithoutHasDraft> {
if (!report) {
return report;
return null;
}
const {hasDraft, ...reportWithoutHasDraft} = report;
return reportWithoutHasDraft;
}

export type {ReportWithoutHasDraft};
4 changes: 2 additions & 2 deletions src/libs/ReportActionsUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ function isModifiedExpenseAction(reportAction: OnyxEntry<ReportAction>): boolean
return reportAction?.actionName === CONST.REPORT.ACTIONS.TYPE.MODIFIEDEXPENSE;
}

function isWhisperAction(reportAction: OnyxEntry<ReportAction>): boolean {
function isWhisperAction(reportAction: OnyxEntry<ReportAction> | EmptyObject): boolean {
return (reportAction?.whisperedToAccountIDs ?? []).length > 0;
}

Expand Down Expand Up @@ -205,7 +205,7 @@ function isSentMoneyReportAction(reportAction: OnyxEntry<ReportAction | Optimist
* Returns whether the thread is a transaction thread, which is any thread with IOU parent
* report action from requesting money (type - create) or from sending money (type - pay with IOUDetails field)
*/
function isTransactionThread(parentReportAction: OnyxEntry<ReportAction>): boolean {
function isTransactionThread(parentReportAction: OnyxEntry<ReportAction> | EmptyObject): boolean {
return (
parentReportAction?.actionName === CONST.REPORT.ACTIONS.TYPE.IOU &&
(parentReportAction.originalMessage.type === CONST.IOU.REPORT_ACTION_TYPE.CREATE ||
Expand Down
8 changes: 4 additions & 4 deletions src/libs/ReportUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1230,7 +1230,7 @@ function isMoneyRequest(reportOrID: OnyxEntry<Report> | string): boolean {
/**
* Checks if a report is an IOU or expense report.
*/
function isMoneyRequestReport(reportOrID: OnyxEntry<Report> | string): boolean {
function isMoneyRequestReport(reportOrID: OnyxEntry<Report> | EmptyObject | string): boolean {
const report = typeof reportOrID === 'object' ? reportOrID : allReports?.[`${ONYXKEYS.COLLECTION.REPORT}${reportOrID}`] ?? null;
return isIOUReport(report) || isExpenseReport(report);
}
Expand Down Expand Up @@ -2806,8 +2806,8 @@ function getReportDescriptionText(report: Report): string {
return parser.htmlToText(report.description);
}

function getPolicyDescriptionText(policy: Policy): string {
if (!policy.description) {
function getPolicyDescriptionText(policy: OnyxEntry<Policy>): string {
if (!policy?.description) {
return '';
}

Expand Down Expand Up @@ -4603,7 +4603,7 @@ function getAddWorkspaceRoomOrChatReportErrors(report: OnyxEntry<Report>): Error
/**
* Return true if the Money Request report is marked for deletion.
*/
function isMoneyRequestReportPendingDeletion(report: OnyxEntry<Report>): boolean {
function isMoneyRequestReportPendingDeletion(report: OnyxEntry<Report> | EmptyObject): boolean {
if (!isMoneyRequestReport(report)) {
return false;
}
Expand Down
2 changes: 1 addition & 1 deletion src/libs/actions/Session/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -253,7 +253,7 @@ function signOutAndRedirectToSignIn(shouldReplaceCurrentScreen?: boolean, should
* @returns same callback if the action is allowed, otherwise a function that signs out and redirects to sign in
*/
// eslint-disable-next-line @typescript-eslint/no-explicit-any
function checkIfActionIsAllowed<TCallback extends (...args: any[]) => any>(callback: TCallback, isAnonymousAction = false): TCallback | (() => void) {
function checkIfActionIsAllowed<TCallback extends ((...args: any[]) => any) | void>(callback: TCallback, isAnonymousAction = false): TCallback | (() => void) {
if (isAnonymousUser() && !isAnonymousAction) {
return () => signOutAndRedirectToSignIn();
}
Expand Down
2 changes: 1 addition & 1 deletion src/libs/actions/Task.ts
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ function createTaskAndNavigate(
assigneeEmail: string,
assigneeAccountID = 0,
assigneeChatReport: OnyxEntry<OnyxTypes.Report> = null,
policyID = CONST.POLICY.OWNER_EMAIL_FAKE,
policyID: string = CONST.POLICY.OWNER_EMAIL_FAKE,
) {
const optimisticTaskReport = ReportUtils.buildOptimisticTaskReport(currentUserAccountID, assigneeAccountID, parentReportID, title, description, policyID);

Expand Down
Loading

0 comments on commit 59ac113

Please sign in to comment.