import { useEffect, useState } from 'react' import { Card, Badge } from '../ui' import { getCustomerAboStatus } from '../../lib/teamApi' import { fmtDate, productLabelOf } from '../../lib/format' import { storageLabel } from '../../lib/storageFormat' import StundenkontoLeiste from './StundenkontoLeiste' // Abo-Status eines Kunden (Reiter "Abo & Angebote"): Appwrite-Spiegel des Stripe-Abos, fuer alle Mitarbeiter export default function AboStatusCard({ customerId }) { const [abo, setAbo] = useState(null) const [error, setError] = useState(null) useEffect(() => { let alive = true setAbo(null) setError(null) getCustomerAboStatus(customerId) .then((a) => { if (alive) setAbo(a) }) .catch((err) => { if (alive) setError(err.message || 'Abo konnte nicht geladen werden.') }) return () => { alive = false } }, [customerId]) // Nur ein aktives Wartungs-Abo hat ein Stundenkonto (das Hosting-Abo nicht) const mitKonto = Boolean(abo && abo.productKey === 'wartung' && abo.active) return ( {error &&
{error}
} {!abo && !error &&
Wird geladen …
} {abo && !abo.status &&

kein Abo

} {abo && abo.status && (
Abo
{productLabelOf(abo.productKey)} {abo.active ? 'aktiv' : abo.status}
Leistungsbeginn
{fmtDate(abo.serviceStart)}
{abo.active && <>
Nächste Abbuchung
{fmtDate(abo.currentPeriodEnd)}
} {abo.cancelAt && <>
Gekündigt zum
{fmtDate(abo.cancelAt)}
}
Zusatzspeicher
{storageLabel(abo.storageUnits)}
)} {mitKonto && }
) }