Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
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
4 changes: 2 additions & 2 deletions src/components/ReportActionItem/MoneyRequestView.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -762,9 +762,9 @@ function MoneyRequestView({report, shouldShowAnimatedBackground, readonly = fals
<MenuItemWithTopDescription
key="attendees"
shouldShowRightIcon
title={transactionAttendees?.map((item) => item?.displayName ?? item?.login).join(', ')}
title={Array.isArray(transactionAttendees) ? transactionAttendees.map((item) => item?.displayName ?? item?.login).join(', ') : ''}
description={`${translate('iou.attendees')} ${
transactionAttendees?.length && transactionAttendees.length > 1 ? `${formattedPerAttendeeAmount} ${translate('common.perPerson')}` : ''
Array.isArray(transactionAttendees) && transactionAttendees.length > 1 ? `${formattedPerAttendeeAmount} ${translate('common.perPerson')}` : ''
}`}
style={[styles.moneyRequestMenuItem]}
titleStyle={styles.flex1}
Expand Down
1 change: 1 addition & 0 deletions src/libs/API/parameters/RequestMoneyParams.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ type RequestMoneyParams = {
createdReportActionIDForThread: string | undefined;
reimbursible?: boolean;
description?: string;
attendees?: string;
};

export default RequestMoneyParams;
17 changes: 3 additions & 14 deletions src/libs/DebugUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import CONST from '@src/CONST';
import type {TranslationPaths} from '@src/languages/types';
import ONYXKEYS from '@src/ONYXKEYS';
import type {Beta, Policy, Report, ReportAction, ReportActions, ReportNameValuePairs, Transaction, TransactionViolation} from '@src/types/onyx';
import type {Comment} from '@src/types/onyx/Transaction';
import {getLinkedTransactionID} from './ReportActionsUtils';
import {getReasonAndReportActionThatRequiresAttention, reasonForReportToBeInOptionList, shouldDisplayViolationsRBRInLHN} from './ReportUtils';
import SidebarUtils from './SidebarUtils';
Expand Down Expand Up @@ -1073,6 +1074,7 @@ function validateTransactionDraftProperty(key: keyof Transaction, value: string)
comment: 'string',
hold: 'string',
waypoints: 'object',
attendees: 'array',
isLoading: 'boolean',
type: CONST.TRANSACTION.TYPE,
customUnit: 'object',
Expand All @@ -1082,21 +1084,8 @@ function validateTransactionDraftProperty(key: keyof Transaction, value: string)
splits: 'array',
dismissedViolations: 'object',
});
case 'attendees':
return validateArray<ArrayElement<Transaction, 'attendees'>>(value, {
email: 'string',
displayName: 'string',
avatarUrl: 'string',
accountID: 'number',
text: 'string',
login: 'string',
searchText: 'string',
selected: 'boolean',
iouType: CONST.IOU.TYPE,
reportID: 'string',
});
case 'modifiedAttendees':
return validateArray<ArrayElement<Transaction, 'attendees'>>(value, {
return validateArray<ArrayElement<Comment, 'attendees'>>(value, {
email: 'string',
displayName: 'string',
avatarUrl: 'string',
Expand Down
8 changes: 4 additions & 4 deletions src/libs/IOUUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -178,10 +178,10 @@ function formatCurrentUserToAttendee(currentUser?: PersonalDetails, reportID?: s
return;
}
const initialAttendee: Attendee = {
email: currentUser?.login,
login: currentUser?.login,
displayName: currentUser.displayName,
avatarUrl: currentUser.avatar?.toString(),
email: currentUser?.login ?? '',
login: currentUser?.login ?? '',
displayName: currentUser.displayName ?? '',
avatarUrl: currentUser.avatar?.toString() ?? '',
accountID: currentUser.accountID,
text: currentUser.login,
selected: true,
Expand Down
16 changes: 5 additions & 11 deletions src/libs/ModifiedExpenseMessage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import {getCleanedTagName, getSortedTagKeys} from './PolicyUtils';
import {getOriginalMessage, isModifiedExpenseAction} from './ReportActionsUtils';
// eslint-disable-next-line import/no-cycle
import {buildReportNameFromParticipantNames, getPolicyExpenseChatName, getPolicyName, getRootParentReport, isPolicyExpenseChat, isSelfDM} from './ReportUtils';
import {getTagArrayFromName} from './TransactionUtils';
import {getFormattedAttendees, getTagArrayFromName} from './TransactionUtils';

let allPolicyTags: OnyxCollection<PolicyTagLists> = {};
Onyx.connect({
Expand Down Expand Up @@ -344,17 +344,11 @@ function getForReportAction({
);
}

const hasModifiedAttendees = isReportActionOriginalMessageAnObject && 'oldAttendees' in reportActionOriginalMessage && 'attendees' in reportActionOriginalMessage;
const hasModifiedAttendees = isReportActionOriginalMessageAnObject && 'oldAttendees' in reportActionOriginalMessage && 'newAttendees' in reportActionOriginalMessage;
if (hasModifiedAttendees) {
buildMessageFragmentForValue(
reportActionOriginalMessage.oldAttendees ?? '',
reportActionOriginalMessage.attendees ?? '',
translateLocal('iou.attendees'),
false,
setFragments,
removalFragments,
changeFragments,
);
const [oldAttendees, attendees] = getFormattedAttendees(reportActionOriginalMessage.newAttendees, reportActionOriginalMessage.oldAttendees);

buildMessageFragmentForValue(oldAttendees, attendees, translateLocal('iou.attendees'), false, setFragments, removalFragments, changeFragments);
}

const message =
Expand Down
2 changes: 1 addition & 1 deletion src/libs/OptionsListUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -496,7 +496,7 @@ function getParticipantsOption(participant: OptionData | Participant, personalDe
const displayName = formatPhoneNumber(getDisplayNameOrDefault(detail, login || participant.text));

return {
keyForList: String(detail?.accountID),
keyForList: String(detail?.accountID ?? login),
login,
accountID: detail?.accountID,
text: displayName,
Expand Down
6 changes: 3 additions & 3 deletions src/libs/ReportUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,6 @@ import {
getCategory,
getCurrency,
getDescription,
getFormattedAttendees,
getFormattedCreated,
getFormattedPostedDate,
getMCCGroup,
Expand Down Expand Up @@ -604,7 +603,7 @@ type OptimisticTaskReport = SetRequired<
type TransactionDetails = {
created: string;
amount: number;
attendees: Attendee[];
attendees: Attendee[] | string;
taxAmount?: number;
taxCode?: string;
currency: string;
Expand Down Expand Up @@ -4204,7 +4203,8 @@ function getModifiedExpenseOriginalMessage(
originalMessage.merchant = transactionChanges?.merchant;
}
if ('attendees' in transactionChanges) {
[originalMessage.oldAttendees, originalMessage.attendees] = getFormattedAttendees(transactionChanges?.attendees, getAttendees(oldTransaction));
originalMessage.oldAttendees = getAttendees(oldTransaction);
originalMessage.newAttendees = transactionChanges?.attendees;
}

// The amount is always a combination of the currency and the number value so when one changes we need to store both
Expand Down
9 changes: 4 additions & 5 deletions src/libs/TransactionUtils/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -256,7 +256,7 @@ function buildOptimisticTransaction(params: BuildOptimisticTransactionParams): T
// Because JS can only handle 53-bit numbers, transactionIDs are strings in the front-end (just like reportActionID)
const transactionID = existingTransactionID ?? NumberUtils.rand64();

const commentJSON: Comment = {comment};
const commentJSON: Comment = {comment, attendees};
if (source) {
commentJSON.source = source;
}
Expand Down Expand Up @@ -299,7 +299,6 @@ function buildOptimisticTransaction(params: BuildOptimisticTransactionParams): T
taxAmount,
billable,
reimbursable,
attendees,
inserted: DateUtils.getDBTime(),
};
}
Expand Down Expand Up @@ -331,10 +330,10 @@ function isMerchantMissing(transaction: OnyxEntry<Transaction>) {

// eslint-disable-next-line @typescript-eslint/no-unused-vars
function shouldShowAttendees(iouType: IOUType, policy: OnyxEntry<Policy>): boolean {
return false;
// return false;
// To be renabled once feature is complete: https://github.com/Expensify/App/issues/44725
// Keep this disabled for per diem expense
// return iouType === CONST.IOU.TYPE.SUBMIT && !!policy?.id && (policy?.type === CONST.POLICY.TYPE.CORPORATE || policy?.type === CONST.POLICY.TYPE.TEAM);
return iouType === CONST.IOU.TYPE.SUBMIT && !!policy?.id && (policy?.type === CONST.POLICY.TYPE.CORPORATE || policy?.type === CONST.POLICY.TYPE.TEAM);
Comment on lines +333 to +336

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we return false here before we merge it?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nah, the rest is ready so let's go ahead and release this to everyone. We'd just need to clean up the commented code here, though I'm not going to block on this so we can get this deployed asap, and I'll clean up the commented code once this is on production.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not having invoice type check here seemed to have created this bug #59602

}

/**
Expand Down Expand Up @@ -656,7 +655,7 @@ function getMerchantOrDescription(transaction: OnyxEntry<Transaction>) {
* Return the list of modified attendees if present otherwise list of attendees
*/
function getAttendees(transaction: OnyxInputOrEntry<Transaction>): Attendee[] {
return transaction?.modifiedAttendees ? transaction.modifiedAttendees : transaction?.attendees ?? [];
return transaction?.modifiedAttendees ? transaction.modifiedAttendees : transaction?.comment?.attendees ?? [];
}

/**
Expand Down
12 changes: 9 additions & 3 deletions src/libs/actions/IOU.ts
Original file line number Diff line number Diff line change
Expand Up @@ -774,7 +774,9 @@ function initMoneyRequest(
return;
}

const comment: Comment = {};
const comment: Comment = {
attendees: formatCurrentUserToAttendee(currentUserPersonalDetails, reportID),
};
let requestCategory: string | null = null;

// Add initial empty waypoints when starting a distance expense
Expand Down Expand Up @@ -809,7 +811,6 @@ function initMoneyRequest(
// Use set() here so that there is no way that data will be leaked between objects when it gets reset
Onyx.set(`${ONYXKEYS.COLLECTION.TRANSACTION_DRAFT}${newTransactionID}`, {
amount: 0,
attendees: formatCurrentUserToAttendee(currentUserPersonalDetails, reportID),
comment,
created,
currency,
Expand Down Expand Up @@ -883,7 +884,7 @@ function setMoneyRequestMerchant(transactionID: string, merchant: string, isDraf
}

function setMoneyRequestAttendees(transactionID: string, attendees: Attendee[], isDraft: boolean) {
Onyx.merge(`${isDraft ? ONYXKEYS.COLLECTION.TRANSACTION_DRAFT : ONYXKEYS.COLLECTION.TRANSACTION}${transactionID}`, {attendees});
Onyx.merge(`${isDraft ? ONYXKEYS.COLLECTION.TRANSACTION_DRAFT : ONYXKEYS.COLLECTION.TRANSACTION}${transactionID}`, {comment: {attendees}});
}

function setMoneyRequestPendingFields(transactionID: string, pendingFields: OnyxTypes.Transaction['pendingFields']) {
Expand Down Expand Up @@ -3854,6 +3855,10 @@ function getUpdateMoneyRequestParams(
}
}

if (Array.isArray(params?.attendees)) {
params.attendees = JSON.stringify(params?.attendees);
}

// Clear out the error fields and loading states on success
successData.push({
onyxMethod: Onyx.METHOD.MERGE,
Expand Down Expand Up @@ -4898,6 +4903,7 @@ function requestMoney(requestMoneyInformation: RequestMoneyInformation) {
createdReportActionIDForThread,
reimbursible,
description: parsedComment,
attendees: attendees ? JSON.stringify(attendees) : undefined,
};
// eslint-disable-next-line rulesdir/no-multiple-api-calls
API.write(WRITE_COMMANDS.REQUEST_MONEY, parameters, onyxData);
Expand Down
2 changes: 1 addition & 1 deletion src/pages/Share/SubmitDetailsPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ function SubmitDetailsPage({
gpsPoints,
action: CONST.IOU.TYPE.CREATE,
transactionParams: {
attendees: transaction.attendees,
attendees: transaction.comment?.attendees,
amount: transactionAmount,
currency: transaction.currency,
comment: trimmedComment,
Expand Down
Loading