krishna_sales/src/components/forms/fields/SmartGridField.tsx
2026-07-24 12:56:03 +05:30

37 lines
1.3 KiB
TypeScript

import type { FormScreenField } from '../../../api/types';
import { StorePotentialGrid } from './StorePotentialGrid';
import { OrderGrid } from './OrderGrid';
import { PotentialMiningGrid } from './PotentialMiningGrid';
export interface SmartGridFieldProps {
label: string;
columns: FormScreenField[];
value: Record<string, unknown>[];
onChange: (val: Record<string, unknown>[]) => void;
totalBagsValue?: number;
totalKgsValue?: number;
showErrors?: boolean;
disableAddRow?: boolean;
hideTotal?: boolean;
readOnlyCols?: string[];
isPotentialMining?: boolean; // We will pass this from DynamicForm
}
export function SmartGridField(props: SmartGridFieldProps) {
const { label, isPotentialMining, disableAddRow } = props;
// Use PotentialMiningGrid if explicitly requested or if we're disabling add row (as a fallback heuristic)
if (isPotentialMining || (disableAddRow && label.toLowerCase().includes('potential'))) {
return <PotentialMiningGrid {...props} />;
}
// Use OrderGrid if it's an order/product details grid
const isOrderGrid = label.toLowerCase().includes('order') || label.toLowerCase().includes('product');
if (isOrderGrid) {
return <OrderGrid {...props} />;
}
// Use StorePotentialGrid for simpler grids like Store adding potential
return <StorePotentialGrid {...props} />;
}