Skip to main content

CreditTransactionsList

The CreditTransactionsList component renders a detailed and paginated table of all credit transactions, providing a clear log of credit usage and adjustments. It is ideal for use in customer portals or administrative dashboards to track how credits are granted and consumed.

This component automatically handles data fetching, pagination, and formatting, offering a straightforward way to display transaction history.

Props

PropTypeDescriptionDefault
customer_idstringThe ID of the customer whose transactions are to be displayed. If not provided, it defaults to the DID of the currently logged-in user from the PaymentProvider context.session.user.did
subscription_idstringFilters the transactions to a specific subscription.undefined
credit_grant_idstringFilters the transactions to a specific credit grant.undefined
pageSizenumberThe number of transactions to display per page.10
onTableDataChange(data, prevData) => voidA callback function that is triggered when the table data is fetched or updated.() => {}
showAdminColumnsbooleanIf true and the user is an admin, additional columns like 'Meter Event' are shown.false
showTimeFilterbooleanIf true, a date range picker is displayed to allow filtering transactions by date.false
sourcestringAn optional source string to filter transactions.''
mode'dashboard' | 'portal'Determines the link structure for related items like credit grants. Use 'dashboard' for admin views and 'portal' for customer-facing views.'portal'

Basic Usage for a Customer Portal

This example shows how to display the credit transaction history for the currently logged-in user. The component automatically uses the user's DID from the PaymentProvider context when customer_id is omitted.

MyCreditHistoryPage.tsx

jsx
import React from 'react';
import { CreditTransactionsList, PaymentProvider } from '@blocklet/payment-react';
import { useSessionContext } from '../hooks/session-context'; // Your session context hook

function MyCreditHistoryPage() {
  const { session, connectApi } = useSessionContext();

  if (!session || !connectApi) {
    return <div>Loading session...</div>;
  }

  return (
    <PaymentProvider session={session} connectApi={connectApi}>
      <h2>My Credit Transactions</h2>
      <CreditTransactionsList />
    </PaymentProvider>
  );
}

export default MyCreditHistoryPage;

Admin View with Filtering

For an admin dashboard, you can pass a specific customer_id and enable admin columns and time filters to provide a more powerful and detailed view of a user's transaction history.

CustomerDetailsPage.tsx

jsx
import React from 'react';
import { CreditTransactionsList, PaymentProvider } from '@blocklet/payment-react';
import { useSessionContext } from '../hooks/session-context'; // Your session context hook

function CustomerDetailsPage({ customerId }) {
  const { session, connectApi } = useSessionContext();

  if (!session || !connectApi) {
    return <div>Loading session...</div>;
  }

  return (
    <PaymentProvider session={session} connectApi={connectApi}>
      <h3>Transaction History for {customerId}</h3>
      <CreditTransactionsList
        customer_id={customerId}
        showAdminColumns={true}
        showTimeFilter={true}
        pageSize={20}
        mode="dashboard"
      />
    </PaymentProvider>
  );
}

export default CustomerDetailsPage;

Displaying Transactions for a Specific Credit Grant

To show a detailed log of how a particular credit grant was consumed, pass the credit_grant_id. This is useful for pages that show the details of a single credit grant.

CreditGrantDetailsPage.tsx

jsx
import React from 'react';
import { CreditTransactionsList, PaymentProvider } from '@blocklet/payment-react';
import { useSessionContext } from '../hooks/session-context'; // Your session context hook

function CreditGrantDetailsPage({ grantId }) {
  const { session, connectApi } = useSessionContext();

  if (!session || !connectApi) {
    return <div>Loading session...</div>;
  }

  return (
    <PaymentProvider session={session} connectApi={connectApi}>
      <h4>Usage Details for Grant {grantId}</h4>
      <CreditTransactionsList credit_grant_id={grantId} />
    </PaymentProvider>
  );
}

export default CreditGrantDetailsPage;