Skip to content

Commit

Permalink
fix inexistent ids lint
Browse files Browse the repository at this point in the history
  • Loading branch information
dominictb committed Jan 20, 2025
1 parent 0913a95 commit 45abb77
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 29 deletions.
8 changes: 6 additions & 2 deletions src/ROUTES.ts
Original file line number Diff line number Diff line change
Expand Up @@ -656,8 +656,12 @@ const ROUTES = {
},
MONEY_REQUEST_STEP_SCAN: {
route: ':action/:iouType/scan/:transactionID/:reportID',
getRoute: (action: IOUAction, iouType: IOUType, transactionID: string, reportID: string, backTo = '') =>
getUrlWithBackToParam(`${action as string}/${iouType as string}/scan/${transactionID}/${reportID}`, backTo),
getRoute: (action: IOUAction, iouType: IOUType, transactionID: string | undefined, reportID: string | undefined, backTo = '') => {
if (!transactionID || !reportID) {
Log.warn('Invalid transactionID or reportID is used to build the MONEY_REQUEST_STEP_SCAN route');
}
return getUrlWithBackToParam(`${action as string}/${iouType as string}/scan/${transactionID}/${reportID}`, backTo);
},
},
MONEY_REQUEST_STEP_TAG: {
route: ':action/:iouType/tag/:orderWeight/:transactionID/:reportID/:reportActionID?',
Expand Down
40 changes: 14 additions & 26 deletions src/components/AttachmentModal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,13 @@ import useWindowDimensions from '@hooks/useWindowDimensions';
import addEncryptedAuthTokenToURL from '@libs/addEncryptedAuthTokenToURL';
import attachmentModalHandler from '@libs/AttachmentModalHandler';
import fileDownload from '@libs/fileDownload';
import * as FileUtils from '@libs/fileDownload/FileUtils';
import {cleanFileName, getFileName, validateImageForCorruption} from '@libs/fileDownload/FileUtils';
import Navigation from '@libs/Navigation/Navigation';
import * as ReportActionsUtils from '@libs/ReportActionsUtils';
import * as TransactionUtils from '@libs/TransactionUtils';
import {getOriginalMessage, getReportAction, isMoneyRequestAction} from '@libs/ReportActionsUtils';
import {hasEReceipt, hasMissingSmartscanFields, hasReceipt, hasReceiptSource, isReceiptBeingScanned} from '@libs/TransactionUtils';
import type {AvatarSource} from '@libs/UserUtils';
import variables from '@styles/variables';
import * as IOU from '@userActions/IOU';
import {detachReceipt} from '@userActions/IOU';
import CONST from '@src/CONST';
import type {TranslationPaths} from '@src/languages/types';
import ONYXKEYS from '@src/ONYXKEYS';
Expand Down Expand Up @@ -183,8 +183,8 @@ function AttachmentModal({
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 parentReportAction = getReportAction(report?.parentReportID, report?.parentReportActionID);
const transactionID = (isMoneyRequestAction(parentReportAction) && getOriginalMessage(parentReportAction)?.IOUTransactionID) || CONST.DEFAULT_NUMBER_ID;

Check failure on line 187 in src/components/AttachmentModal.tsx

View workflow job for this annotation

GitHub Actions / Changed files ESLint check

Prefer using nullish coalescing operator (`??`) instead of a logical or (`||`), as it is a safer operator
const [transaction] = useOnyx(`${ONYXKEYS.COLLECTION.TRANSACTION}${transactionID}`);
const [currentAttachmentLink, setCurrentAttachmentLink] = useState(attachmentLink);

Expand Down Expand Up @@ -249,7 +249,7 @@ function AttachmentModal({
}

if (typeof sourceURL === 'string') {
const fileName = type === CONST.ATTACHMENT_TYPE.SEARCH ? FileUtils.getFileName(`${sourceURL}`) : file?.name;
const fileName = type === CONST.ATTACHMENT_TYPE.SEARCH ? getFileName(`${sourceURL}`) : file?.name;
fileDownload(sourceURL, fileName ?? '');
}

Expand Down Expand Up @@ -288,14 +288,14 @@ function AttachmentModal({
* Detach the receipt and close the modal.
*/
const deleteAndCloseModal = useCallback(() => {
IOU.detachReceipt(transaction?.transactionID ?? '-1');
detachReceipt(transaction?.transactionID);
setIsDeleteReceiptConfirmModalVisible(false);
Navigation.goBack(ROUTES.REPORT_WITH_ID_DETAILS.getRoute(report?.reportID ?? '-1'));
Navigation.goBack(ROUTES.REPORT_WITH_ID_DETAILS.getRoute(report?.reportID));
}, [transaction, report]);

const isValidFile = useCallback(
(fileObject: FileObject) =>
FileUtils.validateImageForCorruption(fileObject)
validateImageForCorruption(fileObject)
.then(() => {
if (fileObject.size && fileObject.size > CONST.API_ATTACHMENT_VALIDATIONS.MAX_SIZE) {
setIsAttachmentInvalid(true);
Expand Down Expand Up @@ -355,7 +355,7 @@ function AttachmentModal({
* upload, drag and drop, copy-paste
*/
let updatedFile = fileObject;
const cleanName = FileUtils.cleanFileName(updatedFile.name);
const cleanName = cleanFileName(updatedFile.name);
if (updatedFile.name !== cleanName) {
updatedFile = new File([updatedFile], cleanName, {type: updatedFile.type});
}
Expand Down Expand Up @@ -432,13 +432,7 @@ function AttachmentModal({
onSelected: () => {
closeModal(true);
Navigation.navigate(
ROUTES.MONEY_REQUEST_STEP_SCAN.getRoute(
CONST.IOU.ACTION.EDIT,
iouType,
transaction?.transactionID ?? '-1',
report?.reportID ?? '-1',
Navigation.getActiveRouteWithoutParams(),
),
ROUTES.MONEY_REQUEST_STEP_SCAN.getRoute(CONST.IOU.ACTION.EDIT, iouType, transaction?.transactionID, report?.reportID, Navigation.getActiveRouteWithoutParams()),
);
},
});
Expand All @@ -451,14 +445,8 @@ function AttachmentModal({
});
}

const hasOnlyEReceipt = TransactionUtils.hasEReceipt(transaction) && !TransactionUtils.hasReceiptSource(transaction);
if (
!hasOnlyEReceipt &&
TransactionUtils.hasReceipt(transaction) &&
!TransactionUtils.isReceiptBeingScanned(transaction) &&
canEditReceipt &&
!TransactionUtils.hasMissingSmartscanFields(transaction)
) {
const hasOnlyEReceipt = hasEReceipt(transaction) && !hasReceiptSource(transaction);
if (!hasOnlyEReceipt && hasReceipt(transaction) && !isReceiptBeingScanned(transaction) && canEditReceipt && !hasMissingSmartscanFields(transaction)) {
menuItems.push({
icon: Expensicons.Trashcan,
text: translate('receipt.deleteReceipt'),
Expand Down
5 changes: 4 additions & 1 deletion src/libs/actions/IOU.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8521,7 +8521,10 @@ function payInvoice(paymentMethodType: PaymentMethodType, chatReport: OnyxTypes.
API.write(WRITE_COMMANDS.PAY_INVOICE, params, {optimisticData, successData, failureData});
}

function detachReceipt(transactionID: string) {
function detachReceipt(transactionID: string | undefined) {
if (!transactionID) {
return;
}
const transaction = allTransactions[`${ONYXKEYS.COLLECTION.TRANSACTION}${transactionID}`];
const newTransaction = transaction
? {
Expand Down

0 comments on commit 45abb77

Please sign in to comment.