Skip to content
Merged
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
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@
"test:debug": "TZ=utc NODE_OPTIONS='--inspect-brk --experimental-vm-modules' jest --runInBand",
"perf-test": "NODE_OPTIONS=--experimental-vm-modules npx reassure",
"typecheck": "NODE_OPTIONS=--max_old_space_size=8192 tsc",
"lint": "NODE_OPTIONS=--max_old_space_size=8192 eslint . --max-warnings=326 --cache --cache-location=node_modules/.cache/eslint",
"lint": "NODE_OPTIONS=--max_old_space_size=8192 eslint . --max-warnings=325 --cache --cache-location=node_modules/.cache/eslint",
"lint-changed": "NODE_OPTIONS=--max_old_space_size=8192 ./scripts/lintChanged.sh",
"lint-watch": "npx eslint-watch --watch --changed",
"shellcheck": "./scripts/shellCheck.sh",
Expand Down
9 changes: 8 additions & 1 deletion src/components/TestDrive/Modal/EmployeeTestDriveModal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import TestReceipt from '@assets/images/fake-test-drive-employee-receipt.jpg';
import TextInput from '@components/TextInput';
import useLocalize from '@hooks/useLocalize';
import useOnboardingMessages from '@hooks/useOnboardingMessages';
import useOnyx from '@hooks/useOnyx';
import {
initMoneyRequest,
setMoneyRequestAmount,
Expand All @@ -24,12 +25,16 @@ import type {TestDriveModalNavigatorParamList} from '@libs/Navigation/types';
import {generateReportID} from '@libs/ReportUtils';
import {generateAccountID} from '@libs/UserUtils';
import CONST from '@src/CONST';
import ONYXKEYS from '@src/ONYXKEYS';
import ROUTES from '@src/ROUTES';
import type SCREENS from '@src/SCREENS';
import BaseTestDriveModal from './BaseTestDriveModal';

function EmployeeTestDriveModal() {
const {translate} = useLocalize();
const reportID = generateReportID();
const [report] = useOnyx(`${ONYXKEYS.COLLECTION.REPORT}${reportID}`, {canBeMissing: true});
const [parentReport] = useOnyx(`${ONYXKEYS.COLLECTION.REPORT}${report?.parentReportID}`, {canBeMissing: true});
const route = useRoute<PlatformStackRouteProp<TestDriveModalNavigatorParamList, typeof SCREENS.TEST_DRIVE_MODAL.ROOT>>();
const [bossEmail, setBossEmail] = useState(route.params?.bossEmail ?? '');
const [formError, setFormError] = useState<string | undefined>();
Expand Down Expand Up @@ -57,11 +62,13 @@ function EmployeeTestDriveModal() {
'jpg',
(source, _, filename) => {
const transactionID = CONST.IOU.OPTIMISTIC_TRANSACTION_ID;
const reportID = generateReportID();

initMoneyRequest({
reportID,
isFromGlobalCreate: false,
newIouRequestType: CONST.IOU.REQUEST_TYPE.SCAN,
report,
parentReport,
});

setMoneyRequestReceipt(transactionID, source, filename, true, CONST.TEST_RECEIPT.FILE_TYPE, false, true);
Expand Down
17 changes: 2 additions & 15 deletions src/libs/PerDiemRequestUtils.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
import {addDays, differenceInDays, differenceInMinutes, format, isSameDay, startOfDay} from 'date-fns';
import lodashSortBy from 'lodash/sortBy';
import type {OnyxCollection, OnyxEntry} from 'react-native-onyx';
import Onyx from 'react-native-onyx';
import type {OnyxEntry} from 'react-native-onyx';
import CONST from '@src/CONST';
import ONYXKEYS from '@src/ONYXKEYS';
import type {Report, Transaction} from '@src/types/onyx';
import type {CustomUnit, Rate} from '@src/types/onyx/Policy';
import {translateLocal} from './Localize';
Expand All @@ -12,21 +10,10 @@ import {getPolicy} from './PolicyUtils';
import {isPolicyExpenseChat} from './ReportUtils';
import tokenizedSearch from './tokenizedSearch';

let allReports: OnyxCollection<Report>;
Onyx.connect({
key: ONYXKEYS.COLLECTION.REPORT,
waitForCollectionCallback: true,
callback: (value) => {
allReports = value;
},
});

/**
* Returns custom unit ID for the per diem transaction
*/
function getCustomUnitID(reportID: string) {
const report = allReports?.[`${ONYXKEYS.COLLECTION.REPORT}${reportID}`];
const parentReport = allReports?.[`${ONYXKEYS.COLLECTION.REPORT}${report?.parentReportID}`];
function getCustomUnitID(report: OnyxEntry<Report>, parentReport: OnyxEntry<Report>) {
// This will be fixed as part of https://github.com/Expensify/Expensify/issues/507850
// eslint-disable-next-line deprecation/deprecation
const policy = getPolicy(report?.policyID ?? parentReport?.policyID);
Expand Down
8 changes: 6 additions & 2 deletions src/libs/actions/IOU.ts
Original file line number Diff line number Diff line change
Expand Up @@ -259,6 +259,8 @@
isFromGlobalCreate?: boolean;
currentIouRequestType?: IOURequestType | undefined;
newIouRequestType: IOURequestType;
report: OnyxEntry<OnyxTypes.Report>;
parentReport: OnyxEntry<OnyxTypes.Report>;
};

type MoneyRequestInformation = {
Expand Down Expand Up @@ -630,7 +632,7 @@
};

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

Check warning on line 635 in src/libs/actions/IOU.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 @@ -670,13 +672,13 @@
};

let allBetas: OnyxEntry<OnyxTypes.Beta[]>;
Onyx.connect({

Check warning on line 675 in src/libs/actions/IOU.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.BETAS,
callback: (value) => (allBetas = value),
});

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

Check warning on line 681 in src/libs/actions/IOU.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 @@ -690,7 +692,7 @@
});

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

Check warning on line 695 in src/libs/actions/IOU.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 @@ -699,7 +701,7 @@
});

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

Check warning on line 704 in src/libs/actions/IOU.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 @@ -713,7 +715,7 @@
});

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

Check warning on line 718 in src/libs/actions/IOU.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.SPLIT_TRANSACTION_DRAFT,
waitForCollectionCallback: true,
callback: (value) => {
Expand All @@ -722,7 +724,7 @@
});

let allNextSteps: NonNullable<OnyxCollection<OnyxTypes.ReportNextStep>> = {};
Onyx.connect({

Check warning on line 727 in src/libs/actions/IOU.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.NEXT_STEP,
waitForCollectionCallback: true,
callback: (value) => {
Expand All @@ -731,14 +733,14 @@
});

let allPolicyCategories: OnyxCollection<OnyxTypes.PolicyCategories> = {};
Onyx.connect({

Check warning on line 736 in src/libs/actions/IOU.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_CATEGORIES,
waitForCollectionCallback: true,
callback: (val) => (allPolicyCategories = val),
});

const allPolicies: OnyxCollection<OnyxTypes.Policy> = {};
Onyx.connect({

Check warning on line 743 in src/libs/actions/IOU.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,
callback: (val, key) => {
if (!key) {
Expand Down Expand Up @@ -771,7 +773,7 @@
});

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

Check warning on line 776 in src/libs/actions/IOU.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 Down Expand Up @@ -895,8 +897,10 @@
* @param policy
* @param isFromGlobalCreate
* @param iouRequestType one of manual/scan/distance
* @param report the report to attach the transaction to
* @param parentReport the parent report to attach the transaction to
*/
function initMoneyRequest({reportID, policy, isFromGlobalCreate, currentIouRequestType, newIouRequestType}: InitMoneyRequestParams) {
function initMoneyRequest({reportID, policy, isFromGlobalCreate, currentIouRequestType, newIouRequestType, report, parentReport}: InitMoneyRequestParams) {
// Generate a brand new transactionID
// This will be fixed as part of https://github.com/Expensify/Expensify/issues/507850
// eslint-disable-next-line deprecation/deprecation
Expand Down Expand Up @@ -952,7 +956,7 @@
},
};
if (!isFromGlobalCreate) {
const {customUnitID, category} = getCustomUnitID(reportID);
const {customUnitID, category} = getCustomUnitID(report, parentReport);
comment.customUnit = {...comment.customUnit, customUnitID};
requestCategory = category ?? null;
}
Expand Down
7 changes: 5 additions & 2 deletions src/pages/Search/SearchPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,9 @@ function SearchPage({route}: SearchPageProps) {
const currentUserPersonalDetails = useCurrentUserPersonalDetails();
const isMobileSelectionModeEnabled = useMobileSelectionMode();
const [lastPaymentMethods] = useOnyx(ONYXKEYS.NVP_LAST_PAYMENT_METHOD, {canBeMissing: true});

const newReportID = generateReportID();
const [newReport] = useOnyx(`${ONYXKEYS.COLLECTION.REPORT}${newReportID}`, {canBeMissing: true});
const [newParentReport] = useOnyx(`${ONYXKEYS.COLLECTION.REPORT}${newReport?.parentReportID}`, {canBeMissing: true});
const [activePolicyID] = useOnyx(ONYXKEYS.NVP_ACTIVE_POLICY_ID, {canBeMissing: false});
const [activePolicy] = useOnyx(`${ONYXKEYS.COLLECTION.POLICY}${activePolicyID}`, {canBeMissing: true});

Expand Down Expand Up @@ -392,11 +394,12 @@ function SearchPage({route}: SearchPageProps) {
};

const saveFileAndInitMoneyRequest = (files: FileObject[]) => {
const newReportID = generateReportID();
const initialTransaction = initMoneyRequest({
isFromGlobalCreate: true,
reportID: newReportID,
newIouRequestType: CONST.IOU.REQUEST_TYPE.SCAN,
report: newReport,
parentReport: newParentReport,
});

const newReceiptFiles: ReceiptFile[] = [];
Expand Down
5 changes: 4 additions & 1 deletion src/pages/Share/SubmitDetailsPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ function SubmitDetailsPage({
const [unknownUserDetails] = useOnyx(ONYXKEYS.SHARE_UNKNOWN_USER_DETAILS, {canBeMissing: true});
const [personalDetails] = useOnyx(`${ONYXKEYS.PERSONAL_DETAILS_LIST}`, {canBeMissing: true});
const report: OnyxEntry<ReportType> = getReportOrDraftReport(reportOrAccountID);
const [parentReport] = useOnyx(`${ONYXKEYS.COLLECTION.REPORT}${report?.parentReportID}`, {canBeMissing: true});
const [policy] = useOnyx(`${ONYXKEYS.COLLECTION.POLICY}${report?.policyID}`, {canBeMissing: false});
const [transaction] = useOnyx(`${ONYXKEYS.COLLECTION.TRANSACTION_DRAFT}${CONST.IOU.OPTIMISTIC_TRANSACTION_ID}`, {canBeMissing: true});
const [policyCategories] = useOnyx(`${ONYXKEYS.COLLECTION.POLICY_CATEGORIES}${getIOURequestPolicyID(transaction, report)}`, {canBeMissing: false});
Expand All @@ -69,8 +70,10 @@ function SubmitDetailsPage({
policy,
currentIouRequestType: CONST.IOU.REQUEST_TYPE.SCAN,
newIouRequestType: CONST.IOU.REQUEST_TYPE.SCAN,
report,
parentReport,
});
}, [reportOrAccountID, policy]);
}, [reportOrAccountID, policy, report, parentReport]);

const selectedParticipants = unknownUserDetails ? [unknownUserDetails] : getMoneyRequestParticipantsFromReport(report);
const participants = selectedParticipants.map((participant) =>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ function ReportActionCompose({
const [blockedFromConcierge] = useOnyx(ONYXKEYS.NVP_BLOCKED_FROM_CONCIERGE, {canBeMissing: true});
const [shouldShowComposeInput = true] = useOnyx(ONYXKEYS.SHOULD_SHOW_COMPOSE_INPUT, {canBeMissing: true});
const [policy] = useOnyx(`${ONYXKEYS.COLLECTION.POLICY}${report?.policyID}`, {canBeMissing: true});

const [newParentReport] = useOnyx(`${ONYXKEYS.COLLECTION.REPORT}${report?.parentReportID}`, {canBeMissing: true});
/**
* Updates the Highlight state of the composer
*/
Expand Down Expand Up @@ -496,6 +496,8 @@ function ReportActionCompose({
const initialTransaction = initMoneyRequest({
reportID,
newIouRequestType: CONST.IOU.REQUEST_TYPE.SCAN,
report,
parentReport: newParentReport,
});

files.forEach((file, index) => {
Expand Down
5 changes: 4 additions & 1 deletion src/pages/iou/request/IOURequestStartPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ function IOURequestStartPage({
const shouldUseTab = iouType !== CONST.IOU.TYPE.SEND && iouType !== CONST.IOU.TYPE.PAY && iouType !== CONST.IOU.TYPE.INVOICE;
const [isDraggingOver, setIsDraggingOver] = useState(false);
const [report] = useOnyx(`${ONYXKEYS.COLLECTION.REPORT}${reportID}`, {canBeMissing: true});
const [parentReport] = useOnyx(`${ONYXKEYS.COLLECTION.REPORT}${report?.parentReportID}`, {canBeMissing: true});
const policy = usePolicy(report?.policyID);
const [selectedTab, selectedTabResult] = useOnyx(`${ONYXKEYS.COLLECTION.SELECTED_TAB}${CONST.TAB.IOU_REQUEST_TYPE}`, {canBeMissing: true});
const [session] = useOnyx(ONYXKEYS.SESSION, {canBeMissing: false});
Expand Down Expand Up @@ -126,9 +127,11 @@ function IOURequestStartPage({
isFromGlobalCreate,
currentIouRequestType: transaction?.iouRequestType,
newIouRequestType: newIOUType,
report,
parentReport,
});
},
[policy, reportID, isFromGlobalCreate, transaction],
[policy, reportID, isFromGlobalCreate, transaction, report, parentReport],
);

// Clear out the temporary expense if the reportID in the URL has changed from the transaction's reportID.
Expand Down
14 changes: 14 additions & 0 deletions tests/actions/IOUTest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5668,6 +5668,14 @@ describe('actions/IOU', () => {
type: CONST.POLICY.TYPE.TEAM,
outputCurrency: 'USD',
};

const fakeParentReport: Report = {
...createRandomReport(1),
reportID: fakeReport.reportID,
type: CONST.REPORT.TYPE.EXPENSE,
policyID: '1',
managerID: CARLOS_ACCOUNT_ID,
};
const fakePersonalPolicy: Policy = {
...createRandomPolicy(2),
type: CONST.POLICY.TYPE.PERSONAL,
Expand Down Expand Up @@ -5715,6 +5723,8 @@ describe('actions/IOU', () => {
policy: fakePolicy,
isFromGlobalCreate: true,
newIouRequestType: CONST.IOU.REQUEST_TYPE.MANUAL,
report: fakeReport,
parentReport: fakeParentReport,
});
})
.then(async () => {
Expand All @@ -5731,6 +5741,8 @@ describe('actions/IOU', () => {
isFromGlobalCreate: true,
currentIouRequestType: CONST.IOU.REQUEST_TYPE.MANUAL,
newIouRequestType: CONST.IOU.REQUEST_TYPE.SCAN,
report: fakeReport,
parentReport: fakeParentReport,
});
})
.then(async () => {
Expand All @@ -5747,6 +5759,8 @@ describe('actions/IOU', () => {
reportID: fakeReport.reportID,
isFromGlobalCreate: true,
newIouRequestType: CONST.IOU.REQUEST_TYPE.MANUAL,
report: fakeReport,
parentReport: fakeParentReport,
});
})
.then(async () => {
Expand Down
61 changes: 61 additions & 0 deletions tests/unit/PerDiemRequestUtilsTest.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,36 @@
import Onyx from 'react-native-onyx';
import type {DestinationTreeSection} from '@libs/PerDiemRequestUtils';
import {getDestinationListSections} from '@libs/PerDiemRequestUtils';
import CONST from '@src/CONST';
import {getCustomUnitID} from '@src/libs/PerDiemRequestUtils';
import ONYXKEYS from '@src/ONYXKEYS';
import type {Policy, Report} from '@src/types/onyx';
import type {Rate} from '@src/types/onyx/Policy';
import {getFakePolicy, getFakeReport} from '../utils/LHNTestUtils';

const policyID = '1';
const report: Report = {
...getFakeReport(),
policyID,
chatType: CONST.REPORT.CHAT_TYPE.POLICY_EXPENSE_CHAT,
};

const parentReport: Report = {
...getFakeReport(),
policyID,
};

describe('PerDiemRequestUtils', () => {
beforeAll(() =>
Onyx.init({
keys: ONYXKEYS,
}),
);

beforeEach(() => {
Onyx.clear();
});

it('getDestinationListSections()', () => {
const tokenizeSearch = 'Antigua Barbuda';

Expand Down Expand Up @@ -48,4 +76,37 @@ describe('PerDiemRequestUtils', () => {
});
expect(tokenizeSearchResult).toStrictEqual(searchResultList);
});

describe('getCustomUnitID', () => {
it('should return the correct custom unit ID', async () => {
const policy: Policy = {
...getFakePolicy(),
id: policyID,
customUnits: {
[CONST.CUSTOM_UNITS.DISTANCE_UNIT_KILOMETERS]: {
name: CONST.CUSTOM_UNITS.NAME_PER_DIEM_INTERNATIONAL,
customUnitID: CONST.CUSTOM_UNITS.DISTANCE_UNIT_KILOMETERS,
rates: {},
},
},
};

await Onyx.set(`${ONYXKEYS.COLLECTION.POLICY}${policyID}`, policy);

const customUnitID = getCustomUnitID(report, parentReport);
expect(customUnitID.customUnitID).toBe(CONST.CUSTOM_UNITS.DISTANCE_UNIT_KILOMETERS);
});

it('should return fake P2P ID if the policy does not have a custom unit', async () => {
const policy: Policy = {
...getFakePolicy(),
customUnits: {},
};

await Onyx.set(`${ONYXKEYS.COLLECTION.POLICY}${policyID}`, policy);

const customUnitID = getCustomUnitID(report, parentReport);
expect(customUnitID.customUnitID).toBe(CONST.CUSTOM_UNITS.FAKE_P2P_ID);
});
});
});
Loading