"use client"; import { useModuleClient } from "@86d-app/core/client"; import { useEffect, useRef, useState } from "react"; interface LoyaltyBalance { customerId: string; totalEarned: number; totalRedeemed: number; balance: number; transactionCount: number; } interface LoyaltyTransaction { id: string; customerId: string; type: "earn" | "redeem" | "adjust"; points: number; balance: number; reason: string; orderId?: string; createdAt: string; } interface LoyaltyStats { totalCustomersWithPoints: number; totalPointsIssued: number; totalPointsRedeemed: number; totalPointsOutstanding: number; averageBalance: number; topCustomers: { customerId: string; email: string; name: string; balance: number; }[]; } interface Customer { id: string; email: string; firstName?: string | null; lastName?: string | null; } function useLoyaltyApi() { const client = useModuleClient(); return { stats: client.module("customers").admin["/admin/customers/loyalty/stats"], listCustomers: client.module("customers").admin["/admin/customers"], }; } function Skeleton({ className = "" }: { className?: string }) { return (
); } function StatCard({ label, value }: { label: string; value: string | number }) { return ({label}
{String(value)}
{actionType === "earn" ? "Add Points" : actionType === "redeem" ? "Redeem Points" : "Adjust Points"}
setPoints(e.target.value)} className="mb-2 w-full rounded border border-border bg-background px-3 py-1.5 text-sm" /> setReason(e.target.value)} className="mb-2 w-full rounded border border-border bg-background px-3 py-1.5 text-sm" />No transactions yet
) : ({formatDate(t.createdAt)}
Failed to load loyalty customers
Check your connection and try again.
Manage customer loyalty points and rewards
| Customer | Balance | |
|---|---|---|
| {tc.name} | {tc.email} | {tc.balance.toLocaleString()} |
Loading customers...
) : customers.length === 0 ? (No customers found
) : ( <>| Name | Actions | |
|---|---|---|
| {c.firstName} {c.lastName} | {c.email} |