udpates on the ui changes on theprodut catalogs

This commit is contained in:
2026-06-16 20:12:45 +05:30
parent a0586dc11c
commit 2e9ffb15bb
22 changed files with 921 additions and 598 deletions

View File

@@ -973,6 +973,20 @@ export async function createTenantLocation(input: CreateTenantLocationInput): Pr
return fiestaSend<Row>('tenants/createtenantlocation', 'POST', input);
}
export interface UpdateTenantLocationInput {
locationid: number;
tenantid?: number;
locationname?: string;
contactno?: string;
email?: string;
status?: string;
}
/** PUT /tenants/updatetenantlocation — Update store location details/status. */
export async function updateTenantLocation(input: UpdateTenantLocationInput): Promise<Row> {
return fiestaSend<Row>('tenants/updatetenantlocation', 'PUT', input);
}
// ════════════════════════════════════════════════════════════════════════════
// RIDERS / DISPATCH
// ════════════════════════════════════════════════════════════════════════════

View File

@@ -59,6 +59,8 @@ import {
createTenantLocation,
CreateTenantInput,
CreateTenantLocationInput,
updateTenantLocation,
UpdateTenantLocationInput,
} from './fiestaApi';
export const fiestaKeys = {
@@ -466,6 +468,112 @@ export function useFiestaStoresStock(
}));
}
export function useFiestaStoresOrderSummary(
tenantid: number,
locations: Array<{ locationid: number; locationname: string }>,
fromdate: string,
todate: string
) {
const results = useQueries({
queries: locations.map((loc) => ({
queryKey: fiestaKeys.orderSummary(tenantid, fromdate, todate, loc.locationid),
queryFn: () => getOrderSummary(tenantid, fromdate, todate, loc.locationid),
enabled: Boolean(tenantid && loc.locationid && fromdate && todate),
})),
});
const agg = { total: 0, created: 0, pending: 0, processing: 0, delivered: 0, cancelled: 0 };
let isLoading = false;
results.forEach(res => {
if (res.isLoading) isLoading = true;
if (res.data) {
agg.total += res.data.total;
agg.created += res.data.created;
agg.pending += res.data.pending;
agg.processing += res.data.processing;
agg.delivered += res.data.delivered;
agg.cancelled += res.data.cancelled;
}
});
return { isLoading, data: agg };
}
export function useFiestaStoresRevenueSummary(
tenantid: number,
locations: Array<{ locationid: number; locationname: string }>,
fromdate: string,
todate: string
) {
const results = useQueries({
queries: locations.map((loc) => ({
queryKey: fiestaKeys.revenueSummary({ scope: 'stores', tenantid, fromdate, todate, locationid: loc.locationid }),
queryFn: () => getRevenueSummary({ tenantid, fromdate, todate, locationid: loc.locationid }),
enabled: Boolean(tenantid && loc.locationid && fromdate && todate),
})),
});
const agg = { grossrevenue: 0, netrevenue: 0, profit: 0, ordercount: 0, avgordervalue: 0 };
let isLoading = false;
results.forEach(res => {
if (res.isLoading) isLoading = true;
if (res.data) {
agg.grossrevenue += res.data.grossrevenue;
agg.netrevenue += res.data.netrevenue;
agg.profit += res.data.profit;
agg.ordercount += res.data.ordercount;
}
});
if (agg.ordercount > 0) {
agg.avgordervalue = Math.round(agg.grossrevenue / agg.ordercount);
}
return { isLoading, data: agg };
}
export function useFiestaStoresTimeSeries(
tenantid: number,
locations: Array<{ locationid: number; locationname: string }>,
granularity: 'day' | 'month' | 'year',
fromdate: string,
todate: string
) {
const results = useQueries({
queries: locations.map((loc) => ({
queryKey: fiestaKeys.timeSeries({ scope: 'stores', tenantid, granularity, fromdate, todate, locationid: loc.locationid }),
queryFn: () => getTimeSeries({ tenantid, granularity, fromdate, todate, locationid: loc.locationid }),
enabled: Boolean(tenantid && loc.locationid && fromdate && todate),
})),
});
const map = new Map<string, any>();
let isLoading = false;
results.forEach(res => {
if (res.isLoading) isLoading = true;
if (res.data) {
res.data.forEach((d: any) => {
const label = d.label || d.date || d.createdat || 'Unknown';
if (!map.has(label)) {
map.set(label, { label, orders: 0, revenue: 0, cancelled: 0, skus: 0 });
}
const existing = map.get(label);
existing.orders += Number(d.orders || d.totalorders || d.total || 0);
existing.revenue += Number(d.revenue || d.grossrevenue || d.overallrevenue || 0);
existing.cancelled += Number(d.cancelled || 0);
existing.skus += Number(d.activeskus || d.skus || 0);
});
}
});
const sortedData = Array.from(map.values()).sort((a, b) => {
if (a.label === 'Unknown') return 1;
if (b.label === 'Unknown') return -1;
return new Date(a.label).getTime() - new Date(b.label).getTime();
});
return { isLoading, data: sortedData };
}
// ── Order details / customer history ───────────────────────────────────────────
export function useFiestaOrderDetails(orderheaderid: number | string | null | undefined) {
return useQuery({
@@ -639,6 +747,18 @@ export function useFiestaCreateLocation() {
});
}
/** Update a tenant location, then refresh tenant locations list on success. */
export function useFiestaUpdateLocation() {
const qc = useQueryClient();
return useMutation({
mutationFn: (input: UpdateTenantLocationInput) => updateTenantLocation(input),
onSuccess: () => {
qc.invalidateQueries({ queryKey: ['fiesta', 'tenantLocations'] });
qc.invalidateQueries({ queryKey: ['fiesta', 'locationSummary'] });
},
});
}
// ── Auth ──────────────────────────────────────────────────────────────────────
/**