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
14 changes: 12 additions & 2 deletions src/pages/iou/request/step/IOURequestEditReportCommon.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import usePolicy from '@hooks/usePolicy';
import usePolicyForMovingExpenses from '@hooks/usePolicyForMovingExpenses';
import useReportTransactions from '@hooks/useReportTransactions';
import Navigation from '@libs/Navigation/Navigation';
import {getPersonalPolicy, isPolicyAdmin} from '@libs/PolicyUtils';
import {canSubmitPerDiemExpenseFromWorkspace, getPersonalPolicy, isPolicyAdmin} from '@libs/PolicyUtils';
import {canAddTransaction, getOutstandingReportsForUser, getPolicyName, isIOUReport, isOpenReport, isReportOwner, isSelfDM, sortOutstandingReportsBySelected} from '@libs/ReportUtils';
import CONST from '@src/CONST';
import ONYXKEYS from '@src/ONYXKEYS';
Expand All @@ -40,6 +40,7 @@ type Props = {
isUnreported?: boolean;
shouldShowNotFoundPage?: boolean;
createReport?: () => void;
isPerDiemRequest?: boolean;
};

const policyIdSelector = (policy: OnyxEntry<Policy>) => policy?.id;
Expand All @@ -57,10 +58,12 @@ function IOURequestEditReportCommon({
isUnreported,
shouldShowNotFoundPage: shouldShowNotFoundPageFromProps,
createReport,
isPerDiemRequest,
}: Props) {
const {translate, localeCompare} = useLocalize();
const {options} = useOptionsList();
const [outstandingReportsByPolicyID] = useOnyx(ONYXKEYS.DERIVED.OUTSTANDING_REPORTS_BY_POLICY_ID, {canBeMissing: true});
const [allPolicies] = useOnyx(ONYXKEYS.COLLECTION.POLICY, {canBeMissing: true});
const currentUserPersonalDetails = useCurrentUserPersonalDetails();
const [selectedReport] = useOnyx(`${ONYXKEYS.COLLECTION.REPORT}${selectedReportID}`, {canBeMissing: true});
const reportOwnerAccountID = useMemo(() => selectedReport?.ownerAccountID ?? currentUserPersonalDetails.accountID, [selectedReport, currentUserPersonalDetails.accountID]);
Expand Down Expand Up @@ -130,6 +133,13 @@ function IOURequestEditReportCommon({
.sort((report1, report2) => sortOutstandingReportsBySelected(report1, report2, selectedReportID, localeCompare))
.filter((report) => !debouncedSearchValue || report?.reportName?.toLowerCase().includes(debouncedSearchValue.toLowerCase()))
.filter((report): report is NonNullable<typeof report> => report !== undefined)
.filter((report) => {
if (isPerDiemRequest && report?.policyID) {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

we missed this case here
#70809 (comment)

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.

@rushatgabhane which case?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

We should not consider checking(filter out) the condition for the selected report, bcoz it caused an issue

const policy = allPolicies?.[`${ONYXKEYS.COLLECTION.POLICY}${report.policyID}`];
return canSubmitPerDiemExpenseFromWorkspace(policy);
}
return true;
})
.filter((report) => canAddTransaction(report))
.map((report) => {
const matchingOption = options.reports.find((option) => option.reportID === report.reportID);
Expand All @@ -144,7 +154,7 @@ function IOURequestEditReportCommon({
policyID: matchingOption?.policyID ?? report.policyID,
};
});
}, [outstandingReportsByPolicyID, debouncedSearchValue, expenseReports, selectedReportID, options.reports, localeCompare]);
}, [outstandingReportsByPolicyID, debouncedSearchValue, expenseReports, selectedReportID, options.reports, localeCompare, allPolicies, isPerDiemRequest]);

const navigateBack = () => {
Navigation.goBack(backTo);
Expand Down
2 changes: 2 additions & 0 deletions src/pages/iou/request/step/IOURequestStepReport.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import Navigation from '@libs/Navigation/Navigation';
import Permissions from '@libs/Permissions';
import {getReportOrDraftReport, hasViolations as hasViolationsReportUtils, isPolicyExpenseChat, isReportOutstanding} from '@libs/ReportUtils';
import {shouldRestrictUserBillableActions} from '@libs/SubscriptionUtils';
import {isPerDiemRequest} from '@libs/TransactionUtils';
import CONST from '@src/CONST';
import ONYXKEYS from '@src/ONYXKEYS';
import ROUTES from '@src/ROUTES';
Expand Down Expand Up @@ -201,6 +202,7 @@ function IOURequestStepReport({route, transaction}: IOURequestStepReportProps) {
isEditing={isEditing}
isUnreported={isUnreported}
shouldShowNotFoundPage={shouldShowNotFoundPage}
isPerDiemRequest={transaction ? isPerDiemRequest(transaction) : false}
createReport={action === CONST.IOU.ACTION.EDIT ? createReport : undefined}
/>
);
Expand Down