Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix unable to upload a receipt size larger than 15mb #53902

Merged
merged 7 commits into from
Dec 31, 2024
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
1 change: 1 addition & 0 deletions src/languages/en.ts
Original file line number Diff line number Diff line change
Expand Up @@ -517,6 +517,7 @@ const translations = {
chooseDocument: 'Choose file',
attachmentTooLarge: 'Attachment is too large',
sizeExceeded: 'Attachment size is larger than 24 MB limit',
sizeExceededWithLimit: ({maxUploadSizeInMB}: SizeExceededParams) => `Attachment size is larger than ${maxUploadSizeInMB} MB limit`,
attachmentTooSmall: 'Attachment is too small',
sizeNotMet: 'Attachment size must be greater than 240 bytes',
wrongFileType: 'Invalid file type',
Expand Down
1 change: 1 addition & 0 deletions src/languages/es.ts
Original file line number Diff line number Diff line change
Expand Up @@ -512,6 +512,7 @@ const translations = {
chooseDocument: 'Elegir un archivo',
attachmentTooLarge: 'Archivo adjunto demasiado grande',
sizeExceeded: 'El archivo adjunto supera el límite de 24 MB.',
sizeExceededWithLimit: ({maxUploadSizeInMB}: SizeExceededParams) => `El archivo adjunto supera el límite de ${maxUploadSizeInMB} MB.`,
attachmentTooSmall: 'Archivo adjunto demasiado pequeño',
sizeNotMet: 'El archivo adjunto debe ser más grande que 240 bytes.',
wrongFileType: 'Tipo de archivo inválido',
Expand Down
4 changes: 2 additions & 2 deletions src/libs/ReportUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1051,8 +1051,8 @@ function isSettled(reportOrID: OnyxInputOrEntry<Report> | SearchReport | string
/**
* Whether the current user is the submitter of the report
*/
function isCurrentUserSubmitter(reportID: string): boolean {
if (!allReports) {
function isCurrentUserSubmitter(reportID: string | undefined): boolean {
if (!allReports || !reportID) {
return false;
}
const report = allReports[`${ONYXKEYS.COLLECTION.REPORT}${reportID}`];
Expand Down
10 changes: 6 additions & 4 deletions src/pages/home/HeaderView.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -70,9 +70,11 @@ function HeaderView({report, parentReportAction, reportID, onNavigationMenuButto
const {isSmallScreenWidth} = useResponsiveLayout();
const route = useRoute();
const [isDeleteTaskConfirmModalVisible, setIsDeleteTaskConfirmModalVisible] = React.useState(false);
const [invoiceReceiverPolicy] = useOnyx(`${ONYXKEYS.COLLECTION.POLICY}${report?.invoiceReceiver && 'policyID' in report.invoiceReceiver ? report.invoiceReceiver.policyID : -1}`);
const [invoiceReceiverPolicy] = useOnyx(
`${ONYXKEYS.COLLECTION.POLICY}${report?.invoiceReceiver && 'policyID' in report.invoiceReceiver ? report.invoiceReceiver.policyID : CONST.DEFAULT_NUMBER_ID}`,
);
// eslint-disable-next-line @typescript-eslint/prefer-nullish-coalescing
const [parentReport] = useOnyx(`${ONYXKEYS.COLLECTION.REPORT}${report?.parentReportID || report?.reportID || '-1'}`);
const [parentReport] = useOnyx(`${ONYXKEYS.COLLECTION.REPORT}${report?.parentReportID || report?.reportID}`);
const policy = usePolicy(report?.policyID);
const [personalDetails] = useOnyx(ONYXKEYS.PERSONAL_DETAILS_LIST);

Expand Down Expand Up @@ -100,7 +102,7 @@ function HeaderView({report, parentReportAction, reportID, onNavigationMenuButto
const reportDescription = Parser.htmlToText(ReportUtils.getReportDescription(report));
const policyName = ReportUtils.getPolicyName(report, true);
const policyDescription = ReportUtils.getPolicyDescriptionText(policy);
const isPersonalExpenseChat = isPolicyExpenseChat && ReportUtils.isCurrentUserSubmitter(report?.reportID ?? '');
const isPersonalExpenseChat = isPolicyExpenseChat && ReportUtils.isCurrentUserSubmitter(report?.reportID);
const shouldShowSubtitle = () => {
if (!subtitle) {
return false;
Expand Down Expand Up @@ -258,7 +260,7 @@ function HeaderView({report, parentReportAction, reportID, onNavigationMenuButto
<PressableWithoutFeedback
onPress={() => {
if (ReportUtils.canEditPolicyDescription(policy)) {
Navigation.navigate(ROUTES.WORKSPACE_PROFILE_DESCRIPTION.getRoute(report.policyID ?? '-1'));
Navigation.navigate(ROUTES.WORKSPACE_PROFILE_DESCRIPTION.getRoute(`${report.policyID ?? CONST.DEFAULT_NUMBER_ID}`));
return;
}
Navigation.navigate(ROUTES.REPORT_WITH_ID_DETAILS.getRoute(reportID, Navigation.getReportRHPActiveRoute()));
Expand Down
15 changes: 9 additions & 6 deletions src/pages/iou/request/step/IOURequestStepScan/index.native.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -74,10 +74,10 @@ function IOURequestStepScan({
const [startLocationPermissionFlow, setStartLocationPermissionFlow] = useState(false);
const [fileResize, setFileResize] = useState<null | FileObject>(null);
const [fileSource, setFileSource] = useState('');
const [reportNameValuePairs] = useOnyx(`${ONYXKEYS.COLLECTION.REPORT_NAME_VALUE_PAIRS}${report?.reportID ?? -1}`);
const [reportNameValuePairs] = useOnyx(`${ONYXKEYS.COLLECTION.REPORT_NAME_VALUE_PAIRS}${report?.reportID ?? CONST.DEFAULT_NUMBER_ID}`);
const policy = usePolicy(report?.policyID);
const [personalDetails] = useOnyx(ONYXKEYS.PERSONAL_DETAILS_LIST);
const [skipConfirmation] = useOnyx(`${ONYXKEYS.COLLECTION.SKIP_CONFIRMATION}${transactionID ?? -1}`);
const [skipConfirmation] = useOnyx(`${ONYXKEYS.COLLECTION.SKIP_CONFIRMATION}${transactionID ?? CONST.DEFAULT_NUMBER_ID}`);
const platform = getPlatform(true);
const [mutedPlatforms = {}] = useOnyx(ONYXKEYS.NVP_MUTED_PLATFORMS);
const isPlatformMuted = mutedPlatforms[platform];
Expand Down Expand Up @@ -198,7 +198,10 @@ function IOURequestStepScan({
}

if (!Str.isImage(file.name ?? '') && (file?.size ?? 0) > CONST.API_ATTACHMENT_VALIDATIONS.RECEIPT_MAX_SIZE) {
Alert.alert(translate('attachmentPicker.attachmentTooLarge'), translate('attachmentPicker.sizeExceeded'));
Alert.alert(
translate('attachmentPicker.attachmentTooLarge'),
translate('attachmentPicker.sizeExceededWithLimit', {maxUploadSizeInMB: CONST.API_ATTACHMENT_VALIDATIONS.RECEIPT_MAX_SIZE / (1024 * 1024)}),
);
return false;
}

Expand Down Expand Up @@ -295,7 +298,7 @@ function IOURequestStepScan({
// be added to the transaction (taken from the chat report participants) and then the person is taken to the confirmation step.
const selectedParticipants = IOU.setMoneyRequestParticipantsFromReport(transactionID, report);
const participants = selectedParticipants.map((participant) => {
const participantAccountID = participant?.accountID ?? -1;
const participantAccountID = participant?.accountID ?? CONST.DEFAULT_NUMBER_ID;
return participantAccountID ? OptionsListUtils.getParticipantsOption(participant, personalDetails) : OptionsListUtils.getReportOption(participant);
});

Expand All @@ -308,10 +311,10 @@ function IOURequestStepScan({
IOU.startSplitBill({
participants,
currentUserLogin: currentUserPersonalDetails?.login ?? '',
currentUserAccountID: currentUserPersonalDetails?.accountID ?? -1,
currentUserAccountID: currentUserPersonalDetails?.accountID ?? CONST.DEFAULT_NUMBER_ID,
comment: '',
receipt,
existingSplitChatReportID: reportID ?? -1,
existingSplitChatReportID: reportID ?? CONST.DEFAULT_NUMBER_ID,
billable: false,
category: '',
tag: '',
Expand Down
24 changes: 17 additions & 7 deletions src/pages/iou/request/step/IOURequestStepScan/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -86,10 +86,10 @@ function IOURequestStepScan({
const [isQueriedPermissionState, setIsQueriedPermissionState] = useState(false);

const getScreenshotTimeoutRef = useRef<NodeJS.Timeout | null>(null);
const [reportNameValuePairs] = useOnyx(`${ONYXKEYS.COLLECTION.REPORT_NAME_VALUE_PAIRS}${report?.reportID ?? -1}`);
const [reportNameValuePairs] = useOnyx(`${ONYXKEYS.COLLECTION.REPORT_NAME_VALUE_PAIRS}${report?.reportID ?? CONST.DEFAULT_NUMBER_ID}`);
const policy = usePolicy(report?.policyID);
const [personalDetails] = useOnyx(ONYXKEYS.PERSONAL_DETAILS_LIST);
const [skipConfirmation] = useOnyx(`${ONYXKEYS.COLLECTION.SKIP_CONFIRMATION}${transactionID ?? -1}`);
const [skipConfirmation] = useOnyx(`${ONYXKEYS.COLLECTION.SKIP_CONFIRMATION}${transactionID ?? CONST.DEFAULT_NUMBER_ID}`);
const [isLoadingReceipt, setIsLoadingReceipt] = useState(false);

const [videoConstraints, setVideoConstraints] = useState<MediaTrackConstraints>();
Expand Down Expand Up @@ -221,7 +221,7 @@ function IOURequestStepScan({
}

if (!Str.isImage(file.name ?? '') && (file?.size ?? 0) > CONST.API_ATTACHMENT_VALIDATIONS.RECEIPT_MAX_SIZE) {
setUploadReceiptError(true, 'attachmentPicker.attachmentTooLarge', 'attachmentPicker.sizeExceeded');
setUploadReceiptError(true, 'attachmentPicker.attachmentTooLarge', 'attachmentPicker.sizeExceededWithLimit');
return false;
}

Expand Down Expand Up @@ -324,7 +324,7 @@ function IOURequestStepScan({
// be added to the transaction (taken from the chat report participants) and then the person is taken to the confirmation step.
const selectedParticipants = IOU.setMoneyRequestParticipantsFromReport(transactionID, report);
const participants = selectedParticipants.map((participant) => {
const participantAccountID = participant?.accountID ?? -1;
const participantAccountID = participant?.accountID ?? CONST.DEFAULT_NUMBER_ID;
return participantAccountID ? OptionsListUtils.getParticipantsOption(participant, personalDetails) : OptionsListUtils.getReportOption(participant);
});

Expand All @@ -337,10 +337,10 @@ function IOURequestStepScan({
IOU.startSplitBill({
participants,
currentUserLogin: currentUserPersonalDetails?.login ?? '',
currentUserAccountID: currentUserPersonalDetails?.accountID ?? -1,
currentUserAccountID: currentUserPersonalDetails?.accountID ?? CONST.DEFAULT_NUMBER_ID,
comment: '',
receipt,
existingSplitChatReportID: reportID ?? -1,
existingSplitChatReportID: reportID ?? CONST.DEFAULT_NUMBER_ID,
billable: false,
category: '',
tag: '',
Expand Down Expand Up @@ -618,6 +618,16 @@ function IOURequestStepScan({
/>
) : null;

const getConfirmModalPrompt = () => {
if (!attachmentInvalidReason) {
return '';
}
if (attachmentInvalidReason === 'attachmentPicker.sizeExceededWithLimit') {
return translate(attachmentInvalidReason, {maxUploadSizeInMB: CONST.API_ATTACHMENT_VALIDATIONS.RECEIPT_MAX_SIZE / (1024 * 1024)});
}
return translate(attachmentInvalidReason);
};

const mobileCameraView = () => (
<>
<View style={[styles.cameraView]}>
Expand Down Expand Up @@ -794,7 +804,7 @@ function IOURequestStepScan({
onConfirm={hideRecieptModal}
onCancel={hideRecieptModal}
isVisible={isAttachmentInvalid}
prompt={attachmentInvalidReason ? translate(attachmentInvalidReason) : ''}
prompt={getConfirmModalPrompt()}
confirmText={translate('common.close')}
shouldShowCancelButton={false}
/>
Expand Down
Loading