import { useMutation } from "@tanstack/react-query"; import { formatDistanceToNow } from "date-fns"; import { HeartIcon } from "lucide-react"; import { toast } from "sonner"; import { healthCheckVolumeMutation, updateVolumeMutation } from "~/client/api-client/@tanstack/react-query.gen"; import { OnOff } from "~/client/components/onoff"; import { Button } from "~/client/components/ui/button"; import { Card, CardContent, CardDescription, CardHeader, CardTitle } from "~/client/components/ui/card"; import type { Volume } from "~/client/lib/types"; type Props = { volume: Volume; }; export const HealthchecksCard = ({ volume }: Props) => { const timeAgo = formatDistanceToNow(volume.lastHealthCheck, { addSuffix: true, }); const healthcheck = useMutation({ ...healthCheckVolumeMutation(), onSuccess: (d) => { if (d.error) { toast.error("Health check failed", { description: d.error }); return; } toast.success("Health check completed", { description: "The volume is healthy." }); }, onError: (error) => { toast.error("Health check failed", { description: error.message }); }, }); const toggleAutoRemount = useMutation({ ...updateVolumeMutation(), onSuccess: (d) => { toast.success("Volume updated", { description: `Auto remount is now ${d.autoRemount ? "enabled" : "paused"}.`, }); }, onError: (error) => { toast.error("Update failed", { description: error.message }); }, }); return ( Health Checks Monitor and automatically remount volumes on errors to ensure availability.
{volume.lastError && {volume.lastError}} {volume.status === "mounted" && Healthy} {volume.status !== "unmounted" && ( Checked {timeAgo || "never"} )} Remount on error toggleAutoRemount.mutate({ path: { name: volume.name }, body: { autoRemount: !volume.autoRemount } }) } disabled={toggleAutoRemount.isPending} enabledLabel="Enabled" disabledLabel="Paused" />
{volume.status !== "unmounted" && (
)}
); };