fix:local storage field store
This commit is contained in:
parent
7495ae8887
commit
34573cf3ab
@ -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<string, unknown>[]) || [];
|
||||
|
||||
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}
|
||||
/>
|
||||
);
|
||||
}
|
||||
|
||||
@ -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({
|
||||
<div className="flex items-center justify-between">
|
||||
<p className="text-sm font-bold text-slate-700 uppercase tracking-wide">
|
||||
{label || 'Order details'}
|
||||
{required && <span className="text-ruby-600 normal-case font-medium ml-1">*</span>}
|
||||
</p>
|
||||
</div>
|
||||
|
||||
|
||||
@ -10,6 +10,7 @@ export interface PotentialMiningGridProps {
|
||||
value: Record<string, unknown>[];
|
||||
onChange: (val: Record<string, unknown>[]) => 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({
|
||||
<div className="flex items-center justify-between">
|
||||
<p className="text-sm font-bold text-slate-700 uppercase tracking-wide">
|
||||
{label || 'Potential Mining'}
|
||||
{required && <span className="text-ruby-600 normal-case font-medium ml-1">*</span>}
|
||||
</p>
|
||||
</div>
|
||||
|
||||
|
||||
@ -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) {
|
||||
|
||||
@ -10,6 +10,7 @@ export interface StorePotentialGridProps {
|
||||
value: Record<string, unknown>[];
|
||||
onChange: (val: Record<string, unknown>[]) => 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({
|
||||
<div className="flex items-center justify-between">
|
||||
<p className="text-sm font-bold text-slate-700 uppercase tracking-wide">
|
||||
{label || 'Store Potential'}
|
||||
{required && <span className="text-ruby-600 normal-case font-medium ml-1">*</span>}
|
||||
</p>
|
||||
</div>
|
||||
|
||||
|
||||
Loading…
Reference in New Issue
Block a user