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
6 changes: 2 additions & 4 deletions src/components/CurrentUserPersonalDetailsProvider.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,10 @@ import type {OnyxEntry} from 'react-native-onyx';
import useOnyx from '@hooks/useOnyx';
import CONST from '@src/CONST';
import ONYXKEYS from '@src/ONYXKEYS';
import type {PersonalDetails, PersonalDetailsList} from '@src/types/onyx';
import type {PersonalDetailsList} from '@src/types/onyx';
import type {CurrentUserPersonalDetails} from '@src/types/onyx/PersonalDetails';
import {useSession} from './OnyxListItemProvider';

type CurrentUserPersonalDetails = PersonalDetails & {email?: string};

const defaultCurrentUserPersonalDetails: CurrentUserPersonalDetails = {
accountID: CONST.DEFAULT_NUMBER_ID,
};
Expand All @@ -32,4 +31,3 @@ function CurrentUserPersonalDetailsProvider({children}: {children: React.ReactNo
}

export {CurrentUserPersonalDetailsContext, CurrentUserPersonalDetailsProvider};
export type {CurrentUserPersonalDetails};
3 changes: 3 additions & 0 deletions src/components/TestDrive/Modal/EmployeeTestDriveModal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import React, {useCallback, useState} from 'react';
import {InteractionManager} from 'react-native';
import TestReceipt from '@assets/images/fake-test-drive-employee-receipt.jpg';
import TextInput from '@components/TextInput';
import useCurrentUserPersonalDetails from '@hooks/useCurrentUserPersonalDetails';
import useLocalize from '@hooks/useLocalize';
import useOnboardingMessages from '@hooks/useOnboardingMessages';
import useOnyx from '@hooks/useOnyx';
Expand Down Expand Up @@ -43,6 +44,7 @@ function EmployeeTestDriveModal() {
const [formError, setFormError] = useState<string | undefined>();
const [isLoading, setIsLoading] = useState(false);
const {testDrive} = useOnboardingMessages();
const currentUserPersonalDetails = useCurrentUserPersonalDetails();

const onBossEmailChange = useCallback((value: string) => {
setBossEmail(value);
Expand Down Expand Up @@ -75,6 +77,7 @@ function EmployeeTestDriveModal() {
report,
parentReport,
currentDate,
currentUserPersonalDetails,
});

setMoneyRequestReceipt(transactionID, source, filename, true, CONST.TEST_RECEIPT.FILE_TYPE, false, true);
Expand Down
2 changes: 1 addition & 1 deletion src/components/withCurrentUserPersonalDetails.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import type {ComponentType} from 'react';
import React from 'react';
import useCurrentUserPersonalDetails from '@hooks/useCurrentUserPersonalDetails';
import getComponentDisplayName from '@libs/getComponentDisplayName';
import type {CurrentUserPersonalDetails} from './CurrentUserPersonalDetailsProvider';
import type {CurrentUserPersonalDetails} from '@src/types/onyx/PersonalDetails';

type HOCProps = {
currentUserPersonalDetails: CurrentUserPersonalDetails;
Expand Down
29 changes: 16 additions & 13 deletions src/libs/actions/IOU.ts
Original file line number Diff line number Diff line change
Expand Up @@ -245,6 +245,7 @@ import type * as OnyxTypes from '@src/types/onyx';
import type {Accountant, Attendee, Participant, Split, SplitExpense} from '@src/types/onyx/IOU';
import type {ErrorFields, Errors, PendingAction, PendingFields} from '@src/types/onyx/OnyxCommon';
import type {PaymentMethodType} from '@src/types/onyx/OriginalMessage';
import type {CurrentUserPersonalDetails} from '@src/types/onyx/PersonalDetails';
import type {QuickActionName} from '@src/types/onyx/QuickAction';
import type RecentlyUsedTags from '@src/types/onyx/RecentlyUsedTags';
import type {InvoiceReceiver, InvoiceReceiverType} from '@src/types/onyx/Report';
Expand Down Expand Up @@ -295,6 +296,7 @@ type InitMoneyRequestParams = {
currentDate: string | undefined;
lastSelectedDistanceRates?: OnyxEntry<OnyxTypes.LastSelectedDistanceRates>;
localeCompare?: (a: string, b: string) => number;
currentUserPersonalDetails: CurrentUserPersonalDetails;
};

type MoneyRequestInformation = {
Expand Down Expand Up @@ -876,11 +878,11 @@ Onyx.connect({
},
});

let currentUserPersonalDetails: OnyxEntry<OnyxTypes.PersonalDetails>;
let deprecatedCurrentUserPersonalDetails: OnyxEntry<OnyxTypes.PersonalDetails>;
Onyx.connect({
key: ONYXKEYS.PERSONAL_DETAILS_LIST,
callback: (value) => {
currentUserPersonalDetails = value?.[userAccountID] ?? undefined;
deprecatedCurrentUserPersonalDetails = value?.[userAccountID] ?? undefined;
},
});

Expand Down Expand Up @@ -1001,6 +1003,7 @@ function initMoneyRequest({
currentDate = '',
lastSelectedDistanceRates,
localeCompare,
currentUserPersonalDetails,
}: InitMoneyRequestParams) {
// Generate a brand new transactionID
// This will be fixed as part of https://github.com/Expensify/Expensify/issues/507850
Expand Down Expand Up @@ -1511,7 +1514,7 @@ function buildOnyxDataForTestDriveIOU(testDriveIOUParams: BuildOnyxDataForTestDr
value: {
...{lastActionType: CONST.REPORT.ACTIONS.TYPE.MARKED_REIMBURSED, statusNum: CONST.REPORT.STATUS_NUM.REIMBURSED},
hasOutstandingChildRequest: false,
lastActorAccountID: currentUserPersonalDetails?.accountID,
lastActorAccountID: deprecatedCurrentUserPersonalDetails?.accountID,
},
},
{
Expand Down Expand Up @@ -1775,7 +1778,7 @@ function buildOnyxDataForMoneyRequest(moneyRequestParams: BuildOnyxDataForMoneyR
...iou.report,
...(!isScanRequest || isTestReceipt ? {lastActionType: CONST.REPORT.ACTIONS.TYPE.MARKED_REIMBURSED, statusNum: CONST.REPORT.STATUS_NUM.REIMBURSED} : undefined),
hasOutstandingChildRequest: false,
lastActorAccountID: currentUserPersonalDetails?.accountID,
lastActorAccountID: deprecatedCurrentUserPersonalDetails?.accountID,
},
},
{
Expand Down Expand Up @@ -10836,9 +10839,9 @@ function submitReport(

const currentNextStep = allNextSteps[`${ONYXKEYS.COLLECTION.NEXT_STEP}${expenseReport.reportID}`] ?? null;
const parentReport = getReportOrDraftReport(expenseReport.parentReportID);
const isCurrentUserManager = currentUserPersonalDetails?.accountID === expenseReport.managerID;
const isCurrentUserManager = currentUserAccountIDParam === expenseReport.managerID;
const isSubmitAndClosePolicy = isSubmitAndClose(policy);
const adminAccountID = policy?.role === CONST.POLICY.ROLE.ADMIN ? currentUserPersonalDetails?.accountID : undefined;
const adminAccountID = policy?.role === CONST.POLICY.ROLE.ADMIN ? currentUserAccountIDParam : undefined;
const optimisticSubmittedReportAction = buildOptimisticSubmittedReportAction(expenseReport?.total ?? 0, expenseReport.currency ?? '', expenseReport.reportID, adminAccountID);
const optimisticNextStep = buildNextStepNew({
report: expenseReport,
Expand Down Expand Up @@ -11538,7 +11541,7 @@ function replaceReceipt({transactionID, file, source, transactionPolicyCategorie
function getMoneyRequestParticipantsFromReport(report: OnyxEntry<OnyxTypes.Report>): Participant[] {
// If the report is iou or expense report, we should get the chat report to set participant for request money
const chatReport = isMoneyRequestReportReportUtils(report) ? getReportOrDraftReport(report?.chatReportID) : report;
const currentUserAccountID = currentUserPersonalDetails?.accountID;
const currentUserAccountID = deprecatedCurrentUserPersonalDetails?.accountID;
const shouldAddAsReport = !isEmptyObject(chatReport) && isSelfDM(chatReport);
let participants: Participant[] = [];

Expand Down Expand Up @@ -12627,7 +12630,7 @@ function getSearchOnyxUpdate({
isInvoice,
}: GetSearchOnyxUpdateParams): OnyxData | undefined {
const toAccountID = participant?.accountID;
const fromAccountID = currentUserPersonalDetails?.accountID;
const fromAccountID = deprecatedCurrentUserPersonalDetails?.accountID;
const currentSearchQueryJSON = getCurrentSearchQueryJSON();

if (currentSearchQueryJSON && toAccountID != null && fromAccountID != null) {
Expand Down Expand Up @@ -12671,9 +12674,9 @@ function getSearchOnyxUpdate({
},
[fromAccountID]: {
accountID: fromAccountID,
avatar: currentUserPersonalDetails?.avatar,
displayName: currentUserPersonalDetails?.displayName,
login: currentUserPersonalDetails?.login,
avatar: deprecatedCurrentUserPersonalDetails?.avatar,
displayName: deprecatedCurrentUserPersonalDetails?.displayName,
login: deprecatedCurrentUserPersonalDetails?.login,
},
},
[`${ONYXKEYS.COLLECTION.TRANSACTION}${transaction.transactionID}`]: {
Expand Down Expand Up @@ -13835,8 +13838,8 @@ function updateSplitTransactions({
const requestMoneyInformation = {
participantParams: {
participant: participants.at(0) ?? ({} as Participant),
payeeEmail: currentUserPersonalDetails?.login ?? '',
payeeAccountID: currentUserPersonalDetails?.accountID ?? CONST.DEFAULT_NUMBER_ID,
payeeEmail: deprecatedCurrentUserPersonalDetails?.login ?? '',
payeeAccountID: deprecatedCurrentUserPersonalDetails?.accountID ?? CONST.DEFAULT_NUMBER_ID,
},
policyParams: {
policy,
Expand Down
3 changes: 1 addition & 2 deletions src/libs/actions/PersonalDetails.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import type {OnyxEntry, OnyxUpdate} from 'react-native-onyx';
import Onyx from 'react-native-onyx';
import type {CurrentUserPersonalDetails} from '@components/CurrentUserPersonalDetailsProvider';
import type {FormOnyxValues} from '@components/Form/types';
import type {LocaleContextProps} from '@components/LocaleContextProvider';
import * as API from '@libs/API';
Expand Down Expand Up @@ -32,7 +31,7 @@ import ONYXKEYS from '@src/ONYXKEYS';
import ROUTES from '@src/ROUTES';
import type {DateOfBirthForm} from '@src/types/form';
import type {PersonalDetails} from '@src/types/onyx';
import type {SelectedTimezone, Timezone} from '@src/types/onyx/PersonalDetails';
import type {CurrentUserPersonalDetails, SelectedTimezone, Timezone} from '@src/types/onyx/PersonalDetails';
import type {Address} from '@src/types/onyx/PrivatePersonalDetails';

function updatePronouns(pronouns: string, currentUserAccountID: number) {
Expand Down
3 changes: 1 addition & 2 deletions src/libs/actions/Report.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import type {NullishDeep, OnyxCollection, OnyxCollectionInputValue, OnyxEntry, O
import Onyx from 'react-native-onyx';
import type {PartialDeep, ValueOf} from 'type-fest';
import type {Emoji} from '@assets/emojis/types';
import type {CurrentUserPersonalDetails} from '@components/CurrentUserPersonalDetailsProvider';
import type {LocaleContextProps} from '@components/LocaleContextProvider';
import * as ActiveClientManager from '@libs/ActiveClientManager';
import addEncryptedAuthTokenToURL from '@libs/addEncryptedAuthTokenToURL';
Expand Down Expand Up @@ -192,7 +191,7 @@ import type {
TransactionViolations,
} from '@src/types/onyx';
import type {Decision} from '@src/types/onyx/OriginalMessage';
import type {Timezone} from '@src/types/onyx/PersonalDetails';
import type {CurrentUserPersonalDetails, Timezone} from '@src/types/onyx/PersonalDetails';
import type {ConnectionName} from '@src/types/onyx/Policy';
import type {NotificationPreference, Participants, Participant as ReportParticipant, RoomVisibility, WriteCapability} from '@src/types/onyx/Report';
import type {Message, ReportActions} from '@src/types/onyx/ReportAction';
Expand Down
1 change: 1 addition & 0 deletions src/pages/Search/SearchPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -666,6 +666,7 @@ function SearchPage({route}: SearchPageProps) {
report: newReport,
parentReport: newParentReport,
currentDate,
currentUserPersonalDetails,
});

const newReceiptFiles: ReceiptFile[] = [];
Expand Down
3 changes: 2 additions & 1 deletion src/pages/Share/SubmitDetailsPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -90,8 +90,9 @@ function SubmitDetailsPage({
report,
parentReport,
currentDate,
currentUserPersonalDetails,
});
}, [reportOrAccountID, policy, report, parentReport, currentDate]);
}, [reportOrAccountID, policy, report, parentReport, currentDate, currentUserPersonalDetails]);
Comment thread
parasharrajat marked this conversation as resolved.
Resolved

const selectedParticipants = unknownUserDetails ? [unknownUserDetails] : getMoneyRequestParticipantsFromReport(report);
const participants = selectedParticipants.map((participant) =>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import {useCallback, useContext, useRef} from 'react';
import type {OnyxEntry} from 'react-native-onyx';
import type {CurrentUserPersonalDetails} from '@components/CurrentUserPersonalDetailsProvider';
import useFilesValidation from '@hooks/useFilesValidation';
import useLocalize from '@hooks/useLocalize';
import useOnyx from '@hooks/useOnyx';
Expand All @@ -16,6 +15,7 @@ import ONYXKEYS from '@src/ONYXKEYS';
import ROUTES from '@src/ROUTES';
import type SCREENS from '@src/SCREENS';
import type * as OnyxTypes from '@src/types/onyx';
import type {CurrentUserPersonalDetails} from '@src/types/onyx/PersonalDetails';
import type {FileObject} from '@src/types/utils/Attachment';

type AttachmentUploadValidationProps = {
Expand Down Expand Up @@ -93,6 +93,7 @@ function useAttachmentUploadValidation({
report,
parentReport: newParentReport,
currentDate,
currentUserPersonalDetails,
});

files.forEach((file, index) => {
Expand Down
7 changes: 6 additions & 1 deletion src/pages/iou/request/DistanceRequestStartPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import FocusTrapContainerElement from '@components/FocusTrap/FocusTrapContainerE
import HeaderWithBackButton from '@components/HeaderWithBackButton';
import ScreenWrapper from '@components/ScreenWrapper';
import TabSelector from '@components/TabSelector/TabSelector';
import useCurrentUserPersonalDetails from '@hooks/useCurrentUserPersonalDetails';
import useLocalize from '@hooks/useLocalize';
import useOnyx from '@hooks/useOnyx';
import usePolicy from '@hooks/usePolicy';
Expand Down Expand Up @@ -55,6 +56,8 @@ function DistanceRequestStartPage({
const [lastSelectedDistanceRates] = useOnyx(ONYXKEYS.NVP_LAST_SELECTED_DISTANCE_RATES, {canBeMissing: true});
const [currentDate] = useOnyx(ONYXKEYS.CURRENT_DATE, {canBeMissing: true});

const currentUserPersonalDetails = useCurrentUserPersonalDetails();

const tabTitles = {
[CONST.IOU.TYPE.REQUEST]: translate('iou.trackDistance'),
[CONST.IOU.TYPE.SUBMIT]: translate('iou.trackDistance'),
Expand Down Expand Up @@ -103,6 +106,7 @@ function DistanceRequestStartPage({
currentDate,
lastSelectedDistanceRates,
localeCompare,
currentUserPersonalDetails,
});
// eslint-disable-next-line
}, []);
Expand All @@ -124,9 +128,10 @@ function DistanceRequestStartPage({
currentDate,
lastSelectedDistanceRates,
localeCompare,
currentUserPersonalDetails,
});
},
[transaction?.iouRequestType, reportID, policy, isFromGlobalCreate, report, parentReport, currentDate, lastSelectedDistanceRates, localeCompare],
[transaction?.iouRequestType, reportID, policy, isFromGlobalCreate, report, parentReport, currentDate, lastSelectedDistanceRates, localeCompare, currentUserPersonalDetails],
Comment thread
parasharrajat marked this conversation as resolved.
Resolved
);

// Clear out the temporary expense if the reportID in the URL has changed from the transaction's reportID.
Expand Down
22 changes: 19 additions & 3 deletions src/pages/iou/request/IOURequestStartPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -95,8 +95,11 @@ function IOURequestStartPage({
};

const isFromGlobalCreate = isEmptyObject(report?.reportID);
const {login: currentUserLogin} = useCurrentUserPersonalDetails();
const policiesWithPerDiemEnabled = useMemo(() => getActivePoliciesWithExpenseChatAndPerDiemEnabled(allPolicies, currentUserLogin), [allPolicies, currentUserLogin]);
const currentUserPersonalDetails = useCurrentUserPersonalDetails();
const policiesWithPerDiemEnabled = useMemo(
() => getActivePoliciesWithExpenseChatAndPerDiemEnabled(allPolicies, currentUserPersonalDetails.login),
[allPolicies, currentUserPersonalDetails.login],
);
const doesPerDiemPolicyExist = policiesWithPerDiemEnabled.length > 0;
const moreThanOnePerDiemExist = policiesWithPerDiemEnabled.length > 1;
const hasCurrentPolicyPerDiemEnabled = !!policy?.arePerDiemRatesEnabled;
Expand Down Expand Up @@ -143,6 +146,7 @@ function IOURequestStartPage({
parentReport,
currentDate,
lastSelectedDistanceRates,
currentUserPersonalDetails,
});
// eslint-disable-next-line
}, []);
Expand All @@ -164,9 +168,21 @@ function IOURequestStartPage({
parentReport,
currentDate,
lastSelectedDistanceRates,
currentUserPersonalDetails,
});
},
[transaction?.iouRequestType, transaction?.isFromGlobalCreate, reportID, policy, isFromGlobalCreate, report, parentReport, currentDate, lastSelectedDistanceRates],
[
transaction?.iouRequestType,
transaction?.isFromGlobalCreate,
reportID,
policy,
isFromGlobalCreate,
report,
parentReport,
currentDate,
lastSelectedDistanceRates,
currentUserPersonalDetails,
Comment thread
parasharrajat marked this conversation as resolved.
Resolved
],
);

// Clear out the temporary expense if the reportID in the URL has changed from the transaction's reportID.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import React, {useCallback} from 'react';
import {View} from 'react-native';
import type {CurrentUserPersonalDetails} from '@components/CurrentUserPersonalDetailsProvider';
import DelegateNoAccessWrapper from '@components/DelegateNoAccessWrapper';
import FormProvider from '@components/Form/FormProvider';
import InputWrapper from '@components/Form/InputWrapper';
Expand All @@ -23,6 +22,7 @@ import ONYXKEYS from '@src/ONYXKEYS';
import INPUT_IDS from '@src/types/form/LegalNameForm';
import type {PrivatePersonalDetails} from '@src/types/onyx';
import type {Errors} from '@src/types/onyx/OnyxCommon';
import type {CurrentUserPersonalDetails} from '@src/types/onyx/PersonalDetails';

const updateLegalName = (
values: PrivatePersonalDetails,
Expand Down
10 changes: 9 additions & 1 deletion src/types/onyx/PersonalDetails.ts
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,14 @@ type PersonalDetailsMetadata = {
/** Record of user personal details, indexed by user id */
type PersonalDetailsList = Record<string, PersonalDetails | null>;

/** Current user's personal details */
type CurrentUserPersonalDetails = PersonalDetails & {
/**
* Current user's email address
*/
email?: string;
};

export default PersonalDetails;

export type {Timezone, Status, SelectedTimezone, PersonalDetailsList, PersonalDetailsMetadata};
export type {Timezone, Status, SelectedTimezone, PersonalDetailsList, PersonalDetailsMetadata, CurrentUserPersonalDetails};
Loading