Skip to content

Commit

Permalink
Merge pull request #37460 from Krishna2323/krishna2323/issue/35377
Browse files Browse the repository at this point in the history
fix: IOU - CMD+ENTER command takes you to the IOU confirmation page without selecting members
  • Loading branch information
stitesExpensify authored Mar 20, 2024
2 parents 873b8d0 + 4272054 commit 4aecfcb
Show file tree
Hide file tree
Showing 4 changed files with 82 additions and 46 deletions.
21 changes: 16 additions & 5 deletions src/components/SelectionList/BaseSelectionList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -455,11 +455,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

0 comments on commit 4aecfcb

Please sign in to comment.