Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion src/hooks/useReceiptScanDrop.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import type {Transaction} from '@src/types/onyx';
import type {FileObject} from '@src/types/utils/Attachment';
import useCurrentUserPersonalDetails from './useCurrentUserPersonalDetails';
import useFilesValidation from './useFilesValidation';
import useIsAnonymousUser from './useIsAnonymousUser';
import useOnyx from './useOnyx';
import useSelfDMReport from './useSelfDMReport';

Expand All @@ -23,6 +24,7 @@ import useSelfDMReport from './useSelfDMReport';
* Returns the drop handler, PDF validation component, and error modal needed for drag-and-drop receipt scanning.
*/
function useReceiptScanDrop() {
const isAnonymousUser = useIsAnonymousUser();
const currentUserPersonalDetails = useCurrentUserPersonalDetails();
const selfDMReport = useSelfDMReport();
const [policies] = useOnyx(ONYXKEYS.COLLECTION.POLICY);
Expand Down Expand Up @@ -115,7 +117,7 @@ function useReceiptScanDrop() {
validateFiles(files, Array.from(e.dataTransfer?.items ?? []));
};

return {initScanRequest, PDFValidationComponent, ErrorModal};
return {initScanRequest, PDFValidationComponent, ErrorModal, isDragDisabled: isAnonymousUser};
}

export default useReceiptScanDrop;
5 changes: 3 additions & 2 deletions src/pages/Search/SearchPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -1121,7 +1121,7 @@ function SearchPage({route}: SearchPageProps) {
personalPolicyID,
]);

const {initScanRequest, PDFValidationComponent, ErrorModal} = useReceiptScanDrop();
const {initScanRequest, PDFValidationComponent, ErrorModal, isDragDisabled} = useReceiptScanDrop();

const {resetVideoPlayerData} = usePlaybackActionsContext();

Expand Down Expand Up @@ -1239,7 +1239,7 @@ function SearchPage({route}: SearchPageProps) {
<>
<Animated.View style={[styles.flex1]}>
{shouldUseNarrowLayout ? (
<DragAndDropProvider>
<DragAndDropProvider isDisabled={isDragDisabled}>
{PDFValidationComponent}
<SearchPageNarrow
queryJSON={queryJSON}
Expand Down Expand Up @@ -1283,6 +1283,7 @@ function SearchPage({route}: SearchPageProps) {
onSortPressedCallback={onSortPressedCallback}
scrollHandler={scrollHandler}
initScanRequest={initScanRequest}
isDragDisabled={isDragDisabled}
PDFValidationComponent={PDFValidationComponent}
ErrorModal={ErrorModal}
shouldShowFooter={shouldShowFooter}
Expand Down
4 changes: 3 additions & 1 deletion src/pages/Search/SearchPageWide.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ type SearchPageWideProps = {
onSortPressedCallback: () => void;
scrollHandler: (event: NativeSyntheticEvent<NativeScrollEvent>) => void;
initScanRequest: (e: DragEvent) => void;
isDragDisabled: boolean;
PDFValidationComponent: React.ReactNode;
ErrorModal: React.ReactNode;
shouldShowFooter: boolean;
Expand All @@ -65,6 +66,7 @@ function SearchPageWide({
onSortPressedCallback,
scrollHandler,
initScanRequest,
isDragDisabled,
PDFValidationComponent,
ErrorModal,
shouldShowFooter,
Expand Down Expand Up @@ -99,7 +101,7 @@ function SearchPageWide({
shouldShowLink={false}
>
{!!queryJSON && (
<DragAndDropProvider>
<DragAndDropProvider isDisabled={isDragDisabled}>
{PDFValidationComponent}
<SearchPageHeader
queryJSON={queryJSON}
Expand Down
4 changes: 2 additions & 2 deletions src/pages/home/HomePage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ function HomePage() {
const theme = useTheme();
const {translate} = useLocalize();
const expensifyIcons = useMemoizedLazyExpensifyIcons(['SmartScan'] as const);
const {initScanRequest, PDFValidationComponent, ErrorModal} = useReceiptScanDrop();
const {initScanRequest, PDFValidationComponent, ErrorModal, isDragDisabled} = useReceiptScanDrop();

// This hook signals that the app is ready to be opened after HomePage mounts
// to make sure everything loads properly
Expand All @@ -40,7 +40,7 @@ function HomePage() {
usePreloadFullScreenNavigators();

return (
<DragAndDropProvider>
<DragAndDropProvider isDisabled={isDragDisabled}>
Comment thread
grgia marked this conversation as resolved.
Resolved
{PDFValidationComponent}
<ScreenWrapper
shouldEnablePickerAvoiding={false}
Expand Down
26 changes: 26 additions & 0 deletions tests/unit/hooks/useReceiptScanDrop.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import {renderHook} from '@testing-library/react-native';
import Onyx from 'react-native-onyx';
import useReceiptScanDrop from '@hooks/useReceiptScanDrop';
import CONST from '@src/CONST';
import ONYXKEYS from '@src/ONYXKEYS';
import waitForBatchedUpdatesWithAct from '../../utils/waitForBatchedUpdatesWithAct';

describe('useReceiptScanDrop', () => {
afterEach(async () => {
await Onyx.clear();
});

it('should disable drag for anonymous users', async () => {
await Onyx.merge(ONYXKEYS.SESSION, {authTokenType: CONST.AUTH_TOKEN_TYPES.ANONYMOUS});
const {result} = renderHook(() => useReceiptScanDrop());
await waitForBatchedUpdatesWithAct();
expect(result.current.isDragDisabled).toBe(true);
});

it('should enable drag for logged-in users', async () => {
await Onyx.merge(ONYXKEYS.SESSION, {authToken: 'test-token'});
const {result} = renderHook(() => useReceiptScanDrop());
await waitForBatchedUpdatesWithAct();
expect(result.current.isDragDisabled).toBe(false);
});
});
Loading