store code fix

This commit is contained in:
suryac 2026-08-03 12:30:57 +05:30
parent b288ebf6cc
commit d9e932ce8c
5 changed files with 34 additions and 22 deletions

View File

@ -249,3 +249,7 @@ export const PIPELINE = {
salesOfficers: '/api/papi2/sales-officers' salesOfficers: '/api/papi2/sales-officers'
} }
}; };
export const HIDDEN_FORM_FIELDS = [
'store_code_3'
];

View File

@ -130,7 +130,7 @@ export function CallDetail({
// Extract store info with fallbacks matching reference // Extract store info with fallbacks matching reference
const selectStore = (rowSrc.select_store || data?.select_store || {}) as Record<string, any>; const selectStore = (rowSrc.select_store || data?.select_store || {}) as Record<string, any>;
const storeName = selectStore.business_name || selectStore.store_name || rowSrc.store_name || 'No data'; const storeName = selectStore.business_name || selectStore.store_name || rowSrc.store_name || 'No data';
const storeCode = selectStore.store_code || selectStore.code || 'No data'; const storeCode = selectStore.store_code_2 || selectStore.code || 'No data';
const ownerName = selectStore.owner_name || selectStore.contact_person || 'No data'; const ownerName = selectStore.owner_name || selectStore.contact_person || 'No data';
const phone = selectStore.phone_number?.phone || selectStore.phone_number?.phone_with_dial_code || selectStore.phone || 'No data'; const phone = selectStore.phone_number?.phone || selectStore.phone_number?.phone_with_dial_code || selectStore.phone || 'No data';
const email = selectStore.email || 'No data'; const email = selectStore.email || 'No data';

View File

@ -77,7 +77,7 @@ export function StoreDetail({ instanceId, onBack, onEdit }: StoreDetailProps) {
const badgeClass = isSuccess ? 'bg-emerald-100 text-emerald-700' : 'bg-blue-100 text-blue-700'; const badgeClass = isSuccess ? 'bg-emerald-100 text-emerald-700' : 'bg-blue-100 text-blue-700';
// Store Overview // Store Overview
const storeCode = extract('store_code', remainingData) || '-'; const storeCode = extract('store_code_2', remainingData) || '-';
const businessName = extract('business_name', remainingData) || '-'; const businessName = extract('business_name', remainingData) || '-';
const area = extract('area', remainingData); const area = extract('area', remainingData);
const completeAddress = extract('complete_address', remainingData); const completeAddress = extract('complete_address', remainingData);

View File

@ -17,7 +17,7 @@ import {
WfLookupField, WfLookupField,
RadioField, RadioField,
} from './fields'; } from './fields';
import { ORDER_BOOKING, STORE, DAILY_REPORTS, PIPELINE } from '../../api/config'; import { ORDER_BOOKING, STORE, DAILY_REPORTS, PIPELINE, HIDDEN_FORM_FIELDS } from '../../api/config';
import { isCategoryColumn, isProductColumn } from './fields/gridUtils'; import { isCategoryColumn, isProductColumn } from './fields/gridUtils';
export interface DynamicFormProps { export interface DynamicFormProps {
@ -75,14 +75,8 @@ export function DynamicForm({ client, activityId: initialActivityId, instanceId:
} }
}); });
} }
const imageFieldIds = new Set(
res.fields.filter(f => f.data_type === 'image' || f.data_type === 'file').map(f => f.id)
);
const mapPrefillData = (sourceData: Record<string, unknown>) => { const mapPrefillData = (sourceData: Record<string, unknown>) => {
res.fields.forEach(f => { res.fields.forEach(f => {
if (imageFieldIds.has(f.id)) return;
const getBaseId = (id: string) => id.replace(/_\d+$/, ''); const getBaseId = (id: string) => id.replace(/_\d+$/, '');
if (sourceData[f.id] !== undefined) { if (sourceData[f.id] !== undefined) {
@ -132,13 +126,13 @@ export function DynamicForm({ client, activityId: initialActivityId, instanceId:
if (customPrefillData) { if (customPrefillData) {
Object.entries(customPrefillData).forEach(([k, v]) => { Object.entries(customPrefillData).forEach(([k, v]) => {
if (!imageFieldIds.has(k)) defaultValues[k] = v; defaultValues[k] = v;
}); });
} }
if (chainedPrefillData) { if (chainedPrefillData) {
Object.entries(chainedPrefillData).forEach(([k, v]) => { Object.entries(chainedPrefillData).forEach(([k, v]) => {
if (!imageFieldIds.has(k)) defaultValues[k] = v; defaultValues[k] = v;
}); });
} }
@ -593,16 +587,22 @@ export function DynamicForm({ client, activityId: initialActivityId, instanceId:
phone: phoneNum, phone: phoneNum,
phone_with_dial_code: `+91${phoneNum}` phone_with_dial_code: `+91${phoneNum}`
}; };
} else if ((f.data_type === 'image' || f.data_type === 'file') && Array.isArray(val) && val.length > 0 && val[0] instanceof File) { } else if ((f.data_type === 'image' || f.data_type === 'file') && Array.isArray(val)) {
const uploadedFiles = []; const uploadedFiles = [];
for (const file of val) { for (const file of val) {
const fileMeta = await client.uploadFile(file, { activityId: currentActivityId, fieldId: f.id, instanceId: currentInstanceId }); if (file instanceof File) {
uploadedFiles.push(fileMeta); const fileMeta = await client.uploadFile(file, { activityId: currentActivityId, fieldId: f.id, instanceId: currentInstanceId });
uploadedFiles.push(fileMeta);
} else {
uploadedFiles.push(file);
}
} }
payload[f.id] = uploadedFiles; payload[f.id] = uploadedFiles;
} else if ((f.data_type === 'image' || f.data_type === 'file') && val instanceof File) { } else if ((f.data_type === 'image' || f.data_type === 'file') && val instanceof File) {
const fileMeta = await client.uploadFile(val, { activityId: currentActivityId, fieldId: f.id, instanceId: currentInstanceId }); const fileMeta = await client.uploadFile(val, { activityId: currentActivityId, fieldId: f.id, instanceId: currentInstanceId });
payload[f.id] = [fileMeta]; payload[f.id] = [fileMeta];
} else if ((f.data_type === 'image' || f.data_type === 'file') && val && typeof val === 'object') {
payload[f.id] = [val];
} else if (f.data_type.startsWith('grid') || f.data_type === 'smart_grid') { } else if (f.data_type.startsWith('grid') || f.data_type === 'smart_grid') {
const gridRows = Array.isArray(val) ? val : []; const gridRows = Array.isArray(val) ? val : [];
const getFormattedGridVal = (colKey: string, rawVal: unknown, colDef?: FormScreenField) => { const getFormattedGridVal = (colKey: string, rawVal: unknown, colDef?: FormScreenField) => {
@ -860,6 +860,9 @@ export function DynamicForm({ client, activityId: initialActivityId, instanceId:
f.id === 'total_kgs'; f.id === 'total_kgs';
if (isTotalField) return false; if (isTotalField) return false;
} }
if (HIDDEN_FORM_FIELDS.includes(f.id) || HIDDEN_FORM_FIELDS.includes(f.name)) {
return false;
}
return true; return true;
}); });

View File

@ -1,12 +1,17 @@
import { useState, useEffect } from 'react'; import { useState, useEffect } from 'react';
import { BASE_URL, APP_ID } from '../../../api/config';
export function ImagePreview({ file }: { file: File }) { export function ImagePreview({ file }: { file: File | any }) {
const [url, setUrl] = useState<string | null>(null); const [url, setUrl] = useState<string | null>(null);
useEffect(() => { useEffect(() => {
const objectUrl = URL.createObjectURL(file); if (file instanceof File) {
setUrl(objectUrl); const objectUrl = URL.createObjectURL(file);
return () => URL.revokeObjectURL(objectUrl); setUrl(objectUrl);
return () => URL.revokeObjectURL(objectUrl);
} else if (file && file.uuid) {
setUrl(`${BASE_URL}/app/${APP_ID}/view/files/${file.uuid}/preview`);
}
}, [file]); }, [file]);
if (!url) return null; if (!url) return null;
@ -23,10 +28,10 @@ export function FileInput({
label: string; label: string;
type: 'image' | 'file' | string; type: 'image' | 'file' | string;
required?: boolean; required?: boolean;
value: File[] | undefined | null | unknown; value: File[] | any[] | undefined | null | unknown;
onChange: (files: File[]) => void; onChange: (files: (File | any)[]) => void;
}) { }) {
const files = Array.isArray(value) ? value : (value instanceof File ? [value] : []); const files = Array.isArray(value) ? value : (value ? [value] : []);
const handleFileChange = (e: React.ChangeEvent<HTMLInputElement>) => { const handleFileChange = (e: React.ChangeEvent<HTMLInputElement>) => {
if (e.target.files) { if (e.target.files) {
@ -68,7 +73,7 @@ export function FileInput({
<ImagePreview file={file} /> <ImagePreview file={file} />
) : ( ) : (
<div className="w-full h-full flex items-center justify-center p-2 text-xs text-center break-all overflow-hidden text-muted"> <div className="w-full h-full flex items-center justify-center p-2 text-xs text-center break-all overflow-hidden text-muted">
{file.name} {file.name || file.original_name || 'File'}
</div> </div>
)} )}
<button <button