Skip to content

Commit 57fbf0b

Browse files
francoislOSBotify
authored andcommitted
Merge pull request #55101 from Expensify/revert-54451-add-toggle-for-enable/disable-instead-of-label
(cherry picked from commit 7c7773b) (CP triggered by thienlnam)
1 parent 97b0412 commit 57fbf0b

11 files changed

+63
-184
lines changed

src/CONST.ts

-1
Original file line numberDiff line numberDiff line change
@@ -866,7 +866,6 @@ const CONST = {
866866
EMPTY_ARRAY,
867867
EMPTY_OBJECT,
868868
DEFAULT_NUMBER_ID: 0,
869-
EMPTY_STRING: '',
870869
USE_EXPENSIFY_URL,
871870
EXPENSIFY_URL,
872871
GOOGLE_MEET_URL_ANDROID: 'https://meet.google.com',

src/libs/OptionsListUtils.ts

+6-2
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ type GetOptionsConfig = {
111111
};
112112

113113
type GetUserToInviteConfig = {
114-
searchValue: string;
114+
searchValue: string | undefined;
115115
optionsToExclude?: Array<Partial<ReportUtils.OptionData>>;
116116
reportActions?: ReportActions;
117117
shouldAcceptName?: boolean;
@@ -1078,6 +1078,10 @@ function getUserToInviteOption({
10781078
showChatPreviewLine = false,
10791079
shouldAcceptName = false,
10801080
}: GetUserToInviteConfig): ReportUtils.OptionData | null {
1081+
if (!searchValue) {
1082+
return null;
1083+
}
1084+
10811085
const parsedPhoneNumber = PhoneNumber.parsePhoneNumber(LoginUtils.appendCountryCode(Str.removeSMSDomain(searchValue)));
10821086
const isCurrentUserLogin = isCurrentUser({login: searchValue} as PersonalDetails);
10831087
const isInSelectedOption = selectedOptions.some((option) => 'login' in option && option.login === searchValue);
@@ -1086,7 +1090,7 @@ function getUserToInviteOption({
10861090
const isInOptionToExclude =
10871091
optionsToExclude.findIndex((optionToExclude) => 'login' in optionToExclude && optionToExclude.login === PhoneNumber.addSMSDomainIfPhoneNumber(searchValue).toLowerCase()) !== -1;
10881092

1089-
if (!searchValue || isCurrentUserLogin || isInSelectedOption || (!isValidEmail && !isValidPhoneNumber && !shouldAcceptName) || isInOptionToExclude) {
1093+
if (isCurrentUserLogin || isInSelectedOption || (!isValidEmail && !isValidPhoneNumber && !shouldAcceptName) || isInOptionToExclude) {
10901094
return null;
10911095
}
10921096

src/pages/NewChatConfirmPage.tsx

+3-3
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ function NewChatConfirmPage({newGroupDraft, allPersonalDetails}: NewChatConfirmP
5555
return [];
5656
}
5757
const options: Participant[] = newGroupDraft.participants.map((participant) =>
58-
OptionsListUtils.getParticipantsOption({accountID: participant.accountID, login: participant.login, reportID: ''}, allPersonalDetails),
58+
OptionsListUtils.getParticipantsOption({accountID: participant.accountID, login: participant?.login, reportID: ''}, allPersonalDetails),
5959
);
6060
return options;
6161
}, [allPersonalDetails, newGroupDraft?.participants]);
@@ -92,7 +92,7 @@ function NewChatConfirmPage({newGroupDraft, allPersonalDetails}: NewChatConfirmP
9292
if (!newGroupDraft) {
9393
return;
9494
}
95-
const newSelectedParticipants = (newGroupDraft.participants ?? []).filter((participant) => participant.login !== option.login);
95+
const newSelectedParticipants = (newGroupDraft.participants ?? []).filter((participant) => participant?.login !== option.login);
9696
Report.setGroupDraft({participants: newSelectedParticipants});
9797
},
9898
[newGroupDraft],
@@ -103,7 +103,7 @@ function NewChatConfirmPage({newGroupDraft, allPersonalDetails}: NewChatConfirmP
103103
return;
104104
}
105105

106-
const logins: string[] = (newGroupDraft.participants ?? []).map((participant) => participant.login);
106+
const logins: string[] = (newGroupDraft.participants ?? []).map((participant) => participant.login).filter((login): login is string => !!login);
107107
Report.navigateToAndOpenReport(logins, true, undefined, newGroupDraft.reportName ?? '', newGroupDraft.avatarUri ?? '', avatarFile, optimisticReportID.current, true);
108108
}, [newGroupDraft, avatarFile]);
109109

src/pages/NewChatPage.tsx

+2-2
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ function useOptions() {
103103
let participantOption: OptionData | undefined | null = listOptions.personalDetails.find((option) => option.accountID === participant.accountID);
104104
if (!participantOption) {
105105
participantOption = OptionsListUtils.getUserToInviteOption({
106-
searchValue: participant.login,
106+
searchValue: participant?.login,
107107
});
108108
}
109109
if (!participantOption) {
@@ -274,7 +274,7 @@ function NewChatPage() {
274274
return;
275275
}
276276
const selectedParticipants: SelectedParticipant[] = selectedOptions.map((option: OptionData) => ({
277-
login: option.login ?? CONST.EMPTY_STRING,
277+
login: option?.login,
278278
accountID: option.accountID ?? CONST.DEFAULT_NUMBER_ID,
279279
}));
280280
const logins = [...selectedParticipants, {login: personalData.login, accountID: personalData.accountID}];

src/pages/workspace/categories/WorkspaceCategoriesPage.tsx

+4-18
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,12 @@ import * as Expensicons from '@components/Icon/Expensicons';
1414
import * as Illustrations from '@components/Icon/Illustrations';
1515
import LottieAnimations from '@components/LottieAnimations';
1616
import ScreenWrapper from '@components/ScreenWrapper';
17+
import ListItemRightCaretWithLabel from '@components/SelectionList/ListItemRightCaretWithLabel';
1718
import TableListItem from '@components/SelectionList/TableListItem';
1819
import type {ListItem} from '@components/SelectionList/types';
1920
import SelectionListWithModal from '@components/SelectionListWithModal';
2021
import CustomListHeader from '@components/SelectionListWithModal/CustomListHeader';
2122
import TableListItemSkeleton from '@components/Skeletons/TableRowSkeleton';
22-
import Switch from '@components/Switch';
2323
import Text from '@components/Text';
2424
import TextLink from '@components/TextLink';
2525
import useAutoTurnSelectionModeOffWhenHasNoActiveOption from '@hooks/useAutoTurnSelectionModeOffWhenHasNoActiveOption';
@@ -42,8 +42,8 @@ import type {FullScreenNavigatorParamList} from '@libs/Navigation/types';
4242
import * as PolicyUtils from '@libs/PolicyUtils';
4343
import AccessOrNotFoundWrapper from '@pages/workspace/AccessOrNotFoundWrapper';
4444
import * as Modal from '@userActions/Modal';
45-
import * as Category from '@userActions/Policy/Category';
4645
import {deleteWorkspaceCategories, setWorkspaceCategoryEnabled} from '@userActions/Policy/Category';
46+
import * as Category from '@userActions/Policy/Category';
4747
import CONST from '@src/CONST';
4848
import ONYXKEYS from '@src/ONYXKEYS';
4949
import ROUTES from '@src/ROUTES';
@@ -105,13 +105,6 @@ function WorkspaceCategoriesPage({route}: WorkspaceCategoriesPageProps) {
105105
setSelectedCategories({});
106106
}, [isFocused]);
107107

108-
const updateWorkspaceRequiresCategory = useCallback(
109-
(value: boolean, categoryName: string) => {
110-
Category.setWorkspaceCategoryEnabled(policyId, {[categoryName]: {name: categoryName, enabled: value}});
111-
},
112-
[policyId],
113-
);
114-
115108
const categoryList = useMemo<PolicyOption[]>(() => {
116109
const categories = lodashSortBy(Object.values(policyCategories ?? {}), 'name', localeCompare) as PolicyCategory[];
117110
return categories.reduce<PolicyOption[]>((acc, value) => {
@@ -128,19 +121,12 @@ function WorkspaceCategoriesPage({route}: WorkspaceCategoriesPageProps) {
128121
isDisabled,
129122
pendingAction: value.pendingAction,
130123
errors: value.errors ?? undefined,
131-
rightElement: (
132-
<Switch
133-
isOn={value.enabled}
134-
disabled={isDisabled}
135-
accessibilityLabel={translate('workspace.categories.enableCategory')}
136-
onToggle={(newValue: boolean) => updateWorkspaceRequiresCategory(newValue, value.name)}
137-
/>
138-
),
124+
rightElement: <ListItemRightCaretWithLabel labelText={value.enabled ? translate('workspace.common.enabled') : translate('workspace.common.disabled')} />,
139125
});
140126

141127
return acc;
142128
}, []);
143-
}, [policyCategories, isOffline, selectedCategories, canSelectMultiple, translate, updateWorkspaceRequiresCategory]);
129+
}, [policyCategories, isOffline, selectedCategories, canSelectMultiple, translate]);
144130

145131
useAutoTurnSelectionModeOffWhenHasNoActiveOption(categoryList);
146132

src/pages/workspace/distanceRates/PolicyDistanceRatesPage.tsx

+8-35
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,11 @@ import HeaderWithBackButton from '@components/HeaderWithBackButton';
88
import * as Expensicons from '@components/Icon/Expensicons';
99
import * as Illustrations from '@components/Icon/Illustrations';
1010
import ScreenWrapper from '@components/ScreenWrapper';
11+
import ListItemRightCaretWithLabel from '@components/SelectionList/ListItemRightCaretWithLabel';
1112
import TableListItem from '@components/SelectionList/TableListItem';
1213
import type {ListItem} from '@components/SelectionList/types';
1314
import SelectionListWithModal from '@components/SelectionListWithModal';
1415
import CustomListHeader from '@components/SelectionListWithModal/CustomListHeader';
15-
import Switch from '@components/Switch';
1616
import Text from '@components/Text';
1717
import useLocalize from '@hooks/useLocalize';
1818
import useMobileSelectionMode from '@hooks/useMobileSelectionMode';
@@ -74,11 +74,11 @@ function PolicyDistanceRatesPage({
7474
const dismissError = useCallback(
7575
(item: RateForList) => {
7676
if (customUnitRates[item.value].errors) {
77-
DistanceRate.clearDeleteDistanceRateError(policyID, customUnit?.customUnitID ?? CONST.EMPTY_STRING, item.value);
77+
DistanceRate.clearDeleteDistanceRateError(policyID, customUnit?.customUnitID ?? '', item.value);
7878
return;
7979
}
8080

81-
DistanceRate.clearCreateDistanceRateItemAndError(policyID, customUnit?.customUnitID ?? CONST.EMPTY_STRING, item.value);
81+
DistanceRate.clearCreateDistanceRateItemAndError(policyID, customUnit?.customUnitID ?? '', item.value);
8282
},
8383
[customUnit?.customUnitID, customUnitRates, policyID],
8484
);
@@ -98,36 +98,16 @@ function PolicyDistanceRatesPage({
9898
setSelectedDistanceRates([]);
9999
}, [isFocused]);
100100

101-
const updateDistanceRateEnabled = useCallback(
102-
(value: boolean, rateID: string) => {
103-
if (!customUnit) {
104-
return;
105-
}
106-
const rate = customUnit?.rates?.[rateID];
107-
// Rates can be disabled or deleted as long as in the remaining rates there is always at least one enabled rate and there are no pending delete action
108-
const canDisableOrDeleteRate = Object.values(customUnit?.rates ?? {}).some(
109-
(distanceRate: Rate) => distanceRate?.enabled && rateID !== distanceRate?.customUnitRateID && distanceRate?.pendingAction !== CONST.RED_BRICK_ROAD_PENDING_ACTION.DELETE,
110-
);
111-
112-
if (!rate?.enabled || canDisableOrDeleteRate) {
113-
DistanceRate.setPolicyDistanceRatesEnabled(policyID, customUnit, [{...rate, enabled: value}]);
114-
} else {
115-
setIsWarningModalVisible(true);
116-
}
117-
},
118-
[customUnit, policyID],
119-
);
120-
121101
const distanceRatesList = useMemo<RateForList[]>(
122102
() =>
123103
Object.values(customUnitRates)
124104
.sort((rateA, rateB) => (rateA?.rate ?? 0) - (rateB?.rate ?? 0))
125105
.map((value) => ({
126-
value: value.customUnitRateID ?? CONST.EMPTY_STRING,
106+
value: value.customUnitRateID ?? '',
127107
text: `${CurrencyUtils.convertAmountToDisplayString(value.rate, value.currency ?? CONST.CURRENCY.USD)} / ${translate(
128108
`common.${customUnit?.attributes?.unit ?? CONST.CUSTOM_UNITS.DISTANCE_UNIT_MILES}`,
129109
)}`,
130-
keyForList: value.customUnitRateID ?? CONST.EMPTY_STRING,
110+
keyForList: value.customUnitRateID ?? '',
131111
isSelected: selectedDistanceRates.find((rate) => rate.customUnitRateID === value.customUnitRateID) !== undefined && canSelectMultiple,
132112
isDisabled: value.pendingAction === CONST.RED_BRICK_ROAD_PENDING_ACTION.DELETE,
133113
pendingAction:
@@ -139,16 +119,9 @@ function PolicyDistanceRatesPage({
139119
value.pendingFields?.taxClaimablePercentage ??
140120
(policy?.pendingAction === CONST.RED_BRICK_ROAD_PENDING_ACTION.ADD ? policy?.pendingAction : undefined),
141121
errors: value.errors ?? undefined,
142-
rightElement: (
143-
<Switch
144-
isOn={!!value?.enabled}
145-
accessibilityLabel={translate('workspace.distanceRates.trackTax')}
146-
onToggle={(newValue: boolean) => updateDistanceRateEnabled(newValue, value.customUnitRateID)}
147-
disabled={value.pendingAction === CONST.RED_BRICK_ROAD_PENDING_ACTION.DELETE}
148-
/>
149-
),
122+
rightElement: <ListItemRightCaretWithLabel labelText={value.enabled ? translate('workspace.common.enabled') : translate('workspace.common.disabled')} />,
150123
})),
151-
[customUnitRates, translate, customUnit, selectedDistanceRates, canSelectMultiple, policy?.pendingAction, updateDistanceRateEnabled],
124+
[customUnit?.attributes?.unit, customUnitRates, selectedDistanceRates, translate, policy?.pendingAction, canSelectMultiple],
152125
);
153126

154127
const addRate = () => {
@@ -197,7 +170,7 @@ function PolicyDistanceRatesPage({
197170
DistanceRate.deletePolicyDistanceRates(
198171
policyID,
199172
customUnit,
200-
selectedDistanceRates.map((rate) => rate.customUnitRateID ?? CONST.EMPTY_STRING),
173+
selectedDistanceRates.map((rate) => rate.customUnitRateID ?? ''),
201174
);
202175
setSelectedDistanceRates([]);
203176
setIsDeleteModalVisible(false);

src/pages/workspace/reportFields/ReportFieldsListValuesPage.tsx

+4-22
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import React, {useCallback, useMemo, useState} from 'react';
1+
import React, {useMemo, useState} from 'react';
22
import {View} from 'react-native';
33
import {useOnyx} from 'react-native-onyx';
44
import Button from '@components/Button';
@@ -10,12 +10,12 @@ import HeaderWithBackButton from '@components/HeaderWithBackButton';
1010
import * as Expensicons from '@components/Icon/Expensicons';
1111
import * as Illustrations from '@components/Icon/Illustrations';
1212
import ScreenWrapper from '@components/ScreenWrapper';
13+
import ListItemRightCaretWithLabel from '@components/SelectionList/ListItemRightCaretWithLabel';
1314
import TableListItem from '@components/SelectionList/TableListItem';
1415
import type {ListItem} from '@components/SelectionList/types';
1516
import SelectionListWithModal from '@components/SelectionListWithModal';
1617
import CustomListHeader from '@components/SelectionListWithModal/CustomListHeader';
1718
import TableListItemSkeleton from '@components/Skeletons/TableRowSkeleton';
18-
import Switch from '@components/Switch';
1919
import Text from '@components/Text';
2020
import useLocalize from '@hooks/useLocalize';
2121
import useMobileSelectionMode from '@hooks/useMobileSelectionMode';
@@ -90,18 +90,6 @@ function ReportFieldsListValuesPage({
9090
return [reportFieldValues, reportFieldDisabledValues];
9191
}, [formDraft?.disabledListValues, formDraft?.listValues, policy?.fieldList, reportFieldID]);
9292

93-
const updateReportFieldListValueEnabled = useCallback(
94-
(value: boolean, valueIndex: number) => {
95-
if (reportFieldID) {
96-
ReportField.updateReportFieldListValueEnabled(policyID, reportFieldID, [Number(valueIndex)], value);
97-
return;
98-
}
99-
100-
ReportField.setReportFieldsListValueEnabled([valueIndex], value);
101-
},
102-
[policyID, reportFieldID],
103-
);
104-
10593
const listValuesSections = useMemo(() => {
10694
const data = listValues
10795
.map<ValueListItem>((value, index) => ({
@@ -111,17 +99,11 @@ function ReportFieldsListValuesPage({
11199
keyForList: value,
112100
isSelected: selectedValues[value] && canSelectMultiple,
113101
enabled: !disabledListValues.at(index) ?? true,
114-
rightElement: (
115-
<Switch
116-
isOn={!disabledListValues.at(index) ?? true}
117-
accessibilityLabel={translate('workspace.distanceRates.trackTax')}
118-
onToggle={(newValue: boolean) => updateReportFieldListValueEnabled(newValue, index)}
119-
/>
120-
),
102+
rightElement: <ListItemRightCaretWithLabel labelText={disabledListValues.at(index) ? translate('workspace.common.disabled') : translate('workspace.common.enabled')} />,
121103
}))
122104
.sort((a, b) => localeCompare(a.value, b.value));
123105
return [{data, isDisabled: false}];
124-
}, [canSelectMultiple, disabledListValues, listValues, selectedValues, translate, updateReportFieldListValueEnabled]);
106+
}, [canSelectMultiple, disabledListValues, listValues, selectedValues, translate]);
125107

126108
const shouldShowEmptyState = Object.values(listValues ?? {}).length <= 0;
127109
const selectedValuesArray = Object.keys(selectedValues).filter((key) => selectedValues[key]);

0 commit comments

Comments
 (0)