From 7ec90984b73f75b112393b69b7d6359ae1b9e0e0 Mon Sep 17 00:00:00 2001 From: Trevor Coleman Date: Tue, 12 Dec 2023 16:12:13 -0500 Subject: [PATCH] feat(Violations): move propTypes into MoneyRequestView --- .../ReportActionItem/MoneyRequestView.js | 11 ++++++++++- src/components/ViolationMessages.tsx | 2 +- src/libs/Violations/propTypes.ts | 15 --------------- src/libs/{Violations => }/ViolationsUtils.ts | 2 +- tests/unit/ViolationUtilsTest.js | 2 +- 5 files changed, 13 insertions(+), 19 deletions(-) delete mode 100644 src/libs/Violations/propTypes.ts rename src/libs/{Violations => }/ViolationsUtils.ts (99%) diff --git a/src/components/ReportActionItem/MoneyRequestView.js b/src/components/ReportActionItem/MoneyRequestView.js index 9fa0121fc60e..b142ebcb5ee8 100644 --- a/src/components/ReportActionItem/MoneyRequestView.js +++ b/src/components/ReportActionItem/MoneyRequestView.js @@ -30,7 +30,6 @@ import * as ReceiptUtils from '@libs/ReceiptUtils'; import * as ReportActionsUtils from '@libs/ReportActionsUtils'; import * as ReportUtils from '@libs/ReportUtils'; import * as TransactionUtils from '@libs/TransactionUtils'; -import {transactionViolationsPropTypes} from '@libs/Violations/propTypes'; import AnimatedEmptyStateBackground from '@pages/home/report/AnimatedEmptyStateBackground'; import reportActionPropTypes from '@pages/home/report/reportActionPropTypes'; import iouReportPropTypes from '@pages/iouReportPropTypes'; @@ -44,6 +43,16 @@ import ONYXKEYS from '@src/ONYXKEYS'; import ROUTES from '@src/ROUTES'; import ReportActionItemImage from './ReportActionItemImage'; +const violationNames = lodashValues(CONST.VIOLATIONS); + +const transactionViolationPropType = PropTypes.shape({ + type: PropTypes.string.isRequired, + name: PropTypes.oneOf(violationNames).isRequired, + data: PropTypes.objectOf(PropTypes.string), +}); + +const transactionViolationsPropTypes = PropTypes.arrayOf(transactionViolationPropType); + const propTypes = { /** The report currently being looked at */ report: reportPropTypes.isRequired, diff --git a/src/components/ViolationMessages.tsx b/src/components/ViolationMessages.tsx index a53272904540..94d112f3e849 100644 --- a/src/components/ViolationMessages.tsx +++ b/src/components/ViolationMessages.tsx @@ -1,7 +1,7 @@ import React, {useMemo} from 'react'; import {View} from 'react-native'; import useLocalize from '@hooks/useLocalize'; -import ViolationsUtils from '@libs/Violations/ViolationsUtils'; +import ViolationsUtils from '@libs/ViolationsUtils'; import useThemeStyles from '@styles/useThemeStyles'; import {TransactionViolation} from '@src/types/onyx'; import Text from './Text'; diff --git a/src/libs/Violations/propTypes.ts b/src/libs/Violations/propTypes.ts deleted file mode 100644 index c3c0527dfa9a..000000000000 --- a/src/libs/Violations/propTypes.ts +++ /dev/null @@ -1,15 +0,0 @@ -import PropTypes from 'prop-types'; -import CONST from '@src/CONST'; -import {ViolationName} from '@src/types/onyx'; - -const violationNames = Object.values(CONST.VIOLATIONS) as ViolationName[]; - -const transactionViolationPropType = PropTypes.shape({ - type: PropTypes.string.isRequired, - name: PropTypes.oneOf(violationNames).isRequired, - userMessage: PropTypes.string.isRequired, - data: PropTypes.objectOf(PropTypes.string), -}); -const transactionViolationsPropTypes = PropTypes.arrayOf(transactionViolationPropType); - -export {transactionViolationsPropTypes, transactionViolationPropType}; diff --git a/src/libs/Violations/ViolationsUtils.ts b/src/libs/ViolationsUtils.ts similarity index 99% rename from src/libs/Violations/ViolationsUtils.ts rename to src/libs/ViolationsUtils.ts index 553fcc942068..6a36e2ca58a5 100644 --- a/src/libs/Violations/ViolationsUtils.ts +++ b/src/libs/ViolationsUtils.ts @@ -1,9 +1,9 @@ import reject from 'lodash/reject'; import Onyx from 'react-native-onyx'; -import {Phrase, PhraseParameters} from '@libs/Localize'; import {TranslationPaths} from '@src/languages/types'; import ONYXKEYS from '@src/ONYXKEYS'; import {PolicyCategories, PolicyTags, Transaction, TransactionViolation} from '@src/types/onyx'; +import {Phrase, PhraseParameters} from './Localize'; const ViolationsUtils = { /** diff --git a/tests/unit/ViolationUtilsTest.js b/tests/unit/ViolationUtilsTest.js index f0b53443831e..cc84c547da2e 100644 --- a/tests/unit/ViolationUtilsTest.js +++ b/tests/unit/ViolationUtilsTest.js @@ -1,6 +1,6 @@ import {beforeEach} from '@jest/globals'; import Onyx from 'react-native-onyx'; -import ViolationsUtils from '@libs/Violations/ViolationsUtils'; +import ViolationsUtils from '@libs/ViolationsUtils'; import ONYXKEYS from '@src/ONYXKEYS'; const categoryOutOfPolicyViolation = {