import { useEffect, useState } from "react"; import { FormattedDate, FormattedMessage, FormattedNumber } from "react-intl"; import { Link } from "react-router-dom"; import PageSpinner from "Element/PageSpinner"; import useEventPublisher from "Feed/EventPublisher"; import SnortApi, { Subscription } from "SnortApi"; import { mapPlanName } from "."; import Icon from "Icons/Icon"; export default function ManageSubscriptionPage() { const publisher = useEventPublisher(); const api = new SnortApi(undefined, publisher); const [subs, setSubs] = useState>(); const [error, setError] = useState(""); useEffect(() => { (async () => { try { const s = await api.listSubscriptions(); setSubs(s); } catch (e) { if (e instanceof Error) { setError(e.message); } else { setError("Unknown error"); } } })(); }, []); if (subs === undefined) { return ; } return ( <>

{subs.map(a => { const created = new Date(a.created); const expires = new Date(a.expires); const now = new Date(); const daysToExpire = Math.floor((expires.getTime() - now.getTime()) / 8.64e7); const hoursToExpire = Math.floor((expires.getTime() - now.getTime()) / 3.6e6); const isExpired = expires < now; return (
{mapPlanName(a.type)}

{daysToExpire >= 1 && (

)} {daysToExpire >= 0 && daysToExpire < 1 && (

)} {daysToExpire < 0 && (

)}
{isExpired && (
)}
); })} {subs.length === 0 && (

), }} />

)} {error && {error}} ); }