Skip to main content

Usage

const { 
  data, 
  isLoading, 
  isError, 
  error, 
  isSuccess,
  fetchSkuList 
} = useGetSkuList();

Parameters

  • query (object): Object containing parameters: limit, page, offset, provider and category. Default values are page 1, limit 10 and offset 0.
  • getBearerToken (function): Function that returns a bearer token for authentication

Available SKU Categories

The available SKU categories include:
  • TELEPEAJE: Electronic toll payment services.
  • TELEFONIA: Telephony or mobile phone services.
  • GENERAL: General category for miscellaneous SKUs.
  • TESORERIA: Treasury or payment services.
  • LUZ: Electricity or utility bill payments.
  • INTERNET: Internet service payments or packages.
  • TV: Television or cable subscription services.
  • MOVILIDAD: Mobility-related services (e.g., transit, transportation).
  • RECARGAS: Prepaid mobile or service top-ups.
  • GIFT_CARDS: Various gift cards available for purchase.
  • GAMING: Video game-related products or services.
  • VENTAS_CATALOGO: Catalog sales or retail products.
  • DEPORTES: Sports-related goods or services.
  • STREAMING: Streaming service subscriptions (e.g., video or music platforms).
These categories define the type of products or services you can retrieve and purchase as SKUs using the useGetSkus hook.

Return Value

Returns an object containing:
  • data: Paginated response containing SKU data (PaginatedResponse<Sku>)
  • isLoading: Boolean indicating if the operation is in progress
  • isError: Boolean indicating if an error occurred
  • error: Error instance when isError is true, otherwise null
  • isSuccess: Boolean indicating if the query completed successfully
  • fetchSkuList: Function to manually fetch SKU list with new parameters

Example Implementation

export function GetSkusPage() {
  const { getToken } = useAuth();
  
  const { data, isLoading, error } = useGetSkuList({
    query: {
      page: 1,
      limit: 10, 
      category: "TELEFONIA",
    },
    getBearerToken: async () => {
      const token = await getToken();
      if (!token) throw new Error("No token found");
      return token;
    },
  });

  // Or use fetchSkuList manually:
  const loadSkus = async () => {
    try {
      const token = await getToken();
      if (!token) throw new Error("No token found");
      
      const result = await fetchSkuList({
        query: {
          page: 1,
          limit: 10,
          category: "TELEFONIA",
        },
        getBearerToken: async () => token,
      });
      
      console.log("SKUs loaded:", result.data);
    } catch (error) {
      console.error("Error loading SKUs:", error);
    }
  };

  return (
    <div>
      {isLoading && <p>Loading SKUs...</p>}
      {error && <p>Error: {error.message}</p>}
      {data && (
        <div>
          <p>Total SKUs: {data.total}</p>
          <p>Page: {data.page} of {data.totalPages}</p>
          <ul>
            {data.data.map((sku) => (
              <li key={sku.id}>{sku.name}</li>
            ))}
          </ul>
        </div>
      )}
    </div>
  );
}