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: IOU - CMD+ENTER command takes you to the IOU confirmation page without selecting members #37460

Merged
merged 9 commits into from
Mar 20, 2024
21 changes: 16 additions & 5 deletions src/components/SelectionList/BaseSelectionList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -454,11 +454,22 @@ function BaseSelectionList<TItem extends ListItem>(
});

/** Calls confirm action when pressing CTRL (CMD) + Enter */
useKeyboardShortcut(CONST.KEYBOARD_SHORTCUTS.CTRL_ENTER, onConfirm ?? selectFocusedOption, {
captureOnInputs: true,
shouldBubble: !flattenedSections.allOptions[focusedIndex],
isActive: !disableKeyboardShortcuts && isFocused,
});
useKeyboardShortcut(
CONST.KEYBOARD_SHORTCUTS.CTRL_ENTER,
(e) => {
const focusedOption = flattenedSections.allOptions[focusedIndex];
if (onConfirm) {
onConfirm(e, focusedOption);
return;
}
selectFocusedOption();
},
{
captureOnInputs: true,
shouldBubble: !flattenedSections.allOptions[focusedIndex],
isActive: !disableKeyboardShortcuts && isFocused,
},
);

return (
<ArrowKeyFocusManager
Expand Down
2 changes: 1 addition & 1 deletion src/components/SelectionList/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -227,7 +227,7 @@ type BaseSelectionListProps<TItem extends ListItem> = Partial<ChildrenProps> & {
confirmButtonText?: string;

/** Callback to fire when the confirm button is pressed */
onConfirm?: (e?: GestureResponderEvent | KeyboardEvent | undefined) => void;
onConfirm?: (e?: GestureResponderEvent | KeyboardEvent | undefined, option?: TItem) => void;

/** Whether to show the vertical scroll indicator */
showScrollIndicator?: boolean;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -187,15 +187,18 @@ function MoneyTemporaryForRefactorRequestParticipantsSelector({
*
* @param {Object} option
*/
const addSingleParticipant = (option) => {
onParticipantsAdded([
{
..._.pick(option, 'accountID', 'login', 'isPolicyExpenseChat', 'reportID', 'searchText'),
selected: true,
},
]);
onFinish();
};
const addSingleParticipant = useCallback(
(option) => {
onParticipantsAdded([
{
..._.pick(option, 'accountID', 'login', 'isPolicyExpenseChat', 'reportID', 'searchText'),
selected: true,
},
]);
onFinish();
},
[onFinish, onParticipantsAdded],
);

/**
* Removes a selected option from list if already selected. If not already selected add this option to the list.
Expand Down Expand Up @@ -257,13 +260,22 @@ function MoneyTemporaryForRefactorRequestParticipantsSelector({
const shouldShowSplitBillErrorMessage = participants.length > 1 && hasPolicyExpenseChatParticipant;
const isAllowedToSplit = (canUseP2PDistanceRequests || iouRequestType !== CONST.IOU.REQUEST_TYPE.DISTANCE) && iouType !== CONST.IOU.TYPE.SEND;

const handleConfirmSelection = useCallback(() => {
if (shouldShowSplitBillErrorMessage) {
return;
}
const handleConfirmSelection = useCallback(
(keyEvent, option) => {
const shouldAddSingleParticipant = option && !participants.length;
if (shouldShowSplitBillErrorMessage || (!participants.length && !option)) {
return;
}

onFinish(CONST.IOU.TYPE.SPLIT);
}, [shouldShowSplitBillErrorMessage, onFinish]);
if (shouldAddSingleParticipant) {
addSingleParticipant(option);
return;
}

onFinish(CONST.IOU.TYPE.SPLIT);
},
[shouldShowSplitBillErrorMessage, onFinish, addSingleParticipant, participants],
);

const footerContent = useMemo(
() => (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -196,25 +196,28 @@ function MoneyRequestParticipantsSelector({
*
* @param {Object} option
*/
const addSingleParticipant = (option) => {
if (participants.length) {
return;
}
onAddParticipants(
[
{
accountID: option.accountID,
login: option.login,
isPolicyExpenseChat: option.isPolicyExpenseChat,
reportID: option.reportID,
selected: true,
searchText: option.searchText,
},
],
false,
);
navigateToRequest();
};
const addSingleParticipant = useCallback(
(option) => {
if (participants.length) {
return;
}
onAddParticipants(
[
{
accountID: option.accountID,
login: option.login,
isPolicyExpenseChat: option.isPolicyExpenseChat,
reportID: option.reportID,
selected: true,
searchText: option.searchText,
},
],
false,
);
navigateToRequest();
},
[navigateToRequest, onAddParticipants, participants.length],
);

/**
* Removes a selected option from list if already selected. If not already selected add this option to the list.
Expand Down Expand Up @@ -275,13 +278,23 @@ function MoneyRequestParticipantsSelector({
const shouldShowSplitBillErrorMessage = participants.length > 1 && hasPolicyExpenseChatParticipant;
const isAllowedToSplit = (canUseP2PDistanceRequests || !isDistanceRequest) && iouType !== CONST.IOU.TYPE.SEND;

const handleConfirmSelection = useCallback(() => {
if (shouldShowSplitBillErrorMessage) {
return;
}
const handleConfirmSelection = useCallback(
(keyEvent, option) => {
const shouldAddSingleParticipant = option && !participants.length;

navigateToSplit();
}, [shouldShowSplitBillErrorMessage, navigateToSplit]);
if (shouldShowSplitBillErrorMessage || (!participants.length && !option)) {
return;
}

if (shouldAddSingleParticipant) {
addSingleParticipant(option);
return;
}

navigateToSplit();
},
[shouldShowSplitBillErrorMessage, navigateToSplit, addSingleParticipant, participants.length],
);

const footerContent = useMemo(
() => (
Expand Down
Loading