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