|
| 1 | +import {useMemo} from 'react'; |
| 2 | +import type {ValueOf} from 'type-fest'; |
| 3 | +import {canEditFieldOfMoneyRequest} from '@libs/ReportUtils'; |
| 4 | +import type {IOUAction, IOUType} from '@src/CONST'; |
| 5 | +import CONST from '@src/CONST'; |
| 6 | +import ONYXKEYS from '@src/ONYXKEYS'; |
| 7 | +import type {OnyxInputOrEntry, Report} from '@src/types/onyx'; |
| 8 | +import useOnyx from './useOnyx'; |
| 9 | + |
| 10 | +// eslint-disable-next-line rulesdir/no-negated-variables |
| 11 | +const useShowNotFoundPageInIOUStep = (action: IOUAction, iouType: IOUType, report: OnyxInputOrEntry<Report>, fieldToEdit: ValueOf<typeof CONST.EDIT_REQUEST_FIELD>) => { |
| 12 | + const isEditing = action === CONST.IOU.ACTION.EDIT; |
| 13 | + const reportActionsReportID = useMemo(() => { |
| 14 | + let actionsReportID; |
| 15 | + if (isEditing) { |
| 16 | + actionsReportID = iouType === CONST.IOU.TYPE.SPLIT ? report?.reportID : report?.parentReportID; |
| 17 | + } |
| 18 | + return actionsReportID; |
| 19 | + }, [isEditing, iouType, report?.reportID, report?.parentReportID]); |
| 20 | + |
| 21 | + const [reportAction] = useOnyx(`${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${reportActionsReportID}`, { |
| 22 | + canEvict: false, |
| 23 | + canBeMissing: true, |
| 24 | + // eslint-disable-next-line @typescript-eslint/prefer-nullish-coalescing |
| 25 | + selector: (reportActions) => reportActions?.[`${report?.parentReportActionID}`], |
| 26 | + }); |
| 27 | + return isEditing && !canEditFieldOfMoneyRequest(reportAction, fieldToEdit); |
| 28 | +}; |
| 29 | + |
| 30 | +export default useShowNotFoundPageInIOUStep; |
0 commit comments