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: {
ORDERS: '1e424561-9a27-44f5-9b68-64d63296d837',
CALLS: '56b21b46-6d2c-4e10-b5a3-c63d058d0afa',
ANALYTICS_ORDERS: '63714ac2-c9fb-40e2-abba-d4081a70b768',
CALLS: 'b4d7a710-24e7-416d-885a-31fd1e727aab',
ANALYTICS: '56b21b46-6d2c-4e10-b5a3-c63d058d0afa'
},
detailViews: {

View File

@ -15,9 +15,14 @@ export function CallCard({ row, isDetailView = false }: { row: Record<string, an
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
const storeName = formatValue(row.store || row.store_name || row.customer_name || 'Unknown Store');
const storeCode = formatValue(row.store_code || '—');
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 || '—');
// Grid Details
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);
// Route & Assignment
const routeName = formatValue(row.route_name || row.route || '—');
const areaName = formatValue(row.area || row.area_name || '—');
const routeName = formatValue(storeObj?.route_name || storeObj?.route || row.route_name || row.route || '—');
const areaName = formatValue(storeObj?.area || row.area || row.area_name || '—');
// User
const userName = formatValue(row.sales_officer || row.user_name || '—');
const userEmail = formatValue(row.performed_by_email || row.user_email || '—');
const userName = formatValue(userObj?.name || row.sales_officer || row.user_name || '—');
const userEmail = formatValue(userObj?.email || row.performed_by_email || row.user_email || '—');
const initials = userName !== '—' ? String(userName).substring(0, 2).toUpperCase() : 'SO';
// Date & Time
let dateStr = '—';
let timeStr = '—';
if (row.visit_date) {
if (row.date_of_visit || row.visit_date) {
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];
else dateStr = dVal.split('T')[0];
} 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 {
const t = String(row.visit_time);
const t = String(row.time_of_visit || row.visit_time);
if (t.includes('T')) {
timeStr = t.split('T')[1].replace('Z', '').split('.')[0];
} else {
timeStr = t;
}
} 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 { ORDER_BOOKING } from '../../api/config';
import { RecordView } from './RecordView';
import { OrderCard } from '../cards/OrderCard';
import { StatsTiles } from '../reusable/StatsTiles';
import type { TileItem } from '../../api/types';
export interface WiredRecordViewProps {
onRowClick?: (row: Record<string, unknown>, index: number) => void;
@ -16,32 +13,7 @@ export interface WiredRecordViewProps {
/** Orders record view (Order Booking workflow). */
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 (
<div className="flex flex-col gap-5 w-full">
{analyticsTiles.length > 0 && <StatsTiles tiles={analyticsTiles} />}
<RecordView
client={orderBookingClient}
rvUid={ORDER_BOOKING.recordViews.ORDERS}
@ -55,6 +27,5 @@ export function OrdersView({ onRowClick, pageSize, headerActions, rowActions, re
sortDir="desc"
renderItem={(row, fields) => <OrderCard row={row} fields={fields} />}
/>
</div>
);
}