Files
Homelab-manager/web/src/components/HetznerServerCard.tsx
T
bobbanandClaude Sonnet 5.5 645816d5a8 Add a Swedish interface with a per-person language switch
A small translation system (the English text is its own key, so anything
without a Swedish entry stays English) and a Language switch in the user menu,
saved on the account (users.language) and following the browser when no choice
has been made. Swedish covers the menu, shared parts (search, tables, dialogs,
relative times), the sign-in page and the everyday pages: Dashboard, Alerts,
Servers, Updates, Maintenance, My work, Coming up, To do, Integrations and the
display settings. Server-written messages stay English for now.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
2026-11-12 21:49:49 +01:00

71 lines
2.9 KiB
TypeScript

import { useEffect, useState } from "react";
import { Link } from "react-router-dom";
import { api, type HetznerForServer } from "../api/client";
import TimeAgo from "./TimeAgo";
import { ForecastText, StatusBadge, TrafficBar } from "../pages/Hetzner";
import { t } from "../i18n";
/** On a server's page: the Hetzner Cloud server it is (matched by address, else by name), when there is one. Nothing is shown for a server that is not at Hetzner. */
export default function HetznerServerCard({ serverId }: { serverId: number }) {
const [match, setMatch] = useState<HetznerForServer["match"]>(null);
useEffect(() => {
let live = true;
api.hetzner
.forServer(serverId)
.then((r) => live && setMatch(r.match))
.catch(() => live && setMatch(null));
return () => {
live = false;
};
}, [serverId]);
if (!match) return null;
const s = match.server;
return (
<div className="card mb-3">
<div className="card-header">
<h3 className="card-title">Hetzner Cloud</h3>
<div className="card-actions">
<Link to="/hetzner" className="btn btn-sm btn-outline-secondary">
{match.integrationName}
</Link>
</div>
</div>
<div className="card-body">
{match.problems.length > 0 && (
<ul className="mb-3">
{match.problems.map((p) => (
<li key={p.key} className={p.severity === "critical" ? "text-red" : ""}>
{p.message}
</li>
))}
</ul>
)}
<div className="row g-3">
<div className="col-6 col-lg-3">
<div className="text-secondary small">{t("Status")}</div>
<StatusBadge status={s.status} />
{s.rescueEnabled && <span className="badge bg-yellow-lt text-yellow ms-1">rescue on</span>}
</div>
<div className="col-6 col-lg-3">
<div className="text-secondary small">Type and place</div>
{s.type ?? "—"} · {s.location ?? "?"}
</div>
<div className="col-6 col-lg-3">
<div className="text-secondary small">{t("Backups")}</div>
{s.backupWindow ? (match.newestBackup ? <>newest <TimeAgo value={match.newestBackup} /></> : "on, none made yet") : "off"}
{match.snapshots > 0 && <span className="text-secondary small"> · {match.snapshots} snapshot{match.snapshots === 1 ? "" : "s"}</span>}
</div>
<div className="col-6 col-lg-3">
<div className="text-secondary small">Traffic this month</div>
<TrafficBar used={s.outgoingTraffic} included={s.includedTraffic} />
<ForecastText forecast={match.forecast} included={s.includedTraffic} />
</div>
</div>
<div className="text-secondary small mt-2">
{match.fresh ? <>read <TimeAgo value={match.updatedAt} /></> : "Hetzner could not be read lately — this is how it was"}
</div>
</div>
</div>
);
}