Skip to content

Commit

Permalink
Merge pull request #55535 from callstack-internal/VickyStash/refactor…
Browse files Browse the repository at this point in the history
…/50360-wrong-default-number-id-usage

Fix wrong default number id usages
  • Loading branch information
thienlnam authored Jan 30, 2025
2 parents 6d914ce + fa465a4 commit 8e1aad2
Show file tree
Hide file tree
Showing 31 changed files with 278 additions and 151 deletions.
8 changes: 4 additions & 4 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -289,7 +289,7 @@
"electron-builder": "25.0.0",
"eslint": "^8.57.0",
"eslint-config-airbnb-typescript": "^18.0.0",
"eslint-config-expensify": "2.0.75",
"eslint-config-expensify": "2.0.76",
"eslint-config-prettier": "^9.1.0",
"eslint-plugin-deprecation": "^3.0.0",
"eslint-plugin-jest": "^28.6.0",
Expand Down
121 changes: 102 additions & 19 deletions src/ROUTES.ts
Original file line number Diff line number Diff line change
Expand Up @@ -493,7 +493,12 @@ const ROUTES = {
},
MONEY_REQUEST_CREATE: {
route: ':action/:iouType/start/:transactionID/:reportID',
getRoute: (action: IOUAction, iouType: IOUType, transactionID: string, reportID: string) => `${action as string}/${iouType as string}/start/${transactionID}/${reportID}` as const,
getRoute: (action: IOUAction, iouType: IOUType, transactionID: string, reportID: string | undefined) => {
if (!reportID) {
Log.warn('Invalid reportID is used to build the MONEY_REQUEST_CREATE route');
}
return `${action as string}/${iouType as string}/start/${transactionID}/${reportID}` as const;
},
},
MONEY_REQUEST_STEP_SEND_FROM: {
route: 'create/:iouType/from/:transactionID/:reportID',
Expand Down Expand Up @@ -730,16 +735,30 @@ const ROUTES = {
},
MONEY_REQUEST_CREATE_TAB_DISTANCE: {
route: ':action/:iouType/start/:transactionID/:reportID/distance',
getRoute: (action: IOUAction, iouType: IOUType, transactionID: string, reportID: string) => `create/${iouType as string}/start/${transactionID}/${reportID}/distance` as const,
getRoute: (action: IOUAction, iouType: IOUType, transactionID: string, reportID: string | undefined) => {
if (!reportID) {
Log.warn('Invalid reportID is used to build the MONEY_REQUEST_CREATE_TAB_DISTANCE route');
}
return `create/${iouType as string}/start/${transactionID}/${reportID}/distance` as const;
},
},
MONEY_REQUEST_CREATE_TAB_MANUAL: {
route: ':action/:iouType/start/:transactionID/:reportID/manual',
getRoute: (action: IOUAction, iouType: IOUType, transactionID: string, reportID: string) =>
`${action as string}/${iouType as string}/start/${transactionID}/${reportID}/manual` as const,
getRoute: (action: IOUAction, iouType: IOUType, transactionID: string, reportID: string | undefined) => {
if (!reportID) {
Log.warn('Invalid reportID is used to build the MONEY_REQUEST_CREATE_TAB_MANUAL route');
}
return `${action as string}/${iouType as string}/start/${transactionID}/${reportID}/manual` as const;
},
},
MONEY_REQUEST_CREATE_TAB_SCAN: {
route: ':action/:iouType/start/:transactionID/:reportID/scan',
getRoute: (action: IOUAction, iouType: IOUType, transactionID: string, reportID: string) => `create/${iouType as string}/start/${transactionID}/${reportID}/scan` as const,
getRoute: (action: IOUAction, iouType: IOUType, transactionID: string, reportID: string | undefined) => {
if (!reportID) {
Log.warn('Invalid reportID is used to build the MONEY_REQUEST_CREATE_TAB_SCAN route');
}
return `create/${iouType as string}/start/${transactionID}/${reportID}/scan` as const;
},
},
MONEY_REQUEST_CREATE_TAB_PER_DIEM: {
route: ':action/:iouType/start/:transactionID/:reportID/per-diem',
Expand Down Expand Up @@ -845,23 +864,43 @@ const ROUTES = {
},
POLICY_ACCOUNTING_QUICKBOOKS_ONLINE_EXPORT: {
route: 'settings/workspaces/:policyID/accounting/quickbooks-online/export',
getRoute: (policyID: string, backTo?: string) => getUrlWithBackToParam(`settings/workspaces/${policyID}/accounting/quickbooks-online/export` as const, backTo, false),
getRoute: (policyID: string | undefined, backTo?: string) => {
if (!policyID) {
Log.warn('Invalid policyID is used to build the POLICY_ACCOUNTING_QUICKBOOKS_ONLINE_EXPORT route');
}
return getUrlWithBackToParam(`settings/workspaces/${policyID}/accounting/quickbooks-online/export` as const, backTo, false);
},
},
POLICY_ACCOUNTING_QUICKBOOKS_ONLINE_COMPANY_CARD_EXPENSE_ACCOUNT: {
route: 'settings/workspaces/:policyID/accounting/quickbooks-online/export/company-card-expense-account',
getRoute: (policyID: string) => `settings/workspaces/${policyID}/accounting/quickbooks-online/export/company-card-expense-account` as const,
},
POLICY_ACCOUNTING_QUICKBOOKS_ONLINE_COMPANY_CARD_EXPENSE_ACCOUNT_SELECT: {
route: 'settings/workspaces/:policyID/accounting/quickbooks-online/export/company-card-expense-account/account-select',
getRoute: (policyID: string) => `settings/workspaces/${policyID}/accounting/quickbooks-online/export/company-card-expense-account/account-select` as const,
getRoute: (policyID: string | undefined) => {
if (!policyID) {
Log.warn('Invalid policyID is used to build the POLICY_ACCOUNTING_QUICKBOOKS_ONLINE_COMPANY_CARD_EXPENSE_ACCOUNT_SELECT route');
}
return `settings/workspaces/${policyID}/accounting/quickbooks-online/export/company-card-expense-account/account-select` as const;
},
},
POLICY_ACCOUNTING_QUICKBOOKS_ONLINE_NON_REIMBURSABLE_DEFAULT_VENDOR_SELECT: {
route: 'settings/workspaces/:policyID/accounting/quickbooks-online/export/company-card-expense-account/default-vendor-select',
getRoute: (policyID: string) => `settings/workspaces/${policyID}/accounting/quickbooks-online/export/company-card-expense-account/default-vendor-select` as const,
getRoute: (policyID: string | undefined) => {
if (!policyID) {
Log.warn('Invalid policyID is used to build the POLICY_ACCOUNTING_QUICKBOOKS_ONLINE_COMPANY_CARD_EXPENSE_SELECT route');
}
return `settings/workspaces/${policyID}/accounting/quickbooks-online/export/company-card-expense-account/default-vendor-select` as const;
},
},
POLICY_ACCOUNTING_QUICKBOOKS_ONLINE_COMPANY_CARD_EXPENSE_SELECT: {
route: 'settings/workspaces/:policyID/accounting/quickbooks-online/export/company-card-expense-account/card-select',
getRoute: (policyID: string) => `settings/workspaces/${policyID}/accounting/quickbooks-online/export/company-card-expense-account/card-select` as const,
getRoute: (policyID: string | undefined) => {
if (!policyID) {
Log.warn('Invalid policyID is used to build the POLICY_ACCOUNTING_QUICKBOOKS_ONLINE_COMPANY_CARD_EXPENSE_SELECT route');
}
return `settings/workspaces/${policyID}/accounting/quickbooks-online/export/company-card-expense-account/card-select` as const;
},
},
POLICY_ACCOUNTING_QUICKBOOKS_ONLINE_INVOICE_ACCOUNT_SELECT: {
route: 'settings/workspaces/:policyID/accounting/quickbooks-online/export/invoice-account-select',
Expand Down Expand Up @@ -1907,36 +1946,75 @@ const ROUTES = {
},
POLICY_ACCOUNTING_NETSUITE_REIMBURSEMENT_ACCOUNT_SELECT: {
route: 'settings/workspaces/:policyID/connections/netsuite/advanced/reimbursement-account/select',
getRoute: (policyID: string) => `settings/workspaces/${policyID}/connections/netsuite/advanced/reimbursement-account/select` as const,
getRoute: (policyID: string | undefined) => {
if (!policyID) {
Log.warn('Invalid policyID is used to build the POLICY_ACCOUNTING_NETSUITE_REIMBURSEMENT_ACCOUNT_SELECT route');
}
return `settings/workspaces/${policyID}/connections/netsuite/advanced/reimbursement-account/select` as const;
},
},
POLICY_ACCOUNTING_NETSUITE_COLLECTION_ACCOUNT_SELECT: {
route: 'settings/workspaces/:policyID/connections/netsuite/advanced/collection-account/select',
getRoute: (policyID: string) => `settings/workspaces/${policyID}/connections/netsuite/advanced/collection-account/select` as const,
getRoute: (policyID: string | undefined) => {
if (!policyID) {
Log.warn('Invalid policyID is used to build the POLICY_ACCOUNTING_NETSUITE_COLLECTION_ACCOUNT_SELECT route');
}
return `settings/workspaces/${policyID}/connections/netsuite/advanced/collection-account/select` as const;
},
},
POLICY_ACCOUNTING_NETSUITE_EXPENSE_REPORT_APPROVAL_LEVEL_SELECT: {
route: 'settings/workspaces/:policyID/connections/netsuite/advanced/expense-report-approval-level/select',
getRoute: (policyID: string) => `settings/workspaces/${policyID}/connections/netsuite/advanced/expense-report-approval-level/select` as const,
getRoute: (policyID: string | undefined) => {
if (!policyID) {
Log.warn('Invalid policyID is used to build the POLICY_ACCOUNTING_NETSUITE_EXPENSE_REPORT_APPROVAL_LEVEL_SELECT route');
}
return `settings/workspaces/${policyID}/connections/netsuite/advanced/expense-report-approval-level/select` as const;
},
},
POLICY_ACCOUNTING_NETSUITE_VENDOR_BILL_APPROVAL_LEVEL_SELECT: {
route: 'settings/workspaces/:policyID/connections/netsuite/advanced/vendor-bill-approval-level/select',
getRoute: (policyID: string) => `settings/workspaces/${policyID}/connections/netsuite/advanced/vendor-bill-approval-level/select` as const,
getRoute: (policyID: string | undefined) => {
if (!policyID) {
Log.warn('Invalid policyID is used to build the POLICY_ACCOUNTING_NETSUITE_VENDOR_BILL_APPROVAL_LEVEL_SELECT route');
}
return `settings/workspaces/${policyID}/connections/netsuite/advanced/vendor-bill-approval-level/select` as const;
},
},
POLICY_ACCOUNTING_NETSUITE_JOURNAL_ENTRY_APPROVAL_LEVEL_SELECT: {
route: 'settings/workspaces/:policyID/connections/netsuite/advanced/journal-entry-approval-level/select',
getRoute: (policyID: string) => `settings/workspaces/${policyID}/connections/netsuite/advanced/journal-entry-approval-level/select` as const,
getRoute: (policyID: string | undefined) => {
if (!policyID) {
Log.warn('Invalid policyID is used to build the POLICY_ACCOUNTING_NETSUITE_JOURNAL_ENTRY_APPROVAL_LEVEL_SELECT route');
}
return `settings/workspaces/${policyID}/connections/netsuite/advanced/journal-entry-approval-level/select` as const;
},
},
POLICY_ACCOUNTING_NETSUITE_APPROVAL_ACCOUNT_SELECT: {
route: 'settings/workspaces/:policyID/connections/netsuite/advanced/approval-account/select',
getRoute: (policyID: string) => `settings/workspaces/${policyID}/connections/netsuite/advanced/approval-account/select` as const,
getRoute: (policyID: string | undefined) => {
if (!policyID) {
Log.warn('Invalid policyID is used to build the POLICY_ACCOUNTING_NETSUITE_APPROVAL_ACCOUNT_SELECT route');
}
return `settings/workspaces/${policyID}/connections/netsuite/advanced/approval-account/select` as const;
},
},
POLICY_ACCOUNTING_NETSUITE_CUSTOM_FORM_ID: {
route: 'settings/workspaces/:policyID/connections/netsuite/advanced/custom-form-id/:expenseType',
getRoute: (policyID: string, expenseType: ValueOf<typeof CONST.NETSUITE_EXPENSE_TYPE>) =>
`settings/workspaces/${policyID}/connections/netsuite/advanced/custom-form-id/${expenseType as string}` as const,
getRoute: (policyID: string | undefined, expenseType: ValueOf<typeof CONST.NETSUITE_EXPENSE_TYPE>) => {
if (!policyID) {
Log.warn('Invalid policyID is used to build the POLICY_ACCOUNTING_NETSUITE_CUSTOM_FORM_ID route');
}
return `settings/workspaces/${policyID}/connections/netsuite/advanced/custom-form-id/${expenseType as string}` as const;
},
},
POLICY_ACCOUNTING_NETSUITE_AUTO_SYNC: {
route: 'settings/workspaces/:policyID/connections/netsuite/advanced/autosync',
getRoute: (policyID: string) => `settings/workspaces/${policyID}/connections/netsuite/advanced/autosync` as const,
getRoute: (policyID: string | undefined) => {
if (!policyID) {
Log.warn('Invalid policyID is used to build the POLICY_ACCOUNTING_NETSUITE_AUTO_SYNC route');
}
return `settings/workspaces/${policyID}/connections/netsuite/advanced/autosync` as const;
},
},
POLICY_ACCOUNTING_NETSUITE_ACCOUNTING_METHOD: {
route: 'settings/workspaces/:policyID/connections/netsuite/advanced/autosync/accounting-method',
Expand Down Expand Up @@ -1972,7 +2050,12 @@ const ROUTES = {
},
POLICY_ACCOUNTING_SAGE_INTACCT_USER_DIMENSIONS: {
route: 'settings/workspaces/:policyID/accounting/sage-intacct/import/user-dimensions',
getRoute: (policyID: string) => `settings/workspaces/${policyID}/accounting/sage-intacct/import/user-dimensions` as const,
getRoute: (policyID: string | undefined) => {
if (!policyID) {
Log.warn('Invalid policyID is used to build the POLICY_ACCOUNTING_SAGE_INTACCT_USER_DIMENSIONS route');
}
return `settings/workspaces/${policyID}/accounting/sage-intacct/import/user-dimensions` as const;
},
},
POLICY_ACCOUNTING_SAGE_INTACCT_ADD_USER_DIMENSION: {
route: 'settings/workspaces/:policyID/accounting/sage-intacct/import/add-user-dimension',
Expand Down
2 changes: 1 addition & 1 deletion src/components/BrokenConnectionDescription.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ type BrokenConnectionDescriptionProps = {
function BrokenConnectionDescription({transactionID, policy, report}: BrokenConnectionDescriptionProps) {
const styles = useThemeStyles();
const {translate} = useLocalize();
const [transactionViolations] = useOnyx(`${ONYXKEYS.COLLECTION.TRANSACTION_VIOLATIONS}${transactionID ?? CONST.DEFAULT_NUMBER_ID}`);
const [transactionViolations] = useOnyx(`${ONYXKEYS.COLLECTION.TRANSACTION_VIOLATIONS}${transactionID}`);

const brokenConnection530Error = transactionViolations?.find((violation) => violation.data?.rterType === CONST.RTER_VIOLATION_TYPES.BROKEN_CARD_CONNECTION_530);
const brokenConnectionError = transactionViolations?.find((violation) => violation.data?.rterType === CONST.RTER_VIOLATION_TYPES.BROKEN_CARD_CONNECTION);
Expand Down
6 changes: 2 additions & 4 deletions src/components/MoneyReportHeader.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -104,10 +104,8 @@ function MoneyReportHeader({policy, report: moneyRequestReport, transactionThrea
// eslint-disable-next-line rulesdir/prefer-shouldUseNarrowLayout-instead-of-isSmallScreenWidth
const {shouldUseNarrowLayout, isSmallScreenWidth} = useResponsiveLayout();
const route = useRoute();
// eslint-disable-next-line @typescript-eslint/prefer-nullish-coalescing
const [chatReport] = useOnyx(`${ONYXKEYS.COLLECTION.REPORT}${moneyRequestReport?.chatReportID || CONST.DEFAULT_NUMBER_ID}`);
// eslint-disable-next-line @typescript-eslint/prefer-nullish-coalescing
const [nextStep] = useOnyx(`${ONYXKEYS.COLLECTION.NEXT_STEP}${moneyRequestReport?.reportID || CONST.DEFAULT_NUMBER_ID}`);
const [chatReport] = useOnyx(`${ONYXKEYS.COLLECTION.REPORT}${moneyRequestReport?.chatReportID}`);
const [nextStep] = useOnyx(`${ONYXKEYS.COLLECTION.NEXT_STEP}${moneyRequestReport?.reportID}`);
const [transactionThreadReport] = useOnyx(`${ONYXKEYS.COLLECTION.REPORT}${transactionThreadReportID}`);
const [session] = useOnyx(ONYXKEYS.SESSION);
const requestParentReportAction = useMemo(() => {
Expand Down
20 changes: 10 additions & 10 deletions src/components/ReportActionItem/MoneyRequestView.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -107,16 +107,16 @@ function MoneyRequestView({report, shouldShowAnimatedBackground, readonly = fals
const {translate, toLocaleDigit} = useLocalize();
const parentReportID = report?.parentReportID;
const policyID = report?.policyID;
const [parentReport] = useOnyx(`${ONYXKEYS.COLLECTION.REPORT}${parentReportID ?? CONST.DEFAULT_NUMBER_ID}`);
const [chatReport] = useOnyx(`${ONYXKEYS.COLLECTION.REPORT}${parentReport?.parentReportID ?? CONST.DEFAULT_NUMBER_ID}`, {
const [parentReport] = useOnyx(`${ONYXKEYS.COLLECTION.REPORT}${parentReportID}`);
const [chatReport] = useOnyx(`${ONYXKEYS.COLLECTION.REPORT}${parentReport?.parentReportID}`, {
selector: (chatReportValue) => chatReportValue && {reportID: chatReportValue.reportID, errorFields: chatReportValue.errorFields},
});
const [policy] = useOnyx(`${ONYXKEYS.COLLECTION.POLICY}${policyID ?? CONST.DEFAULT_NUMBER_ID}`);
const [policyCategories] = useOnyx(`${ONYXKEYS.COLLECTION.POLICY_CATEGORIES}${policyID ?? CONST.DEFAULT_NUMBER_ID}`);
const [transactionReport] = useOnyx(`${ONYXKEYS.COLLECTION.REPORT}${updatedTransaction?.reportID ?? CONST.DEFAULT_NUMBER_ID}`);
const [policy] = useOnyx(`${ONYXKEYS.COLLECTION.POLICY}${policyID}`);
const [policyCategories] = useOnyx(`${ONYXKEYS.COLLECTION.POLICY_CATEGORIES}${policyID}`);
const [transactionReport] = useOnyx(`${ONYXKEYS.COLLECTION.REPORT}${updatedTransaction?.reportID}`);
const targetPolicyID = updatedTransaction?.reportID ? transactionReport?.policyID : policyID;
const [policyTagList] = useOnyx(`${ONYXKEYS.COLLECTION.POLICY_TAGS}${targetPolicyID ?? CONST.DEFAULT_NUMBER_ID}`);
const [parentReportActions] = useOnyx(`${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${parentReportID ?? CONST.DEFAULT_NUMBER_ID}`, {
const [policyTagList] = useOnyx(`${ONYXKEYS.COLLECTION.POLICY_TAGS}${targetPolicyID}`);
const [parentReportActions] = useOnyx(`${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${parentReportID}`, {
canEvict: false,
});

Expand All @@ -131,9 +131,9 @@ function MoneyRequestView({report, shouldShowAnimatedBackground, readonly = fals
return originalMessage?.IOUTransactionID;
}, [parentReportAction]);

const [transaction] = useOnyx(`${ONYXKEYS.COLLECTION.TRANSACTION}${linkedTransactionID ?? CONST.DEFAULT_NUMBER_ID}`);
const [transactionBackup] = useOnyx(`${ONYXKEYS.COLLECTION.TRANSACTION_BACKUP}${linkedTransactionID ?? CONST.DEFAULT_NUMBER_ID}`);
const [transactionViolations] = useOnyx(`${ONYXKEYS.COLLECTION.TRANSACTION_VIOLATIONS}${linkedTransactionID ?? CONST.DEFAULT_NUMBER_ID}`);
const [transaction] = useOnyx(`${ONYXKEYS.COLLECTION.TRANSACTION}${linkedTransactionID}`);
const [transactionBackup] = useOnyx(`${ONYXKEYS.COLLECTION.TRANSACTION_BACKUP}${linkedTransactionID}`);
const [transactionViolations] = useOnyx(`${ONYXKEYS.COLLECTION.TRANSACTION_VIOLATIONS}${linkedTransactionID}`);

const {
created: transactionDate,
Expand Down
2 changes: 1 addition & 1 deletion src/components/ReportActionItem/ReportPreview.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ function ReportPreview({
const [transactionViolations] = useOnyx(ONYXKEYS.COLLECTION.TRANSACTION_VIOLATIONS);
const [userWallet] = useOnyx(ONYXKEYS.USER_WALLET);
const [invoiceReceiverPolicy] = useOnyx(
`${ONYXKEYS.COLLECTION.POLICY}${chatReport?.invoiceReceiver && 'policyID' in chatReport.invoiceReceiver ? chatReport.invoiceReceiver.policyID : CONST.DEFAULT_NUMBER_ID}`,
`${ONYXKEYS.COLLECTION.POLICY}${chatReport?.invoiceReceiver && 'policyID' in chatReport.invoiceReceiver ? chatReport.invoiceReceiver.policyID : undefined}`,
);
const [invoiceReceiverPersonalDetail] = useOnyx(ONYXKEYS.PERSONAL_DETAILS_LIST, {
selector: (personalDetails) =>
Expand Down
Loading

0 comments on commit 8e1aad2

Please sign in to comment.