From 34573cf3ab0a078a86a5a359583c762d32482774 Mon Sep 17 00:00:00 2001 From: suryac Date: Thu, 1 Oct 2026 17:04:17 +0530 Subject: [PATCH] fix:local storage field store --- src/components/forms/DynamicForm.tsx | 60 ++----------------- src/components/forms/fields/OrderGrid.tsx | 3 + .../forms/fields/PotentialMiningGrid.tsx | 3 + .../forms/fields/SmartGridField.tsx | 1 + .../forms/fields/StorePotentialGrid.tsx | 3 + 5 files changed, 16 insertions(+), 54 deletions(-) diff --git a/src/components/forms/DynamicForm.tsx b/src/components/forms/DynamicForm.tsx index e7bc373..70aa40f 100644 --- a/src/components/forms/DynamicForm.tsx +++ b/src/components/forms/DynamicForm.tsx @@ -494,61 +494,12 @@ export function DynamicForm({ client, activityId: initialActivityId, instanceId: } }); - // 2. Validate grid fields (Order Details) + // 2. Validate grid fields for (const f of normalFields) { - if (f.data_type.startsWith('grid')) { - if (currentActivityId === 'af8ac8df-d868-4f7d-88b2-123955d69c56') { - continue; - } - - const gridRows = (finalValues[f.id] as Record[]) || []; - - const hasProdCol = f.columns?.some(c => - c.id.toLowerCase().includes('product_name') || - c.id.toLowerCase() === 'product' || - c.id.toLowerCase() === 'name' || - (c.name || '').toLowerCase().includes('product name') || - (c.name || '').toLowerCase() === 'product' || - ((c.name || '').toLowerCase().includes('product') && !(c.name || '').toLowerCase().includes('category')) - ); - - // Check if grid has at least one valid row - const validRows = gridRows.filter((r) => { - const { cat, prod, bags } = extractGridRowDetails(r, f.columns); - if (hasProdCol) { - return cat && prod && bags > 0; - } - return cat && bags > 0; - }); - - if (f.mandatory && validRows.length === 0) { - setSubmitError(`Please add at least one complete row for ${f.name}.`); - return; - } - - // Check if any row is partially filled - const hasIncompleteRow = gridRows.some((r) => { - const { cat, prod, bags } = extractGridRowDetails(r, f.columns); - - if (!hasProdCol) { - if (cat && bags <= 0) return true; - if (bags > 0 && !cat) return true; - return false; - } - - if (!cat && !prod && bags <= 0) return false; - if (cat && (!prod || bags <= 0)) return true; - if (prod && (!cat || bags <= 0)) return true; - if (bags > 0 && (!cat || !prod)) return true; - return false; - }); - - if (hasIncompleteRow) { - if (!hasProdCol) { - setSubmitError(`Please complete all required details (Category and Quantity) for ${f.name} before submitting.`); - } else { - setSubmitError('Please complete all required product details (Category, Product Name, and Bags) before submitting.'); - } + if (f.mandatory && f.data_type.startsWith('grid')) { + const val = finalValues[f.id]; + if (!Array.isArray(val) || val.length === 0) { + setSubmitError(`Please add at least one item to ${f.name}`); return; } } @@ -975,6 +926,7 @@ export function DynamicForm({ client, activityId: initialActivityId, instanceId: hideTotal={isPotentialMiningGrid} readOnlyCols={isPotentialMiningGrid ? ['product_category_', 'actual_potential', 'total_ordered', 'difference'] : []} isPotentialMining={isPotentialMiningGrid} + required={f.mandatory} /> ); } diff --git a/src/components/forms/fields/OrderGrid.tsx b/src/components/forms/fields/OrderGrid.tsx index 27a54d6..0f7963b 100644 --- a/src/components/forms/fields/OrderGrid.tsx +++ b/src/components/forms/fields/OrderGrid.tsx @@ -12,6 +12,7 @@ export interface OrderGridProps { totalBagsValue?: number; totalKgsValue?: number; showErrors?: boolean; + required?: boolean; } export function OrderGrid({ @@ -22,6 +23,7 @@ export function OrderGrid({ totalBagsValue, totalKgsValue, showErrors = false, + required, }: OrderGridProps) { const rows = value.length > 0 ? value : [{}]; @@ -320,6 +322,7 @@ export function OrderGrid({

{label || 'Order details'} + {required && *}

diff --git a/src/components/forms/fields/PotentialMiningGrid.tsx b/src/components/forms/fields/PotentialMiningGrid.tsx index 68ee2ab..0ecfeb4 100644 --- a/src/components/forms/fields/PotentialMiningGrid.tsx +++ b/src/components/forms/fields/PotentialMiningGrid.tsx @@ -10,6 +10,7 @@ export interface PotentialMiningGridProps { value: Record[]; onChange: (val: Record[]) => void; readOnlyCols?: string[]; + required?: boolean; } export function PotentialMiningGrid({ @@ -18,6 +19,7 @@ export function PotentialMiningGrid({ value = [], onChange, readOnlyCols = [], + required, }: PotentialMiningGridProps) { const rows = value.length > 0 ? value : [{}]; @@ -77,6 +79,7 @@ export function PotentialMiningGrid({

{label || 'Potential Mining'} + {required && *}

diff --git a/src/components/forms/fields/SmartGridField.tsx b/src/components/forms/fields/SmartGridField.tsx index 83b38c2..b262917 100644 --- a/src/components/forms/fields/SmartGridField.tsx +++ b/src/components/forms/fields/SmartGridField.tsx @@ -15,6 +15,7 @@ export interface SmartGridFieldProps { hideTotal?: boolean; readOnlyCols?: string[]; isPotentialMining?: boolean; // We will pass this from DynamicForm + required?: boolean; } export function SmartGridField(props: SmartGridFieldProps) { diff --git a/src/components/forms/fields/StorePotentialGrid.tsx b/src/components/forms/fields/StorePotentialGrid.tsx index ed9e16c..29e3140 100644 --- a/src/components/forms/fields/StorePotentialGrid.tsx +++ b/src/components/forms/fields/StorePotentialGrid.tsx @@ -10,6 +10,7 @@ export interface StorePotentialGridProps { value: Record[]; onChange: (val: Record[]) => void; showErrors?: boolean; + required?: boolean; } export function StorePotentialGrid({ @@ -18,6 +19,7 @@ export function StorePotentialGrid({ value = [], onChange, showErrors = false, + required, }: StorePotentialGridProps) { const rows = value.length > 0 ? value : [{}]; @@ -153,6 +155,7 @@ export function StorePotentialGrid({

{label || 'Store Potential'} + {required && *}