refactor subscriptionsTable.jsx

This commit is contained in:
2026-01-29 18:46:16 -06:00
parent 27d5c48805
commit de719d9d69

View File

@@ -33,6 +33,17 @@ const HeaderCell = ({ align, children }) => (
</th> </th>
); );
const TableCell = ({ align = 'text-left', className = '', style, children, ...props }) => (
<td
className={`p-4 ${align} ${className}`.trim()}
style={style}
{...props}
>
{children}
</td>
);
const SubscriptionRow = ({ const SubscriptionRow = ({
sub, sub,
isExpanded, isExpanded,
@@ -47,41 +58,53 @@ const SubscriptionRow = ({
}) => ( }) => (
<> <>
<tr className="border-b border-[var(--neutral-800)] hover:bg-[var(--lavender-400)] transition-colors"> <tr className="border-b border-[var(--neutral-800)] hover:bg-[var(--lavender-400)] transition-colors">
<td className="p-4"> <TableCell>
<div className="font-medium text-[var(--purple-ink)]" style={{ fontFamily: "'Inter', sans-serif" }}> <div className="font-medium text-[var(--purple-ink)]" style={{ fontFamily: "'Inter', sans-serif" }}>
{sub.user.first_name} {sub.user.last_name} {sub.user.first_name} {sub.user.last_name}
</div> </div>
<div className="text-sm text-brand-purple " style={{ fontFamily: "'Nunito Sans', sans-serif" }}> <div className="text-sm text-brand-purple " style={{ fontFamily: "'Nunito Sans', sans-serif" }}>
{sub.user.email} {sub.user.email}
</div> </div>
</td> </TableCell>
<td className="p-4"> <TableCell>
<div className="text-[var(--purple-ink)]" style={{ fontFamily: "'Nunito Sans', sans-serif" }}> <div className="text-[var(--purple-ink)]" style={{ fontFamily: "'Nunito Sans', sans-serif" }}>
{sub.plan.name} {sub.plan.name}
</div> </div>
<div className="text-xs text-brand-purple "> <div className="text-xs text-brand-purple ">
{sub.plan.billing_cycle} {sub.plan.billing_cycle}
</div> </div>
</td> </TableCell>
<td className="p-4"> <TableCell>
<StatusBadge status={sub.status} /> <StatusBadge status={sub.status} />
</td> </TableCell>
<td className="p-4"> <TableCell>
<div className="text-sm text-[var(--purple-ink)]" style={{ fontFamily: "'Nunito Sans', sans-serif" }}> <div className="text-sm text-[var(--purple-ink)]" style={{ fontFamily: "'Nunito Sans', sans-serif" }}>
<div>{formatDate(sub.start_date)}</div> <div>{formatDate(sub.start_date)}</div>
<div className="text-xs text-brand-purple ">to {formatDate(sub.end_date)}</div> <div className="text-xs text-brand-purple ">to {formatDate(sub.end_date)}</div>
</div> </div>
</td> </TableCell>
<td className="p-4 text-right text-[var(--purple-ink)]" style={{ fontFamily: "'Inter', sans-serif" }}> <TableCell
align="text-right"
className="text-[var(--purple-ink)]"
style={{ fontFamily: "'Inter', sans-serif" }}
>
{formatPrice(sub.base_subscription_cents || 0)} {formatPrice(sub.base_subscription_cents || 0)}
</td> </TableCell>
<td className="p-4 text-right text-[var(--orange-light)]" style={{ fontFamily: "'Inter', sans-serif" }}> <TableCell
align="text-right"
className="text-[var(--orange-light)]"
style={{ fontFamily: "'Inter', sans-serif" }}
>
{formatPrice(sub.donation_cents || 0)} {formatPrice(sub.donation_cents || 0)}
</td> </TableCell>
<td className="p-4 text-right font-semibold text-[var(--purple-ink)]" style={{ fontFamily: "'Inter', sans-serif" }}> <TableCell
align="text-right"
className="font-semibold text-[var(--purple-ink)]"
style={{ fontFamily: "'Inter', sans-serif" }}
>
{formatPrice(sub.amount_paid_cents || 0)} {formatPrice(sub.amount_paid_cents || 0)}
</td> </TableCell>
<td className="p-4"> <TableCell>
<Button <Button
size="sm" size="sm"
variant="ghost" variant="ghost"
@@ -90,8 +113,8 @@ const SubscriptionRow = ({
> >
{isExpanded ? <ChevronUp className="h-4 w-4" /> : <ChevronDown className="h-4 w-4" />} {isExpanded ? <ChevronUp className="h-4 w-4" /> : <ChevronDown className="h-4 w-4" />}
</Button> </Button>
</td> </TableCell>
<td className="p-4"> <TableCell>
<div className="flex items-center justify-center gap-2"> <div className="flex items-center justify-center gap-2">
{hasPermission('subscriptions.edit') && ( {hasPermission('subscriptions.edit') && (
<Button <Button
@@ -113,12 +136,12 @@ const SubscriptionRow = ({
</Button> </Button>
)} )}
</div> </div>
</td> </TableCell>
</tr> </tr>
{isExpanded && ( {isExpanded && (
<tr className="bg-[var(--lavender-400)]/30"> <tr className="bg-[var(--lavender-400)]/30">
<td colSpan={9} className="p-6"> <TableCell colSpan={9} className="p-6">
<div className="space-y-4"> <div className="space-y-4">
<h4 className="font-semibold text-[var(--purple-ink)] text-lg mb-4" style={{ fontFamily: "'Inter', sans-serif" }}> <h4 className="font-semibold text-[var(--purple-ink)] text-lg mb-4" style={{ fontFamily: "'Inter', sans-serif" }}>
Transaction Details Transaction Details
@@ -260,7 +283,7 @@ const SubscriptionRow = ({
</div> </div>
</div> </div>
</div> </div>
</td> </TableCell>
</tr> </tr>
)} )}
</> </>
@@ -307,9 +330,14 @@ const SubscriptionsTable = ({
)) ))
) : ( ) : (
<tr> <tr>
<td colSpan={9} className="p-12 text-center text-brand-purple " style={{ fontFamily: "'Nunito Sans', sans-serif" }}> <TableCell
align="text-center"
className="p-12 text-brand-purple "
style={{ fontFamily: "'Nunito Sans', sans-serif" }}
colSpan={9}
>
No subscriptions found No subscriptions found
</td> </TableCell>
</tr> </tr>
)} )}
</tbody> </tbody>