my calls and my orders done

This commit is contained in:
suryacp23 2026-07-15 12:22:03 +05:30
parent e391056b82
commit 26bf86b9fe
3 changed files with 33 additions and 56 deletions

View File

@ -55,8 +55,7 @@ export const ORDER_BOOKING = {
}, },
recordViews: { recordViews: {
ORDERS: '1e424561-9a27-44f5-9b68-64d63296d837', ORDERS: '1e424561-9a27-44f5-9b68-64d63296d837',
CALLS: '56b21b46-6d2c-4e10-b5a3-c63d058d0afa', CALLS: 'b4d7a710-24e7-416d-885a-31fd1e727aab',
ANALYTICS_ORDERS: '63714ac2-c9fb-40e2-abba-d4081a70b768',
ANALYTICS: '56b21b46-6d2c-4e10-b5a3-c63d058d0afa' ANALYTICS: '56b21b46-6d2c-4e10-b5a3-c63d058d0afa'
}, },
detailViews: { detailViews: {

View File

@ -15,9 +15,14 @@ export function CallCard({ row, isDetailView = false }: { row: Record<string, an
imageObj = imgData; imageObj = imgData;
} }
// Extract nested objects if they exist
const storeObj = typeof row.select_store === 'object' ? row.select_store : (typeof row.store === 'object' ? row.store : {});
const userKey = Object.keys(row).find(k => k.includes('user_id'));
const userObj = userKey ? row[userKey] : null;
// Store Details // Store Details
const storeName = formatValue(row.store || row.store_name || row.customer_name || '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(row.store_code || '—'); const storeCode = formatValue(storeObj?.store_code || row.store_code || '—');
// Grid Details // Grid Details
const totalWeight = formatValue(row.total_kgs || row.total_weight || row.weight || 0); const totalWeight = formatValue(row.total_kgs || row.total_weight || row.weight || 0);
@ -25,37 +30,39 @@ export function CallCard({ row, isDetailView = false }: { row: Record<string, an
const totalOrders = formatValue(row.order_count || row.total_orders || 0); const totalOrders = formatValue(row.order_count || row.total_orders || 0);
// Route & Assignment // Route & Assignment
const routeName = formatValue(row.route_name || row.route || '—'); const routeName = formatValue(storeObj?.route_name || storeObj?.route || row.route_name || row.route || '—');
const areaName = formatValue(row.area || row.area_name || '—'); const areaName = formatValue(storeObj?.area || row.area || row.area_name || '—');
// User // User
const userName = formatValue(row.sales_officer || row.user_name || '—'); const userName = formatValue(userObj?.name || row.sales_officer || row.user_name || '—');
const userEmail = formatValue(row.performed_by_email || row.user_email || '—'); const userEmail = formatValue(userObj?.email || row.performed_by_email || row.user_email || '—');
const initials = userName !== '—' ? String(userName).substring(0, 2).toUpperCase() : 'SO'; const initials = userName !== '—' ? String(userName).substring(0, 2).toUpperCase() : 'SO';
// Date & Time // Date & Time
let dateStr = '—'; let dateStr = '—';
let timeStr = '—'; let timeStr = '—';
if (row.visit_date) { if (row.date_of_visit || row.visit_date) {
try { try {
const d = new Date(row.visit_date as string); const dVal = String(row.date_of_visit || row.visit_date);
const d = new Date(dVal);
if (!isNaN(d.getTime())) dateStr = d.toISOString().split('T')[0]; if (!isNaN(d.getTime())) dateStr = d.toISOString().split('T')[0];
else dateStr = dVal.split('T')[0];
} catch { } catch {
dateStr = String(row.visit_date).split('T')[0]; dateStr = String(row.date_of_visit || row.visit_date).split('T')[0];
} }
} }
if (row.visit_time) { if (row.time_of_visit || row.visit_time) {
try { try {
const t = String(row.visit_time); const t = String(row.time_of_visit || row.visit_time);
if (t.includes('T')) { if (t.includes('T')) {
timeStr = t.split('T')[1].replace('Z', '').split('.')[0]; timeStr = t.split('T')[1].replace('Z', '').split('.')[0];
} else { } else {
timeStr = t; timeStr = t;
} }
} catch { } catch {
timeStr = String(row.visit_time); timeStr = String(row.time_of_visit || row.visit_time);
} }
} }

View File

@ -1,10 +1,7 @@
import { useEffect, useState } from 'react';
import { orderBookingClient } from '../../api/clients'; import { orderBookingClient } from '../../api/clients';
import { ORDER_BOOKING } from '../../api/config'; import { ORDER_BOOKING } from '../../api/config';
import { RecordView } from './RecordView'; import { RecordView } from './RecordView';
import { OrderCard } from '../cards/OrderCard'; import { OrderCard } from '../cards/OrderCard';
import { StatsTiles } from '../reusable/StatsTiles';
import type { TileItem } from '../../api/types';
export interface WiredRecordViewProps { export interface WiredRecordViewProps {
onRowClick?: (row: Record<string, unknown>, index: number) => void; onRowClick?: (row: Record<string, unknown>, index: number) => void;
@ -16,45 +13,19 @@ export interface WiredRecordViewProps {
/** Orders record view (Order Booking workflow). */ /** Orders record view (Order Booking workflow). */
export function OrdersView({ onRowClick, pageSize, headerActions, rowActions, refreshKey }: WiredRecordViewProps) { export function OrdersView({ onRowClick, pageSize, headerActions, rowActions, refreshKey }: WiredRecordViewProps) {
const [analyticsTiles, setAnalyticsTiles] = useState<TileItem[]>([]);
useEffect(() => {
let live = true;
// Defer the fetch so it doesn't compete with the main list fetch
const timer = setTimeout(async () => {
try {
const res = await orderBookingClient.recordView(ORDER_BOOKING.recordViews.ANALYTICS_ORDERS, { limit: 0 });
if (live && res.tile_values) {
const filteredTiles = (res.tile_values as TileItem[]).filter(
(t) => t.key !== 'total_orders' && t.key !== 'total_orders_count'
);
setAnalyticsTiles(filteredTiles);
}
} catch (e) {
console.error("Failed to load analytics tiles for orders", e);
}
}, 100);
return () => { live = false; clearTimeout(timer); };
}, [refreshKey]);
return ( return (
<div className="flex flex-col gap-5 w-full"> <RecordView
{analyticsTiles.length > 0 && <StatsTiles tiles={analyticsTiles} />} client={orderBookingClient}
<RecordView rvUid={ORDER_BOOKING.recordViews.ORDERS}
client={orderBookingClient} title="Orders"
rvUid={ORDER_BOOKING.recordViews.ORDERS} onRowClick={onRowClick}
title="Orders" pageSize={pageSize}
onRowClick={onRowClick} headerActions={headerActions}
pageSize={pageSize} rowActions={rowActions}
headerActions={headerActions} refreshKey={refreshKey}
rowActions={rowActions} sortBy="instance_id"
refreshKey={refreshKey} sortDir="desc"
sortBy="instance_id" renderItem={(row, fields) => <OrderCard row={row} fields={fields} />}
sortDir="desc" />
renderItem={(row, fields) => <OrderCard row={row} fields={fields} />}
/>
</div>
); );
} }