store user login
This commit is contained in:
@@ -14,7 +14,8 @@ import { insightsApi, type DateRange, type OrderQuery } from '@/api/insights';
|
||||
import { productsApi } from '@/api/products';
|
||||
import { posUsersApi, staffApi } from '@/api/people';
|
||||
import { stockApi, type StockRequestQuery } from '@/api/stock';
|
||||
import { tenantsApi } from '@/api/tenants';
|
||||
import { tenantsApi, utilsApi, type TenantListQuery } from '@/api/tenants';
|
||||
import { customersApi, type CustomerQuery } from '@/api/customers';
|
||||
import { queryKeys } from './keys';
|
||||
import { LIVE_REFETCH_MS } from './interval';
|
||||
|
||||
@@ -46,10 +47,33 @@ const stable = {
|
||||
|
||||
/* ── Tenants ─────────────────────────────────────────────────────────────── */
|
||||
|
||||
export function useTenants() {
|
||||
export function useTenants(query: TenantListQuery = {}) {
|
||||
return useQuery({
|
||||
queryKey: queryKeys.tenants.list(),
|
||||
queryFn: () => tenantsApi.listAll(),
|
||||
queryKey: queryKeys.tenants.list({ ...query }),
|
||||
queryFn: () => tenantsApi.listAll(query),
|
||||
...stable,
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* The approval queue.
|
||||
*
|
||||
* Its own hook rather than a filter over `useTenants`, because it is a
|
||||
* different endpoint: `getalltenants` cannot see an unapproved tenant at all.
|
||||
*/
|
||||
export function useTenantsByApproval(status: 'pending' | 'Active' | 'InActive', keyword?: string) {
|
||||
return useQuery({
|
||||
queryKey: queryKeys.tenants.approval(status, keyword ?? ''),
|
||||
queryFn: () => tenantsApi.byApproval(status, keyword),
|
||||
...stable,
|
||||
});
|
||||
}
|
||||
|
||||
/** The business-category master, for onboarding. */
|
||||
export function useAppCategories() {
|
||||
return useQuery({
|
||||
queryKey: queryKeys.tenants.appCategories(),
|
||||
queryFn: () => utilsApi.appCategories(),
|
||||
...stable,
|
||||
});
|
||||
}
|
||||
@@ -103,6 +127,37 @@ export function useProductCategories(tenantid: number | undefined) {
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* The tenant's categories as they are actually used.
|
||||
*
|
||||
* Prefer this over `useProductCategories`, which reads a master table missing
|
||||
* rows for live categoryids and hardcoded to `moduleid = 2`.
|
||||
*/
|
||||
export function useTenantCategories(tenantid: number | undefined) {
|
||||
return useQuery({
|
||||
queryKey: queryKeys.products.tenantCategories(tenantid ?? 0),
|
||||
queryFn: () => productsApi.tenantCategories(tenantid as number),
|
||||
enabled: typeof tenantid === 'number' && tenantid > 0,
|
||||
...stable,
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* One global-catalogue row, for the product drawer.
|
||||
*
|
||||
* Not retried: the common failure is that a re-scrape retired the source row,
|
||||
* and asking three more times does not bring it back.
|
||||
*/
|
||||
export function useCatalogueProduct(brand: string | undefined, sku: string | undefined) {
|
||||
return useQuery({
|
||||
queryKey: queryKeys.catalogue.product(brand ?? '', sku ?? ''),
|
||||
queryFn: () => catalogueApi.product(brand as string, sku as string),
|
||||
enabled: Boolean(brand) && Boolean(sku),
|
||||
retry: false,
|
||||
...stable,
|
||||
});
|
||||
}
|
||||
|
||||
export function useLocationProducts(
|
||||
tenantid: number | undefined,
|
||||
locationid: number | undefined,
|
||||
@@ -267,6 +322,21 @@ export function useDeliveries(query: OrderQuery | undefined) {
|
||||
/* ── People ──────────────────────────────────────────────────────────────── */
|
||||
|
||||
/** The back-office directory. Role names arrive resolved; never map ids here. */
|
||||
/**
|
||||
* The branch's customers.
|
||||
*
|
||||
* Page size is always sent — see `customersApi`. Left off, the backend returns
|
||||
* an empty list rather than an error, which reads as "no customers".
|
||||
*/
|
||||
export function useCustomers(query: CustomerQuery | undefined) {
|
||||
return useQuery({
|
||||
queryKey: queryKeys.customers.list({ ...query }),
|
||||
queryFn: () => customersApi.list(query as CustomerQuery),
|
||||
enabled: Boolean(query?.tenantid),
|
||||
...live,
|
||||
});
|
||||
}
|
||||
|
||||
export function useStaff(tenantid: number | undefined) {
|
||||
return useQuery({
|
||||
queryKey: queryKeys.people.staff(tenantid ?? 0),
|
||||
|
||||
Reference in New Issue
Block a user