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
47 changes: 33 additions & 14 deletions src/components/DropZone/DualDropZone.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
import React from 'react';
import {View} from 'react-native';
// We use Animated for all functionality related to wide RHP to make it easier
// to interact with react-navigation components (e.g., CardContainer, interpolator), which also use Animated.
// eslint-disable-next-line no-restricted-imports
import {Animated, View} from 'react-native';
import type {ViewStyle} from 'react-native';
import DragAndDropConsumer from '@components/DragAndDrop/Consumer';
import {useWideRHPState} from '@components/WideRHPContextProvider';
import {useMemoizedLazyExpensifyIcons} from '@hooks/useLazyAsset';
import useLocalize from '@hooks/useLocalize';
import useResponsiveLayout from '@hooks/useResponsiveLayout';
Expand Down Expand Up @@ -30,12 +35,20 @@ function DualDropZone({isEditing, onAttachmentDrop, onReceiptDrop, shouldAcceptS
const theme = useTheme();
const icons = useMemoizedLazyExpensifyIcons(['MessageInABottle', 'SmartScan', 'ReplaceReceipt']);

const shouldStackVertically = shouldUseNarrowLayout || isMediumScreenWidth;
const {isWideRHPFocused} = useWideRHPState();
Comment thread
nkdengineer marked this conversation as resolved.
Resolved
const shouldStackVertically = (shouldUseNarrowLayout || isMediumScreenWidth) && !isWideRHPFocused;
const scanReceiptsText = shouldAcceptSingleReceipt ? 'dropzone.addReceipt' : 'dropzone.scanReceipts';
const shouldStackRevertHorizontally = isWideRHPFocused;
let flexStyle: ViewStyle = styles.flexRow;
if (shouldStackVertically) {
flexStyle = styles.flexColumn;
} else if (shouldStackRevertHorizontally) {
flexStyle = styles.flexRowReverse;
}

return (
<DragAndDropConsumer onDrop={() => {}}>
<View style={[shouldStackVertically ? styles.flexColumn : styles.flexRow, styles.w100, styles.h100]}>
<View style={[flexStyle, styles.w100, styles.h100]}>
<DropZoneWrapper onDrop={onAttachmentDrop}>
{({isDraggingOver}) => (
<DropZoneUI
Expand All @@ -52,17 +65,23 @@ function DualDropZone({isEditing, onAttachmentDrop, onReceiptDrop, shouldAcceptS
/>
)}
</DropZoneWrapper>
<DropZoneWrapper onDrop={onReceiptDrop}>
{({isDraggingOver}) => (
<DropZoneUI
icon={isEditing ? icons.ReplaceReceipt : icons.SmartScan}
dropTitle={translate(isEditing ? 'dropzone.replaceReceipt' : scanReceiptsText)}
dropStyles={styles.receiptDropOverlay(isDraggingOver)}
dropTextStyles={styles.receiptDropText}
dashedBorderStyles={[styles.dropzoneArea, styles.easeInOpacityTransition, styles.activeDropzoneDashedBorder(theme.receiptDropBorderColorActive, isDraggingOver)]}
/>
)}
</DropZoneWrapper>
<Animated.View style={isWideRHPFocused ? styles.wideRHPDropZoneContainer : [styles.flex1, styles.h100]}>
<DropZoneWrapper onDrop={onReceiptDrop}>
{({isDraggingOver}) => (
<DropZoneUI
icon={isEditing ? icons.ReplaceReceipt : icons.SmartScan}
dropTitle={translate(isEditing ? 'dropzone.replaceReceipt' : scanReceiptsText)}
dropStyles={styles.receiptDropOverlay(isDraggingOver)}
dropTextStyles={styles.receiptDropText}
dashedBorderStyles={[
styles.dropzoneArea,
styles.easeInOpacityTransition,
styles.activeDropzoneDashedBorder(theme.receiptDropBorderColorActive, isDraggingOver),
]}
/>
)}
</DropZoneWrapper>
</Animated.View>
</View>
</DragAndDropConsumer>
);
Expand Down
93 changes: 58 additions & 35 deletions src/components/ReceiptEmptyState.tsx
Original file line number Diff line number Diff line change
@@ -1,11 +1,15 @@
import React, {useEffect, useRef} from 'react';
import {View} from 'react-native';
import type {StyleProp, ViewStyle} from 'react-native';
import useFilesValidation from '@hooks/useFilesValidation';
import {useMemoizedLazyExpensifyIcons} from '@hooks/useLazyAsset';
import useLocalize from '@hooks/useLocalize';
import useTheme from '@hooks/useTheme';
import useThemeStyles from '@hooks/useThemeStyles';
import variables from '@styles/variables';
import CONST from '@src/CONST';
import type {FileObject} from '@src/types/utils/Attachment';
import AttachmentPicker from './AttachmentPicker';
import Icon from './Icon';
import PressableWithoutFeedback from './Pressable/PressableWithoutFeedback';
import ReceiptAlternativeMethods from './ReceiptAlternativeMethods';
Expand Down Expand Up @@ -34,6 +38,9 @@ type ReceiptEmptyStateProps = {

/** Whether it's displayed in Wide RHP */
isDisplayedInWideRHP?: boolean;

/** Callback to be called when a receipt is selected */
setReceiptFile?: (files: FileObject[]) => void;
};

// Returns an SVG icon indicating that the user should attach a receipt
Expand All @@ -46,12 +53,14 @@ function ReceiptEmptyState({
style,
onLoad,
isDisplayedInWideRHP = false,
setReceiptFile = () => {},
}: ReceiptEmptyStateProps) {
const styles = useThemeStyles();
const {translate} = useLocalize();
const theme = useTheme();
const isLoadedRef = useRef(false);
const icons = useMemoizedLazyExpensifyIcons(['ReceiptPlaceholderPlus', 'Receipt']);
Comment thread
nkdengineer marked this conversation as resolved.
Resolved
const {validateFiles, PDFValidationComponent, ErrorModal} = useFilesValidation(setReceiptFile);

const Wrapper = onPress ? PressableWithoutFeedback : View;
const containerStyle = [
Expand All @@ -73,42 +82,56 @@ function ReceiptEmptyState({
}, [onLoad]);

return (
<Wrapper
accessibilityRole="imagebutton"
accessibilityLabel={translate('receipt.upload')}
onPress={onPress}
disabled={disabled}
disabledStyle={styles.cursorDefault}
style={containerStyle}
>
<View style={[styles.flex1, styles.justifyContentCenter, styles.alignItemsCenter]}>
<View style={[styles.alignItemsCenter, styles.justifyContentCenter]}>
<View style={styles.pRelative}>
<Icon
fill={theme.border}
src={icons.Receipt}
width={variables.eReceiptEmptyIconWidth}
height={variables.eReceiptEmptyIconWidth}
/>
{!isThumbnail && (
<Icon
src={icons.ReceiptPlaceholderPlus}
width={variables.avatarSizeSmall}
height={variables.avatarSizeSmall}
additionalStyles={styles.moneyRequestAttachReceiptThumbnailIcon}
/>
)}
<AttachmentPicker acceptedFileTypes={[...CONST.API_ATTACHMENT_VALIDATIONS.ALLOWED_RECEIPT_EXTENSIONS]}>
{({openPicker}) => (
<Wrapper
accessibilityRole="imagebutton"
accessibilityLabel={translate('receipt.upload')}
onPress={() => {
if (isDisplayedInWideRHP) {
openPicker({
onPicked: validateFiles,
});
return;
}
onPress?.();
}}
disabled={disabled}
disabledStyle={styles.cursorDefault}
style={containerStyle}
>
{PDFValidationComponent}
{ErrorModal}
<View style={[styles.flex1, styles.justifyContentCenter, styles.alignItemsCenter]}>
<View style={[styles.alignItemsCenter, styles.justifyContentCenter]}>
<View style={styles.pRelative}>
<Icon
fill={theme.border}
src={icons.Receipt}
width={variables.eReceiptEmptyIconWidth}
height={variables.eReceiptEmptyIconWidth}
/>
{!isThumbnail && (
<Icon
src={icons.ReceiptPlaceholderPlus}
width={variables.avatarSizeSmall}
height={variables.avatarSizeSmall}
additionalStyles={styles.moneyRequestAttachReceiptThumbnailIcon}
/>
)}
</View>
{!isThumbnail && isDisplayedInWideRHP && (
<>
<Text style={[styles.textHeadline, styles.mt4]}>{translate('receipt.addAReceipt.phrase1')}</Text>
<Text style={[styles.textSupporting, styles.textNormal]}>{translate('receipt.addAReceipt.phrase2')}</Text>
</>
)}
</View>
</View>
{!isThumbnail && isDisplayedInWideRHP && (
<>
<Text style={[styles.textHeadline, styles.mt4]}>{translate('receipt.addAReceipt.phrase1')}</Text>
<Text style={[styles.textSupporting, styles.textNormal]}>{translate('receipt.addAReceipt.phrase2')}</Text>
</>
)}
</View>
</View>
{isDisplayedInWideRHP && !disabled && <ReceiptAlternativeMethods />}
</Wrapper>
{isDisplayedInWideRHP && !disabled && <ReceiptAlternativeMethods />}
Comment thread
nkdengineer marked this conversation as resolved.
Resolved
</Wrapper>
)}
</AttachmentPicker>
);
}

Expand Down
19 changes: 18 additions & 1 deletion src/components/ReportActionItem/MoneyRequestReceiptView.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ import {
} from '@libs/TransactionUtils';
import ViolationsUtils, {filterReceiptViolations} from '@libs/Violations/ViolationsUtils';
import Navigation from '@navigation/Navigation';
import {cleanUpMoneyRequest} from '@userActions/IOU';
import {cleanUpMoneyRequest, replaceReceipt} from '@userActions/IOU';
import {navigateToConciergeChatAndDeleteReport} from '@userActions/Report';
import {clearAllRelatedReportActionErrors} from '@userActions/ReportActions';
import {clearError, getLastModifiedExpense, revert} from '@userActions/Transaction';
Expand All @@ -55,6 +55,7 @@ import ONYXKEYS from '@src/ONYXKEYS';
import ROUTES from '@src/ROUTES';
import type * as OnyxTypes from '@src/types/onyx';
import type {TransactionPendingFieldsKey} from '@src/types/onyx/Transaction';
import type {FileObject} from '@src/types/utils/Attachment';
import {isEmptyObject} from '@src/types/utils/EmptyObject';
import ReportActionItemImage from './ReportActionItemImage';

Expand Down Expand Up @@ -123,6 +124,7 @@ function MoneyRequestReceiptView({report, readonly = false, updatedTransaction,
const [policy] = useOnyx(`${ONYXKEYS.COLLECTION.POLICY}${moneyRequestReport?.policyID}`);
const [cardList] = useOnyx(ONYXKEYS.CARD_LIST);
const transactionViolations = useTransactionViolations(transaction?.transactionID);
const [policyCategories] = useOnyx(`${ONYXKEYS.COLLECTION.POLICY_CATEGORIES}${moneyRequestReport?.policyID}`);

const isDistanceRequest = isDistanceRequestTransactionUtils(transaction);
const hasReceipt = hasReceiptTransactionUtils(updatedTransaction ?? transaction);
Expand Down Expand Up @@ -327,6 +329,20 @@ function MoneyRequestReceiptView({report, readonly = false, updatedTransaction,
</View>
);

const setReceiptFile = (files: FileObject[]) => {
if (files.length === 0) {
return;
}

const file = files.at(0);

if (!file || !linkedTransactionID) {
return;
}
const source = URL.createObjectURL(file as Blob);
Comment thread
nkdengineer marked this conversation as resolved.
Resolved
Comment thread
nkdengineer marked this conversation as resolved.
Resolved
replaceReceipt({transactionID: linkedTransactionID, file: file as File, source, transactionPolicy: policy, transactionPolicyCategories: policyCategories});
Comment on lines +342 to +343

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge Use file URI when replacing receipt from wide RHP

setReceiptFile now always derives source via URL.createObjectURL(file as Blob), but the wide-RHP picker can run through AttachmentPicker/index.native.tsx, which returns native FileObjects with a uri rather than a web Blob/File; the existing native scan flow already uses file.uri directly (IOURequestStepScan/index.native.tsx). In native large-screen contexts where isDisplayedInWideRHP is true, this path can throw or produce an invalid source, preventing replaceReceipt from attaching the selected receipt.

Useful? React with 👍 / 👎.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's incorrect, the wide-RHP is only available on web.

};

// For empty receipt should be fullHeight
// For the rest, expand to match the content
return (
Expand Down Expand Up @@ -359,6 +375,7 @@ function MoneyRequestReceiptView({report, readonly = false, updatedTransaction,
isInMoneyRequestView
style={receiptStyle}
isDisplayedInWideRHP={isDisplayedInWideRHP}
setReceiptFile={setReceiptFile}
/>
</OfflineWithFeedback>
)}
Expand Down
5 changes: 5 additions & 0 deletions src/styles/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5631,6 +5631,11 @@ const staticStyles = (theme: ThemeColors) =>
borderColor: theme.border,
},

wideRHPDropZoneContainer: {
width: animatedReceiptPaneRHPWidth,
height: '100%',
},

wideRHPMoneyRequestReceiptViewScrollViewContainer: {
...spacing.pt3,
...spacing.pb2,
Expand Down
Loading
Loading