import React from 'react' import { useOrg } from '@components/Contexts/OrgContext' import { useLHSession } from '@components/Contexts/LHSessionContext' import useSWR from 'swr' import { Table, TableBody, TableCell, TableHead, TableHeader, TableRow, } from "@/components/ui/table" import { getOrgCustomers } from '@services/payments/payments' import { Badge } from '@/components/ui/badge' import PageLoading from '@components/Objects/Loaders/PageLoading' import { RefreshCcw, SquareCheck } from 'lucide-react' import { getUserAvatarMediaDirectory } from '@services/media/media' import UserAvatar from '@components/Objects/UserAvatar' import { usePaymentsEnabled } from '@hooks/usePaymentsEnabled' import { Alert, AlertDescription, AlertTitle } from "@/components/ui/alert" import { AlertTriangle, Settings, CreditCard, ShoppingCart, Users, ChevronRight } from 'lucide-react' import Link from 'next/link' import UnconfiguredPaymentsDisclaimer from '../../Pages/Payments/UnconfiguredPaymentsDisclaimer' interface PaymentUserData { payment_user_id: number; user: { username: string; first_name: string; last_name: string; email: string; avatar_image: string; user_uuid: string; }; product: { name: string; description: string; product_type: string; amount: number; currency: string; }; status: string; creation_date: string; } function PaymentsUsersTable({ data }: { data: PaymentUserData[] }) { return ( User Product Type Amount Status Purchase Date {data.map((item) => (
{item.user.first_name || item.user.username} {item.user.email}
{item.product.name}
{item.product.product_type === 'subscription' ? ( Subscription ) : ( One-time )}
{new Intl.NumberFormat('en-US', { style: 'currency', currency: item.product.currency }).format(item.product.amount)} {item.status} {new Date(item.creation_date).toLocaleDateString()}
))}
); } function PaymentsCustomersPage() { const org = useOrg() as any const session = useLHSession() as any const access_token = session?.data?.tokens?.access_token const { isEnabled, isLoading } = usePaymentsEnabled() const { data: customers, error, isLoading: customersLoading } = useSWR( org ? [`/payments/${org.id}/customers`, access_token] : null, ([url, token]) => getOrgCustomers(org.id, token) ) if (!isEnabled && !isLoading) { return ( ) } if (isLoading) return if (error) return
Error loading customers
return (

Customers

View and manage your customer information

) } export default PaymentsCustomersPage