-
Notifications
You must be signed in to change notification settings - Fork 2.9k
/
AttachmentModal.tsx
647 lines (582 loc) · 27.3 KB
/
AttachmentModal.tsx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
import {Str} from 'expensify-common';
import React, {memo, useCallback, useEffect, useMemo, useRef, useState} from 'react';
import {Animated, Keyboard, View} from 'react-native';
import {GestureHandlerRootView} from 'react-native-gesture-handler';
import {useOnyx} from 'react-native-onyx';
import type {OnyxEntry} from 'react-native-onyx';
import {useSharedValue} from 'react-native-reanimated';
import type {ValueOf} from 'type-fest';
import useLocalize from '@hooks/useLocalize';
import useNetwork from '@hooks/useNetwork';
import useResponsiveLayout from '@hooks/useResponsiveLayout';
import useStyleUtils from '@hooks/useStyleUtils';
import useThemeStyles from '@hooks/useThemeStyles';
import useWindowDimensions from '@hooks/useWindowDimensions';
import addEncryptedAuthTokenToURL from '@libs/addEncryptedAuthTokenToURL';
import fileDownload from '@libs/fileDownload';
import * as FileUtils from '@libs/fileDownload/FileUtils';
import Navigation from '@libs/Navigation/Navigation';
import * as ReportActionsUtils from '@libs/ReportActionsUtils';
import * as TransactionUtils from '@libs/TransactionUtils';
import type {AvatarSource} from '@libs/UserUtils';
import variables from '@styles/variables';
import * as IOU from '@userActions/IOU';
import CONST from '@src/CONST';
import type {TranslationPaths} from '@src/languages/types';
import ONYXKEYS from '@src/ONYXKEYS';
import ROUTES from '@src/ROUTES';
import type * as OnyxTypes from '@src/types/onyx';
import {isEmptyObject} from '@src/types/utils/EmptyObject';
import type ModalType from '@src/types/utils/ModalType';
import viewRef from '@src/types/utils/viewRef';
import AttachmentCarousel from './Attachments/AttachmentCarousel';
import AttachmentCarouselPagerContext from './Attachments/AttachmentCarousel/Pager/AttachmentCarouselPagerContext';
import AttachmentView from './Attachments/AttachmentView';
import type {Attachment} from './Attachments/types';
import BlockingView from './BlockingViews/BlockingView';
import Button from './Button';
import ConfirmModal from './ConfirmModal';
import FullScreenLoadingIndicator from './FullscreenLoadingIndicator';
import HeaderGap from './HeaderGap';
import HeaderWithBackButton from './HeaderWithBackButton';
import * as Expensicons from './Icon/Expensicons';
import * as Illustrations from './Icon/Illustrations';
import Modal from './Modal';
import SafeAreaConsumer from './SafeAreaConsumer';
/**
* Modal render prop component that exposes modal launching triggers that can be used
* to display a full size image or PDF modally with optional confirmation button.
*/
type ImagePickerResponse = {
height?: number;
name: string;
size?: number | null;
type: string;
uri: string;
width?: number;
};
type FileObject = Partial<File | ImagePickerResponse>;
type ChildrenProps = {
displayFileInModal: (data: FileObject) => void;
show: () => void;
};
type AttachmentModalProps = {
/** Optional source (URL, SVG function) for the image shown. If not passed in via props must be specified when modal is opened. */
source?: AvatarSource;
/** Optional callback to fire when we want to preview an image and approve it for use. */
onConfirm?: ((file: FileObject) => void) | null;
/** Whether the modal should be open by default */
defaultOpen?: boolean;
/** Trigger when we explicity click close button in ProfileAttachment modal */
onModalClose?: () => void;
/** Optional original filename when uploading */
originalFileName?: string;
/** Whether source url requires authentication */
isAuthTokenRequired?: boolean;
/** Determines if download Button should be shown or not */
allowDownload?: boolean;
/** Determines if the receipt comes from track expense action */
isTrackExpenseAction?: boolean;
/** Title shown in the header of the modal */
headerTitle?: string;
/** The report that has this attachment */
report?: OnyxEntry<OnyxTypes.Report>;
/** The type of the attachment */
type?: ValueOf<typeof CONST.ATTACHMENT_TYPE>;
/** If the attachment originates from a note, the accountID will represent the author of that note. */
accountID?: number;
/** Optional callback to fire when we want to do something after modal show. */
onModalShow?: () => void;
/** Optional callback to fire when we want to do something after modal hide. */
onModalHide?: () => void;
/** The data is loading or not */
isLoading?: boolean;
/** Should display not found page or not */
shouldShowNotFoundPage?: boolean;
/** Optional callback to fire when we want to do something after attachment carousel changes. */
onCarouselAttachmentChange?: (attachment: Attachment) => void;
/** Denotes whether it is a workspace avatar or not */
isWorkspaceAvatar?: boolean;
/** Denotes whether it can be an icon (ex: SVG) */
maybeIcon?: boolean;
/** Whether it is a receipt attachment or not */
isReceiptAttachment?: boolean;
/** A function as a child to pass modal launching methods to */
children?: React.FC<ChildrenProps>;
fallbackSource?: AvatarSource;
canEditReceipt?: boolean;
shouldDisableSendButton?: boolean;
};
function AttachmentModal({
source = '',
onConfirm,
defaultOpen = false,
originalFileName = '',
isAuthTokenRequired = false,
allowDownload = false,
isTrackExpenseAction = false,
report,
onModalShow = () => {},
onModalHide = () => {},
onCarouselAttachmentChange = () => {},
isReceiptAttachment = false,
isWorkspaceAvatar = false,
maybeIcon = false,
headerTitle,
children,
fallbackSource,
canEditReceipt = false,
onModalClose = () => {},
isLoading = false,
shouldShowNotFoundPage = false,
type = undefined,
accountID = undefined,
shouldDisableSendButton = false,
}: AttachmentModalProps) {
const styles = useThemeStyles();
const StyleUtils = useStyleUtils();
const [isModalOpen, setIsModalOpen] = useState(defaultOpen);
const [shouldLoadAttachment, setShouldLoadAttachment] = useState(false);
const [isAttachmentInvalid, setIsAttachmentInvalid] = useState(false);
const [isDeleteReceiptConfirmModalVisible, setIsDeleteReceiptConfirmModalVisible] = useState(false);
const [isAuthTokenRequiredState, setIsAuthTokenRequiredState] = useState(isAuthTokenRequired);
const [attachmentInvalidReasonTitle, setAttachmentInvalidReasonTitle] = useState<TranslationPaths | null>(null);
const [attachmentInvalidReason, setAttachmentInvalidReason] = useState<TranslationPaths | null>(null);
const [sourceState, setSourceState] = useState<AvatarSource>(() => source);
const [modalType, setModalType] = useState<ModalType>(CONST.MODAL.MODAL_TYPE.CENTERED_UNSWIPEABLE);
const [isConfirmButtonDisabled, setIsConfirmButtonDisabled] = useState(false);
const [confirmButtonFadeAnimation] = useState(() => new Animated.Value(1));
const [isDownloadButtonReadyToBeShown, setIsDownloadButtonReadyToBeShown] = React.useState(true);
const isPDFLoadError = useRef(false);
const {windowWidth} = useWindowDimensions();
const {shouldUseNarrowLayout} = useResponsiveLayout();
const nope = useSharedValue(false);
const isOverlayModalVisible = (isReceiptAttachment && isDeleteReceiptConfirmModalVisible) || (!isReceiptAttachment && isAttachmentInvalid);
const iouType = useMemo(() => (isTrackExpenseAction ? CONST.IOU.TYPE.TRACK : CONST.IOU.TYPE.SUBMIT), [isTrackExpenseAction]);
const parentReportAction = ReportActionsUtils.getReportAction(report?.parentReportID ?? '-1', report?.parentReportActionID ?? '-1');
const transactionID = ReportActionsUtils.isMoneyRequestAction(parentReportAction) ? ReportActionsUtils.getOriginalMessage(parentReportAction)?.IOUTransactionID ?? '-1' : '-1';
const [transaction] = useOnyx(`${ONYXKEYS.COLLECTION.TRANSACTION}${transactionID}`);
const [file, setFile] = useState<FileObject | undefined>(
originalFileName
? {
name: originalFileName,
}
: undefined,
);
const {translate} = useLocalize();
const {isOffline} = useNetwork();
const isLocalSource = typeof sourceState === 'string' && /^file:|^blob:/.test(sourceState);
useEffect(() => {
setFile(originalFileName ? {name: originalFileName} : undefined);
}, [originalFileName]);
/**
* Keeps the attachment source in sync with the attachment displayed currently in the carousel.
*/
const onNavigate = useCallback(
(attachment: Attachment) => {
setSourceState(attachment.source);
setFile(attachment.file);
setIsAuthTokenRequiredState(attachment.isAuthTokenRequired ?? false);
onCarouselAttachmentChange(attachment);
},
[onCarouselAttachmentChange],
);
/**
* If our attachment is a PDF, return the unswipeablge Modal type.
*/
const getModalType = useCallback(
(sourceURL: string, fileObject: FileObject) =>
sourceURL && (Str.isPDF(sourceURL) || (fileObject && Str.isPDF(fileObject.name ?? translate('attachmentView.unknownFilename'))))
? CONST.MODAL.MODAL_TYPE.CENTERED_UNSWIPEABLE
: CONST.MODAL.MODAL_TYPE.CENTERED,
[translate],
);
const setDownloadButtonVisibility = useCallback(
(isButtonVisible: boolean) => {
if (isDownloadButtonReadyToBeShown === isButtonVisible) {
return;
}
setIsDownloadButtonReadyToBeShown(isButtonVisible);
},
[isDownloadButtonReadyToBeShown],
);
/**
* Download the currently viewed attachment.
*/
const downloadAttachment = useCallback(() => {
let sourceURL = sourceState;
if (isAuthTokenRequiredState && typeof sourceURL === 'string') {
sourceURL = addEncryptedAuthTokenToURL(sourceURL);
}
if (typeof sourceURL === 'string') {
const fileName = type === CONST.ATTACHMENT_TYPE.SEARCH ? FileUtils.getFileName(`${sourceURL}`) : file?.name;
fileDownload(sourceURL, fileName ?? '');
}
// At ios, if the keyboard is open while opening the attachment, then after downloading
// the attachment keyboard will show up. So, to fix it we need to dismiss the keyboard.
Keyboard.dismiss();
}, [isAuthTokenRequiredState, sourceState, file, type]);
/**
* Execute the onConfirm callback and close the modal.
*/
const submitAndClose = useCallback(() => {
// If the modal has already been closed or the confirm button is disabled
// do not submit.
if (!isModalOpen || isConfirmButtonDisabled) {
return;
}
if (onConfirm) {
onConfirm(Object.assign(file ?? {}, {source: sourceState} as FileObject));
}
setIsModalOpen(false);
// eslint-disable-next-line react-compiler/react-compiler, react-hooks/exhaustive-deps
}, [isModalOpen, isConfirmButtonDisabled, onConfirm, file, sourceState]);
/**
* Close the confirm modals.
*/
const closeConfirmModal = useCallback(() => {
setIsAttachmentInvalid(false);
setIsDeleteReceiptConfirmModalVisible(false);
}, []);
/**
* Detach the receipt and close the modal.
*/
const deleteAndCloseModal = useCallback(() => {
IOU.detachReceipt(transaction?.transactionID ?? '-1');
setIsDeleteReceiptConfirmModalVisible(false);
Navigation.goBack(ROUTES.REPORT_WITH_ID_DETAILS.getRoute(report?.reportID ?? '-1'));
}, [transaction, report]);
const isValidFile = useCallback(
(fileObject: FileObject) =>
FileUtils.validateImageForCorruption(fileObject)
.then(() => {
if (fileObject.size && fileObject.size > CONST.API_ATTACHMENT_VALIDATIONS.MAX_SIZE) {
setIsAttachmentInvalid(true);
setAttachmentInvalidReasonTitle('attachmentPicker.attachmentTooLarge');
setAttachmentInvalidReason('attachmentPicker.sizeExceeded');
return false;
}
if (fileObject.size && fileObject.size < CONST.API_ATTACHMENT_VALIDATIONS.MIN_SIZE) {
setIsAttachmentInvalid(true);
setAttachmentInvalidReasonTitle('attachmentPicker.attachmentTooSmall');
setAttachmentInvalidReason('attachmentPicker.sizeNotMet');
return false;
}
return true;
})
.catch(() => {
setIsAttachmentInvalid(true);
setAttachmentInvalidReasonTitle('attachmentPicker.attachmentError');
setAttachmentInvalidReason('attachmentPicker.errorWhileSelectingCorruptedAttachment');
return false;
}),
[],
);
const isDirectoryCheck = useCallback((data: FileObject) => {
if ('webkitGetAsEntry' in data && (data as DataTransferItem).webkitGetAsEntry()?.isDirectory) {
setIsAttachmentInvalid(true);
setAttachmentInvalidReasonTitle('attachmentPicker.attachmentError');
setAttachmentInvalidReason('attachmentPicker.folderNotAllowedMessage');
return false;
}
return true;
}, []);
const validateAndDisplayFileToUpload = useCallback(
(data: FileObject) => {
if (!data || !isDirectoryCheck(data)) {
return;
}
let fileObject = data;
if ('getAsFile' in data && typeof data.getAsFile === 'function') {
fileObject = data.getAsFile() as FileObject;
}
if (!fileObject) {
return;
}
isValidFile(fileObject).then((isValid) => {
if (!isValid) {
return;
}
if (fileObject instanceof File) {
/**
* Cleaning file name, done here so that it covers all cases:
* upload, drag and drop, copy-paste
*/
let updatedFile = fileObject;
const cleanName = FileUtils.cleanFileName(updatedFile.name);
if (updatedFile.name !== cleanName) {
updatedFile = new File([updatedFile], cleanName, {type: updatedFile.type});
}
const inputSource = URL.createObjectURL(updatedFile);
updatedFile.uri = inputSource;
const inputModalType = getModalType(inputSource, updatedFile);
setIsModalOpen(true);
setSourceState(inputSource);
setFile(updatedFile);
setModalType(inputModalType);
} else if (fileObject.uri) {
const inputModalType = getModalType(fileObject.uri, fileObject);
setIsModalOpen(true);
setSourceState(fileObject.uri);
setFile(fileObject);
setModalType(inputModalType);
}
});
},
[isValidFile, getModalType, isDirectoryCheck],
);
/**
* close the modal
*/
const closeModal = useCallback(() => {
setIsModalOpen(false);
if (typeof onModalClose === 'function') {
onModalClose();
}
// eslint-disable-next-line react-compiler/react-compiler, react-hooks/exhaustive-deps
}, [onModalClose]);
/**
* open the modal
*/
const openModal = useCallback(() => {
setIsModalOpen(true);
}, []);
useEffect(() => {
setSourceState(() => source);
}, [source]);
useEffect(() => {
setIsAuthTokenRequiredState(isAuthTokenRequired);
}, [isAuthTokenRequired]);
const sourceForAttachmentView = sourceState || source;
const threeDotsMenuItems = useMemo(() => {
if (!isReceiptAttachment) {
return [];
}
const menuItems = [];
if (canEditReceipt) {
menuItems.push({
icon: Expensicons.Camera,
text: translate('common.replace'),
onSelected: () => {
closeModal();
Navigation.navigate(
ROUTES.MONEY_REQUEST_STEP_SCAN.getRoute(
CONST.IOU.ACTION.EDIT,
iouType,
transaction?.transactionID ?? '-1',
report?.reportID ?? '-1',
Navigation.getActiveRouteWithoutParams(),
),
);
},
});
}
if (!isOffline && allowDownload && !isLocalSource) {
menuItems.push({
icon: Expensicons.Download,
text: translate('common.download'),
onSelected: () => downloadAttachment(),
});
}
if (
!TransactionUtils.hasEReceipt(transaction) &&
TransactionUtils.hasReceipt(transaction) &&
!TransactionUtils.isReceiptBeingScanned(transaction) &&
canEditReceipt &&
!TransactionUtils.hasMissingSmartscanFields(transaction)
) {
menuItems.push({
icon: Expensicons.Trashcan,
text: translate('receipt.deleteReceipt'),
onSelected: () => {
setIsDeleteReceiptConfirmModalVisible(true);
},
shouldCallAfterModalHide: true,
});
}
return menuItems;
// eslint-disable-next-line react-compiler/react-compiler, react-hooks/exhaustive-deps
}, [isReceiptAttachment, transaction, file, sourceState, iouType]);
// There are a few things that shouldn't be set until we absolutely know if the file is a receipt or an attachment.
// props.isReceiptAttachment will be null until its certain what the file is, in which case it will then be true|false.
let headerTitleNew = headerTitle;
let shouldShowDownloadButton = false;
let shouldShowThreeDotsButton = false;
if (!isEmptyObject(report) || type === CONST.ATTACHMENT_TYPE.SEARCH) {
headerTitleNew = translate(isReceiptAttachment ? 'common.receipt' : 'common.attachment');
shouldShowDownloadButton = allowDownload && isDownloadButtonReadyToBeShown && !shouldShowNotFoundPage && !isReceiptAttachment && !isOffline && !isLocalSource;
shouldShowThreeDotsButton = isReceiptAttachment && isModalOpen && threeDotsMenuItems.length !== 0;
}
const context = useMemo(
() => ({
pagerItems: [{source: sourceForAttachmentView, index: 0, isActive: true}],
activePage: 0,
pagerRef: undefined,
isPagerScrolling: nope,
isScrollEnabled: nope,
onTap: () => {},
onScaleChanged: () => {},
onSwipeDown: closeModal,
}),
[closeModal, nope, sourceForAttachmentView],
);
const submitRef = useRef<View | HTMLElement>(null);
return (
<>
<Modal
type={modalType}
onSubmit={submitAndClose}
onClose={isOverlayModalVisible ? closeConfirmModal : closeModal}
isVisible={isModalOpen}
onModalShow={() => {
onModalShow();
setShouldLoadAttachment(true);
}}
onModalHide={() => {
if (!isPDFLoadError.current) {
onModalHide();
}
setShouldLoadAttachment(false);
if (isPDFLoadError.current) {
setIsAttachmentInvalid(true);
setAttachmentInvalidReasonTitle('attachmentPicker.attachmentError');
setAttachmentInvalidReason('attachmentPicker.errorWhileSelectingCorruptedAttachment');
}
}}
propagateSwipe
initialFocus={() => {
if (!submitRef.current) {
return false;
}
return submitRef.current;
}}
>
<GestureHandlerRootView style={styles.flex1}>
{shouldUseNarrowLayout && <HeaderGap />}
<HeaderWithBackButton
title={headerTitleNew}
shouldShowBorderBottom
shouldShowDownloadButton={shouldShowDownloadButton}
onDownloadButtonPress={() => downloadAttachment()}
shouldShowCloseButton={!shouldUseNarrowLayout}
shouldShowBackButton={shouldUseNarrowLayout}
onBackButtonPress={closeModal}
onCloseButtonPress={closeModal}
shouldShowThreeDotsButton={shouldShowThreeDotsButton}
threeDotsAnchorPosition={styles.threeDotsPopoverOffsetAttachmentModal(windowWidth)}
threeDotsMenuItems={threeDotsMenuItems}
shouldOverlayDots
/>
<View style={styles.imageModalImageCenterContainer}>
{isLoading && <FullScreenLoadingIndicator />}
{shouldShowNotFoundPage && !isLoading && (
<BlockingView
icon={Illustrations.ToddBehindCloud}
iconWidth={variables.modalTopIconWidth}
iconHeight={variables.modalTopIconHeight}
title={translate('notFound.notHere')}
subtitle={translate('notFound.pageNotFound')}
linkKey="notFound.goBackHome"
shouldShowLink
onLinkPress={() => Navigation.dismissModal()}
/>
)}
{!shouldShowNotFoundPage &&
(!isEmptyObject(report) && !isReceiptAttachment ? (
<AttachmentCarousel
accountID={accountID}
type={type}
report={report}
onNavigate={onNavigate}
onClose={closeModal}
source={source}
setDownloadButtonVisibility={setDownloadButtonVisibility}
/>
) : (
!!sourceForAttachmentView &&
shouldLoadAttachment &&
!isLoading && (
<AttachmentCarouselPagerContext.Provider value={context}>
<AttachmentView
containerStyles={[styles.mh5]}
source={sourceForAttachmentView}
isAuthTokenRequired={isAuthTokenRequiredState}
file={file}
onToggleKeyboard={setIsConfirmButtonDisabled}
onPDFLoadError={() => {
isPDFLoadError.current = true;
setIsModalOpen(false);
}}
isWorkspaceAvatar={isWorkspaceAvatar}
maybeIcon={maybeIcon}
fallbackSource={fallbackSource}
isUsedInAttachmentModal
transactionID={transaction?.transactionID}
isUploaded={!isEmptyObject(report)}
/>
</AttachmentCarouselPagerContext.Provider>
)
))}
</View>
{/* If we have an onConfirm method show a confirmation button */}
{!!onConfirm && !isConfirmButtonDisabled && (
<SafeAreaConsumer>
{({safeAreaPaddingBottomStyle}) => (
<Animated.View style={[StyleUtils.fade(confirmButtonFadeAnimation), safeAreaPaddingBottomStyle]}>
<Button
ref={viewRef(submitRef)}
success
large
style={[styles.buttonConfirm, shouldUseNarrowLayout ? {} : styles.attachmentButtonBigScreen]}
textStyles={[styles.buttonConfirmText]}
text={translate('common.send')}
onPress={submitAndClose}
isDisabled={isConfirmButtonDisabled || shouldDisableSendButton}
pressOnEnter
/>
</Animated.View>
)}
</SafeAreaConsumer>
)}
{isReceiptAttachment && (
<ConfirmModal
title={translate('receipt.deleteReceipt')}
isVisible={isDeleteReceiptConfirmModalVisible}
onConfirm={deleteAndCloseModal}
onCancel={closeConfirmModal}
prompt={translate('receipt.deleteConfirmation')}
confirmText={translate('common.delete')}
cancelText={translate('common.cancel')}
danger
/>
)}
</GestureHandlerRootView>
</Modal>
{!isReceiptAttachment && (
<ConfirmModal
title={attachmentInvalidReasonTitle ? translate(attachmentInvalidReasonTitle) : ''}
onConfirm={closeConfirmModal}
onCancel={closeConfirmModal}
isVisible={isAttachmentInvalid}
prompt={attachmentInvalidReason ? translate(attachmentInvalidReason) : ''}
confirmText={translate('common.close')}
shouldShowCancelButton={false}
onModalHide={() => {
if (!isPDFLoadError.current) {
return;
}
isPDFLoadError.current = false;
onModalHide?.();
}}
/>
)}
{children?.({
displayFileInModal: validateAndDisplayFileToUpload,
show: openModal,
})}
</>
);
}
AttachmentModal.displayName = 'AttachmentModal';
export default memo(AttachmentModal);
export type {Attachment, FileObject, ImagePickerResponse};