storecode fix

This commit is contained in:
suryac 2026-08-03 13:39:53 +05:30
parent d3765ceaf8
commit 810e4997ae
17 changed files with 137 additions and 90 deletions

View File

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

View File

@ -28,7 +28,7 @@ export function CallCard({ row, isDetailView = false }: { row: Record<string, an
const storeName = formatValue(storeObj?.business_name || storeObj?.distributor_name || row.store_name || row.customer_name || (typeof row.store === 'string' ? row.store : 'Unknown Store')); const storeName = formatValue(storeObj?.business_name || storeObj?.distributor_name || row.store_name || row.customer_name || (typeof row.store === 'string' ? row.store : 'Unknown Store'));
const storeCode = formatValue(storeObj?.store_code || row.store_code || '—'); const storeCode = formatValue(storeObj?.store_code_2 || row.store_code_2 || '—');
// Phone and Email // Phone and Email
const storeEmail = formatValue(storeObj?.email || row.email || row.store_email || '—'); const storeEmail = formatValue(storeObj?.email || row.email || row.store_email || '—');

View File

@ -20,7 +20,7 @@ export function StoreCard({ row, isDetailView = false, onEdit }: { row: Record<s
// Store Details // Store Details
const storeName = formatValue(row.business_name || row.store_name || row.name || 'Unknown Store'); const storeName = formatValue(row.business_name || row.store_name || row.name || 'Unknown Store');
const storeCode = formatValue(row.store_code || row.code || '—'); const storeCode = formatValue(row.store_code_2 || row.code || '—');
const ownerName = formatValue(row.owner_name || row.contact_person || '—'); const ownerName = formatValue(row.owner_name || row.contact_person || '—');
const phoneObj = row.phone_number as Record<string, unknown> | null; const phoneObj = row.phone_number as Record<string, unknown> | null;
const phone = formatValue(phoneObj?.phone_with_dial_code || phoneObj?.phone || row.phone || row.mobile || '—'); const phone = formatValue(phoneObj?.phone_with_dial_code || phoneObj?.phone || row.phone || row.mobile || '—');

View File

@ -53,7 +53,7 @@ export function CallDetail({
setData(r.data || {}); setData(r.data || {});
if (onDataLoad) onDataLoad(r.data || {}); if (onDataLoad) onDataLoad(r.data || {});
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; const storeCode = (r.data?.select_store as any)?.store_code_2 || (r.data?.select_store as any)?.code || (r.data as any)?.store_code || (r.data as any)?.store?.store_code;
if (storeCode) { if (storeCode) {
orderBookingClient.request<{ potential: { potential: any[] } }>( orderBookingClient.request<{ potential: { potential: any[] } }>(
'POST', 'POST',
@ -98,7 +98,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

@ -10,10 +10,11 @@ import { NearestStoresMap } from '../maps/NearestStoresMap';
export interface DailyLogDetailProps extends WiredDetailViewProps { export interface DailyLogDetailProps extends WiredDetailViewProps {
onBack?: () => void; onBack?: () => void;
refreshKey?: number;
} }
export function DailyLogDetail({ instanceId, onBack }: DailyLogDetailProps) { export function DailyLogDetail({ instanceId, onBack, refreshKey }: DailyLogDetailProps) {
const { data, loading, error } = useDetailViewData(dailyReportsClient, DAILY_REPORTS.detailViews.DAILY_LOGS, instanceId); const { data, loading, error } = useDetailViewData(dailyReportsClient, DAILY_REPORTS.detailViews.DAILY_LOGS, instanceId, refreshKey);
if (error) { if (error) {
return ( return (

View File

@ -11,9 +11,10 @@ export interface WiredDetailViewProps {
columns?: 1 | 2 | 3; columns?: 1 | 2 | 3;
onDataLoad?: (data: Record<string, unknown>) => void; onDataLoad?: (data: Record<string, unknown>) => void;
onBack?: () => void; onBack?: () => void;
refreshKey?: number;
} }
export function OrderDetail({ instanceId, onDataLoad, onBack }: WiredDetailViewProps) { export function OrderDetail({ instanceId, onDataLoad, onBack, refreshKey }: WiredDetailViewProps) {
const [data, setData] = useState<Record<string, unknown> | null>(null); const [data, setData] = useState<Record<string, unknown> | null>(null);
const [loading, setLoading] = useState(true); const [loading, setLoading] = useState(true);
const [error, setError] = useState<string | null>(null); const [error, setError] = useState<string | null>(null);
@ -37,7 +38,7 @@ export function OrderDetail({ instanceId, onDataLoad, onBack }: WiredDetailViewP
} }
run(); run();
return () => { live = false; }; return () => { live = false; };
}, [instanceId]); }, [instanceId, refreshKey]);
if (error) { if (error) {
return ( return (

View File

@ -11,9 +11,10 @@ export interface StoreDetailProps {
instanceId: string | number; instanceId: string | number;
onBack?: () => void; onBack?: () => void;
onEdit?: () => void; onEdit?: () => void;
refreshKey?: number;
} }
export function StoreDetail({ instanceId, onBack, onEdit }: StoreDetailProps) { export function StoreDetail({ instanceId, onBack, onEdit, refreshKey }: StoreDetailProps) {
const [data, setData] = useState<Record<string, unknown> | null>(null); const [data, setData] = useState<Record<string, unknown> | null>(null);
const [loading, setLoading] = useState(true); const [loading, setLoading] = useState(true);
const [error, setError] = useState<string | null>(null); const [error, setError] = useState<string | null>(null);
@ -34,7 +35,7 @@ export function StoreDetail({ instanceId, onBack, onEdit }: StoreDetailProps) {
} }
run(); run();
return () => { live = false; }; return () => { live = false; };
}, [instanceId]); }, [instanceId, refreshKey]);
if (error) { if (error) {
return ( return (
@ -77,7 +78,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

@ -1,7 +1,7 @@
import { useState, useEffect } from 'react'; import { useState, useEffect } from 'react';
import type { ZinoClient } from '../../api/client'; import type { ZinoClient } from '../../api/client';
export function useDetailViewData(client: ZinoClient, dvUid: string | undefined, instanceId: string | number) { export function useDetailViewData(client: ZinoClient, dvUid: string | undefined, instanceId: string | number, refreshKey?: number) {
const [data, setData] = useState<Record<string, any> | null>(null); const [data, setData] = useState<Record<string, any> | null>(null);
const [config, setConfig] = useState<any>(null); const [config, setConfig] = useState<any>(null);
const [loading, setLoading] = useState(true); const [loading, setLoading] = useState(true);
@ -29,7 +29,7 @@ export function useDetailViewData(client: ZinoClient, dvUid: string | undefined,
return () => { return () => {
live = false; live = false;
}; };
}, [client, dvUid, instanceId]); }, [client, dvUid, instanceId, refreshKey]);
return { data, config, loading, error }; return { data, config, loading, error };
} }

View File

@ -17,7 +17,7 @@ import {
WfLookupField, WfLookupField,
RadioField, RadioField,
} from './fields'; } from './fields';
import { ORDER_BOOKING, STORE, DAILY_REPORTS } from '../../api/config'; import { ORDER_BOOKING, STORE, DAILY_REPORTS, HIDDEN_FORM_FIELDS } from '../../api/config';
export interface DynamicFormProps { export interface DynamicFormProps {
client: ZinoClient; client: ZinoClient;
@ -198,6 +198,7 @@ export function DynamicForm({ client, activityId: initialActivityId, instanceId:
const [submitError, setSubmitError] = useState<string | null>(null); const [submitError, setSubmitError] = useState<string | null>(null);
const clickedActionRef = useRef<string | null>(null); const clickedActionRef = useRef<string | null>(null);
const hasSubmittedRef = useRef(false);
const handleFieldChange = (fieldId: string, newVal: unknown, rawRow?: any) => { const handleFieldChange = (fieldId: string, newVal: unknown, rawRow?: any) => {
setValues(prev => { setValues(prev => {
@ -340,7 +341,7 @@ export function DynamicForm({ client, activityId: initialActivityId, instanceId:
} }
// Filter out disabled fields (usually server-generated IDs) // Filter out disabled fields (usually server-generated IDs)
const fields = schema.fields.filter(f => !f.properties?.disabled); 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 normalFields = fields.filter(f => f !== actionField);
@ -357,7 +358,12 @@ export function DynamicForm({ client, activityId: initialActivityId, instanceId:
} }
for (const f of fields) { for (const f of fields) {
const val = finalValues[f.id]; 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')));
if (isNotesOrRemarks && val == null) {
val = '';
}
if (val == null) continue; if (val == null) continue;
if (f.data_type === 'phone' && typeof val === 'string') { if (f.data_type === 'phone' && typeof val === 'string') {
@ -389,6 +395,7 @@ export function DynamicForm({ client, activityId: initialActivityId, instanceId:
res = await client.startInstance(currentActivityId, payload); res = await client.startInstance(currentActivityId, payload);
} }
hasSubmittedRef.current = true;
let pending = [...chainQueue]; let pending = [...chainQueue];
let chainSource = (res as any).activity_chain || schema.activity_chain || []; let chainSource = (res as any).activity_chain || schema.activity_chain || [];
@ -418,19 +425,19 @@ export function DynamicForm({ client, activityId: initialActivityId, instanceId:
if (nextActivity) { if (nextActivity) {
let nextPrefillData = undefined; let nextPrefillData = undefined;
if (nextActivity.activity_uid === ORDER_BOOKING.activities.POTENTIAL_MINING.uid) { if (nextActivity.activity_uid === ORDER_BOOKING.activities.POTENTIAL_MINING.uid) {
let storeCodeToSend = String((values['select_store_row'] as any)?.store_code || (chainedPrefillData?.['select_store_row'] as any)?.store_code || ''); let storeCodeToSend = String((values['select_store_row'] as any)?.store_code_2 || (chainedPrefillData?.['select_store_row'] as any)?.store_code_2 || '');
if (!storeCodeToSend) { if (!storeCodeToSend) {
let storeId = values['select_store'] || chainedPrefillData?.['select_store'] || (schema?.prefill_data as any)?.select_store || (schema?.data as any)?.select_store; let storeId = values['select_store'] || chainedPrefillData?.['select_store'] || (schema?.prefill_data as any)?.select_store || (schema?.data as any)?.select_store;
if (typeof storeId === 'object' && storeId !== null) { if (typeof storeId === 'object' && storeId !== null) {
storeCodeToSend = (storeId as any).store_code || storeCodeToSend; storeCodeToSend = (storeId as any).store_code_2 || storeCodeToSend;
storeId = (storeId as any).value || (storeId as any).instance_id || String(storeId); storeId = (storeId as any).value || (storeId as any).instance_id || String(storeId);
} }
if (!storeCodeToSend && storeId) { if (!storeCodeToSend && storeId) {
try { try {
const detailRes = await client.detailView(STORE.detailViews.STORE, storeId); const detailRes = await client.detailView(STORE.detailViews.STORE, storeId);
if (detailRes.data && detailRes.data.store_code) { if (detailRes.data && (detailRes.data.store_code_2 || detailRes.data.store_code)) {
storeCodeToSend = String(detailRes.data.store_code); storeCodeToSend = String(detailRes.data.store_code_2 || detailRes.data.store_code);
} }
} catch (e) { } catch (e) {
try { try {
@ -442,8 +449,8 @@ export function DynamicForm({ client, activityId: initialActivityId, instanceId:
}); });
const arr = Array.isArray(lookupRes) ? lookupRes : (lookupRes.data || lookupRes.records || []); const arr = Array.isArray(lookupRes) ? lookupRes : (lookupRes.data || lookupRes.records || []);
const row = arr.find((r: any) => String(r.instance_id || r.id) === String(storeId)); const row = arr.find((r: any) => String(r.instance_id || r.id) === String(storeId));
if (row && row.store_code) { if (row && (row.store_code_2 || row.store_code)) {
storeCodeToSend = String(row.store_code); storeCodeToSend = String(row.store_code_2 || row.store_code);
} }
} catch (err) { } catch (err) {
console.error("Failed to fetch store code:", err); console.error("Failed to fetch store code:", err);
@ -693,7 +700,10 @@ export function DynamicForm({ client, activityId: initialActivityId, instanceId:
<div className="flex items-center justify-end gap-3 mt-4 pt-4 border-t border-border-subtle"> <div className="flex items-center justify-end gap-3 mt-4 pt-4 border-t border-border-subtle">
{onCancel && ( {onCancel && (
<Button type="button" variant="secondary" onClick={onCancel} disabled={submitting}> <Button type="button" variant="secondary" onClick={() => {
if (hasSubmittedRef.current) onSuccess?.();
else onCancel?.();
}} disabled={submitting}>
Cancel Cancel
</Button> </Button>
)} )}

View File

@ -1,7 +1,7 @@
import { useState, useEffect, useCallback, useRef } from 'react'; import { useState, useEffect, useCallback, useRef } from 'react';
import type { ZinoClient } from '../../api/client'; import type { ZinoClient } from '../../api/client';
import type { FormScreenResponse } from '../../api/types'; import type { FormScreenResponse } from '../../api/types';
import { ORDER_BOOKING } from '../../api/config'; import { ORDER_BOOKING, HIDDEN_FORM_FIELDS } from '../../api/config';
import { Button } from '../buttons/Button'; import { Button } from '../buttons/Button';
import { Select } from '../reusable/Select'; import { Select } from '../reusable/Select';
import { DateField, TimeField, FileInput, TextField } from './fields'; import { DateField, TimeField, FileInput, TextField } from './fields';
@ -308,7 +308,12 @@ export function LogVisitForm({ client, onSuccess, onCancel, onActivityChange }:
const payload: Record<string, any> = {}; const payload: Record<string, any> = {};
validFieldIds.forEach(fieldId => { validFieldIds.forEach(fieldId => {
const val = valuesRef.current[fieldId]; const val = valuesRef.current[fieldId];
if (val !== undefined && val !== null && val !== '') { const fieldDef = validFields.find(f => f.id === fieldId);
const isNotesOrRemarks = fieldId.toLowerCase().includes('notes') || fieldId.toLowerCase().includes('remarks') || (fieldDef?.name && (fieldDef.name.toLowerCase().includes('notes') || fieldDef.name.toLowerCase().includes('remarks')));
if (isNotesOrRemarks && (val == null || val === '')) {
payload[fieldId] = '';
} else if (val !== undefined && val !== null && val !== '') {
payload[fieldId] = val; payload[fieldId] = val;
} }
}); });
@ -365,7 +370,7 @@ export function LogVisitForm({ client, onSuccess, onCancel, onActivityChange }:
instanceId={chainedActivity.instanceId} instanceId={chainedActivity.instanceId}
customPrefillData={chainedActivity.prefillData} customPrefillData={chainedActivity.prefillData}
onSuccess={onSuccess} onSuccess={onSuccess}
onCancel={onCancel} onCancel={onSuccess}
onActivityChange={onActivityChange} onActivityChange={onActivityChange}
/> />
); );
@ -388,7 +393,7 @@ export function LogVisitForm({ client, onSuccess, onCancel, onActivityChange }:
const lowerId = fieldId.toLowerCase(); const lowerId = fieldId.toLowerCase();
const lowerName = f.name.toLowerCase(); const lowerName = f.name.toLowerCase();
const isHidden = schema?.field_defaults?.[fieldId]?.hidden === true || (f.properties as any)?.hidden === true; const isHidden = schema?.field_defaults?.[fieldId]?.hidden === true || (f.properties as any)?.hidden === true || HIDDEN_FORM_FIELDS.includes(fieldId);
// Skip daily_log and route_code (or hidden fields) from visual rendering // Skip daily_log and route_code (or hidden fields) from visual rendering
if ( if (

View File

@ -403,7 +403,7 @@ export function SmartGridField({
editingIdx === null ? 'grid-rows-[1fr] opacity-100 mt-4' : 'grid-rows-[0fr] opacity-0 mt-0 hidden' editingIdx === null ? 'grid-rows-[1fr] opacity-100 mt-4' : 'grid-rows-[0fr] opacity-0 mt-0 hidden'
}`} }`}
> >
<div className="overflow-hidden min-h-0"> <div className={`min-h-0 ${editingIdx === null ? 'overflow-visible' : 'overflow-hidden'}`}>
<div className="p-4 border border-border-subtle rounded-2xl bg-card shadow-sm"> <div className="p-4 border border-border-subtle rounded-2xl bg-card shadow-sm">
<h4 className="text-sm font-semibold text-strong mb-4 flex items-center gap-2"> <h4 className="text-sm font-semibold text-strong mb-4 flex items-center gap-2">
Add New Item Add New Item

View File

@ -49,7 +49,7 @@ export function AnalyticsChart({ data }: AnalyticsChartProps) {
<Card key={chart.chart_uid || idx} title={title} className="shadow-sm"> <Card key={chart.chart_uid || idx} title={title} className="shadow-sm">
<div className="h-[320px] w-full mt-4 [&_.recharts-wrapper]:!outline-none [&_.recharts-surface]:!outline-none [&_*]:!outline-none"> <div className="h-[320px] w-full mt-4 [&_.recharts-wrapper]:!outline-none [&_.recharts-surface]:!outline-none [&_*]:!outline-none">
<ResponsiveContainer width="100%" height="100%"> <ResponsiveContainer width="100%" height="100%">
<BarChart data={formattedRows} margin={{ top: 25, right: 10, left: -20, bottom: 0 }}> <BarChart data={formattedRows} margin={{ top: 25, right: 10, left: -20, bottom: 20 }}>
<defs> <defs>
<linearGradient id={`colorGradient-${idx}`} x1="0" y1="0" x2="0" y2="1"> <linearGradient id={`colorGradient-${idx}`} x1="0" y1="0" x2="0" y2="1">
<stop offset="0%" stopColor="var(--primary-color)" stopOpacity={1} /> <stop offset="0%" stopColor="var(--primary-color)" stopOpacity={1} />
@ -62,7 +62,10 @@ export function AnalyticsChart({ data }: AnalyticsChartProps) {
axisLine={false} axisLine={false}
tickLine={false} tickLine={false}
tick={{ fontSize: 12, fill: '#64748B' }} tick={{ fontSize: 12, fill: '#64748B' }}
angle={-45}
textAnchor="end"
dy={10} dy={10}
height={60}
/> />
<YAxis <YAxis
axisLine={false} axisLine={false}

View File

@ -88,7 +88,7 @@ export function AllDailyLogsPage() {
title={instanceId != null ? `Daily Log #${instanceId}` : undefined} title={instanceId != null ? `Daily Log #${instanceId}` : undefined}
width="lg" width="lg"
> >
{instanceId != null && <DailyLogDetail instanceId={instanceId} />} {instanceId != null && <DailyLogDetail instanceId={instanceId} refreshKey={refreshKey} />}
</Modal> </Modal>
</> </>
); );

View File

@ -27,7 +27,7 @@ export function CallsPage() {
setMiningLoading(true); setMiningLoading(true);
setMiningPrefill(undefined); setMiningPrefill(undefined);
try { try {
const storeCode = selectedRow?.store_code || selectedRow?.code || selectedRow?.store?.store_code || selectedRow?.select_store?.store_code || selectedRow?.select_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) { if (!storeCode) {
console.warn("Store code not found on selected row, proceeding anyway."); console.warn("Store code not found on selected row, proceeding anyway.");
@ -72,7 +72,7 @@ export function CallsPage() {
return ( return (
<div className="flex flex-col h-full bg-transparent w-full relative"> <div className="flex flex-col h-full bg-transparent w-full relative">
<div className="flex-1 pb-24 w-full overflow-y-auto"> <div className="flex-1 pb-24 w-full overflow-y-auto">
<CallDetail instanceId={instanceId} onDataLoad={setSelectedRow} onBack={() => { navigate(`/calls`); setIsFabOpen(false); }} /> <CallDetail instanceId={instanceId} refreshKey={refreshKey} onDataLoad={setSelectedRow} onBack={() => { navigate(`/calls`); setIsFabOpen(false); }} />
</div> </div>
<div className="fixed bottom-24 right-6 flex flex-col items-end gap-3 z-50"> <div className="fixed bottom-24 right-6 flex flex-col items-end gap-3 z-50">
@ -105,6 +105,17 @@ export function CallsPage() {
Place Order Place Order
</Button> </Button>
); );
} else if (stateName === 'visited') {
return (
<Button size="sm" onClick={(e) => {
e.stopPropagation();
e.preventDefault();
setActiveActivity({ id: ORDER_BOOKING.activities.PRODUCTIVITY_OF_VISIT.uid, name: 'Productivity of Visit' });
setIsFabOpen(false);
}}>
Productivity of Visit
</Button>
);
} else if (stateName.includes('no order') || stateName.includes('non-productive') || stateName.includes('non productive')) { } else if (stateName.includes('no order') || stateName.includes('non-productive') || stateName.includes('non productive')) {
return null; return null;
} }

View File

@ -24,7 +24,7 @@ export function DailyLogsPage() {
return ( return (
<div className="flex flex-col h-full bg-transparent w-full relative"> <div className="flex flex-col h-full bg-transparent w-full relative">
<div className="flex-1 pb-24 w-full overflow-y-auto"> <div className="flex-1 pb-24 w-full overflow-y-auto">
<DailyLogDetail instanceId={instanceId} onBack={() => navigate(`/daily`)} /> <DailyLogDetail instanceId={instanceId} refreshKey={refreshKey} onBack={() => navigate(`/daily`)} />
</div> </div>
</div> </div>
); );

View File

@ -29,7 +29,7 @@ export function OrdersPage() {
setMiningLoading(true); setMiningLoading(true);
setMiningPrefill(undefined); setMiningPrefill(undefined);
try { try {
const storeCode = selectedRow?.store_code || selectedRow?.code || selectedRow?.store?.store_code || selectedRow?.select_store?.store_code || selectedRow?.select_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) { if (!storeCode) {
console.warn("Store code not found on selected row, proceeding anyway."); console.warn("Store code not found on selected row, proceeding anyway.");
@ -74,7 +74,7 @@ export function OrdersPage() {
return ( return (
<div className="flex flex-col h-full bg-transparent w-full relative"> <div className="flex flex-col h-full bg-transparent w-full relative">
<div className="flex-1 pb-24 w-full overflow-y-auto"> <div className="flex-1 pb-24 w-full overflow-y-auto">
<OrderDetail instanceId={instanceId} onDataLoad={setSelectedRow} onBack={() => { navigate(`/orders`); setIsFabOpen(false); }} /> <OrderDetail instanceId={instanceId} refreshKey={refreshKey} onDataLoad={setSelectedRow} onBack={() => { navigate(`/orders`); setIsFabOpen(false); }} />
</div> </div>
<div className="fixed bottom-24 right-6 flex flex-col items-end gap-3 z-50"> <div className="fixed bottom-24 right-6 flex flex-col items-end gap-3 z-50">
@ -107,6 +107,17 @@ export function OrdersPage() {
Place Order Place Order
</Button> </Button>
); );
} else if (stateName === 'visited') {
return (
<Button size="sm" onClick={(e) => {
e.stopPropagation();
e.preventDefault();
setActiveActivity({ id: ORDER_BOOKING.activities.PRODUCTIVITY_OF_VISIT.uid, name: 'Productivity of Visit' });
setIsFabOpen(false);
}}>
Productivity of Visit
</Button>
);
} else if (stateName.includes('no order') || stateName.includes('non-productive') || stateName.includes('non productive')) { } else if (stateName.includes('no order') || stateName.includes('non-productive') || stateName.includes('non productive')) {
return null; return null;
} }

View File

@ -23,7 +23,7 @@ export function StoresPage() {
return ( return (
<div className="flex flex-col h-full bg-transparent w-full relative"> <div className="flex flex-col h-full bg-transparent w-full relative">
<div className="flex-1 pb-24 w-full overflow-y-auto"> <div className="flex-1 pb-24 w-full overflow-y-auto">
<StoreDetail instanceId={instanceId} onBack={() => navigate(`/stores`)} /> <StoreDetail instanceId={instanceId} refreshKey={refreshKey} onBack={() => navigate(`/stores`)} />
</div> </div>
{/* Edit store modal can still open over the detail view if needed */} {/* Edit store modal can still open over the detail view if needed */}