67 lines
3.1 KiB
TypeScript
67 lines
3.1 KiB
TypeScript
import { LoaderFunctionArgs, useLoaderData } from "react-router";
|
|
import { useTranslation } from "react-i18next";
|
|
import ServerError from "~/components/ui/errors/ServerError";
|
|
import NotificationMessagesTable from "~/modules/notifications/components/NotificationMessagesTable";
|
|
import NotificationService, { IGetIntegrationsData, IGetMessagesData, IGetSubscribersData } from "~/modules/notifications/services/.server/NotificationService";
|
|
import { useLocaleFormatters } from "~/locale/format";
|
|
import { verifyUserHasPermission } from "~/utils/helpers/.server/PermissionsService";
|
|
|
|
type LoaderData = {
|
|
subscribers: IGetSubscribersData | null;
|
|
messages: IGetMessagesData | null;
|
|
integrations: IGetIntegrationsData | null;
|
|
};
|
|
export const loader = async ({ request }: LoaderFunctionArgs) => {
|
|
await verifyUserHasPermission(request, "admin.notifications.view");
|
|
const subscribers = await NotificationService.getSubscribers({});
|
|
const messages = await NotificationService.getMessages({});
|
|
const integrations = await NotificationService.getIntegrations();
|
|
const data: LoaderData = {
|
|
subscribers,
|
|
messages,
|
|
integrations,
|
|
};
|
|
return data;
|
|
};
|
|
|
|
export default function () {
|
|
const { t } = useTranslation();
|
|
const formatters = useLocaleFormatters();
|
|
const data = useLoaderData<LoaderData>();
|
|
return (
|
|
<div className="mx-auto mb-12 max-w-5xl space-y-5 px-4 py-4 sm:px-6 lg:px-8 xl:max-w-7xl">
|
|
<div className="border-border border-b pb-5">
|
|
<h3 className="text-foreground text-lg leading-6 font-medium">{t("shared.overview")}</h3>
|
|
</div>
|
|
<dl className="grid gap-2 sm:grid-cols-3">
|
|
<div className="bg-card border-border overflow-hidden rounded-lg border px-4 py-3 shadow-xs">
|
|
<dt className="text-muted-foreground truncate text-xs font-medium uppercase">
|
|
<div>{t("notifications.admin.overview.subscribers")}</div>
|
|
</dt>
|
|
<dd className="text-foreground mt-1 truncate text-2xl font-semibold">{formatters.number(data.subscribers?.totalCount ?? 0)}</dd>
|
|
</div>
|
|
<div className="bg-card border-border overflow-hidden rounded-lg border px-4 py-3 shadow-xs">
|
|
<dt className="text-muted-foreground truncate text-xs font-medium uppercase">
|
|
<div>{t("notifications.admin.overview.messages")}</div>
|
|
</dt>
|
|
<dd className="text-foreground mt-1 truncate text-2xl font-semibold">{formatters.number(data.messages?.totalCount ?? 0)}</dd>
|
|
</div>
|
|
<div className="bg-card border-border overflow-hidden rounded-lg border px-4 py-3 shadow-xs">
|
|
<dt className="text-muted-foreground flex items-center space-x-2 truncate text-xs font-medium uppercase">
|
|
<div>{t("notifications.admin.overview.integrations")}</div>
|
|
</dt>
|
|
<dd className="text-foreground mt-1 flex items-baseline space-x-1 truncate text-2xl font-semibold">
|
|
<div>{formatters.number(data.integrations?.data?.length ?? 0)}</div>
|
|
</dd>
|
|
</div>
|
|
</dl>
|
|
|
|
<NotificationMessagesTable items={data.messages} withPagination={false} />
|
|
</div>
|
|
);
|
|
}
|
|
|
|
export function ErrorBoundary() {
|
|
return <ServerError />;
|
|
}
|