diff --git a/config/oxlint/oxlint.seatbelt.tsv b/config/oxlint/oxlint.seatbelt.tsv index e32698eeaa1f..de17117d876b 100644 --- a/config/oxlint/oxlint.seatbelt.tsv +++ b/config/oxlint/oxlint.seatbelt.tsv @@ -234,7 +234,6 @@ "../../src/components/MoneyRequestConfirmationList/hooks/useSplitParticipants.tsx" "@typescript-eslint/no-deprecated/MoneyRequestAmountInput" 1 "../../src/components/MoneyRequestConfirmationList/hooks/useSplitParticipants.tsx" "no-restricted-imports" 1 "../../src/components/MoneyRequestConfirmationList/hooks/useTransactionReportForConfirmation.ts" "@typescript-eslint/no-unsafe-type-assertion" 1 -"../../src/components/MoneyRequestConfirmationList/sections/AmountField.tsx" "@typescript-eslint/no-deprecated/MenuItemWithTopDescription" 1 "../../src/components/MoneyRequestConfirmationList/sections/AmountField.tsx" "@typescript-eslint/no-deprecated/NumberWithSymbolForm" 1 "../../src/components/MoneyRequestConfirmationList/sections/AmountField.tsx" "@typescript-eslint/no-unsafe-type-assertion" 1 "../../src/components/MoneyRequestConfirmationList/sections/AmountField.tsx" "no-restricted-imports" 1 @@ -305,7 +304,6 @@ "../../src/components/ProductMarketingWindow/ProductMarketingWindowManager.tsx" "rulesdir/no-onyx-loading-status" 2 "../../src/components/ProductTrainingContext/index.tsx" "rulesdir/no-onyx-loading-status" 4 "../../src/components/PromotedActionsBar.tsx" "no-restricted-imports" 1 -"../../src/components/PushRowWithModal/index.tsx" "@typescript-eslint/no-deprecated/MenuItemWithTopDescription" 1 "../../src/components/PushRowWithModal/PushRowModal.tsx" "no-restricted-imports" 1 "../../src/components/RadioButtonWithLabel.tsx" "no-restricted-syntax" 1 "../../src/components/Reactions/AddReactionBubble.tsx" "react-hooks/refs" 1 @@ -417,7 +415,6 @@ "../../src/components/StatePicker/index.tsx" "@typescript-eslint/no-unsafe-type-assertion" 1 "../../src/components/StatePicker/StateSelectorModal.tsx" "no-restricted-imports" 1 "../../src/components/SubStepForms/AddressStep.tsx" "@typescript-eslint/no-unsafe-type-assertion" 3 -"../../src/components/SubStepForms/ConfirmationStep.tsx" "@typescript-eslint/no-deprecated/MenuItemWithTopDescription" 1 "../../src/components/SubStepForms/CountryFullStep.tsx" "@typescript-eslint/no-unsafe-type-assertion" 1 "../../src/components/SubStepForms/DateOfBirthStep.tsx" "@typescript-eslint/no-unsafe-type-assertion" 2 "../../src/components/SubStepForms/DateOfBirthStep.tsx" "react-hooks/purity" 2 @@ -2227,7 +2224,6 @@ "../../tests/ui/NumberWithSymbolFormWithoutTouchScreenTest.tsx" "no-restricted-imports" 1 "../../tests/ui/ProfilePageTest.tsx" "@typescript-eslint/no-unnecessary-type-assertion" 5 "../../tests/ui/PublicProfilePageTest.tsx" "@typescript-eslint/no-unnecessary-type-assertion" 4 -"../../tests/ui/PushRowWithModalTest.tsx" "@typescript-eslint/no-deprecated/MenuItemWithTopDescription" 1 "../../tests/ui/RecentlyAddedSectionTest.tsx" "@typescript-eslint/no-unnecessary-type-assertion" 1 "../../tests/ui/ReportActionItemTest.tsx" "@typescript-eslint/no-unnecessary-type-assertion" 2 "../../tests/ui/ReportActionItemTest.tsx" "react-hooks/globals" 1 diff --git a/src/components/MoneyRequestConfirmationList/sections/AmountField.tsx b/src/components/MoneyRequestConfirmationList/sections/AmountField.tsx index 2f825c5ca7a8..53d30c0391c4 100644 --- a/src/components/MoneyRequestConfirmationList/sections/AmountField.tsx +++ b/src/components/MoneyRequestConfirmationList/sections/AmountField.tsx @@ -1,4 +1,4 @@ -import MenuItemWithTopDescription from '@components/MenuItemWithTopDescription'; +import MenuItem from '@components/MenuItem'; import {useConfirmationFields} from '@components/MoneyRequestConfirmationFields/context'; import NumberWithSymbolForm from '@components/NumberWithSymbolForm'; import type {BaseTextInputRef} from '@components/TextInput/BaseTextInput/types'; @@ -29,6 +29,7 @@ import {calculateTaxAmount, getTaxCode, getTaxValue, hasAnyManuallyEnteredScanFi import IOURequestStepCurrencyModal from '@pages/iou/request/step/IOURequestStepCurrencyModal'; import {resetSplitShares, setDraftSplitTransaction, setSplitShares} from '@userActions/IOU/Split'; +import {callIfAuthenticated} from '@userActions/Session'; import CONST from '@src/CONST'; import type {TranslationPaths} from '@src/languages/types'; @@ -40,6 +41,7 @@ import type * as OnyxTypes from '@src/types/onyx'; import type {OnyxEntry} from 'react-native-onyx'; import {useIsFocused, useNavigation} from '@react-navigation/native'; +import {authTokenTypeSelector} from '@selectors/Session'; import React, {useEffect, useRef, useState} from 'react'; import {View} from 'react-native'; @@ -90,6 +92,7 @@ function AmountField({ const {translate, preferredLocale} = useLocalize(); const {getCurrencyDecimals, getCurrencySymbol} = useCurrencyListActions(); const [report] = useOnyx(`${ONYXKEYS.COLLECTION.REPORT}${reportID}`); + const [session] = useOnyx(ONYXKEYS.SESSION, {selector: authTokenTypeSelector}); const {splitDraftTransaction, baseTransaction} = useSplitDraftBaseTransaction(transactionID); const currentUserPersonalDetails = useCurrentUserPersonalDetails(); const amountInputRef = useRef(null); @@ -413,23 +416,35 @@ function AmountField({ onPress={openAmountPage} isDisabled={didConfirm} isInteractive={canOpenAmountPage} - errorText={shouldDisplayFieldError && amountIsMissing ? translate('common.error.enterAmount') : ''} + errorText={shouldShowAmountMissingError ? translate('common.error.enterAmount') : ''} sentryLabel={CONST.SENTRY_LABEL.REQUEST_CONFIRMATION_LIST.AMOUNT_FIELD} /> ) : ( - + > + + + {translate('iou.amount')} + {formattedAmount} + + {(canOpenAmountPage || shouldShowAmountMissingError) && ( + + {shouldShowAmountMissingError && } + {canOpenAmountPage && } + + )} + + {shouldShowAmountMissingError && ( + + )} + )} {/* The push row carries its own 20px of horizontal padding, so the button is inset to the 16px diff --git a/src/components/PushRowWithModal/index.tsx b/src/components/PushRowWithModal/index.tsx index f5202804376a..6ee57d5b1b08 100644 --- a/src/components/PushRowWithModal/index.tsx +++ b/src/components/PushRowWithModal/index.tsx @@ -1,12 +1,19 @@ -import MenuItemWithTopDescription from '@components/MenuItemWithTopDescription'; +import MenuItem from '@components/MenuItem'; +import MenuItemField from '@components/MenuItem/presets/MenuItemField'; + +import useOnyx from '@hooks/useOnyx'; import toggleArrayItem from '@libs/toggleArrayItem'; +import {callIfAuthenticated} from '@userActions/Session'; + import CONST from '@src/CONST'; +import ONYXKEYS from '@src/ONYXKEYS'; import KeyboardUtils from '@src/utils/keyboard'; import type {StyleProp, ViewStyle} from 'react-native'; +import {authTokenTypeSelector} from '@selectors/Session'; import React, {useRef, useState} from 'react'; import PushRowModal from './PushRowModal'; @@ -65,6 +72,7 @@ function PushRowWithModal(props: PushRowWithModalProps) { const [isModalVisible, setIsModalVisible] = useState(false); const [pendingSelection, setPendingSelection] = useState([]); const shouldBlurOnCloseRef = useRef(true); + const [session] = useOnyx(ONYXKEYS.SESSION, {selector: authTokenTypeSelector}); let selection: string[] = []; if (props.canSelectMultiple) { @@ -111,21 +119,29 @@ function PushRowWithModal(props: PushRowWithModalProps) { return ( <> - optionsList[key]) - .filter(Boolean) - .join(', ')} - shouldShowRightIcon={shouldAllowChange} - onPress={handleModalOpen} - wrapperStyle={wrapperStyles} - interactive={shouldAllowChange} - disabled={disabled} + + > + optionsList[key]) + .filter(Boolean) + .join(', ')} + > + {!!errorText && } + {shouldAllowChange && } + + {!!errorText && ( + + )} + + > + + {!!brickRoadIndicator && } + {shouldShowRightIcon && } + + {!!errorText && ( + + )} + ); }; diff --git a/tests/ui/PushRowWithModalTest.tsx b/tests/ui/PushRowWithModalTest.tsx index 6e4752e65047..8988fea5f44d 100644 --- a/tests/ui/PushRowWithModalTest.tsx +++ b/tests/ui/PushRowWithModalTest.tsx @@ -1,6 +1,7 @@ import {act, render} from '@testing-library/react-native'; -import MenuItemWithTopDescription from '@components/MenuItemWithTopDescription'; +import MenuItem from '@components/MenuItem'; +import MenuItemField from '@components/MenuItem/presets/MenuItemField'; import PushRowWithModal from '@src/components/PushRowWithModal'; import PushRowModal from '@src/components/PushRowWithModal/PushRowModal'; @@ -11,7 +12,18 @@ import React from 'react'; import createMock from '../utils/createMock'; -jest.mock('@components/MenuItemWithTopDescription', () => jest.fn(() => null)); +jest.mock('@components/MenuItem', () => ({ + __esModule: true, + default: { + Root: jest.fn(({children}: {children?: React.ReactNode}) => children), + Chevron: () => null, + BrickRoadIndicator: () => null, + HelpText: () => null, + }, +})); +jest.mock('@components/MenuItem/presets/MenuItemField', () => ({__esModule: true, default: {Row: jest.fn(() => null)}})); +jest.mock('@hooks/useOnyx', () => () => [undefined]); +jest.mock('@userActions/Session', () => ({callIfAuthenticated: (callback: () => void) => callback})); jest.mock('@src/components/PushRowWithModal/PushRowModal', () => jest.fn(() => null)); jest.mock('@src/utils/keyboard', () => ({ __esModule: true, @@ -21,13 +33,15 @@ jest.mock('@src/utils/keyboard', () => ({ const optionsList = {RETAIL: 'Retail', SERVICES: 'Services', SOFTWARE: 'Software'}; describe('PushRowWithModal', () => { - const mockedRow = jest.mocked(MenuItemWithTopDescription); + const mockedRow = jest.mocked(MenuItem.Root); + const mockedFieldRow = jest.mocked(MenuItemField.Row); const mockedModal = jest.mocked(PushRowModal); const getRow = () => mockedRow.mock.lastCall?.[0]; const getModal = () => mockedModal.mock.lastCall?.[0]; beforeEach(() => { mockedRow.mockClear(); + mockedFieldRow.mockClear(); mockedModal.mockClear(); }); @@ -46,6 +60,51 @@ describe('PushRowWithModal', () => { ); } + it('keeps an unchangeable answer non-interactive without dimming it', () => { + // Given a field whose saved answer cannot be changed + render( + , + ); + + // When the field row is composed + const row = getRow(); + const field = mockedFieldRow.mock.lastCall?.[0]; + + // Then it retains the answer without a press handler or disabled opacity + expect(row?.onPress).toBeUndefined(); + expect(row?.isDisabled).toBe(false); + expect(field?.name).toBe('Industry'); + expect(field?.value).toBe('Retail'); + }); + + it('passes temporary disabled state to the root while retaining its edit action', () => { + // Given an editable field temporarily unavailable, such as while offline + render( + , + ); + + // When the row is composed + const row = getRow(); + + // Then the root blocks interaction and dims the row, rather than making the field permanently read-only + expect(row?.isDisabled).toBe(true); + expect(row?.onPress).toEqual(expect.any(Function)); + expect(mockedFieldRow.mock.lastCall?.[0].value).toBe(''); + }); + it('saves the ticked options together when the user presses Save', async () => { // Given a multi-select row with Retail saved const onInputChange = jest.fn(); @@ -81,7 +140,7 @@ describe('PushRowWithModal', () => { expect(onInputChange).not.toHaveBeenCalled(); expect(onBlur).toHaveBeenCalledTimes(1); expect(getModal()?.selectedOptions).toEqual(['RETAIL']); - expect(getRow()?.title).toBe('Retail'); + expect(mockedFieldRow.mock.lastCall?.[0].value).toBe('Retail'); }); it('drops a saved option missing from the list when the user saves', async () => { diff --git a/tests/ui/components/SubStepForms/ConfirmationStepTest.tsx b/tests/ui/components/SubStepForms/ConfirmationStepTest.tsx index 8ec3d540075d..af90238a8b30 100644 --- a/tests/ui/components/SubStepForms/ConfirmationStepTest.tsx +++ b/tests/ui/components/SubStepForms/ConfirmationStepTest.tsx @@ -15,20 +15,20 @@ jest.mock('@hooks/useThemeStyles', () => () => new Proxy({}, {get: () => ({})})) jest.mock('@hooks/useNetwork', () => () => ({isOffline: false})); jest.mock('@hooks/useSafeAreaPaddings', () => () => ({paddingTop: 0, paddingBottom: 0, insets: undefined, safeAreaPaddingBottomStyle: {}})); -jest.mock('@components/MenuItemWithTopDescription', () => { +jest.mock('@components/MenuItem', () => { const reactNative = jest.requireActual('react-native'); const RNPressable = reactNative.Pressable; - const RNView = reactNative.View; return { __esModule: true, - default: ({pressableTestID, title, description}: {pressableTestID?: string; title: string; description: string}) => ( - - {title} - {description} - - ), + default: {Root: RNPressable, Chevron: () => null, BrickRoadIndicator: () => null, HelpText: () => null}, }; }); +jest.mock('@components/MenuItem/presets/MenuItemField', () => { + const {Text: RNText} = jest.requireActual('react-native'); + return {__esModule: true, default: {Row: ({name, value}: {name: string; value: string}) => {`${name}: ${value}`}}}; +}); +jest.mock('@hooks/useOnyx', () => () => [undefined]); +jest.mock('@userActions/Session', () => ({callIfAuthenticated: (callback: () => void) => callback})); jest.mock('@components/RenderHTML', () => ({__esModule: true, default: () => null})); jest.mock('@components/DotIndicatorMessage', () => ({__esModule: true, default: () => null})); @@ -79,7 +79,7 @@ describe('ConfirmationStep — caller-provided id contract', () => { ]; renderStep(after); expect(screen.getByTestId('legal-name')).toBeOnTheScreen(); - expect(screen.getByTestId('legal-name-title').props.children).toBe('Jane Smith'); + expect(screen.getByText('Legal name: Jane Smith')).toBeOnTheScreen(); }); it('honors an explicit `testID` over the id', () => { diff --git a/tests/unit/components/MoneyRequestConfirmationList/AmountField.test.tsx b/tests/unit/components/MoneyRequestConfirmationList/AmountField.test.tsx index a77d623f270c..bf2cd78d20f1 100644 --- a/tests/unit/components/MoneyRequestConfirmationList/AmountField.test.tsx +++ b/tests/unit/components/MoneyRequestConfirmationList/AmountField.test.tsx @@ -75,14 +75,27 @@ jest.mock('@pages/iou/request/step/IOURequestStepCurrencyModal', () => { ); }; }); -jest.mock('@components/MenuItemWithTopDescription', () => { +jest.mock('@components/MenuItem', () => { const {Text} = jest.requireActual>>('react-native'); - return ({title, interactive = true}: {title?: string; interactive?: boolean}) => ( - <> - {`Read-only amount: ${title ?? ''}`} - {interactive && Opens amount page} - - ); + return { + __esModule: true, + default: { + Root: ({children, onPress}: {children?: React.ReactNode; onPress?: () => void}) => ( + <> + {children} + {!!onPress && Opens amount page} + + ), + Row: ({children}: {children?: React.ReactNode}) => children, + Content: ({children}: {children?: React.ReactNode}) => children, + Trailing: ({children}: {children?: React.ReactNode}) => children, + FieldName: Text, + FieldValue: ({children}: {children?: string}) => {`Read-only amount: ${children ?? ''}`}, + Chevron: () => null, + BrickRoadIndicator: () => null, + HelpText: ({message}: {message: string}) => {message}, + }, + }; }); jest.mock('@components/MoneyRequestConfirmationList/sections/ExpenseFieldRow', () => { const {Text} = jest.requireActual>>('react-native');