Compare commits
No commits in common. "3a9df191b636843d3658361a44772f49c2081a84" and "6f0e86007eb53392b43cb8ece72e8f6a35d946d8" have entirely different histories.
3a9df191b6
...
6f0e86007e
@ -1,16 +0,0 @@
|
||||
const fs = require('fs');
|
||||
const files = [
|
||||
'f:/WorkPlace/dev/krishnasales_mobile/src/components/forms/fields/SmartGridField.tsx',
|
||||
'f:/WorkPlace/dev/krishnasales_mobile/src/components/forms/DynamicForm.tsx'
|
||||
];
|
||||
files.forEach(file => {
|
||||
let content = fs.readFileSync(file, 'utf8');
|
||||
content = content.replace(/col\.name\.toLowerCase/g, "(col.name || '').toLowerCase");
|
||||
content = content.replace(/col\.id\.toLowerCase/g, "(col.id || '').toLowerCase");
|
||||
content = content.replace(/c\.name\.toLowerCase/g, "(c.name || '').toLowerCase");
|
||||
content = content.replace(/f\.id\.toLowerCase/g, "(f.id || '').toLowerCase");
|
||||
content = content.replace(/f\.name\.toLowerCase/g, "(f.name || '').toLowerCase");
|
||||
content = content.replace(/col\.mapped_workflow_field\?\.toLowerCase/g, "(col.mapped_workflow_field || '').toLowerCase");
|
||||
fs.writeFileSync(file, content, 'utf8');
|
||||
console.log('Fixed', file);
|
||||
});
|
||||
@ -211,7 +211,7 @@ export function DynamicForm({ client, activityId: initialActivityId, instanceId:
|
||||
c.id.toLowerCase() === lowerKey ||
|
||||
(c.mapped_workflow_field || '').toLowerCase() === lowerKey ||
|
||||
getBaseId(c.id).toLowerCase() === lowerKey ||
|
||||
(c.name || '').toLowerCase().replace(/\s+/g, '') === lowerKey.replace(/_/g, '')
|
||||
c.name.toLowerCase().replace(/\s+/g, '') === lowerKey.replace(/_/g, '')
|
||||
);
|
||||
if (targetCol && targetCol.id !== fieldId) {
|
||||
next[targetCol.id] = rawRow[key];
|
||||
@ -238,7 +238,7 @@ export function DynamicForm({ client, activityId: initialActivityId, instanceId:
|
||||
c.id.toLowerCase() === lowerKey ||
|
||||
(c.mapped_workflow_field || '').toLowerCase() === lowerKey ||
|
||||
getBaseId(c.id).toLowerCase() === lowerKey ||
|
||||
(c.name || '').toLowerCase().replace(/\s+/g, '') === lowerKey.replace(/_/g, '')
|
||||
c.name.toLowerCase().replace(/\s+/g, '') === lowerKey.replace(/_/g, '')
|
||||
);
|
||||
|
||||
if (fieldId.startsWith('route_name') && targetCol) {
|
||||
@ -266,7 +266,7 @@ export function DynamicForm({ client, activityId: initialActivityId, instanceId:
|
||||
c.id.toLowerCase() === pKey ||
|
||||
(c.mapped_workflow_field || '').toLowerCase() === pKey ||
|
||||
getBaseId(c.id).toLowerCase() === pKey ||
|
||||
(c.name || '').toLowerCase().replace(/\s+/g, '') === pKey.replace(/_/g, '')
|
||||
c.name.toLowerCase().replace(/\s+/g, '') === pKey.replace(/_/g, '')
|
||||
);
|
||||
}
|
||||
|
||||
@ -303,7 +303,7 @@ export function DynamicForm({ client, activityId: initialActivityId, instanceId:
|
||||
const getBaseId = (id: string) => id.replace(/_\d+$/, '');
|
||||
|
||||
const bagsColId = fieldDef?.columns?.find(c =>
|
||||
c.id === 'bags' || getBaseId(c.id) === 'bags' || c.mapped_workflow_field === 'bags' || (c.name || '').toLowerCase() === 'bags'
|
||||
c.id === 'bags' || getBaseId(c.id) === 'bags' || c.mapped_workflow_field === 'bags' || c.name.toLowerCase() === 'bags'
|
||||
)?.id || 'bags';
|
||||
|
||||
const rowKgsColId = fieldDef?.columns?.find(c =>
|
||||
@ -339,7 +339,7 @@ export function DynamicForm({ client, activityId: initialActivityId, instanceId:
|
||||
// Filter out disabled fields (usually server-generated IDs)
|
||||
const fields = schema.fields.filter(f => !f.properties?.disabled && !HIDDEN_FORM_FIELDS.includes(f.id));
|
||||
|
||||
const actionField = fields.find(f => (f.name || '').toLowerCase() === 'action' && f.data_type === 'radio');
|
||||
const actionField = fields.find(f => f.name.toLowerCase() === 'action' && f.data_type === 'radio');
|
||||
const normalFields = fields.filter(f => f !== actionField);
|
||||
|
||||
const handleSubmit = async (e: React.FormEvent) => {
|
||||
@ -355,16 +355,11 @@ export function DynamicForm({ client, activityId: initialActivityId, instanceId:
|
||||
|
||||
for (const f of fields) {
|
||||
let val = finalValues[f.id];
|
||||
const isNotesOrRemarks = (f.id || '').toLowerCase().includes('notes') || (f.id || '').toLowerCase().includes('remarks') || (f.name && ((f.name || '').toLowerCase().includes('notes') || (f.name || '').toLowerCase().includes('remarks')));
|
||||
const isNotesOrRemarks = f.id.toLowerCase().includes('notes') || f.id.toLowerCase().includes('remarks') || (f.name && (f.name.toLowerCase().includes('notes') || f.name.toLowerCase().includes('remarks')));
|
||||
if (isNotesOrRemarks && val == null) {
|
||||
val = '';
|
||||
}
|
||||
|
||||
// If select options are unselected/empty, explicitly send an empty string to the payload
|
||||
if ((f.data_type === 'select' || f.data_type === 'multiselect' || f.data_type === 'wf_lookup' || f.data_type === 'radio') && val == null) {
|
||||
val = '';
|
||||
}
|
||||
|
||||
if (val == null) continue;
|
||||
|
||||
if (f.data_type === 'phone' && typeof val === 'string') {
|
||||
@ -385,17 +380,6 @@ export function DynamicForm({ client, activityId: initialActivityId, instanceId:
|
||||
const fileMeta = await client.uploadFile(val, { activityId: currentActivityId, fieldId: f.id, instanceId: currentInstanceId });
|
||||
payload[f.id] = [fileMeta];
|
||||
} else {
|
||||
if (f.data_type === 'grid' && Array.isArray(val)) {
|
||||
val = val.map(row => {
|
||||
const newRow = { ...row };
|
||||
f.columns?.forEach(col => {
|
||||
if ((col.data_type === 'select' || col.data_type === 'multiselect' || col.data_type === 'wf_lookup' || col.data_type === 'radio') && newRow[col.id] == null) {
|
||||
newRow[col.id] = '';
|
||||
}
|
||||
});
|
||||
return newRow;
|
||||
});
|
||||
}
|
||||
payload[f.id] = val;
|
||||
}
|
||||
}
|
||||
@ -531,7 +515,7 @@ export function DynamicForm({ client, activityId: initialActivityId, instanceId:
|
||||
const isDisabled = schema.field_defaults?.[f.id]?.disabled || f.properties?.disabled;
|
||||
|
||||
const isPlaceOrder = currentActivityId === ORDER_BOOKING.activities.PLACE_ORDER.uid;
|
||||
const isOrderId = (f.name || '').toLowerCase() === 'order id' || (f.id || '').toLowerCase().includes('order_id') || f.mapped_workflow_field === 'order_id';
|
||||
const isOrderId = f.name.toLowerCase() === 'order id' || f.id.toLowerCase().includes('order_id') || f.mapped_workflow_field === 'order_id';
|
||||
|
||||
if (isPlaceOrder && isOrderId) {
|
||||
return null;
|
||||
|
||||
@ -70,7 +70,7 @@ export function SmartGridField({
|
||||
if (option && option._raw) {
|
||||
const getBaseId = (id: string) => id.replace(/_\d+$/, '');
|
||||
for (const key of Object.keys(option._raw)) {
|
||||
const targetCol = columns.find(c => c.id === key || c.mapped_workflow_field === key || getBaseId(c.id) === key || (c.name || '').toLowerCase().replace(/\s+/g, '') === key.toLowerCase().replace(/_/g, ''));
|
||||
const targetCol = columns.find(c => c.id === key || c.mapped_workflow_field === key || getBaseId(c.id) === key || c.name.toLowerCase().replace(/\s+/g, '') === key.toLowerCase().replace(/_/g, ''));
|
||||
if (targetCol && targetCol.id !== fieldId) {
|
||||
row[targetCol.id] = option._raw[key];
|
||||
} else if (!targetCol && key !== fieldId) {
|
||||
@ -83,7 +83,7 @@ export function SmartGridField({
|
||||
// Auto-calculate row_kgs if sku and bags are present
|
||||
const getBaseId = (id: string) => id.replace(/_\d+$/, '');
|
||||
const getVal = (key: string) => {
|
||||
const c = columns.find(c => c.id === key || c.mapped_workflow_field === key || getBaseId(c.id) === key || (c.name || '').toLowerCase().replace(/\s+/g, '') === key.toLowerCase().replace(/_/g, ''));
|
||||
const c = columns.find(c => c.id === key || c.mapped_workflow_field === key || getBaseId(c.id) === key || c.name.toLowerCase().replace(/\s+/g, '') === key.toLowerCase().replace(/_/g, ''));
|
||||
return c ? row[c.id] : row[key];
|
||||
};
|
||||
|
||||
@ -111,13 +111,13 @@ export function SmartGridField({
|
||||
|
||||
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');
|
||||
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');
|
||||
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');
|
||||
|
||||
let isRequired = col.mandatory || (isCatSelected && (isProductName || isBags));
|
||||
if (isOrderDetails && (isCategory || isProductName || isBags)) {
|
||||
@ -155,7 +155,7 @@ export function SmartGridField({
|
||||
const next = [...value];
|
||||
const existingRow = { ...next[foundIdx] };
|
||||
|
||||
const bagsCol = columns.find(c => c.id === 'bags' || getBaseId(c.id) === 'bags' || c.mapped_workflow_field === 'bags' || (c.name || '').toLowerCase() === 'bags');
|
||||
const bagsCol = columns.find(c => c.id === 'bags' || getBaseId(c.id) === 'bags' || c.mapped_workflow_field === 'bags' || c.name.toLowerCase() === 'bags');
|
||||
const rowKgsCol = columns.find(c => c.id === 'row_kgs' || getBaseId(c.id) === 'row_kgs' || c.mapped_workflow_field === 'row_kgs' || getBaseId(c.id) === 'rowkgs');
|
||||
const skuCol = columns.find(c => c.id === 'sku' || getBaseId(c.id) === 'sku' || c.mapped_workflow_field === 'sku');
|
||||
|
||||
@ -194,14 +194,14 @@ export function SmartGridField({
|
||||
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');
|
||||
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 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') {
|
||||
@ -275,10 +275,10 @@ export function SmartGridField({
|
||||
let reasonStr = '';
|
||||
|
||||
visibleColumns.forEach(col => {
|
||||
const isName = (col.id || '').toLowerCase().includes('name') || (col.name || '').toLowerCase().includes('name') || ((col.id || '').toLowerCase().includes('category') && productName === 'Unknown Product');
|
||||
const isBags = (col.id || '').toLowerCase().includes('bags') || (col.name || '').toLowerCase().includes('bags') || (col.id || '').toLowerCase().includes('quantity');
|
||||
const isDiff = (col.id || '').toLowerCase().includes('diff') || (col.name || '').toLowerCase().includes('diff');
|
||||
const isReason = (col.id || '').toLowerCase().includes('reason') || (col.name || '').toLowerCase().includes('reason');
|
||||
const isName = col.id.toLowerCase().includes('name') || col.name.toLowerCase().includes('name') || (col.id.toLowerCase().includes('category') && productName === 'Unknown Product');
|
||||
const isBags = col.id.toLowerCase().includes('bags') || col.name.toLowerCase().includes('bags') || col.id.toLowerCase().includes('quantity');
|
||||
const isDiff = col.id.toLowerCase().includes('diff') || col.name.toLowerCase().includes('diff');
|
||||
const isReason = col.id.toLowerCase().includes('reason') || col.name.toLowerCase().includes('reason');
|
||||
|
||||
const val = row[col.id];
|
||||
let displayVal = String(val ?? '-');
|
||||
@ -288,7 +288,7 @@ export function SmartGridField({
|
||||
if (opt) displayVal = opt.label;
|
||||
}
|
||||
|
||||
if (isName && (productName === 'Unknown Product' || (col.id || '').toLowerCase().includes('name'))) {
|
||||
if (isName && (productName === 'Unknown Product' || col.id.toLowerCase().includes('name'))) {
|
||||
productName = displayVal;
|
||||
}
|
||||
if (isBags) {
|
||||
|
||||
@ -163,7 +163,7 @@ export function NearestStoresMap() {
|
||||
<Marker
|
||||
position={userLocation}
|
||||
icon={{
|
||||
url: 'https://maps.google.com/mapfiles/ms/icons/blue-dot.png'
|
||||
url: 'http://maps.google.com/mapfiles/ms/icons/blue-dot.png'
|
||||
}}
|
||||
title="You are here"
|
||||
/>
|
||||
|
||||
@ -52,36 +52,6 @@ export interface RecordViewProps {
|
||||
initialFilters?: Record<string, string | string[]>;
|
||||
}
|
||||
|
||||
/**
|
||||
* Helper to remove ugly UUIDs (with or without hyphens) from raw string values.
|
||||
*/
|
||||
function formatFilterLabel(raw: string): string {
|
||||
if (!raw) return raw;
|
||||
const stripped = raw.replace(/[_\-\s]*\(?(?:[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}|[0-9a-f]{32})\)?/gi, '').trim();
|
||||
return stripped || raw; // fallback to raw if the whole string was a UUID
|
||||
}
|
||||
|
||||
/**
|
||||
* Resolves a human-readable label for a field key, handling nested sub-columns and stripping UUIDs.
|
||||
*/
|
||||
function getFieldLabel(key: string, fields: RecordViewField[] = []): string {
|
||||
const exactMatch = fields.find((f) => f.field_key === key);
|
||||
if (exactMatch?.output_label) return exactMatch.output_label;
|
||||
|
||||
if (key.includes('.')) {
|
||||
const [mainKey, subKey] = key.split('.', 2);
|
||||
const mainField = fields.find((f) => f.field_key === mainKey);
|
||||
if (mainField?.output_label) {
|
||||
const subLabel = subKey.replace(/_/g, ' ').replace(/\b\w/g, c => c.toUpperCase());
|
||||
return `${mainField.output_label} (${subLabel})`;
|
||||
}
|
||||
}
|
||||
|
||||
// Fallback: Strip UUIDs and format the raw key
|
||||
const noUuid = formatFilterLabel(key);
|
||||
return noUuid.replace(/_/g, ' ').replace(/\b\w/g, c => c.toUpperCase()).trim();
|
||||
}
|
||||
|
||||
/**
|
||||
* Generic Zino record-view table for mobile. Fetches `POST /app/{id}/view/recordview`
|
||||
* (server-side paginated + searchable) and renders cards or table items.
|
||||
@ -262,14 +232,15 @@ export function RecordView({
|
||||
<div className="flex flex-wrap items-center gap-2 px-3 py-2 bg-slate-100/80 rounded-lg border border-border-subtle max-w-full overflow-hidden">
|
||||
<span className="text-xs font-semibold text-slate-600 mr-0.5 shrink-0">Filters:</span>
|
||||
{Object.entries(activeFilters).flatMap(([key, vals]) => {
|
||||
const label = getFieldLabel(key, resp?.config?.fields);
|
||||
const fieldDef = resp?.config?.fields?.find((f) => f.field_key === key);
|
||||
const label = fieldDef?.output_label || key.replace(/_/g, ' ').replace(/\b\w/g, (c) => c.toUpperCase());
|
||||
return (vals || []).map((val) => (
|
||||
<span
|
||||
key={`${key}-${val}`}
|
||||
className="inline-flex items-center gap-1 px-2.5 py-0.5 rounded-full text-xs font-medium bg-navy-50 text-navy-900 border border-navy-200/80 shadow-xs max-w-full truncate"
|
||||
>
|
||||
<span className="font-bold text-navy-950 truncate max-w-[110px]">{label}:</span>
|
||||
<span className="truncate max-w-[130px]">{formatFilterLabel(val)}</span>
|
||||
<span className="truncate max-w-[130px]">{val}</span>
|
||||
<button
|
||||
type="button"
|
||||
onClick={() => {
|
||||
@ -330,8 +301,8 @@ export function RecordView({
|
||||
>
|
||||
<div className="flex flex-col gap-5">
|
||||
{filterEntries.map((key) => {
|
||||
const label = getFieldLabel(key, resp?.config?.fields);
|
||||
const fieldDef = resp?.config?.fields?.find((f) => f.field_key === key);
|
||||
const fieldDef = resp?.config.fields.find((f) => f.field_key === key);
|
||||
const label = fieldDef?.output_label || key.replace(/_/g, ' ').replace(/\b\w/g, (c) => c.toUpperCase());
|
||||
const isDateField =
|
||||
fieldDef?.data_type === 'date' ||
|
||||
fieldDef?.data_type === 'datetime' ||
|
||||
@ -360,7 +331,7 @@ export function RecordView({
|
||||
const options = resp?.config.filter_options?.[key] || [];
|
||||
const opts = options.map((o) => ({
|
||||
value: o,
|
||||
label: formatFilterLabel(o),
|
||||
label: o.replace(/[_\-\s]*\(?[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}\)?/i, '').trim() || o,
|
||||
}));
|
||||
|
||||
return (
|
||||
|
||||
@ -27,10 +27,10 @@ export function CallsPage() {
|
||||
setMiningLoading(true);
|
||||
setMiningPrefill(undefined);
|
||||
try {
|
||||
const storeCode = selectedRow?.select_store_row?.store_code_2 || selectedRow?.select_store_row?.store_code || selectedRow?.select_store?.store_code_2 || selectedRow?.select_store?.store_code || selectedRow?.select_store?.code || selectedRow?.store_code_2 || selectedRow?.store_code || selectedRow?.code || selectedRow?.store?.store_code_2 || selectedRow?.store?.store_code;
|
||||
const storeCode = selectedRow?.select_store?.store_code_2 || selectedRow?.select_store?.store_code || selectedRow?.select_store?.code || selectedRow?.store_code_2 || selectedRow?.store_code || selectedRow?.code || selectedRow?.store?.store_code_2 || selectedRow?.store?.store_code;
|
||||
|
||||
if (!storeCode) {
|
||||
console.warn("Store code not found on selected row, proceeding anyway.", selectedRow);
|
||||
console.warn("Store code not found on selected row, proceeding anyway.");
|
||||
}
|
||||
|
||||
const payload = {
|
||||
|
||||
@ -29,10 +29,10 @@ export function OrdersPage() {
|
||||
setMiningLoading(true);
|
||||
setMiningPrefill(undefined);
|
||||
try {
|
||||
const storeCode = selectedRow?.select_store_row?.store_code_2 || selectedRow?.select_store_row?.store_code || selectedRow?.select_store?.store_code_2 || selectedRow?.select_store?.store_code || selectedRow?.select_store?.code || selectedRow?.store_code_2 || selectedRow?.store_code || selectedRow?.code || selectedRow?.store?.store_code_2 || selectedRow?.store?.store_code;
|
||||
const storeCode = selectedRow?.select_store?.store_code_2 || selectedRow?.select_store?.store_code || selectedRow?.select_store?.code || selectedRow?.store_code_2 || selectedRow?.store_code || selectedRow?.code || selectedRow?.store?.store_code_2 || selectedRow?.store?.store_code;
|
||||
|
||||
if (!storeCode) {
|
||||
console.warn("Store code not found on selected row, proceeding anyway.", selectedRow);
|
||||
console.warn("Store code not found on selected row, proceeding anyway.");
|
||||
}
|
||||
|
||||
const payload = {
|
||||
|
||||
Loading…
Reference in New Issue
Block a user