From bd3c1c79fe69656a1ddcb7aecfdd309e4bac2967 Mon Sep 17 00:00:00 2001 From: "Antony M. Kithinzi" Date: Tue, 22 Jul 2025 21:52:24 +0000 Subject: [PATCH 1/4] Fixed report fields error --- src/libs/ReportUtils.ts | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/src/libs/ReportUtils.ts b/src/libs/ReportUtils.ts index 35235ca23893..89fd0bc384ba 100644 --- a/src/libs/ReportUtils.ts +++ b/src/libs/ReportUtils.ts @@ -10633,11 +10633,22 @@ function getChatUsedForOnboarding(): OnyxEntry { * Checks if given field has any violations and returns name of the first encountered one */ function getFieldViolation(violations: OnyxEntry, reportField: PolicyReportField): ReportViolationName | undefined { - if (!violations || !reportField) { + if (!reportField) { return undefined; } - return Object.values(CONST.REPORT_VIOLATIONS).find((violation) => !!violations[violation] && violations[violation][reportField.fieldID]); + if (!violations) { + return reportField.value ? 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; } /** From 8cddc2f21be30f90031393fc0c6b3a63a3f1405c Mon Sep 17 00:00:00 2001 From: Antony Kithinzi Date: Sat, 16 Aug 2025 03:40:32 +0300 Subject: [PATCH 2/4] build next step --- src/libs/actions/Report.ts | 10 +++++++++- src/pages/EditReportFieldPage.tsx | 14 ++++++++++++-- 2 files changed, 21 insertions(+), 3 deletions(-) diff --git a/src/libs/actions/Report.ts b/src/libs/actions/Report.ts index f20705aa5d2a..9cdfff047898 100644 --- a/src/libs/actions/Report.ts +++ b/src/libs/actions/Report.ts @@ -2371,13 +2371,16 @@ function clearReportFieldKeyErrors(reportID: string | undefined, fieldKey: strin }); } -function updateReportField(reportID: string, reportField: PolicyReportField, previousReportField: PolicyReportField) { +function updateReportField(report: Report, reportField: PolicyReportField, previousReportField: PolicyReportField, policy: Policy, shouldFixViolations = false) { + const reportID = report.reportID; const fieldKey = getReportFieldKey(reportField.fieldID); const reportViolations = getReportViolations(reportID); const fieldViolation = getFieldViolation(reportViolations, reportField); const recentlyUsedValues = allRecentlyUsedReportFields?.[fieldKey] ?? []; const optimisticChangeFieldAction = buildOptimisticChangeFieldAction(reportField, previousReportField); + const predictedNextStatus = policy?.reimbursementChoice === CONST.POLICY.REIMBURSEMENT_CHOICES.REIMBURSEMENT_NO ? CONST.REPORT.STATUS_NUM.CLOSED : CONST.REPORT.STATUS_NUM.OPEN; + const optimisticNextStep = buildNextStep(report, predictedNextStatus, shouldFixViolations); const optimisticData: OnyxUpdate[] = [ { @@ -2392,6 +2395,11 @@ function updateReportField(reportID: string, reportField: PolicyReportField, pre }, }, }, + { + onyxMethod: Onyx.METHOD.MERGE, + key: `${ONYXKEYS.COLLECTION.NEXT_STEP}${reportID}`, + value: optimisticNextStep, + }, { onyxMethod: Onyx.METHOD.MERGE, key: `${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${reportID}`, diff --git a/src/pages/EditReportFieldPage.tsx b/src/pages/EditReportFieldPage.tsx index 966ccfafd3aa..fe531bf64b80 100644 --- a/src/pages/EditReportFieldPage.tsx +++ b/src/pages/EditReportFieldPage.tsx @@ -23,6 +23,7 @@ import type SCREENS from '@src/SCREENS'; import EditReportFieldDate from './EditReportFieldDate'; import EditReportFieldDropdown from './EditReportFieldDropdown'; import EditReportFieldText from './EditReportFieldText'; +import { Policy } from '@src/types/onyx'; type EditReportFieldPageProps = PlatformStackScreenProps; @@ -40,7 +41,10 @@ function EditReportFieldPage({route}: EditReportFieldPageProps) { const {translate} = useLocalize(); const isReportFieldTitle = isReportFieldOfTypeTitle(reportField); const reportFieldsEnabled = ((isPaidGroupPolicyExpenseReport(report) || isInvoiceReport(report)) && !!policy?.areReportFieldsEnabled) || isReportFieldTitle; - + const hasOtherViolations = report?.fieldList && Object.entries(report.fieldList).some( + ([key, field] : any) => key !== fieldKey && field.value === "" && !isReportFieldDisabled(report, reportField, policy) + ); + if (!reportFieldsEnabled || !reportField || !policyField || !report || isDisabled) { return ( Date: Sat, 16 Aug 2025 04:07:47 +0300 Subject: [PATCH 3/4] lint --- src/pages/EditReportFieldPage.tsx | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/pages/EditReportFieldPage.tsx b/src/pages/EditReportFieldPage.tsx index fe531bf64b80..f3485190b27e 100644 --- a/src/pages/EditReportFieldPage.tsx +++ b/src/pages/EditReportFieldPage.tsx @@ -20,10 +20,10 @@ import CONST from '@src/CONST'; import ONYXKEYS from '@src/ONYXKEYS'; import ROUTES from '@src/ROUTES'; import type SCREENS from '@src/SCREENS'; +import type { Policy } from '@src/types/onyx'; import EditReportFieldDate from './EditReportFieldDate'; import EditReportFieldDropdown from './EditReportFieldDropdown'; import EditReportFieldText from './EditReportFieldText'; -import { Policy } from '@src/types/onyx'; type EditReportFieldPageProps = PlatformStackScreenProps; @@ -32,8 +32,8 @@ function EditReportFieldPage({route}: EditReportFieldPageProps) { const threeDotsAnchorPosition = useThreeDotsAnchorPosition(styles.threeDotsPopoverOffsetNoCloseButton); const {backTo, reportID, policyID} = route.params; const fieldKey = getReportFieldKey(route.params.fieldID); - const [report] = useOnyx(`${ONYXKEYS.COLLECTION.REPORT}${reportID}`); - const [policy] = useOnyx(`${ONYXKEYS.COLLECTION.POLICY}${policyID}`); + const [report] = useOnyx(`${ONYXKEYS.COLLECTION.REPORT}${reportID}`, {canBeMissing: false}); + const [policy] = useOnyx(`${ONYXKEYS.COLLECTION.POLICY}${policyID}`, {canBeMissing: false}); const reportField = report?.fieldList?.[fieldKey] ?? policy?.fieldList?.[fieldKey]; const policyField = policy?.fieldList?.[fieldKey] ?? reportField; const isDisabled = isReportFieldDisabled(report, reportField, policy); @@ -42,7 +42,7 @@ function EditReportFieldPage({route}: EditReportFieldPageProps) { const isReportFieldTitle = isReportFieldOfTypeTitle(reportField); const reportFieldsEnabled = ((isPaidGroupPolicyExpenseReport(report) || isInvoiceReport(report)) && !!policy?.areReportFieldsEnabled) || isReportFieldTitle; const hasOtherViolations = report?.fieldList && Object.entries(report.fieldList).some( - ([key, field] : any) => key !== fieldKey && field.value === "" && !isReportFieldDisabled(report, reportField, policy) + ([key, field]) => key !== fieldKey && field.value === "" && !isReportFieldDisabled(report, reportField, policy) ); if (!reportFieldsEnabled || !reportField || !policyField || !report || isDisabled) { From ddfb2136c679318d38bef26b304ebbf1d1bb3ae7 Mon Sep 17 00:00:00 2001 From: Antony Kithinzi Date: Sat, 16 Aug 2025 04:24:10 +0300 Subject: [PATCH 4/4] prettier --- src/pages/EditReportFieldPage.tsx | 17 +++++------------ 1 file changed, 5 insertions(+), 12 deletions(-) diff --git a/src/pages/EditReportFieldPage.tsx b/src/pages/EditReportFieldPage.tsx index f3485190b27e..2e133bf11c92 100644 --- a/src/pages/EditReportFieldPage.tsx +++ b/src/pages/EditReportFieldPage.tsx @@ -20,7 +20,7 @@ import CONST from '@src/CONST'; import ONYXKEYS from '@src/ONYXKEYS'; import ROUTES from '@src/ROUTES'; import type SCREENS from '@src/SCREENS'; -import type { Policy } from '@src/types/onyx'; +import type {Policy} from '@src/types/onyx'; import EditReportFieldDate from './EditReportFieldDate'; import EditReportFieldDropdown from './EditReportFieldDropdown'; import EditReportFieldText from './EditReportFieldText'; @@ -41,10 +41,9 @@ function EditReportFieldPage({route}: EditReportFieldPageProps) { const {translate} = useLocalize(); const isReportFieldTitle = isReportFieldOfTypeTitle(reportField); const reportFieldsEnabled = ((isPaidGroupPolicyExpenseReport(report) || isInvoiceReport(report)) && !!policy?.areReportFieldsEnabled) || isReportFieldTitle; - const hasOtherViolations = report?.fieldList && Object.entries(report.fieldList).some( - ([key, field]) => key !== fieldKey && field.value === "" && !isReportFieldDisabled(report, reportField, policy) - ); - + const hasOtherViolations = + report?.fieldList && Object.entries(report.fieldList).some(([key, field]) => key !== fieldKey && field.value === '' && !isReportFieldDisabled(report, reportField, policy)); + if (!reportFieldsEnabled || !reportField || !policyField || !report || isDisabled) { return (