Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 8 additions & 8 deletions src/libs/actions/IOU/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -791,7 +791,7 @@
};

let allPersonalDetails: OnyxTypes.PersonalDetailsList = {};
Onyx.connect({

Check warning on line 794 in src/libs/actions/IOU/index.ts

View workflow job for this annotation

GitHub Actions / Changed files ESLint check

Onyx.connect() is deprecated. Use useOnyx() hook instead and pass the data as parameters to a pure function
key: ONYXKEYS.PERSONAL_DETAILS_LIST,
callback: (value) => {
allPersonalDetails = value ?? {};
Expand Down Expand Up @@ -885,7 +885,7 @@
};

let allTransactions: NonNullable<OnyxCollection<OnyxTypes.Transaction>> = {};
Onyx.connect({

Check warning on line 888 in src/libs/actions/IOU/index.ts

View workflow job for this annotation

GitHub Actions / Changed files ESLint check

Onyx.connect() is deprecated. Use useOnyx() hook instead and pass the data as parameters to a pure function
key: ONYXKEYS.COLLECTION.TRANSACTION,
waitForCollectionCallback: true,
callback: (value) => {
Expand All @@ -899,7 +899,7 @@
});

let allTransactionDrafts: NonNullable<OnyxCollection<OnyxTypes.Transaction>> = {};
Onyx.connect({

Check warning on line 902 in src/libs/actions/IOU/index.ts

View workflow job for this annotation

GitHub Actions / Changed files ESLint check

Onyx.connect() is deprecated. Use useOnyx() hook instead and pass the data as parameters to a pure function
key: ONYXKEYS.COLLECTION.TRANSACTION_DRAFT,
waitForCollectionCallback: true,
callback: (value) => {
Expand All @@ -908,7 +908,7 @@
});

let allTransactionViolations: NonNullable<OnyxCollection<OnyxTypes.TransactionViolations>> = {};
Onyx.connect({

Check warning on line 911 in src/libs/actions/IOU/index.ts

View workflow job for this annotation

GitHub Actions / Changed files ESLint check

Onyx.connect() is deprecated. Use useOnyx() hook instead and pass the data as parameters to a pure function
key: ONYXKEYS.COLLECTION.TRANSACTION_VIOLATIONS,
waitForCollectionCallback: true,
callback: (value) => {
Expand All @@ -922,7 +922,7 @@
});

let allPolicyTags: OnyxCollection<OnyxTypes.PolicyTagLists> = {};
Onyx.connect({

Check warning on line 925 in src/libs/actions/IOU/index.ts

View workflow job for this annotation

GitHub Actions / Changed files ESLint check

Onyx.connect() is deprecated. Use useOnyx() hook instead and pass the data as parameters to a pure function
key: ONYXKEYS.COLLECTION.POLICY_TAGS,
waitForCollectionCallback: true,
callback: (value) => {
Expand All @@ -935,7 +935,7 @@
});

let allReports: OnyxCollection<OnyxTypes.Report>;
Onyx.connect({

Check warning on line 938 in src/libs/actions/IOU/index.ts

View workflow job for this annotation

GitHub Actions / Changed files ESLint check

Onyx.connect() is deprecated. Use useOnyx() hook instead and pass the data as parameters to a pure function
key: ONYXKEYS.COLLECTION.REPORT,
waitForCollectionCallback: true,
callback: (value) => {
Expand All @@ -944,7 +944,7 @@
});

let allReportNameValuePairs: OnyxCollection<OnyxTypes.ReportNameValuePairs>;
Onyx.connect({

Check warning on line 947 in src/libs/actions/IOU/index.ts

View workflow job for this annotation

GitHub Actions / Changed files ESLint check

Onyx.connect() is deprecated. Use useOnyx() hook instead and pass the data as parameters to a pure function
key: ONYXKEYS.COLLECTION.REPORT_NAME_VALUE_PAIRS,
waitForCollectionCallback: true,
callback: (value) => {
Expand All @@ -954,7 +954,7 @@

let userAccountID = -1;
let currentUserEmail = '';
Onyx.connect({

Check warning on line 957 in src/libs/actions/IOU/index.ts

View workflow job for this annotation

GitHub Actions / Changed files ESLint check

Onyx.connect() is deprecated. Use useOnyx() hook instead and pass the data as parameters to a pure function
key: ONYXKEYS.SESSION,
callback: (value) => {
currentUserEmail = value?.email ?? '';
Expand All @@ -963,7 +963,7 @@
});

let deprecatedCurrentUserPersonalDetails: OnyxEntry<OnyxTypes.PersonalDetails>;
Onyx.connect({

Check warning on line 966 in src/libs/actions/IOU/index.ts

View workflow job for this annotation

GitHub Actions / Changed files ESLint check

Onyx.connect() is deprecated. Use useOnyx() hook instead and pass the data as parameters to a pure function
key: ONYXKEYS.PERSONAL_DETAILS_LIST,
callback: (value) => {
deprecatedCurrentUserPersonalDetails = value?.[userAccountID] ?? undefined;
Expand All @@ -971,7 +971,7 @@
});

let allReportActions: OnyxCollection<OnyxTypes.ReportActions>;
Onyx.connect({

Check warning on line 974 in src/libs/actions/IOU/index.ts

View workflow job for this annotation

GitHub Actions / Changed files ESLint check

Onyx.connect() is deprecated. Use useOnyx() hook instead and pass the data as parameters to a pure function
key: ONYXKEYS.COLLECTION.REPORT_ACTIONS,
waitForCollectionCallback: true,
callback: (actions) => {
Expand Down Expand Up @@ -1741,13 +1741,14 @@
* Set the distance rate of a transaction.
* Used when creating a new transaction or moving an existing one from Self DM
*/
function setMoneyRequestDistanceRate(transactionID: string, customUnitRateID: string, policy: OnyxEntry<OnyxTypes.Policy>, isDraft: boolean) {
function setMoneyRequestDistanceRate(currentTransaction: OnyxEntry<OnyxTypes.Transaction>, customUnitRateID: string, policy: OnyxEntry<OnyxTypes.Policy>, isDraft: boolean) {
if (policy) {
Onyx.merge(ONYXKEYS.NVP_LAST_SELECTED_DISTANCE_RATES, {[policy.id]: customUnitRateID});
}

const distanceRate = DistanceRequestUtils.getRateByCustomUnitRateID({policy, customUnitRateID});
const transaction = isDraft ? allTransactionDrafts[`${ONYXKEYS.COLLECTION.TRANSACTION_DRAFT}${transactionID}`] : allTransactions[`${ONYXKEYS.COLLECTION.TRANSACTION}${transactionID}`];
const transactionID = currentTransaction?.transactionID;
const transaction = isDraft ? allTransactionDrafts[`${ONYXKEYS.COLLECTION.TRANSACTION_DRAFT}${transactionID}`] : currentTransaction;
let newDistance;
if (distanceRate?.unit && distanceRate?.unit !== transaction?.comment?.customUnit?.distanceUnit) {
newDistance = DistanceRequestUtils.convertDistanceUnit(getDistanceInMeters(transaction, transaction?.comment?.customUnit?.distanceUnit), distanceRate.unit);
Expand Down Expand Up @@ -5792,7 +5793,7 @@

/** Updates the distance rate of an expense */
function updateMoneyRequestDistanceRate({
transactionID,
transaction,

Check failure on line 5796 in src/libs/actions/IOU/index.ts

View workflow job for this annotation

GitHub Actions / typecheck

Property 'transaction' does not exist on type '{ transactionID: OnyxEntry<{ amount: number; accountant?: Accountant | undefined; convertedAmount?: number | undefined; taxAmount?: number | undefined; convertedTaxAmount?: number | undefined; ... 53 more ...; transactionType?: string | undefined; } & OfflineFeedback<...>>; ... 11 more ...; parentReportNextStep: Ony...'.
transactionThreadReport,
parentReport,
rateID,
Expand All @@ -5806,7 +5807,7 @@
updatedTaxCode,
parentReportNextStep,
}: {
transactionID: string;
transactionID: OnyxEntry<OnyxTypes.Transaction>;
transactionThreadReport: OnyxEntry<OnyxTypes.Report>;
parentReport: OnyxEntry<OnyxTypes.Report>;
rateID: string;
Expand All @@ -5826,24 +5827,23 @@
...(updatedTaxCode ? {taxCode: updatedTaxCode} : {}),
};

const transaction = allTransactions?.[`${ONYXKEYS.COLLECTION.TRANSACTION}${transactionID}`];
if (transaction) {
if (transaction?.transactionID) {

Check failure on line 5830 in src/libs/actions/IOU/index.ts

View workflow job for this annotation

GitHub Actions / Changed files ESLint check

Unsafe member access .transactionID on an `error` typed value

Check failure on line 5830 in src/libs/actions/IOU/index.ts

View workflow job for this annotation

GitHub Actions / Changed files ESLint check

Unsafe member access .transactionID on an `error` typed value

Check failure on line 5830 in src/libs/actions/IOU/index.ts

View workflow job for this annotation

GitHub Actions / ESLint check

Unsafe member access .transactionID on an `error` typed value

Check failure on line 5830 in src/libs/actions/IOU/index.ts

View workflow job for this annotation

GitHub Actions / ESLint check

Unsafe member access .transactionID on an `error` typed value
const existingDistanceUnit = transaction?.comment?.customUnit?.distanceUnit;

Check failure on line 5831 in src/libs/actions/IOU/index.ts

View workflow job for this annotation

GitHub Actions / Changed files ESLint check

Unsafe assignment of an error typed value

Check failure on line 5831 in src/libs/actions/IOU/index.ts

View workflow job for this annotation

GitHub Actions / Changed files ESLint check

Unsafe member access .comment on an `error` typed value

Check failure on line 5831 in src/libs/actions/IOU/index.ts

View workflow job for this annotation

GitHub Actions / Changed files ESLint check

Unsafe assignment of an error typed value

Check failure on line 5831 in src/libs/actions/IOU/index.ts

View workflow job for this annotation

GitHub Actions / ESLint check

Unsafe assignment of an error typed value

Check failure on line 5831 in src/libs/actions/IOU/index.ts

View workflow job for this annotation

GitHub Actions / ESLint check

Unsafe member access .comment on an `error` typed value

Check failure on line 5831 in src/libs/actions/IOU/index.ts

View workflow job for this annotation

GitHub Actions / ESLint check

Unsafe assignment of an error typed value
const newDistanceUnit = DistanceRequestUtils.getRateByCustomUnitRateID({customUnitRateID: rateID, policy})?.unit;

// If the distanceUnit is set and the rate is changed to one that has a different unit, mark the merchant as modified to make the distance field pending
if (existingDistanceUnit && newDistanceUnit && newDistanceUnit !== existingDistanceUnit) {
transactionChanges.merchant = getMerchant(transaction);

Check failure on line 5836 in src/libs/actions/IOU/index.ts

View workflow job for this annotation

GitHub Actions / Changed files ESLint check

Unsafe argument of type error typed assigned to a parameter of type `OnyxInputOrEntry<{ amount: number; accountant?: Accountant | undefined; convertedAmount?: number | undefined; taxAmount?: number | undefined; convertedTaxAmount?: number | undefined; ... 53 more ...; transactionType?: string | undefined; } & OfflineFeedback<...>>`

Check failure on line 5836 in src/libs/actions/IOU/index.ts

View workflow job for this annotation

GitHub Actions / ESLint check

Unsafe argument of type error typed assigned to a parameter of type `OnyxInputOrEntry<{ amount: number; accountant?: Accountant | undefined; convertedAmount?: number | undefined; taxAmount?: number | undefined; convertedTaxAmount?: number | undefined; ... 53 more ...; transactionType?: string | undefined; } & OfflineFeedback<...>>`
}
}

let data: UpdateMoneyRequestData<UpdateMoneyRequestDataKeys>;
// eslint-disable-next-line @typescript-eslint/no-deprecated
if (isTrackExpenseReport(transactionThreadReport) && isSelfDM(parentReport)) {
data = getUpdateTrackExpenseParams(transactionID, transactionThreadReport?.reportID, transactionChanges, policy);
data = getUpdateTrackExpenseParams(transaction?.transactionID, transactionThreadReport?.reportID, transactionChanges, policy);

Check failure on line 5843 in src/libs/actions/IOU/index.ts

View workflow job for this annotation

GitHub Actions / Changed files ESLint check

Unsafe member access .transactionID on an `error` typed value

Check failure on line 5843 in src/libs/actions/IOU/index.ts

View workflow job for this annotation

GitHub Actions / Changed files ESLint check

Unsafe argument of type error typed assigned to a parameter of type `string | undefined`

Check failure on line 5843 in src/libs/actions/IOU/index.ts

View workflow job for this annotation

GitHub Actions / ESLint check

Unsafe member access .transactionID on an `error` typed value

Check failure on line 5843 in src/libs/actions/IOU/index.ts

View workflow job for this annotation

GitHub Actions / ESLint check

Unsafe argument of type error typed assigned to a parameter of type `string | undefined`
} else {
data = getUpdateMoneyRequestParams({
transactionID,
transactionID: transaction?.transactionID,

Check failure on line 5846 in src/libs/actions/IOU/index.ts

View workflow job for this annotation

GitHub Actions / Changed files ESLint check

Unsafe member access .transactionID on an `error` typed value

Check failure on line 5846 in src/libs/actions/IOU/index.ts

View workflow job for this annotation

GitHub Actions / Changed files ESLint check

Unsafe assignment of an error typed value

Check failure on line 5846 in src/libs/actions/IOU/index.ts

View workflow job for this annotation

GitHub Actions / ESLint check

Unsafe member access .transactionID on an `error` typed value

Check failure on line 5846 in src/libs/actions/IOU/index.ts

View workflow job for this annotation

GitHub Actions / ESLint check

Unsafe assignment of an error typed value
transactionThreadReport,
iouReport: parentReport,
transactionChanges,
Expand Down
4 changes: 2 additions & 2 deletions src/pages/iou/request/step/IOURequestStepDistanceRate.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -119,11 +119,11 @@
}

if (currentRateID !== customUnitRateID) {
setMoneyRequestDistanceRate(transactionID, customUnitRateID, policy, shouldUseTransactionDraft(action));
setMoneyRequestDistanceRate(transaction, customUnitRateID, policy, shouldUseTransactionDraft(action));

if (isEditing && transaction?.transactionID) {
updateMoneyRequestDistanceRate({
transactionID: transaction.transactionID,
transaction,

Check failure on line 126 in src/pages/iou/request/step/IOURequestStepDistanceRate.tsx

View workflow job for this annotation

GitHub Actions / typecheck

Object literal may only specify known properties, but 'transaction' does not exist in type '{ transactionID: OnyxEntry<{ amount: number; accountant?: Accountant | undefined; convertedAmount?: number | undefined; taxAmount?: number | undefined; convertedTaxAmount?: number | undefined; ... 53 more ...; transactionType?: string | undefined; } & OfflineFeedback<...>>; ... 11 more ...; parentReportNextStep: Ony...'. Did you mean to write 'transactionID'?
transactionThreadReport: report,
parentReport,
parentReportNextStep,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,11 @@ import HeaderWithBackButton from '@components/HeaderWithBackButton';
import ScreenWrapper from '@components/ScreenWrapper';
import useAutoFocusInput from '@hooks/useAutoFocusInput';
import useLocalize from '@hooks/useLocalize';
import useOnyx from '@hooks/useOnyx';
import usePolicy from '@hooks/usePolicy';
import useThemeStyles from '@hooks/useThemeStyles';
import {setMoneyRequestDistanceRate} from '@libs/actions/IOU';
import getNonEmptyStringOnyxID from '@libs/getNonEmptyStringOnyxID';
import type {PlatformStackScreenProps} from '@libs/Navigation/PlatformStackNavigation/types';
import {getOptimisticRateName, validateRateValue} from '@libs/PolicyDistanceRatesUtils';
import {getDistanceRateCustomUnit} from '@libs/PolicyUtils';
Expand Down Expand Up @@ -43,6 +45,7 @@ function CreateDistanceRatePage({
const customUnitRateID = generateCustomUnitID();
const {inputCallbackRef} = useAutoFocusInput();
const isDistanceRateUpgrade = transactionID && reportID;
const [transaction] = useOnyx(`${ONYXKEYS.COLLECTION.TRANSACTION}${getNonEmptyStringOnyxID(transactionID)}`, {canBeMissing: true});

const FullPageBlockingView = !customUnitID ? FullPageOfflineBlockingView : View;

Expand All @@ -67,7 +70,7 @@ function CreateDistanceRatePage({

createPolicyDistanceRate(policyID, customUnitID, newRate);
if (isDistanceRateUpgrade) {
setMoneyRequestDistanceRate(transactionID, customUnitRateID, policy, true);
setMoneyRequestDistanceRate(transaction, customUnitRateID, policy, true);
Navigation.goBack(ROUTES.MONEY_REQUEST_STEP_CONFIRMATION.getRoute(CONST.IOU.ACTION.CREATE, CONST.IOU.TYPE.SUBMIT, transactionID, reportID), {compareParams: false});
return;
}
Expand Down
Loading