From 32ddfff807e01c4824be79628a983b45705bc223 Mon Sep 17 00:00:00 2001 From: suryacp23 Date: Mon, 27 Jul 2026 13:41:06 +0530 Subject: [PATCH] order details and potential mining did edit and add --- src/components/dv/CallDetail.tsx | 5 +- src/components/dv/PotentialMiningTable.tsx | 2 +- .../forms/fields/SmartGridField.tsx | 204 +++++++++++------- src/screens/CallsPage.tsx | 2 +- src/screens/OrdersPage.tsx | 2 +- 5 files changed, 129 insertions(+), 86 deletions(-) diff --git a/src/components/dv/CallDetail.tsx b/src/components/dv/CallDetail.tsx index acb4eec..2b8d582 100644 --- a/src/components/dv/CallDetail.tsx +++ b/src/components/dv/CallDetail.tsx @@ -9,7 +9,6 @@ import { User, ClipboardList, TrendingUp, - Edit3, MapPin, Clock, Phone, @@ -25,7 +24,6 @@ export interface CallDetailProps { instanceId: number | string; selectedRow?: Record; potentialMiningAction?: ReactNode; - placeOrderAction?: ReactNode; refreshKey?: number; onBack?: () => void; onDataLoad?: (data: Record) => void; @@ -35,7 +33,6 @@ export function CallDetail({ instanceId, selectedRow, potentialMiningAction, - placeOrderAction, refreshKey, onBack, onDataLoad, @@ -56,7 +53,7 @@ export function CallDetail({ setData(r.data || {}); if (onDataLoad) onDataLoad(r.data || {}); - const storeCode = (r.data?.select_store as any)?.store_code || (r.data?.select_store as any)?.code; + const storeCode = (r.data?.select_store as any)?.store_code || (r.data?.select_store as any)?.code || (r.data as any)?.store_code || (r.data as any)?.store?.store_code; if (storeCode) { orderBookingClient.request<{ potential: { potential: any[] } }>( 'POST', diff --git a/src/components/dv/PotentialMiningTable.tsx b/src/components/dv/PotentialMiningTable.tsx index 4ef4881..83fd189 100644 --- a/src/components/dv/PotentialMiningTable.tsx +++ b/src/components/dv/PotentialMiningTable.tsx @@ -1,4 +1,4 @@ -import { ArrowUpRight, ArrowDownRight, Pencil, Trash2 } from 'lucide-react'; +import { Pencil, Trash2 } from 'lucide-react'; import { cn } from '../../lib/cn'; export interface MiningItem { diff --git a/src/components/forms/fields/SmartGridField.tsx b/src/components/forms/fields/SmartGridField.tsx index 4db2018..0922f4b 100644 --- a/src/components/forms/fields/SmartGridField.tsx +++ b/src/components/forms/fields/SmartGridField.tsx @@ -16,7 +16,7 @@ export function SmartGridField({ value: Record[]; onChange: (val: Record[]) => void; }) { - const [isModalOpen, setIsModalOpen] = useState(true); + const isPotentialMining = label.toLowerCase().includes('potential'); const formRef = useRef(null); const [newRow, setNewRow] = useState>({}); const [editingIdx, setEditingIdx] = useState(null); @@ -44,7 +44,6 @@ export function SmartGridField({ const startEdit = (idx: number) => { setEditingIdx(idx); setNewRow({ ...value[idx] }); - setIsModalOpen(true); }; const updateNewRowField = (fieldId: string, val: unknown) => { @@ -109,6 +108,11 @@ export function SmartGridField({ const hasAnyValue = visibleColumns.some(col => newRow[col.id] !== undefined && newRow[col.id] !== null && String(newRow[col.id]).trim() !== ''); for (const col of visibleColumns) { + if (isPotentialMining) { + const isReasonOrRemark = col.id.toLowerCase().includes('reason') || col.name.toLowerCase().includes('reason') || col.id.toLowerCase().includes('remark') || col.name.toLowerCase().includes('remark'); + if (!isReasonOrRemark) continue; + } + const isCategory = col.id === 'product_category' || col.name === 'Product Category' || col.mapped_workflow_field === 'product_category' || getBaseId(col.id) === 'product_category'; const isProductName = col.id === 'product_name' || col.name === 'Product Name' || col.mapped_workflow_field === 'product_name' || getBaseId(col.id) === 'product_name'; const isBags = col.id === 'bags' || col.name === 'Bags' || col.mapped_workflow_field === 'bags' || getBaseId(col.id) === 'bags' || col.id.toLowerCase().includes('quantity') || col.name.toLowerCase().includes('quantity') || col.mapped_workflow_field?.toLowerCase().includes('quantity'); @@ -173,13 +177,85 @@ export function SmartGridField({ // Only close form if we were editing an existing row. For new rows, stay open. if (editingIdx !== null) { - setIsModalOpen(false); + // Nothing needed here anymore since we removed isModalOpen } setNewRow({}); setEditingIdx(null); }; - const isPotentialMining = label.toLowerCase().includes('potential'); + + + const renderFormFields = () => { + return visibleColumns.map(col => { + const val = newRow[col.id]; + + const getBaseId = (id: string) => id.replace(/_\d+$/, ''); + + if (isPotentialMining) { + const isReasonOrRemark = col.id.toLowerCase().includes('reason') || col.name.toLowerCase().includes('reason') || col.id.toLowerCase().includes('remark') || col.name.toLowerCase().includes('remark'); + if (!isReasonOrRemark) return null; + } + + const catColId = columns.find(c => c.id === 'product_category' || c.name === 'Product Category' || c.mapped_workflow_field === 'product_category' || getBaseId(c.id) === 'product_category')?.id; + const isCatSelected = catColId ? !!newRow[catColId] : false; + const isProductName = col.id === 'product_name' || col.name === 'Product Name' || col.mapped_workflow_field === 'product_name' || getBaseId(col.id) === 'product_name'; + const isBags = col.id === 'bags' || col.name === 'Bags' || col.mapped_workflow_field === 'bags' || getBaseId(col.id) === 'bags' || col.id.toLowerCase().includes('quantity') || col.name.toLowerCase().includes('quantity') || col.mapped_workflow_field?.toLowerCase().includes('quantity'); + const isRequired = col.mandatory || (isCatSelected && (isProductName || isBags)); + + if (col.data_type === 'select' || col.data_type === 'multiselect') { + const allOpts = col.properties?.options || []; + let filteredOpts = allOpts; + + if (col.id === 'product_name' || col.name === 'Product Name' || col.mapped_workflow_field === 'product_name') { + const catCol = columns.find(c => c.id === 'product_category' || c.name === 'Product Category' || c.mapped_workflow_field === 'product_category'); + if (catCol) { + const selectedCategory = newRow[catCol.id] as string; + if (selectedCategory) { + filteredOpts = allOpts.filter(opt => { + const labelStr = String(opt.label || opt.value || ''); + return labelStr.startsWith(selectedCategory); + }); + } + } + } else { + filteredOpts = allOpts.filter(opt => { + if (!opt._raw) return true; + for (const [rowKey, rowVal] of Object.entries(newRow)) { + if (rowKey === col.id || rowVal == null || rowVal === '') continue; + const rawKey = Object.keys(opt._raw).find(rk => rk === rowKey || rk.replace(/_/g, '') === rowKey.replace(/_/g, '')); + if (rawKey && String(opt._raw[rawKey]) !== String(rowVal)) { + return false; + } + } + return true; + }); + } + + return ( + updateNewRowField(col.id, col.data_type === 'number' ? Number(e.target.value) : e.target.value)} + /> + ); + }); + }; return (
@@ -243,6 +319,40 @@ export function SmartGridField({ } const kgsStr = kgsNum > 0 ? ` (${kgsNum} kg)` : ''; + if (editingIdx === i) { + return ( +
+

+ Edit Row +

+
+ {productName} +
+ {(!isPotentialMining || hasBagsCol) && ( + {bags} {isPotentialMining ? 'Kgs' : 'Bags'}{!isPotentialMining ? kgsStr : ''} + )} + {isPotentialMining && diffVal !== null && !isNaN(diffVal) && diffVal !== 0 && ( + 0 ? 'bg-emerald-100 text-emerald-700' : 'bg-red-100 text-red-700'}`}> + {Math.abs(diffVal)} {diffVal > 0 ? 'Surplus' : 'Less'} + + )} +
+
+
+ {renderFormFields()} +
+
+ + +
+
+ ); + } + return (
@@ -270,9 +380,11 @@ export function SmartGridField({ - + {!isPotentialMining && ( + + )}
); @@ -285,94 +397,28 @@ export function SmartGridField({

- {editingIdx !== null ? ( - <> Edit Row - ) : ( - <>Add New Item - )} + Add New Item

- {visibleColumns.map(col => { - const val = newRow[col.id]; - - const getBaseId = (id: string) => id.replace(/_\d+$/, ''); - const catColId = columns.find(c => c.id === 'product_category' || c.name === 'Product Category' || c.mapped_workflow_field === 'product_category' || getBaseId(c.id) === 'product_category')?.id; - const isCatSelected = catColId ? !!newRow[catColId] : false; - const isProductName = col.id === 'product_name' || col.name === 'Product Name' || col.mapped_workflow_field === 'product_name' || getBaseId(col.id) === 'product_name'; - const isBags = col.id === 'bags' || col.name === 'Bags' || col.mapped_workflow_field === 'bags' || getBaseId(col.id) === 'bags' || col.id.toLowerCase().includes('quantity') || col.name.toLowerCase().includes('quantity') || col.mapped_workflow_field?.toLowerCase().includes('quantity'); - const isRequired = col.mandatory || (isCatSelected && (isProductName || isBags)); - - if (col.data_type === 'select' || col.data_type === 'multiselect') { - const allOpts = col.properties?.options || []; - let filteredOpts = allOpts; - - if (col.id === 'product_name' || col.name === 'Product Name' || col.mapped_workflow_field === 'product_name') { - const catCol = columns.find(c => c.id === 'product_category' || c.name === 'Product Category' || c.mapped_workflow_field === 'product_category'); - if (catCol) { - const selectedCategory = newRow[catCol.id] as string; - if (selectedCategory) { - filteredOpts = allOpts.filter(opt => { - const labelStr = String(opt.label || opt.value || ''); - return labelStr.startsWith(selectedCategory); - }); - } - } - } else { - filteredOpts = allOpts.filter(opt => { - if (!opt._raw) return true; - for (const [rowKey, rowVal] of Object.entries(newRow)) { - if (rowKey === col.id || rowVal == null || rowVal === '') continue; - const rawKey = Object.keys(opt._raw).find(rk => rk === rowKey || rk.replace(/_/g, '') === rowKey.replace(/_/g, '')); - if (rawKey && String(opt._raw[rawKey]) !== String(rowVal)) { - return false; - } - } - return true; - }); - } - - return ( - updateNewRowField(col.id, col.data_type === 'number' ? Number(e.target.value) : e.target.value)} - /> - ); - })} + {editingIdx === null && renderFormFields()} +
-
-
); diff --git a/src/screens/CallsPage.tsx b/src/screens/CallsPage.tsx index e6ef542..69f713e 100644 --- a/src/screens/CallsPage.tsx +++ b/src/screens/CallsPage.tsx @@ -26,7 +26,7 @@ export function CallsPage() { setMiningLoading(true); setMiningPrefill(undefined); try { - const storeCode = selectedRow?.store_code || selectedRow?.code || selectedRow?.store?.store_code; + const storeCode = selectedRow?.store_code || selectedRow?.code || selectedRow?.store?.store_code || selectedRow?.select_store?.store_code || selectedRow?.select_store?.code; if (!storeCode) { console.warn("Store code not found on selected row, proceeding anyway."); diff --git a/src/screens/OrdersPage.tsx b/src/screens/OrdersPage.tsx index 5765eab..5833822 100644 --- a/src/screens/OrdersPage.tsx +++ b/src/screens/OrdersPage.tsx @@ -28,7 +28,7 @@ export function OrdersPage() { setMiningLoading(true); setMiningPrefill(undefined); try { - const storeCode = selectedRow?.store_code || selectedRow?.code || selectedRow?.store?.store_code; + const storeCode = selectedRow?.store_code || selectedRow?.code || selectedRow?.store?.store_code || selectedRow?.select_store?.store_code || selectedRow?.select_store?.code; if (!storeCode) { console.warn("Store code not found on selected row, proceeding anyway.");