Skip to content

Commit 66cf824

Browse files
authored
Merge pull request #50700 from bernhardoj/fix/50577-inconsistent-money-request-and-task-behavior
Fix inconsistent money request and task behavior
2 parents f7d08e0 + 4d4edb1 commit 66cf824

File tree

5 files changed

+21
-65
lines changed

5 files changed

+21
-65
lines changed

src/components/MoneyRequestConfirmationList.tsx

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -715,6 +715,7 @@ function MoneyRequestConfirmationList({
715715
}
716716

717717
if (selectedParticipants.length === 0) {
718+
setFormError('iou.error.noParticipantSelected');
718719
return;
719720
}
720721
if (!isEditingSplitBill && isMerchantRequired && (isMerchantEmpty || (shouldDisplayFieldError && TransactionUtils.isMerchantMissing(transaction)))) {
@@ -801,12 +802,10 @@ function MoneyRequestConfirmationList({
801802
}
802803

803804
const shouldShowSettlementButton = iouType === CONST.IOU.TYPE.PAY;
804-
const shouldDisableButton = selectedParticipants.length === 0;
805805

806806
const button = shouldShowSettlementButton ? (
807807
<SettlementButton
808808
pressOnEnter
809-
isDisabled={shouldDisableButton}
810809
onPress={confirm}
811810
enablePaymentsRoute={ROUTES.IOU_SEND_ENABLE_PAYMENTS}
812811
addBankAccountRoute={bankAccountRoute}
@@ -829,7 +828,6 @@ function MoneyRequestConfirmationList({
829828
<ButtonWithDropdownMenu
830829
success
831830
pressOnEnter
832-
isDisabled={shouldDisableButton}
833831
onPress={(event, value) => confirm(value as PaymentMethodType)}
834832
options={splitOrRequestOptions}
835833
buttonSize={CONST.DROPDOWN_BUTTON_SIZE.LARGE}
@@ -855,7 +853,6 @@ function MoneyRequestConfirmationList({
855853
isReadOnly,
856854
isTypeSplit,
857855
iouType,
858-
selectedParticipants.length,
859856
confirm,
860857
bankAccountRoute,
861858
iouCurrencyCode,
@@ -926,6 +923,7 @@ function MoneyRequestConfirmationList({
926923
shouldSingleExecuteRowSelect
927924
canSelectMultiple={false}
928925
shouldPreventDefaultFocusOnSelectRow
926+
shouldShowListEmptyContent={false}
929927
footerContent={footerContent}
930928
listFooterContent={listFooterContent}
931929
containerStyle={[styles.flexBasisAuto]}

src/components/SelectionList/BaseSelectionList.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -718,7 +718,7 @@ function BaseSelectionList<TItem extends ListItem>(
718718
</View>
719719
)}
720720
{!!headerContent && headerContent}
721-
{flattenedSections.allOptions.length === 0 ? (
721+
{flattenedSections.allOptions.length === 0 && (showLoadingPlaceholder || shouldShowListEmptyContent) ? (
722722
renderListEmptyContent()
723723
) : (
724724
<>

src/languages/en.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -955,6 +955,7 @@ const translations = {
955955
invalidSplit: 'The sum of splits must equal the total amount.',
956956
invalidSplitParticipants: 'Please enter an amount greater than zero for at least two participants.',
957957
invalidSplitYourself: 'Please enter a non-zero amount for your split.',
958+
noParticipantSelected: 'Please select a participant.',
958959
other: 'Unexpected error. Please try again later.',
959960
genericCreateFailureMessage: 'Unexpected error submitting this expense. Please try again later.',
960961
genericCreateInvoiceFailureMessage: 'Unexpected error sending this invoice. Please try again later.',

src/languages/es.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -952,6 +952,7 @@ const translations = {
952952
invalidSplit: 'La suma de las partes debe ser igual al importe total.',
953953
invalidSplitParticipants: 'Introduce un importe superior a cero para al menos dos participantes.',
954954
invalidSplitYourself: 'Por favor, introduce una cantidad diferente de cero para tu parte.',
955+
noParticipantSelected: 'Por favor, selecciona un participante.',
955956
other: 'Error inesperado. Por favor, inténtalo más tarde.',
956957
genericHoldExpenseFailureMessage: 'Error inesperado al bloquear el gasto. Por favor, inténtalo de nuevo más tarde.',
957958
genericUnholdExpenseFailureMessage: 'Error inesperado al desbloquear el gasto. Por favor, inténtalo de nuevo más tarde.',

src/pages/tasks/NewTaskPage.tsx

Lines changed: 16 additions & 60 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,7 @@ import {useFocusEffect} from '@react-navigation/native';
22
import type {StackScreenProps} from '@react-navigation/stack';
33
import React, {useCallback, useEffect, useMemo, useRef, useState} from 'react';
44
import {InteractionManager, View} from 'react-native';
5-
import type {OnyxCollection, OnyxEntry} from 'react-native-onyx';
6-
import {withOnyx} from 'react-native-onyx';
5+
import {useOnyx} from 'react-native-onyx';
76
import FullPageNotFoundView from '@components/BlockingViews/FullPageNotFoundView';
87
import FormAlertWithSubmitButton from '@components/FormAlertWithSubmitButton';
98
import FormHelpMessage from '@components/FormHelpMessage';
@@ -27,35 +26,27 @@ import CONST from '@src/CONST';
2726
import ONYXKEYS from '@src/ONYXKEYS';
2827
import ROUTES from '@src/ROUTES';
2928
import type SCREENS from '@src/SCREENS';
30-
import type {PersonalDetailsList, Report, Task} from '@src/types/onyx';
3129
import {isEmptyObject} from '@src/types/utils/EmptyObject';
3230

33-
type NewTaskPageOnyxProps = {
34-
/** Task Creation Data */
35-
task: OnyxEntry<Task>;
31+
type NewTaskPageProps = StackScreenProps<NewTaskNavigatorParamList, typeof SCREENS.NEW_TASK.ROOT>;
3632

37-
/** All of the personal details for everyone */
38-
personalDetails: OnyxEntry<PersonalDetailsList>;
39-
40-
/** All reports shared with the user */
41-
reports: OnyxCollection<Report>;
42-
};
43-
44-
type NewTaskPageProps = NewTaskPageOnyxProps & StackScreenProps<NewTaskNavigatorParamList, typeof SCREENS.NEW_TASK.ROOT>;
45-
46-
function NewTaskPage({task, reports, personalDetails, route}: NewTaskPageProps) {
33+
function NewTaskPage({route}: NewTaskPageProps) {
34+
const [task] = useOnyx(ONYXKEYS.TASK);
35+
const [reports] = useOnyx(ONYXKEYS.COLLECTION.REPORT);
36+
const [personalDetails] = useOnyx(ONYXKEYS.PERSONAL_DETAILS_LIST);
4737
const styles = useThemeStyles();
4838
const {translate} = useLocalize();
49-
const [assignee, setAssignee] = useState<TaskActions.Assignee>();
39+
const assignee = useMemo(() => TaskActions.getAssignee(task?.assigneeAccountID ?? -1, personalDetails), [task?.assigneeAccountID, personalDetails]);
5040
const assigneeTooltipDetails = ReportUtils.getDisplayNamesWithTooltips(
5141
OptionsListUtils.getPersonalDetailsForAccountIDs(task?.assigneeAccountID ? [task.assigneeAccountID] : [], personalDetails),
5242
false,
5343
);
54-
const [shareDestination, setShareDestination] = useState<TaskActions.ShareDestination>();
55-
const [title, setTitle] = useState('');
56-
const [description, setDescription] = useState('');
44+
const shareDestination = useMemo(
45+
() => (task?.shareDestination ? TaskActions.getShareDestination(task.shareDestination, reports, personalDetails) : undefined),
46+
[task?.shareDestination, reports, personalDetails],
47+
);
48+
const parentReport = useMemo(() => (task?.shareDestination ? reports?.[`${ONYXKEYS.COLLECTION.REPORT}${task.shareDestination}`] : undefined), [reports, task?.shareDestination]);
5749
const [errorMessage, setErrorMessage] = useState('');
58-
const [parentReport, setParentReport] = useState<OnyxEntry<Report>>();
5950

6051
const hasDestinationError = task?.skipConfirmation && !task?.parentReportID;
6152
const isAllowedToCreateTask = useMemo(() => isEmptyObject(parentReport) || ReportUtils.isAllowedToComment(parentReport), [parentReport]);
@@ -79,38 +70,13 @@ function NewTaskPage({task, reports, personalDetails, route}: NewTaskPageProps)
7970
useEffect(() => {
8071
setErrorMessage('');
8172

82-
// If we have an assignee, we want to set the assignee data
83-
// If there's an issue with the assignee chosen, we want to notify the user
84-
if (task?.assignee) {
85-
const displayDetails = TaskActions.getAssignee(task?.assigneeAccountID ?? -1, personalDetails);
86-
setAssignee(displayDetails);
87-
}
88-
8973
// We only set the parentReportID if we are creating a task from a report
9074
// this allows us to go ahead and set that report as the share destination
9175
// and disable the share destination selector
9276
if (task?.parentReportID) {
9377
TaskActions.setShareDestinationValue(task.parentReportID);
9478
}
95-
96-
// If we have a share destination, we want to set the parent report and
97-
// the share destination data
98-
if (task?.shareDestination) {
99-
setParentReport(reports?.[`report_${task.shareDestination}`]);
100-
const displayDetails = TaskActions.getShareDestination(task.shareDestination, reports, personalDetails);
101-
setShareDestination(displayDetails);
102-
}
103-
104-
// If we have a title, we want to set the title
105-
if (task?.title !== undefined) {
106-
setTitle(task.title);
107-
}
108-
109-
// If we have a description, we want to set the description
110-
if (task?.description !== undefined) {
111-
setDescription(task.description);
112-
}
113-
}, [personalDetails, reports, task?.assignee, task?.assigneeAccountID, task?.description, task?.parentReportID, task?.shareDestination, task?.title]);
79+
}, [task?.assignee, task?.assigneeAccountID, task?.description, task?.parentReportID, task?.shareDestination, task?.title]);
11480

11581
// On submit, we want to call the createTask function and wait to validate
11682
// the response
@@ -179,14 +145,14 @@ function NewTaskPage({task, reports, personalDetails, route}: NewTaskPageProps)
179145
<View style={styles.mb5}>
180146
<MenuItemWithTopDescription
181147
description={translate('task.title')}
182-
title={title}
148+
title={task?.title}
183149
onPress={() => Navigation.navigate(ROUTES.NEW_TASK_TITLE.getRoute(backTo))}
184150
shouldShowRightIcon
185151
rightLabel={translate('common.required')}
186152
/>
187153
<MenuItemWithTopDescription
188154
description={translate('task.description')}
189-
title={description}
155+
title={task?.description}
190156
onPress={() => Navigation.navigate(ROUTES.NEW_TASK_DESCRIPTION.getRoute(backTo))}
191157
shouldShowRightIcon
192158
shouldParseTitle
@@ -234,14 +200,4 @@ function NewTaskPage({task, reports, personalDetails, route}: NewTaskPageProps)
234200

235201
NewTaskPage.displayName = 'NewTaskPage';
236202

237-
export default withOnyx<NewTaskPageProps, NewTaskPageOnyxProps>({
238-
task: {
239-
key: ONYXKEYS.TASK,
240-
},
241-
reports: {
242-
key: ONYXKEYS.COLLECTION.REPORT,
243-
},
244-
personalDetails: {
245-
key: ONYXKEYS.PERSONAL_DETAILS_LIST,
246-
},
247-
})(NewTaskPage);
203+
export default NewTaskPage;

0 commit comments

Comments
 (0)