diff --git a/src/CONST/index.ts b/src/CONST/index.ts index 77403685225b4..b6345217774d0 100644 --- a/src/CONST/index.ts +++ b/src/CONST/index.ts @@ -6341,10 +6341,6 @@ const CONST = { RBR_MESSAGE_MAX_CHARACTERS_FOR_PREVIEW: 40, }, - REPORT_VIOLATIONS_EXCLUDED_FIELDS: { - TEXT_TITLE: 'text_title', - }, - /** Context menu types */ CONTEXT_MENU_TYPES: { LINK: 'LINK', diff --git a/src/ONYXKEYS.ts b/src/ONYXKEYS.ts index 152fec8fbd875..87f5f6c8be379 100755 --- a/src/ONYXKEYS.ts +++ b/src/ONYXKEYS.ts @@ -713,7 +713,6 @@ const ONYXKEYS = { REPORT_USER_IS_TYPING: 'reportUserIsTyping_', PENDING_CONCIERGE_RESPONSE: 'pendingConciergeResponse_', REPORT_USER_IS_LEAVING_ROOM: 'reportUserIsLeavingRoom_', - REPORT_VIOLATIONS: 'reportViolations_', SECURITY_GROUP: 'securityGroup_', TRANSACTION: 'transactions_', TRANSACTION_VIOLATIONS: 'transactionViolations_', @@ -1198,7 +1197,6 @@ type OnyxCollectionValuesMapping = { [ONYXKEYS.COLLECTION.REPORT_USER_IS_TYPING]: OnyxTypes.ReportUserIsTyping; [ONYXKEYS.COLLECTION.PENDING_CONCIERGE_RESPONSE]: OnyxTypes.PendingConciergeResponse; [ONYXKEYS.COLLECTION.REPORT_USER_IS_LEAVING_ROOM]: boolean; - [ONYXKEYS.COLLECTION.REPORT_VIOLATIONS]: OnyxTypes.ReportViolations; [ONYXKEYS.COLLECTION.SECURITY_GROUP]: OnyxTypes.SecurityGroup; [ONYXKEYS.COLLECTION.TRANSACTION]: OnyxTypes.Transaction; [ONYXKEYS.COLLECTION.TRANSACTION_DRAFT]: OnyxTypes.Transaction; diff --git a/src/components/MoneyRequestReportView/MoneyRequestViewReportFields.tsx b/src/components/MoneyRequestReportView/MoneyRequestViewReportFields.tsx index 0c4abfbdf46b4..564a6a121327b 100644 --- a/src/components/MoneyRequestReportView/MoneyRequestViewReportFields.tsx +++ b/src/components/MoneyRequestReportView/MoneyRequestViewReportFields.tsx @@ -4,7 +4,6 @@ import {View} from 'react-native'; import type {OnyxEntry} from 'react-native-onyx'; import MenuItemWithTopDescription from '@components/MenuItemWithTopDescription'; import OfflineWithFeedback from '@components/OfflineWithFeedback'; -import useOnyx from '@hooks/useOnyx'; import useThemeStyles from '@hooks/useThemeStyles'; import {clearReportFieldKeyErrors} from '@libs/actions/Report'; import {resolveReportFieldValue} from '@libs/Formula'; @@ -23,7 +22,6 @@ import { } from '@libs/ReportUtils'; import type {ThemeStyles} from '@styles/index'; import CONST from '@src/CONST'; -import ONYXKEYS from '@src/ONYXKEYS'; import ROUTES from '@src/ROUTES'; import type {Policy, PolicyReportField, Report, ReportViolationName} from '@src/types/onyx'; import type {PendingAction} from '@src/types/onyx/OnyxCommon'; @@ -82,8 +80,6 @@ function ReportFieldView(reportField: EnrichedPolicyReportField, report: OnyxEnt function MoneyRequestViewReportFields({report, policy, isCombinedReport = false, pendingAction}: MoneyRequestViewReportFieldsProps) { const styles = useThemeStyles(); - const [violations] = useOnyx(`${ONYXKEYS.COLLECTION.REPORT_VIOLATIONS}${report?.reportID}`); - const sortedPolicyReportFields = useMemo((): EnrichedPolicyReportField[] => { const {fieldValues, fieldsByName} = getReportFieldMaps(report, policy?.fieldList ?? {}); const fields = Object.values(fieldsByName); @@ -98,7 +94,7 @@ function MoneyRequestViewReportFields({report, policy, isCombinedReport = false, const isDeletedFormulaField = field.type === CONST.REPORT_FIELD_TYPES.FORMULA && field.deletable; const fieldKey = getReportFieldKey(field.fieldID); - const violation = isFieldDisabled ? undefined : getFieldViolation(violations, field); + const violation = isFieldDisabled ? undefined : getFieldViolation(field); const violationTranslation = getFieldViolationTranslation(field, violation); return { @@ -110,7 +106,7 @@ function MoneyRequestViewReportFields({report, policy, isCombinedReport = false, violationTranslation, }; }); - }, [policy, report, violations]); + }, [policy, report]); const enabledReportFields = sortedPolicyReportFields.filter( (reportField) => !isReportFieldDisabled(report, reportField, policy) || reportField.type === CONST.REPORT_FIELD_TYPES.FORMULA, diff --git a/src/components/ReportActionItem/MoneyReportView.tsx b/src/components/ReportActionItem/MoneyReportView.tsx index ed8946cc980ec..290fca2804082 100644 --- a/src/components/ReportActionItem/MoneyReportView.tsx +++ b/src/components/ReportActionItem/MoneyReportView.tsx @@ -13,7 +13,6 @@ import UnreadActionIndicator from '@components/UnreadActionIndicator'; import {useMemoizedLazyExpensifyIcons} from '@hooks/useLazyAsset'; import useLocalize from '@hooks/useLocalize'; import useNetwork from '@hooks/useNetwork'; -import useOnyx from '@hooks/useOnyx'; import useReportTransactions from '@hooks/useReportTransactions'; import useStyleUtils from '@hooks/useStyleUtils'; import useTheme from '@hooks/useTheme'; @@ -46,7 +45,6 @@ import variables from '@styles/variables'; import CONST from '@src/CONST'; import type {TranslationPaths} from '@src/languages/types'; import {clearReportFieldKeyErrors} from '@src/libs/actions/Report'; -import ONYXKEYS from '@src/ONYXKEYS'; import ROUTES from '@src/ROUTES'; import type {Policy, Report} from '@src/types/onyx'; import type {PendingAction} from '@src/types/onyx/OnyxCommon'; @@ -115,8 +113,6 @@ function MoneyReportView({ StyleUtils.getColorStyle(theme.textSupporting), ]; - const [violations] = useOnyx(`${ONYXKEYS.COLLECTION.REPORT_VIOLATIONS}${report?.reportID}`); - const {sortedPolicyReportFields, fieldValues, fieldsByName} = useMemo(() => { const {fieldValues: values, fieldsByName: byName} = getReportFieldMaps(report, policy?.fieldList ?? {}); const sorted = Object.values(byName) @@ -176,7 +172,7 @@ function MoneyReportView({ const isFieldDisabled = isReportFieldDisabledForUser(report, reportField, policy); const fieldKey = getReportFieldKey(reportField.fieldID); - const violation = isFieldDisabled ? undefined : getFieldViolation(violations, reportField); + const violation = isFieldDisabled ? undefined : getFieldViolation(reportField); const violationTranslation = getFieldViolationTranslation(reportField, violation); return ( diff --git a/src/components/ReportActionItem/TransactionPreview/TransactionPreviewContent.tsx b/src/components/ReportActionItem/TransactionPreview/TransactionPreviewContent.tsx index b121ee9927c0c..357002985a073 100644 --- a/src/components/ReportActionItem/TransactionPreview/TransactionPreviewContent.tsx +++ b/src/components/ReportActionItem/TransactionPreview/TransactionPreviewContent.tsx @@ -73,7 +73,6 @@ function TransactionPreviewContent({ const styles = useThemeStyles(); const {translate} = useLocalize(); const {environmentURL} = useEnvironment(); - const [reportViolations] = useOnyx(`${ONYXKEYS.COLLECTION.REPORT_VIOLATIONS}${getNonEmptyStringOnyxID(report?.reportID)}`); const [policy] = useOnyx(`${ONYXKEYS.COLLECTION.POLICY}${report?.policyID}`); const isParentPolicyExpenseChat = isPolicyExpenseChat(chatReport); const transactionDetails = useMemo>( @@ -115,9 +114,8 @@ function TransactionPreviewContent({ currentUserEmail, currentUserAccountID, reportActions, - reportViolations, }), - [areThereDuplicates, transactionPreviewCommonArguments, isReportAPolicyExpenseChat, currentUserEmail, currentUserAccountID, reportActions, reportViolations], + [areThereDuplicates, transactionPreviewCommonArguments, isReportAPolicyExpenseChat, currentUserEmail, currentUserAccountID, reportActions], ); const {shouldShowRBR, shouldShowMerchant, shouldShowSplitShare, shouldShowTag, shouldShowCategory, shouldShowSkeleton, shouldShowDescription} = conditionals; diff --git a/src/libs/ReportUtils.ts b/src/libs/ReportUtils.ts index fc0b902aa73c9..e4f6c7252bc12 100644 --- a/src/libs/ReportUtils.ts +++ b/src/libs/ReportUtils.ts @@ -56,7 +56,6 @@ import type { ReportMetadata, ReportNameValuePairs, ReportViolationName, - ReportViolations, Task, Transaction, TransactionViolation, @@ -9282,13 +9281,6 @@ function hasAnyViolations( ); } -function hasReportViolations(reportViolations: OnyxEntry) { - if (!reportViolations) { - return false; - } - return Object.values(reportViolations ?? {}).some((violations) => !isEmptyObject(violations)); -} - /** * Checks if submission should be blocked due to strict policy rules being enabled and violations present. * When a user's domain has "strictly enforce workspace rules" enabled, they cannot submit reports with violations. @@ -12378,23 +12370,12 @@ function getChatUsedForOnboarding(onboardingValue: OnyxEntry, concie /** * Checks if given field has any violations and returns name of the first encountered one */ -function getFieldViolation(violations: OnyxEntry, reportField: PolicyReportField): ReportViolationName | undefined { +function getFieldViolation(reportField: PolicyReportField): ReportViolationName | undefined { if (!reportField) { return undefined; } - if (!violations) { - return (reportField.value ?? reportField.defaultValue) ? undefined : CONST.REPORT_VIOLATIONS.FIELD_REQUIRED; - } - - const fieldViolation = Object.values(CONST.REPORT_VIOLATIONS).find((violation) => !!violations[violation] && violations[violation][reportField.fieldID]); - - // If the field has no value or no violation, we return 'fieldRequired' violation - if (!fieldViolation) { - return reportField.value ? undefined : CONST.REPORT_VIOLATIONS.FIELD_REQUIRED; - } - - return fieldViolation; + return (reportField.value ?? reportField.defaultValue) ? undefined : CONST.REPORT_VIOLATIONS.FIELD_REQUIRED; } /** @@ -13481,7 +13462,6 @@ export { getMostRecentlyVisitedReport, getSourceIDFromReportAction, getIntegrationNameFromExportMessage, - hasReportViolations, isPayAtEndExpenseReport, getApprovalChain, isIndividualInvoiceRoom, diff --git a/src/libs/TransactionPreviewUtils.ts b/src/libs/TransactionPreviewUtils.ts index 349df6f990ef0..ce01f0d59bf9f 100644 --- a/src/libs/TransactionPreviewUtils.ts +++ b/src/libs/TransactionPreviewUtils.ts @@ -11,16 +11,7 @@ import {convertToDisplayString} from './CurrencyUtils'; import DateUtils from './DateUtils'; import {hasDynamicExternalWorkflow} from './PolicyUtils'; import {getMostRecentActiveDEWSubmitFailedAction, getOriginalMessage, isDynamicExternalWorkflowSubmitFailedAction, isMessageDeleted, isMoneyRequestAction} from './ReportActionsUtils'; -import { - hasActionWithErrorsForTransaction, - hasReceiptError, - hasReportViolations, - isPaidGroupPolicyExpenseReport, - isPaidGroupPolicy as isPaidGroupPolicyUtil, - isReportApproved, - isReportOwner, - isSettled, -} from './ReportUtils'; +import {hasActionWithErrorsForTransaction, hasReceiptError, isPaidGroupPolicyExpenseReport, isPaidGroupPolicy as isPaidGroupPolicyUtil, isReportApproved, isSettled} from './ReportUtils'; import type {TransactionDetails} from './ReportUtils'; import StringUtils from './StringUtils'; import { @@ -368,7 +359,6 @@ function getTransactionPreviewTextAndTranslationPaths({ } function createTransactionPreviewConditionals({ - reportViolations, iouReport, policy, transaction, @@ -382,7 +372,6 @@ function createTransactionPreviewConditionals({ currentUserAccountID, reportActions, }: { - reportViolations: OnyxEntry; iouReport: OnyxEntry; policy: OnyxEntry; transaction: OnyxEntry | undefined; @@ -433,8 +422,7 @@ function createTransactionPreviewConditionals({ (violation) => violation.name === CONST.VIOLATIONS.MODIFIED_AMOUNT && (violation.type === CONST.VIOLATION_TYPES.VIOLATION || violation.type === CONST.VIOLATION_TYPES.NOTICE), )); const hasErrorOrOnHold = hasFieldErrors || (!isFullySettled && !isFullyApproved && isTransactionOnHold); - const hasReportViolationsOrActionErrors = - (isReportOwner(iouReport) && hasReportViolations(reportViolations)) || hasActionWithErrorsForTransaction(iouReport?.reportID, transaction, reportActions); + const hasReportViolationsOrActionErrors = hasActionWithErrorsForTransaction(iouReport?.reportID, transaction, reportActions); const isDEWSubmitFailed = hasDynamicExternalWorkflow(policy) && !!getMostRecentActiveDEWSubmitFailedAction(reportActions); const shouldShowRBR = hasAnyViolations || hasErrorOrOnHold || hasReportViolationsOrActionErrors || hasReceiptError(transaction) || isDEWSubmitFailed; diff --git a/src/libs/actions/IOU/index.ts b/src/libs/actions/IOU/index.ts index 3841fd6e1bca7..ff96472669a2f 100644 --- a/src/libs/actions/IOU/index.ts +++ b/src/libs/actions/IOU/index.ts @@ -79,7 +79,6 @@ import { getSubmitToAccountID, hasDependentTags, hasDynamicExternalWorkflow, - isControlPolicy, isDelayedSubmissionEnabled, isPaidGroupPolicy, isPolicyAdmin, @@ -1781,39 +1780,6 @@ function getReceiptError( ); } -/** Helper function to get optimistic fields violations onyx data */ -function getFieldViolationsOnyxData(iouReport: OnyxTypes.Report): OnyxData { - const missingFields: OnyxTypes.ReportFieldsViolations = {}; - const excludedFields = Object.values(CONST.REPORT_VIOLATIONS_EXCLUDED_FIELDS) as string[]; - - for (const field of Object.values(iouReport.fieldList ?? {})) { - if (excludedFields.includes(field.fieldID) || !!field.value || !!field.defaultValue) { - continue; - } - // in case of missing field violation the empty object is indicator. - missingFields[field.fieldID] = {}; - } - - return { - optimisticData: [ - { - onyxMethod: Onyx.METHOD.SET, - key: `${ONYXKEYS.COLLECTION.REPORT_VIOLATIONS}${iouReport.reportID}`, - value: { - fieldRequired: missingFields, - }, - }, - ], - failureData: [ - { - onyxMethod: Onyx.METHOD.SET, - key: `${ONYXKEYS.COLLECTION.REPORT_VIOLATIONS}${iouReport.reportID}`, - value: null, - }, - ], - }; -} - type BuildOnyxDataForTestDriveIOUParams = { transaction: OnyxTypes.Transaction; iouOptimisticParams: MoneyRequestOptimisticParams['iou']; @@ -2584,7 +2550,6 @@ type BuildOnyxDataForTrackExpenseParams = { chat: {report: OnyxInputValue; previewAction: OnyxInputValue}; iou: {report: OnyxInputValue; createdAction: OptimisticCreatedReportAction; action: OptimisticIOUReportAction}; transactionParams: {transaction: OnyxTypes.Transaction; threadReport: OptimisticChatReport | null; threadCreatedReportAction: OptimisticCreatedReportAction | null}; - policyParams: {policy?: OnyxInputValue; tagList?: OnyxInputValue; categories?: OnyxInputValue}; shouldCreateNewMoneyRequestReport: boolean; existingTransactionThreadReportID?: string; actionableTrackExpenseWhisper?: OnyxInputValue; @@ -2601,15 +2566,13 @@ type BuildOnyxDataForTrackExpenseKeys = | typeof ONYXKEYS.COLLECTION.TRANSACTION | typeof ONYXKEYS.NVP_QUICK_ACTION_GLOBAL_CREATE | typeof ONYXKEYS.COLLECTION.SNAPSHOT - | typeof ONYXKEYS.COLLECTION.TRANSACTION_VIOLATIONS - | typeof ONYXKEYS.COLLECTION.REPORT_VIOLATIONS; + | typeof ONYXKEYS.COLLECTION.TRANSACTION_VIOLATIONS; /** Builds the Onyx data for track expense */ function buildOnyxDataForTrackExpense({ chat, iou, transactionParams, - policyParams = {}, shouldCreateNewMoneyRequestReport, existingTransactionThreadReportID, actionableTrackExpenseWhisper, @@ -2621,8 +2584,6 @@ function buildOnyxDataForTrackExpense({ const {report: chatReport, previewAction: reportPreviewAction} = chat; const {report: iouReport, createdAction: iouCreatedAction, action: iouAction} = iou; const {transaction, threadReport: transactionThreadReport, threadCreatedReportAction: transactionThreadCreatedReportAction} = transactionParams; - const {policy, tagList: policyTagList, categories: policyCategories} = policyParams; - const isScanRequest = isScanRequestTransactionUtils(transaction); const isDistanceRequest = isDistanceRequestTransactionUtils(transaction); const clearedPendingFields = Object.fromEntries(Object.keys(transaction.pendingFields ?? {}).map((key) => [key, null])); @@ -2998,38 +2959,6 @@ function buildOnyxDataForTrackExpense({ onyxData.successData?.push(...searchUpdate.successData); } } - - // We don't need to compute violations unless we're on a paid policy - if (!policy || !isPaidGroupPolicy(policy) || transaction.reportID === CONST.REPORT.UNREPORTED_REPORT_ID) { - return onyxData; - } - - const violationsOnyxData = ViolationsUtils.getViolationsOnyxData( - transaction, - [], - policy, - policyTagList ?? {}, - policyCategories ?? {}, - hasDependentTags(policy, policyTagList ?? {}), - false, - ); - - if (violationsOnyxData) { - onyxData.optimisticData?.push(violationsOnyxData); - onyxData.failureData?.push({ - onyxMethod: Onyx.METHOD.SET, - key: `${ONYXKEYS.COLLECTION.TRANSACTION_VIOLATIONS}${transaction.transactionID}`, - value: [], - }); - } - - // Show field violations only for control policies - if (isControlPolicy(policy) && iouReport) { - const {optimisticData: fieldViolationsOptimisticData, failureData: fieldViolationsFailureData} = getFieldViolationsOnyxData(iouReport); - onyxData.optimisticData?.push(...(fieldViolationsOptimisticData ?? [])); - onyxData.failureData?.push(...(fieldViolationsFailureData ?? [])); - } - return onyxData; } @@ -3722,7 +3651,7 @@ function getTrackExpenseInformation(params: GetTrackExpenseInformationParams): T isSelfTourViewed, } = params; const {payeeAccountID = userAccountID, payeeEmail = currentUserEmail, participant} = participantParams; - const {policy, policyCategories, policyTagList} = policyParams; + const {policy} = policyParams; const { comment, amount, @@ -4017,7 +3946,6 @@ function getTrackExpenseInformation(params: GetTrackExpenseInformationParams): T threadCreatedReportAction: optimisticCreatedActionForTransactionThread, threadReport: optimisticTransactionThread ?? {}, }, - policyParams: {policy, tagList: policyTagList, categories: policyCategories}, shouldCreateNewMoneyRequestReport, actionableTrackExpenseWhisper, retryParams, diff --git a/src/libs/actions/Report/index.ts b/src/libs/actions/Report/index.ts index f520810ed5fc8..4cf159788a74e 100644 --- a/src/libs/actions/Report/index.ts +++ b/src/libs/actions/Report/index.ts @@ -127,7 +127,6 @@ import { getChatByParticipants, getChildReportNotificationPreference, getDefaultNotificationPreferenceForReport, - getFieldViolation, getLastVisibleMessage, getNextApproverAccountID, getOptimisticDataForAncestors, @@ -211,7 +210,6 @@ import type { ReportActionReactions, ReportNextStepDeprecated, ReportUserIsTyping, - ReportViolations, Transaction, TransactionViolations, VisibleReportActionsDerivedValue, @@ -3070,7 +3068,6 @@ function updateReportField({ email, hasViolationsParam, recentlyUsedReportFields, - reportViolations, shouldFixViolations = false, }: { report: Report; @@ -3082,12 +3079,10 @@ function updateReportField({ email: string; hasViolationsParam: boolean; recentlyUsedReportFields: OnyxEntry; - reportViolations: OnyxEntry; shouldFixViolations: boolean | undefined; }) { const reportID = report.reportID; const fieldKey = getReportFieldKey(reportField.fieldID); - const fieldViolation = getFieldViolation(reportViolations, reportField); const recentlyUsedValues = recentlyUsedReportFields?.[fieldKey] ?? []; const optimisticChangeFieldAction = buildOptimisticChangeFieldAction(reportField, previousReportField); @@ -3117,13 +3112,7 @@ function updateReportField({ }); const optimisticData: Array< - OnyxUpdate< - | typeof ONYXKEYS.COLLECTION.REPORT - | typeof ONYXKEYS.COLLECTION.NEXT_STEP - | typeof ONYXKEYS.COLLECTION.REPORT_ACTIONS - | typeof ONYXKEYS.COLLECTION.REPORT_VIOLATIONS - | typeof ONYXKEYS.RECENTLY_USED_REPORT_FIELDS - > + OnyxUpdate > = [ { onyxMethod: Onyx.METHOD.MERGE, @@ -3153,18 +3142,6 @@ function updateReportField({ }, ]; - if (fieldViolation) { - optimisticData.push({ - onyxMethod: Onyx.METHOD.MERGE, - key: `${ONYXKEYS.COLLECTION.REPORT_VIOLATIONS}${reportID}`, - value: { - [fieldViolation]: { - [reportField.fieldID]: null, - }, - }, - }); - } - if (reportField.type === 'dropdown' && reportField.value) { optimisticData.push({ onyxMethod: Onyx.METHOD.MERGE, diff --git a/src/pages/Debug/Report/DebugReportPage.tsx b/src/pages/Debug/Report/DebugReportPage.tsx index 1c16568608515..705328f9373ae 100644 --- a/src/pages/Debug/Report/DebugReportPage.tsx +++ b/src/pages/Debug/Report/DebugReportPage.tsx @@ -21,7 +21,7 @@ import DebugTabNavigator from '@libs/Navigation/DebugTabNavigator'; import Navigation from '@libs/Navigation/Navigation'; import type {PlatformStackScreenProps} from '@libs/Navigation/PlatformStackNavigation/types'; import type {DebugParamList} from '@libs/Navigation/types'; -import {getViolatingReportIDForRBRInLHN, hasReportViolations, isReportOwner} from '@libs/ReportUtils'; +import {getViolatingReportIDForRBRInLHN} from '@libs/ReportUtils'; import DebugDetails from '@pages/Debug/DebugDetails'; import DebugJSON from '@pages/Debug/DebugJSON'; import NotFoundPage from '@pages/ErrorPage/NotFoundPage'; @@ -59,7 +59,6 @@ function DebugReportPage({ const [reportActions] = useOnyx(`${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${reportID}`); const [transactions] = useOnyx(ONYXKEYS.COLLECTION.TRANSACTION); const [transactionViolations] = useOnyx(ONYXKEYS.COLLECTION.TRANSACTION_VIOLATIONS); - const [reportViolations] = useOnyx(`${ONYXKEYS.COLLECTION.REPORT_VIOLATIONS}${reportID}`); const reportAttributesSelector = useCallback((attributes: OnyxEntry) => attributes?.reports?.[reportID], [reportID]); const [reportAttributes] = useOnyx( ONYXKEYS.DERIVED.REPORT_ATTRIBUTES, @@ -83,8 +82,7 @@ function DebugReportPage({ } const shouldDisplayViolations = !!getViolatingReportIDForRBRInLHN(report, transactionViolations); - const shouldDisplayReportViolations = isReportOwner(report) && hasReportViolations(reportViolations); - const hasViolations = !!shouldDisplayViolations || shouldDisplayReportViolations; + const hasViolations = !!shouldDisplayViolations; const {reason: reasonGBR, reportAction: reportActionGBR} = DebugUtils.getReasonAndReportActionForGBRInLHNRow(report, isReportArchived) ?? {}; const {reason: reasonRBR, reportAction: reportActionRBR} = DebugUtils.getReasonAndReportActionForRBRInLHNRow( @@ -153,20 +151,7 @@ function DebugReportPage({ : undefined, }, ]; - }, [ - report, - transactionViolations, - reportViolations, - isReportArchived, - chatReport, - reportActions, - transactions, - reportAttributes?.reportErrors, - betas, - priorityMode, - draftComment, - translate, - ]); + }, [report, transactionViolations, isReportArchived, chatReport, reportActions, transactions, reportAttributes?.reportErrors, betas, priorityMode, draftComment, translate]); const icons = useMemoizedLazyExpensifyIcons(['Eye'] as const); diff --git a/src/pages/EditReportFieldPage.tsx b/src/pages/EditReportFieldPage.tsx index 7ff09c307da9e..c0dfedbef248f 100644 --- a/src/pages/EditReportFieldPage.tsx +++ b/src/pages/EditReportFieldPage.tsx @@ -68,7 +68,6 @@ function EditReportFieldPage({route}: EditReportFieldPageProps) { const session = useSession(); const [transactionViolations] = useOnyx(ONYXKEYS.COLLECTION.TRANSACTION_VIOLATIONS); const hasViolations = hasViolationsReportUtils(report?.reportID, transactionViolations, session?.accountID ?? CONST.DEFAULT_NUMBER_ID, session?.email ?? ''); - const [reportViolations] = useOnyx(`${ONYXKEYS.COLLECTION.REPORT_VIOLATIONS}${reportID}`); const {translate} = useLocalize(); const {showConfirmModal} = useConfirmModal(); const icons = useMemoizedLazyExpensifyIcons(['Trashcan'] as const); @@ -142,7 +141,6 @@ function EditReportFieldPage({route}: EditReportFieldPageProps) { email: session?.email ?? '', hasViolationsParam: hasViolations, recentlyUsedReportFields, - reportViolations, shouldFixViolations: hasOtherViolations ?? false, }); } diff --git a/src/types/onyx/ReportViolation.ts b/src/types/onyx/ReportViolation.ts deleted file mode 100644 index fae385cc674d9..0000000000000 --- a/src/types/onyx/ReportViolation.ts +++ /dev/null @@ -1,21 +0,0 @@ -import type {EmptyObject, ValueOf} from 'type-fest'; -import type CONST from '@src/CONST'; - -/** - * Names of violations. - * Derived from `CONST.VIOLATIONS` to maintain a single source of truth. - */ -type ReportViolationName = ValueOf; - -/** - * Keys of this object are IDs of field that has violations - */ -type ReportFieldsViolations = Record; - -/** - * Report Violation model - */ -type ReportViolations = Record; - -export type {ReportViolationName, ReportFieldsViolations}; -export default ReportViolations; diff --git a/src/types/onyx/ReportViolationName.ts b/src/types/onyx/ReportViolationName.ts new file mode 100644 index 0000000000000..1635ff727d102 --- /dev/null +++ b/src/types/onyx/ReportViolationName.ts @@ -0,0 +1,10 @@ +import type {ValueOf} from 'type-fest'; +import type CONST from '@src/CONST'; + +/** + * Names of violations. + * Derived from `CONST.VIOLATIONS` to maintain a single source of truth. + */ +type ReportViolationName = ValueOf; + +export default ReportViolationName; diff --git a/src/types/onyx/index.ts b/src/types/onyx/index.ts index d6be837a45fda..4a69055dc3590 100644 --- a/src/types/onyx/index.ts +++ b/src/types/onyx/index.ts @@ -134,8 +134,7 @@ import type ReportNameValuePairs from './ReportNameValuePairs'; import type LastSearchParams from './ReportNavigation'; import type ReportNextStepDeprecated from './ReportNextStepDeprecated'; import type ReportUserIsTyping from './ReportUserIsTyping'; -import type {ReportFieldsViolations, ReportViolationName} from './ReportViolation'; -import type ReportViolations from './ReportViolation'; +import type ReportViolationName from './ReportViolationName'; import type Request from './Request'; import type {AnyRequest} from './Request'; import type Response from './Response'; @@ -281,8 +280,6 @@ export type { ReportMetadata, ReportNextStepDeprecated, ReportViolationName, - ReportViolations, - ReportFieldsViolations, ReportLayoutGroupBy, GroupedTransactions, AnyRequest, diff --git a/tests/unit/TransactionPreviewUtils.test.ts b/tests/unit/TransactionPreviewUtils.test.ts index 184d9e0a1b39a..2d5fee83289f6 100644 --- a/tests/unit/TransactionPreviewUtils.test.ts +++ b/tests/unit/TransactionPreviewUtils.test.ts @@ -13,7 +13,6 @@ import CONST from '@src/CONST'; import * as ReportUtils from '@src/libs/ReportUtils'; import ONYXKEYS from '@src/ONYXKEYS'; import type {ReportActions, Transaction} from '@src/types/onyx'; -import type ReportViolations from '@src/types/onyx/ReportViolation'; import createRandomPolicy from '../utils/collections/policies'; import waitForBatchedUpdates from '../utils/waitForBatchedUpdates'; @@ -514,100 +513,6 @@ describe('TransactionPreviewUtils', () => { expect(result.shouldShowRBR).toBeFalsy(); }); - it('should show RBR when report has violations and user is the report owner', () => { - const reportID = basicProps.iouReport.reportID || '1'; - const iouReport = { - ...basicProps.iouReport, - reportID, - ownerAccountID: currentUserAccountID, - }; - - const reportViolations: ReportViolations = { - fieldRequired: { - field1: {}, - field2: {}, - }, - } as unknown as ReportViolations; - - const functionArgs = { - ...basicProps, - iouReport, - reportViolations, - violations: [], - transaction: {...basicProps.transaction, errors: undefined, errorFields: undefined}, - }; - - const result = createTransactionPreviewConditionals(functionArgs); - expect(result.shouldShowRBR).toBeTruthy(); - }); - - it('should not show RBR from report violations when user is not the report owner', () => { - const reportID = basicProps.iouReport.reportID || '1'; - const otherUserAccountID = 888; - const iouReport = { - ...basicProps.iouReport, - reportID, - ownerAccountID: otherUserAccountID, - }; - - // First, test without violations - const functionArgsWithoutViolations = { - ...basicProps, - iouReport, - reportViolations: undefined, - violations: [], - transaction: {...basicProps.transaction, errors: undefined, errorFields: undefined}, - }; - - const resultWithoutViolations = createTransactionPreviewConditionals(functionArgsWithoutViolations); - const shouldShowRBRWithoutViolations = resultWithoutViolations.shouldShowRBR; - - // Then, test with violations - const reportViolations: ReportViolations = { - fieldRequired: { - field1: {}, - }, - } as unknown as ReportViolations; - - const functionArgsWithViolations = { - ...basicProps, - iouReport, - reportViolations, - violations: [], - transaction: {...basicProps.transaction, errors: undefined, errorFields: undefined}, - }; - - const resultWithViolations = createTransactionPreviewConditionals(functionArgsWithViolations); - // RBR should be the same with or without violations when user is not the owner - expect(resultWithViolations.shouldShowRBR).toBe(shouldShowRBRWithoutViolations); - }); - - it('should show RBR when report has violations even if transaction violations are absent', () => { - const reportID = basicProps.iouReport.reportID || '1'; - const iouReport = { - ...basicProps.iouReport, - reportID, - ownerAccountID: currentUserAccountID, - }; - - const reportViolations: ReportViolations = { - fieldRequired: { - merchant: {}, - }, - } as unknown as ReportViolations; - - const functionArgs = { - ...basicProps, - iouReport, - reportViolations, - violations: [], // No transaction violations - transaction: {...basicProps.transaction, errors: undefined, errorFields: undefined}, - }; - - const result = createTransactionPreviewConditionals(functionArgs); - expect(result.shouldShowRBR).toBeTruthy(); - }); - it('should show description if no merchant is presented and is not scanning', () => { const functionArgs = {...basicProps, transactionDetails: {comment: 'A valid comment', merchant: ''}}; const result = createTransactionPreviewConditionals(functionArgs);