new changes
This commit is contained in:
@@ -12,7 +12,8 @@
|
||||
* continues to use the Hasura hooks in `./queries`.
|
||||
*/
|
||||
|
||||
import { useQuery, useMutation, useQueryClient } from '@tanstack/react-query';
|
||||
import { useQuery, useMutation, useQueryClient, useQueries } from '@tanstack/react-query';
|
||||
import type { Row } from './fiestaApi';
|
||||
import {
|
||||
FIESTA_TENANT_ID,
|
||||
FIESTA_APPLOCATION_ID,
|
||||
@@ -204,6 +205,39 @@ export function useFiestaProductsCount(opts: { tenantid: number; categoryid: num
|
||||
});
|
||||
}
|
||||
|
||||
export interface StoreStock {
|
||||
locationid: number;
|
||||
locationname: string;
|
||||
isLoading: boolean;
|
||||
isError: boolean;
|
||||
rows: Row[];
|
||||
}
|
||||
|
||||
/**
|
||||
* Live stock statement for every outlet under the tenant — powers the admin's
|
||||
* "all stores' stock" view. One query per location (deduped/cached by React
|
||||
* Query); the returned array stays aligned with the `locations` input.
|
||||
*/
|
||||
export function useFiestaStoresStock(
|
||||
tenantid: number,
|
||||
locations: Array<{ locationid: number; locationname: string }>,
|
||||
): StoreStock[] {
|
||||
const results = useQueries({
|
||||
queries: locations.map((loc) => ({
|
||||
queryKey: fiestaKeys.stockStatement({ scope: 'stores', tenantid, locationid: loc.locationid }),
|
||||
queryFn: () => getStockStatement({ tenantid, locationid: loc.locationid, pagesize: 200 }),
|
||||
enabled: Boolean(tenantid && loc.locationid),
|
||||
})),
|
||||
});
|
||||
return locations.map((loc, i) => ({
|
||||
locationid: loc.locationid,
|
||||
locationname: loc.locationname,
|
||||
isLoading: results[i]?.isLoading ?? true,
|
||||
isError: results[i]?.isError ?? false,
|
||||
rows: (results[i]?.data as Row[]) ?? [],
|
||||
}));
|
||||
}
|
||||
|
||||
// ── Users ─────────────────────────────────────────────────────────────────────
|
||||
export function useFiestaUsers(opts: {
|
||||
tenantid: number;
|
||||
|
||||
Reference in New Issue
Block a user