112 lines
3.6 KiB
TypeScript
112 lines
3.6 KiB
TypeScript
import type {
|
|
AdminDashboardVM,
|
|
AdminDashboardWidgetVM,
|
|
} from "@hivegrid/view-models";
|
|
import { FeatherArrowRight } from "@subframe/core";
|
|
import { Link } from "react-router";
|
|
import { useTranslation } from "react-i18next";
|
|
|
|
import { BadgeFeedback } from "~/ui/components/BadgeFeedback";
|
|
import { Button } from "~/ui/components/Button";
|
|
import { Card } from "~/ui/components/Card";
|
|
|
|
export function AdminPersonalizedDashboard({
|
|
vm,
|
|
}: {
|
|
vm: AdminDashboardVM;
|
|
}): React.JSX.Element {
|
|
const { t } = useTranslation();
|
|
return (
|
|
<section
|
|
className="space-y-4"
|
|
aria-labelledby="personalized-dashboard-title"
|
|
data-ui-id="ui.admin.personalizedDashboard"
|
|
>
|
|
<div className="flex flex-wrap items-start justify-between gap-3">
|
|
<div>
|
|
<h2
|
|
id="personalized-dashboard-title"
|
|
className="text-body-large-0 font-body-large-0 text-text-neutral-primary"
|
|
>
|
|
{t("admin.dashboard.personalized.title")}
|
|
</h2>
|
|
<p className="text-body-small-regular-150 font-body-small-regular-150 text-text-neutral-secondary">
|
|
{t("admin.dashboard.personalized.description")}
|
|
</p>
|
|
</div>
|
|
<div
|
|
className="flex flex-wrap gap-2"
|
|
aria-label={t("admin.dashboard.personalized.activeRoles")}
|
|
>
|
|
{vm.roles.map((role) => (
|
|
<BadgeFeedback key={role} farbe="subtle-neutral" size="small">
|
|
{t(`admin.sales.adminRoles.roleNames.${role}`)}
|
|
</BadgeFeedback>
|
|
))}
|
|
</div>
|
|
</div>
|
|
{vm.widgets.length === 0 ? (
|
|
<Card variant="neutral">
|
|
<p className="text-body-small-regular-150 font-body-small-regular-150 text-text-neutral-secondary">
|
|
{t("admin.dashboard.personalized.empty")}
|
|
</p>
|
|
</Card>
|
|
) : (
|
|
<div className="grid gap-4 md:grid-cols-2 xl:grid-cols-4">
|
|
{vm.widgets.map((widget) => (
|
|
<PersonalizedWidget key={widget.id} widget={widget} />
|
|
))}
|
|
</div>
|
|
)}
|
|
</section>
|
|
);
|
|
}
|
|
|
|
function PersonalizedWidget({ widget }: { widget: AdminDashboardWidgetVM }) {
|
|
const { t, i18n } = useTranslation();
|
|
const translatedValue = i18n.exists(widget.value)
|
|
? t(widget.value)
|
|
: widget.value;
|
|
return (
|
|
<Card>
|
|
<div className="flex w-full items-start justify-between gap-3">
|
|
<div className="min-w-0">
|
|
<h3 className="text-body-small-medium-0 font-body-small-medium-0 text-text-neutral-primary">
|
|
{t(widget.titleKey)}
|
|
</h3>
|
|
<p className="text-body-extra-small-regular-150 font-body-extra-small-regular-150 text-text-neutral-secondary">
|
|
{t(widget.descriptionKey)}
|
|
</p>
|
|
</div>
|
|
<BadgeFeedback
|
|
farbe={dashboardWidgetBadgeTone(widget.tone)}
|
|
size="small"
|
|
>
|
|
{t(`admin.dashboard.personalized.tones.${widget.tone}`)}
|
|
</BadgeFeedback>
|
|
</div>
|
|
<p className="text-heading-2 font-heading-2 text-text-neutral-primary">
|
|
{translatedValue}
|
|
</p>
|
|
<Link to={widget.href}>
|
|
<Button
|
|
variant="tertiary"
|
|
size="small"
|
|
iconRight={<FeatherArrowRight />}
|
|
>
|
|
{t("admin.dashboard.personalized.open")}
|
|
</Button>
|
|
</Link>
|
|
</Card>
|
|
);
|
|
}
|
|
|
|
function dashboardWidgetBadgeTone(
|
|
tone: AdminDashboardWidgetVM["tone"]
|
|
): "subtle-positive" | "subtle-negative" | "subtle-warning" | "subtle-neutral" {
|
|
if (tone === "positive") return "subtle-positive";
|
|
if (tone === "critical") return "subtle-negative";
|
|
if (tone === "warning") return "subtle-warning";
|
|
return "subtle-neutral";
|
|
}
|