Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix bug connected to submitter in attendees #49008

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
1 change: 1 addition & 0 deletions src/libs/IOUUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,7 @@ function formatCurrentUserToAttendee(currentUser?: PersonalDetails, reportID?: s
}
const initialAttendee: Attendee = {
email: currentUser?.login,
login: currentUser?.login,
displayName: currentUser.displayName,
avatarUrl: currentUser.avatar?.toString(),
accountID: currentUser.accountID,
Expand Down
36 changes: 9 additions & 27 deletions src/pages/iou/request/MoneyRequestAttendeeSelector.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import lodashIsEqual from 'lodash/isEqual';
import lodashReject from 'lodash/reject';
import React, {memo, useCallback, useEffect, useMemo, useState} from 'react';
import React, {memo, useCallback, useEffect, useMemo} from 'react';
import type {GestureResponderEvent} from 'react-native';
import {useOnyx} from 'react-native-onyx';
import Button from '@components/Button';
Expand All @@ -19,7 +19,6 @@ import useThemeStyles from '@hooks/useThemeStyles';
import * as DeviceCapabilities from '@libs/DeviceCapabilities';
import * as OptionsListUtils from '@libs/OptionsListUtils';
import * as PolicyUtils from '@libs/PolicyUtils';
import type {OptionData} from '@libs/ReportUtils';
import * as Report from '@userActions/Report';
import type {IOUAction, IOUType} from '@src/CONST';
import CONST from '@src/CONST';
Expand Down Expand Up @@ -54,8 +53,6 @@ function MoneyRequestAttendeeSelector({attendees = [], onFinish, onAttendeesAdde
const [activePolicyID] = useOnyx(ONYXKEYS.NVP_ACTIVE_POLICY_ID);
const session = useSession();
const isCurrentUserAttendee = attendees.some((attendee) => attendee.accountID === session.accountID);
const currentUserOptionData = OptionsListUtils.getParticipantsOption(session, personalDetails) as OptionData;
const [additionalRecents, setAdditionalRecents] = useState<OptionData[] | []>(isCurrentUserAttendee ? [] : [currentUserOptionData]);
const [recentAttendees] = useOnyx(ONYXKEYS.NVP_RECENT_ATTENDEES);
const policy = usePolicy(activePolicyID);
const [isSearchingForReports] = useOnyx(ONYXKEYS.IS_SEARCHING_FOR_REPORTS, {initWithStoredValues: false});
Expand Down Expand Up @@ -89,7 +86,9 @@ function MoneyRequestAttendeeSelector({attendees = [], onFinish, onAttendeesAdde
action,
isPaidGroupPolicy,
);

if (optionList.currentUserOption && !isCurrentUserAttendee) {
optionList.recentReports = [optionList.currentUserOption, ...optionList.personalDetails];
}
return optionList;
}, [
areOptionsInitialized,
Expand All @@ -103,6 +102,7 @@ function MoneyRequestAttendeeSelector({attendees = [], onFinish, onAttendeesAdde
action,
isCategorizeOrShareAction,
isPaidGroupPolicy,
isCurrentUserAttendee,
]);

const chatOptions = useMemo(() => {
Expand All @@ -118,16 +118,14 @@ function MoneyRequestAttendeeSelector({attendees = [], onFinish, onAttendeesAdde
taxRatesOptions: [],
};
}

const newOptions = OptionsListUtils.filterOptions(defaultOptions, debouncedSearchTerm, {
selectedOptions: attendees,
excludeLogins: CONST.EXPENSIFY_EMAILS,
maxRecentReportsToShow: CONST.IOU.MAX_RECENT_REPORTS_TO_SHOW,
preferPolicyExpenseChat: isPaidGroupPolicy,
shouldAcceptName: true,
});
return newOptions;
}, [areOptionsInitialized, defaultOptions, debouncedSearchTerm, attendees, isPaidGroupPolicy]);
}, [areOptionsInitialized, defaultOptions, debouncedSearchTerm, isPaidGroupPolicy]);

/**
* Returns the sections needed for the OptionsSelector
Expand All @@ -137,8 +135,8 @@ function MoneyRequestAttendeeSelector({attendees = [], onFinish, onAttendeesAdde
if (!areOptionsInitialized || !didScreenTransitionEnd) {
return [newSections, ''];
}
const fiveRecents = [...additionalRecents, ...chatOptions.recentReports].slice(0, 5);
const restOfRecents = [...additionalRecents, ...chatOptions.recentReports].slice(5);
const fiveRecents = [...chatOptions.recentReports].slice(0, 5);
const restOfRecents = [...chatOptions.recentReports].slice(5);
const contactsWithRestOfRecents = [...restOfRecents, ...chatOptions.personalDetails];

const formatResults = OptionsListUtils.formatSectionsFromSearchTerm(
Expand Down Expand Up @@ -196,7 +194,6 @@ function MoneyRequestAttendeeSelector({attendees = [], onFinish, onAttendeesAdde
personalDetails,
translate,
cleanSearchTerm,
additionalRecents,
]);

const addAttendeeToSelection = useCallback(
Expand All @@ -212,23 +209,8 @@ function MoneyRequestAttendeeSelector({attendees = [], onFinish, onAttendeesAdde
let newSelectedOptions: Attendee[];

if (isOptionInList) {
if (session.accountID === option.accountID) {
if (!additionalRecents.some((recent) => recent.accountID === option.accountID)) {
setAdditionalRecents([
{
...option,
selected: false,
isSelected: false,
} as OptionData,
...additionalRecents,
]);
}
}
newSelectedOptions = lodashReject(attendees, isOptionSelected);
} else {
if (session.accountID === option.accountID) {
setAdditionalRecents(additionalRecents.filter((recent) => recent.accountID !== option.accountID));
}
newSelectedOptions = [
...attendees,
{
Expand All @@ -245,7 +227,7 @@ function MoneyRequestAttendeeSelector({attendees = [], onFinish, onAttendeesAdde

onAttendeesAdded(newSelectedOptions);
},
[additionalRecents, attendees, iouType, onAttendeesAdded, session.accountID],
[attendees, iouType, onAttendeesAdded],
);

const shouldShowErrorMessage = attendees.length < 1;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,8 @@ function QuickbooksAdvancedPage({policy}: WithPolicyConnectionsProps) {
() => invoiceAccountCollectionOptions?.find(({id}) => id === collectionAccountID)?.name,
[invoiceAccountCollectionOptions, collectionAccountID],
);
const autoCreateVendorConst = CONST.QUICKBOOKS_CONFIG.AUTO_CREATE_VENDOR;
const defaultVendorConst = CONST.QUICKBOOKS_CONFIG.NON_REIMBURSABLE_BILL_DEFAULT_VENDOR;

const sectionMenuItems = [
{
Expand Down Expand Up @@ -129,12 +131,12 @@ function QuickbooksAdvancedPage({policy}: WithPolicyConnectionsProps) {
QuickbooksOnline.updateQuickbooksOnlineAutoCreateVendor(
policyID,
{
[CONST.QUICKBOOKS_CONFIG.AUTO_CREATE_VENDOR]: isOn,
[CONST.QUICKBOOKS_CONFIG.NON_REIMBURSABLE_BILL_DEFAULT_VENDOR]: nonReimbursableVendorUpdateValue,
[autoCreateVendorConst]: isOn,
[defaultVendorConst]: nonReimbursableVendorUpdateValue,
},
{
[CONST.QUICKBOOKS_CONFIG.AUTO_CREATE_VENDOR]: !!qboConfig?.autoCreateVendor,
[CONST.QUICKBOOKS_CONFIG.NON_REIMBURSABLE_BILL_DEFAULT_VENDOR]: nonReimbursableVendorCurrentValue,
[autoCreateVendorConst]: !!qboConfig?.autoCreateVendor,
[defaultVendorConst]: nonReimbursableVendorCurrentValue,
},
);
},
Expand Down
Loading