70 lines
3.0 KiB
TypeScript
70 lines
3.0 KiB
TypeScript
import { Link } from '@tanstack/react-router'
|
|
import type { StudentFee } from '@gruperly/shared'
|
|
import { ExternalLink, Receipt } from 'lucide-react'
|
|
import { Badge } from '../../components/ui'
|
|
import { formatPrice } from '../../lib/format'
|
|
import { feeLabel } from './format'
|
|
import { FeeStatusBadge } from './FeeStatusBadge'
|
|
import { useTranslation } from 'react-i18next'
|
|
|
|
/* "Tu cuota": only while there is something unpaid. */
|
|
export function FeeCard({ fees }: { fees: StudentFee[] }) {
|
|
const { t } = useTranslation(['student', 'common'])
|
|
if (fees.length === 0) return null
|
|
const first = fees[0] as StudentFee
|
|
const toReport = fees.filter((fee) => fee.status !== 'reported')
|
|
const total = toReport.reduce((sum, fee) => sum + fee.amount, 0)
|
|
// Cada cuota tiene su propio link de MP: con varias, se elige en Pagos.
|
|
const payable = toReport.filter((fee) => fee.checkoutUrl)
|
|
const single = payable.length === 1 ? (payable[0] as StudentFee) : null
|
|
const primary = 'flex min-h-12 items-center justify-center gap-2 rounded-xl bg-accent font-semibold text-on-accent hover:bg-accent-strong'
|
|
|
|
return (
|
|
<article className="rounded-2xl border border-border bg-surface p-5">
|
|
<div className="flex items-start justify-between gap-3">
|
|
<div className="min-w-0">
|
|
<p className="text-xs font-semibold uppercase tracking-wide text-secondary">{t('fee.yourFee')}</p>
|
|
<h2 className="mt-1 truncate text-lg font-bold text-primary">
|
|
{fees.length === 1 ? feeLabel(first) : t('fee.unpaid', { count: fees.length })}
|
|
</h2>
|
|
<p className="mt-1 text-2xl font-bold text-primary">
|
|
{formatPrice(toReport.length > 0 ? total : first.amount, first.currency)}
|
|
</p>
|
|
</div>
|
|
{fees.length === 1 ? (
|
|
<FeeStatusBadge status={first.status} />
|
|
) : toReport.some((fee) => fee.status === 'overdue') ? (
|
|
<Badge variant="warning">{t('fee.overdue')}</Badge>
|
|
) : null}
|
|
</div>
|
|
{toReport.length > 0 ? (
|
|
<div className="mt-4 space-y-2">
|
|
{single ? (
|
|
<a href={single.checkoutUrl ?? undefined} target="_blank" rel="noreferrer" className={primary}>
|
|
{t('fee.payMp')}
|
|
<ExternalLink className="size-4" aria-hidden="true" />
|
|
</a>
|
|
) : payable.length > 1 ? (
|
|
<Link to="/student/payments" className={primary}>
|
|
{t('fee.payMp')}
|
|
</Link>
|
|
) : null}
|
|
<Link
|
|
to="/student/report-payment"
|
|
className={
|
|
payable.length > 0
|
|
? 'flex min-h-12 items-center justify-center gap-2 rounded-xl border border-border font-semibold text-primary hover:bg-primary-soft'
|
|
: primary
|
|
}
|
|
>
|
|
<Receipt className="size-5" aria-hidden="true" />
|
|
{t('fee.report')}
|
|
</Link>
|
|
</div>
|
|
) : (
|
|
<p className="mt-3 text-sm text-secondary">{t('fee.awaiting')}</p>
|
|
)}
|
|
</article>
|
|
)
|
|
}
|