shellphone.app/app/public-area/pages/open.tsx

44 lines
1.4 KiB
TypeScript
Raw Normal View History

import type { BlitzPage } from "blitz";
2021-08-29 21:28:42 +00:00
import { useQuery } from "blitz";
2021-08-28 20:17:01 +00:00
import getMetrics from "../queries/get-metrics";
2021-08-29 21:28:42 +00:00
import Layout from "../components/layout";
2021-08-28 20:17:01 +00:00
const initialData = {
2021-10-20 22:24:29 +00:00
users: 0,
2021-08-28 20:17:01 +00:00
phoneNumbers: 0,
smsExchanged: 0,
minutesCalled: 0,
2021-10-20 22:24:29 +00:00
averageMinutesCalled: 0,
2021-08-28 20:17:01 +00:00
};
const OpenMetrics: BlitzPage = () => {
2021-08-28 20:17:01 +00:00
const [metrics] = useQuery(getMetrics, {}, { suspense: false, initialData });
2021-10-20 22:24:29 +00:00
const { users, phoneNumbers, smsExchanged, minutesCalled, averageMinutesCalled } = metrics ?? initialData;
2021-08-28 20:17:01 +00:00
return (
2021-08-29 21:28:42 +00:00
<dl className="mt-5 grid grid-cols-1 gap-5 sm:grid-cols-3">
2021-10-20 22:24:29 +00:00
<Card title="Users" value={users} />
2021-08-29 21:28:42 +00:00
<Card title="Phone Numbers Registered" value={phoneNumbers} />
<Card title="SMS Exchanged" value={smsExchanged} />
<Card title="Minutes on Call" value={minutesCalled} />
2021-10-20 22:24:29 +00:00
<Card title="Avg Call Length in Minutes" value={averageMinutesCalled} />
2021-08-29 21:28:42 +00:00
</dl>
);
};
function Card({ title, value }: { title: string; value: number | string }) {
2021-08-28 19:56:26 +00:00
return (
<div className="px-4 py-5 bg-white shadow rounded-lg overflow-hidden sm:p-6">
<dt className="text-sm font-medium text-gray-500 truncate">{title}</dt>
<dd className="mt-1 text-3xl font-semibold text-gray-900">{value}</dd>
</div>
);
}
2021-08-29 21:28:42 +00:00
OpenMetrics.getLayout = (page) => <Layout title="Open Metrics">{page}</Layout>;
OpenMetrics.suppressFirstRenderFlicker = true;
export default OpenMetrics;