Uecko_ERP/modules/customers/src/web/hooks/use-customers-query.tsx

23 lines
678 B
TypeScript
Raw Normal View History

2025-08-23 11:57:48 +00:00
import { useDataSource, useQueryKey } from "@erp/core/hooks";
2025-08-11 17:49:52 +00:00
import { useQuery } from "@tanstack/react-query";
2025-09-24 15:09:37 +00:00
import { CustomersListData } from "../schemas";
2025-07-17 18:04:00 +00:00
2025-09-29 08:42:46 +00:00
// Obtener todos los clientes
2025-09-16 17:29:37 +00:00
export const useCustomersQuery = (params?: any) => {
2025-07-17 18:04:00 +00:00
const dataSource = useDataSource();
const keys = useQueryKey();
2025-09-24 15:09:37 +00:00
return useQuery<CustomersListData>({
2025-07-17 18:04:00 +00:00
queryKey: keys().data().resource("customers").action("list").params(params).get(),
2025-09-16 17:29:37 +00:00
queryFn: async (context) => {
2025-07-17 18:04:00 +00:00
const { signal } = context;
2025-09-16 17:29:37 +00:00
const customers = await dataSource.getList("customers", {
2025-07-17 18:04:00 +00:00
signal,
...params,
});
2025-09-16 17:29:37 +00:00
2025-09-24 15:09:37 +00:00
return customers as CustomersListData;
2025-07-17 18:04:00 +00:00
},
});
};