Browse Source

no message

production
[email protected] 1 month ago
parent
commit
85c0962a2f
2 changed files with 33 additions and 25 deletions
  1. +21
    -15
      src/components/ClientMonitor/ClientMonitorPage.tsx
  2. +12
    -10
      src/components/ClientMonitor/PrinterMonitorTab.tsx

+ 21
- 15
src/components/ClientMonitor/ClientMonitorPage.tsx View File

@@ -27,7 +27,17 @@ import Search from "@mui/icons-material/Search";
import PageTitleBar from "@/components/PageTitleBar";
import { NEXT_PUBLIC_API_URL } from "@/config/api";
import { clientAuthFetch } from "@/app/utils/clientAuthFetch";
import { arrayToDateTimeString } from "@/app/utils/formatUtil";
import dayjs from "dayjs";

function formatApiDateTime(value: unknown): string {
if (value == null) return "—";
if (Array.isArray(value)) {
return arrayToDateTimeString(value as (number | undefined)[]);
}
const d = dayjs(value as string | number);
return d.isValid() ? d.format("YYYY-MM-DD HH:mm:ss") : "—";
}
import PrinterMonitorTab from "@/components/ClientMonitor/PrinterMonitorTab";

type ClientRow = {
@@ -383,17 +393,17 @@ export default function ClientMonitorPage() {
</TableCell>
<TableCell>
{formatAgo(row.secondsSinceHeartbeat)}
{row.lastHeartbeat && (
<Typography variant="caption" display="block" color="text.secondary">
{dayjs(row.lastHeartbeat).format("HH:mm:ss")}
</Typography>
)}
</TableCell>
<TableCell>
{row.lastActivity
? dayjs(row.lastActivity).format("HH:mm:ss")
: "—"}
{row.lastHeartbeat && (
<Typography variant="caption" display="block" color="text.secondary">
{formatApiDateTime(row.lastHeartbeat).slice(11)}
</Typography>
)}
</TableCell>
<TableCell>
{row.lastActivity
? formatApiDateTime(row.lastActivity).slice(11)
: "—"}
</TableCell>
</TableRow>
);
})
@@ -528,11 +538,7 @@ export default function ClientMonitorPage() {
const st = STATUS_LABEL[row.status] ?? STATUS_LABEL.offline;
return (
<TableRow key={`${row.id ?? row.recordedAt}-${row.deviceId}`} hover>
<TableCell>
{row.recordedAt
? dayjs(row.recordedAt).format("YYYY-MM-DD HH:mm:ss")
: "—"}
</TableCell>
<TableCell>{formatApiDateTime(row.recordedAt)}</TableCell>
<TableCell>
<Chip size="small" color={st.color} label={st.label} />
</TableCell>


+ 12
- 10
src/components/ClientMonitor/PrinterMonitorTab.tsx View File

@@ -16,8 +16,18 @@ import {
} from "@mui/material";
import { NEXT_PUBLIC_API_URL } from "@/config/api";
import { clientAuthFetch } from "@/app/utils/clientAuthFetch";
import { arrayToDateTimeString } from "@/app/utils/formatUtil";
import dayjs from "dayjs";

function formatApiDateTime(value: unknown): string {
if (value == null) return "—";
if (Array.isArray(value)) {
return arrayToDateTimeString(value as (number | undefined)[]);
}
const d = dayjs(value as string | number);
return d.isValid() ? d.format("YYYY-MM-DD HH:mm:ss") : "—";
}

type PrinterRow = {
id: number;
code?: string;
@@ -172,11 +182,7 @@ export default function PrinterMonitorTab({ active, refreshAt = 0 }: Props) {
{row.errorMessage ?? "無法連線"}
</Typography>
</TableCell>
<TableCell>
{row.lastCheckAt
? dayjs(row.lastCheckAt).format("YYYY-MM-DD HH:mm:ss")
: "—"}
</TableCell>
<TableCell>{formatApiDateTime(row.lastCheckAt)}</TableCell>
</TableRow>
))}
</TableBody>
@@ -241,11 +247,7 @@ export default function PrinterMonitorTab({ active, refreshAt = 0 }: Props) {
<TableCell align="right">
{row.latencyMs != null ? row.latencyMs : "—"}
</TableCell>
<TableCell>
{row.lastCheckAt
? dayjs(row.lastCheckAt).format("YYYY-MM-DD HH:mm:ss")
: "—"}
</TableCell>
<TableCell>{formatApiDateTime(row.lastCheckAt)}</TableCell>
</TableRow>
);
})


Loading…
Cancel
Save