added error message for logvisit form

This commit is contained in:
suryac 2026-08-07 10:27:05 +05:30
parent 9c4128c6a7
commit 0a432f751c

View File

@ -72,6 +72,7 @@ export function LogVisitForm({ client, onSuccess, onCancel, onActivityChange }:
const [submitting, setSubmitting] = useState(false); const [submitting, setSubmitting] = useState(false);
const [submitError, setSubmitError] = useState<string | null>(null); const [submitError, setSubmitError] = useState<string | null>(null);
const [storeError, setStoreError] = useState<string | null>(null);
// 1. Fetch form schema from API (/app/434/view/form-screens) // 1. Fetch form schema from API (/app/434/view/form-screens)
useEffect(() => { useEffect(() => {
@ -138,10 +139,10 @@ export function LogVisitForm({ client, onSuccess, onCancel, onActivityChange }:
if (fetchingStoresRef.current) return; if (fetchingStoresRef.current) return;
fetchingStoresRef.current = true; fetchingStoresRef.current = true;
setFetchingStores(true); setFetchingStores(true);
setStoreError(null);
try { try {
const formDataToSend = cleanFormData(formDataOverride || valuesRef.current); const formDataToSend = cleanFormData(formDataOverride || valuesRef.current);
console.log('[LogVisitForm] Executing select_store lookup with prefilled formData:', formDataToSend);
const lookupRes = await client.wfLookupRecords({ const lookupRes = await client.wfLookupRecords({
activityId, activityId,
@ -187,8 +188,14 @@ export function LogVisitForm({ client, onSuccess, onCancel, onActivityChange }:
}); });
setStoreOptions(opts); setStoreOptions(opts);
} catch (e) { } catch (e: any) {
console.error('Failed to load select_store options:', e); console.error('Failed to load select_store options:', e);
const msg = e?.message || e?.data?.message || String(e);
if (msg.toLowerCase().includes('route_code')) {
setStoreError('Please punch-in in Daily Logs');
} else {
setStoreError('Failed to load stores');
}
} finally { } finally {
setFetchingStores(false); setFetchingStores(false);
fetchingStoresRef.current = false; fetchingStoresRef.current = false;
@ -204,8 +211,6 @@ export function LogVisitForm({ client, onSuccess, onCancel, onActivityChange }:
time_of_visit: timeVal, time_of_visit: timeVal,
}); });
console.log('[LogVisitForm] Fetching initial daily_log lookup with payload:', payload);
const dailyLogLookupRes = await client.wfLookupRecords({ const dailyLogLookupRes = await client.wfLookupRecords({
activityId, activityId,
fieldId: 'daily_log', fieldId: 'daily_log',
@ -219,7 +224,6 @@ export function LogVisitForm({ client, onSuccess, onCancel, onActivityChange }:
if (arr.length > 0) { if (arr.length > 0) {
const firstLog = arr[0]; const firstLog = arr[0];
console.log('[LogVisitForm] Successfully fetched daily log record:', firstLog);
const dailyLogInstanceId = String(firstLog.instance_id || firstLog.id || ''); const dailyLogInstanceId = String(firstLog.instance_id || firstLog.id || '');
const routeCode = String( const routeCode = String(
@ -256,7 +260,6 @@ export function LogVisitForm({ client, onSuccess, onCancel, onActivityChange }:
valuesRef.current = updated; valuesRef.current = updated;
setValues(updated); setValues(updated);
console.log('[LogVisitForm] Daily log prefill complete:', updated);
} else { } else {
console.warn('[LogVisitForm] No daily log records found for date/time:', dateVal, timeVal); console.warn('[LogVisitForm] No daily log records found for date/time:', dateVal, timeVal);
} }
@ -336,14 +339,11 @@ export function LogVisitForm({ client, onSuccess, onCancel, onActivityChange }:
} }
payload['upload_image'] = uploadedFiles; payload['upload_image'] = uploadedFiles;
console.log('[LogVisitForm] Submitting clean startInstance payload:', payload);
const res: any = await client.startInstance(activityId, payload); const res: any = await client.startInstance(activityId, payload);
const chainSource = res?.activity_chain || schema?.activity_chain || []; const chainSource = res?.activity_chain || schema?.activity_chain || [];
if (chainSource && chainSource.length > 0) { if (chainSource && chainSource.length > 0) {
const nextAct = chainSource[0]; const nextAct = chainSource[0];
console.log('[LogVisitForm] Activity chain detected, transitioning to DynamicForm:', nextAct);
onActivityChange?.(nextAct.activity_name); onActivityChange?.(nextAct.activity_name);
setChainedActivity({ setChainedActivity({
@ -414,7 +414,7 @@ export function LogVisitForm({ client, onSuccess, onCancel, onActivityChange }:
if (type === 'wf_lookup' || lowerId === 'select_store' || lowerName.includes('select store')) { if (type === 'wf_lookup' || lowerId === 'select_store' || lowerName.includes('select store')) {
return ( return (
<div key={fieldId} className="relative"> <div key={fieldId} className="flex flex-col gap-1 relative">
<Select <Select
label={f.name} label={f.name}
required={f.mandatory} required={f.mandatory}
@ -429,6 +429,11 @@ export function LogVisitForm({ client, onSuccess, onCancel, onActivityChange }:
<Spinner size={16} /> <Spinner size={16} />
</div> </div>
)} )}
{storeError && (
<div className="text-sm text-ruby-600 mt-1">
{storeError}
</div>
)}
</div> </div>
); );
} }