Skip to content

Commit

Permalink
Merge pull request #49916 from bernhardoj/fix/missing-header
Browse files Browse the repository at this point in the history
[CP Staging] Fix missing header in scan page
  • Loading branch information
luacmartins committed Sep 30, 2024
2 parents 88beaa6 + 44b5b73 commit 648b647
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 12 deletions.
13 changes: 7 additions & 6 deletions src/pages/iou/request/step/IOURequestStepScan/index.native.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ function IOURequestStepScan({
physicalDevices: ['wide-angle-camera', 'ultra-wide-angle-camera'],
});

const isEditing = action === CONST.IOU.ACTION.EDIT;
const hasFlash = !!device?.hasFlash;
const camera = useRef<Camera>(null);
const [flash, setFlash] = useState(false);
Expand Down Expand Up @@ -411,9 +412,9 @@ function IOURequestStepScan({
// Store the receipt on the transaction object in Onyx
// On Android devices, fetching blob for a file with name containing spaces fails to retrieve the type of file.
// So, let us also save the file type in receipt for later use during blob fetch
IOU.setMoneyRequestReceipt(transactionID, file?.uri ?? '', file.name ?? '', action !== CONST.IOU.ACTION.EDIT, file.type);
IOU.setMoneyRequestReceipt(transactionID, file?.uri ?? '', file.name ?? '', !isEditing, file.type);

if (action === CONST.IOU.ACTION.EDIT) {
if (isEditing) {
updateScanAndNavigate(file, file?.uri ?? '');
return;
}
Expand Down Expand Up @@ -448,10 +449,10 @@ function IOURequestStepScan({
.then((photo: PhotoFile) => {
// Store the receipt on the transaction object in Onyx
const source = getPhotoSource(photo.path);
IOU.setMoneyRequestReceipt(transactionID, source, photo.path, action !== CONST.IOU.ACTION.EDIT);
IOU.setMoneyRequestReceipt(transactionID, source, photo.path, !isEditing);

FileUtils.readFileAsync(source, photo.path, (file) => {
if (action === CONST.IOU.ACTION.EDIT) {
if (isEditing) {
updateScanAndNavigate(file, source);
return;
}
Expand All @@ -464,7 +465,7 @@ function IOURequestStepScan({
showCameraAlert();
Log.warn('Error taking photo', error);
});
}, [cameraPermissionStatus, didCapturePhoto, flash, hasFlash, user?.isMutedAllSounds, translate, transactionID, action, navigateToConfirmationStep, updateScanAndNavigate]);
}, [isEditing, cameraPermissionStatus, didCapturePhoto, flash, hasFlash, user?.isMutedAllSounds, translate, transactionID, navigateToConfirmationStep, updateScanAndNavigate]);

// Wait for camera permission status to render
if (cameraPermissionStatus == null) {
Expand All @@ -476,7 +477,7 @@ function IOURequestStepScan({
includeSafeAreaPaddingBottom
headerTitle={translate('common.receipt')}
onBackButtonPress={navigateBack}
shouldShowWrapper={!!backTo}
shouldShowWrapper={!!backTo || isEditing}
testID={IOURequestStepScan.displayName}
>
{isLoadingReceipt && <FullScreenLoadingIndicator />}
Expand Down
13 changes: 7 additions & 6 deletions src/pages/iou/request/step/IOURequestStepScan/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@ function IOURequestStepScan({
const tabIndex = 1;
const isTabActive = useTabNavigatorFocus({tabIndex});

const isEditing = action === CONST.IOU.ACTION.EDIT;
const defaultTaxCode = TransactionUtils.getDefaultTaxCode(policy, transaction);
const transactionTaxCode = (transaction?.taxCode ? transaction?.taxCode : defaultTaxCode) ?? '';
const transactionTaxAmount = transaction?.taxAmount ?? 0;
Expand Down Expand Up @@ -444,9 +445,9 @@ function IOURequestStepScan({
// Store the receipt on the transaction object in Onyx
const source = URL.createObjectURL(file as Blob);
// eslint-disable-next-line @typescript-eslint/prefer-nullish-coalescing
IOU.setMoneyRequestReceipt(transactionID, source, file.name || '', action !== CONST.IOU.ACTION.EDIT);
IOU.setMoneyRequestReceipt(transactionID, source, file.name || '', !isEditing);

if (action === CONST.IOU.ACTION.EDIT) {
if (isEditing) {
updateScanAndNavigate(file, source);
return;
}
Expand Down Expand Up @@ -478,15 +479,15 @@ function IOURequestStepScan({
const filename = `receipt_${Date.now()}.png`;
const file = FileUtils.base64ToFile(imageBase64 ?? '', filename);
const source = URL.createObjectURL(file);
IOU.setMoneyRequestReceipt(transactionID, source, file.name, action !== CONST.IOU.ACTION.EDIT);
IOU.setMoneyRequestReceipt(transactionID, source, file.name, !isEditing);

if (action === CONST.IOU.ACTION.EDIT) {
if (isEditing) {
updateScanAndNavigate(file, source);
return;
}

navigateToConfirmationStep(file, source);
}, [action, transactionID, updateScanAndNavigate, navigateToConfirmationStep, requestCameraPermission]);
}, [isEditing, transactionID, updateScanAndNavigate, navigateToConfirmationStep, requestCameraPermission]);

const clearTorchConstraints = useCallback(() => {
if (!trackRef.current) {
Expand Down Expand Up @@ -695,7 +696,7 @@ function IOURequestStepScan({
<StepScreenDragAndDropWrapper
headerTitle={translate('common.receipt')}
onBackButtonPress={navigateBack}
shouldShowWrapper={!!backTo}
shouldShowWrapper={!!backTo || isEditing}
testID={IOURequestStepScan.displayName}
>
{(isDraggingOverWrapper) => (
Expand Down

0 comments on commit 648b647

Please sign in to comment.