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) {
|
for (const f of normalFields) {
|
||||||
if (f.data_type.startsWith('grid')) {
|
if (f.mandatory && f.data_type.startsWith('grid')) {
|
||||||
if (currentActivityId === 'af8ac8df-d868-4f7d-88b2-123955d69c56') {
|
const val = finalValues[f.id];
|
||||||
continue;
|
if (!Array.isArray(val) || val.length === 0) {
|
||||||
}
|
setSubmitError(`Please add at least one item to ${f.name}`);
|
||||||
|
|
||||||
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.');
|
|
||||||
}
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -975,6 +926,7 @@ export function DynamicForm({ client, activityId: initialActivityId, instanceId:
|
|||||||
hideTotal={isPotentialMiningGrid}
|
hideTotal={isPotentialMiningGrid}
|
||||||
readOnlyCols={isPotentialMiningGrid ? ['product_category_', 'actual_potential', 'total_ordered', 'difference'] : []}
|
readOnlyCols={isPotentialMiningGrid ? ['product_category_', 'actual_potential', 'total_ordered', 'difference'] : []}
|
||||||
isPotentialMining={isPotentialMiningGrid}
|
isPotentialMining={isPotentialMiningGrid}
|
||||||
|
required={f.mandatory}
|
||||||
/>
|
/>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|||||||
@ -12,6 +12,7 @@ export interface OrderGridProps {
|
|||||||
totalBagsValue?: number;
|
totalBagsValue?: number;
|
||||||
totalKgsValue?: number;
|
totalKgsValue?: number;
|
||||||
showErrors?: boolean;
|
showErrors?: boolean;
|
||||||
|
required?: boolean;
|
||||||
}
|
}
|
||||||
|
|
||||||
export function OrderGrid({
|
export function OrderGrid({
|
||||||
@ -22,6 +23,7 @@ export function OrderGrid({
|
|||||||
totalBagsValue,
|
totalBagsValue,
|
||||||
totalKgsValue,
|
totalKgsValue,
|
||||||
showErrors = false,
|
showErrors = false,
|
||||||
|
required,
|
||||||
}: OrderGridProps) {
|
}: OrderGridProps) {
|
||||||
const rows = value.length > 0 ? value : [{}];
|
const rows = value.length > 0 ? value : [{}];
|
||||||
|
|
||||||
@ -320,6 +322,7 @@ export function OrderGrid({
|
|||||||
<div className="flex items-center justify-between">
|
<div className="flex items-center justify-between">
|
||||||
<p className="text-sm font-bold text-slate-700 uppercase tracking-wide">
|
<p className="text-sm font-bold text-slate-700 uppercase tracking-wide">
|
||||||
{label || 'Order details'}
|
{label || 'Order details'}
|
||||||
|
{required && <span className="text-ruby-600 normal-case font-medium ml-1">*</span>}
|
||||||
</p>
|
</p>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
|||||||
@ -10,6 +10,7 @@ export interface PotentialMiningGridProps {
|
|||||||
value: Record<string, unknown>[];
|
value: Record<string, unknown>[];
|
||||||
onChange: (val: Record<string, unknown>[]) => void;
|
onChange: (val: Record<string, unknown>[]) => void;
|
||||||
readOnlyCols?: string[];
|
readOnlyCols?: string[];
|
||||||
|
required?: boolean;
|
||||||
}
|
}
|
||||||
|
|
||||||
export function PotentialMiningGrid({
|
export function PotentialMiningGrid({
|
||||||
@ -18,6 +19,7 @@ export function PotentialMiningGrid({
|
|||||||
value = [],
|
value = [],
|
||||||
onChange,
|
onChange,
|
||||||
readOnlyCols = [],
|
readOnlyCols = [],
|
||||||
|
required,
|
||||||
}: PotentialMiningGridProps) {
|
}: PotentialMiningGridProps) {
|
||||||
const rows = value.length > 0 ? value : [{}];
|
const rows = value.length > 0 ? value : [{}];
|
||||||
|
|
||||||
@ -77,6 +79,7 @@ export function PotentialMiningGrid({
|
|||||||
<div className="flex items-center justify-between">
|
<div className="flex items-center justify-between">
|
||||||
<p className="text-sm font-bold text-slate-700 uppercase tracking-wide">
|
<p className="text-sm font-bold text-slate-700 uppercase tracking-wide">
|
||||||
{label || 'Potential Mining'}
|
{label || 'Potential Mining'}
|
||||||
|
{required && <span className="text-ruby-600 normal-case font-medium ml-1">*</span>}
|
||||||
</p>
|
</p>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
|||||||
@ -15,6 +15,7 @@ export interface SmartGridFieldProps {
|
|||||||
hideTotal?: boolean;
|
hideTotal?: boolean;
|
||||||
readOnlyCols?: string[];
|
readOnlyCols?: string[];
|
||||||
isPotentialMining?: boolean; // We will pass this from DynamicForm
|
isPotentialMining?: boolean; // We will pass this from DynamicForm
|
||||||
|
required?: boolean;
|
||||||
}
|
}
|
||||||
|
|
||||||
export function SmartGridField(props: SmartGridFieldProps) {
|
export function SmartGridField(props: SmartGridFieldProps) {
|
||||||
|
|||||||
@ -10,6 +10,7 @@ export interface StorePotentialGridProps {
|
|||||||
value: Record<string, unknown>[];
|
value: Record<string, unknown>[];
|
||||||
onChange: (val: Record<string, unknown>[]) => void;
|
onChange: (val: Record<string, unknown>[]) => void;
|
||||||
showErrors?: boolean;
|
showErrors?: boolean;
|
||||||
|
required?: boolean;
|
||||||
}
|
}
|
||||||
|
|
||||||
export function StorePotentialGrid({
|
export function StorePotentialGrid({
|
||||||
@ -18,6 +19,7 @@ export function StorePotentialGrid({
|
|||||||
value = [],
|
value = [],
|
||||||
onChange,
|
onChange,
|
||||||
showErrors = false,
|
showErrors = false,
|
||||||
|
required,
|
||||||
}: StorePotentialGridProps) {
|
}: StorePotentialGridProps) {
|
||||||
const rows = value.length > 0 ? value : [{}];
|
const rows = value.length > 0 ? value : [{}];
|
||||||
|
|
||||||
@ -153,6 +155,7 @@ export function StorePotentialGrid({
|
|||||||
<div className="flex items-center justify-between">
|
<div className="flex items-center justify-between">
|
||||||
<p className="text-sm font-bold text-slate-700 uppercase tracking-wide">
|
<p className="text-sm font-bold text-slate-700 uppercase tracking-wide">
|
||||||
{label || 'Store Potential'}
|
{label || 'Store Potential'}
|
||||||
|
{required && <span className="text-ruby-600 normal-case font-medium ml-1">*</span>}
|
||||||
</p>
|
</p>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user