Files
HiveGrid-Wireframes/03 Quellen und Referenzen/hivegrid-cloud/apps/web/app/components/screens/notifications/NotificationSettingsPage.tsx
T
2026-07-08 16:15:37 +02:00

147 lines
6.5 KiB
TypeScript

// AK-P3 Interim-UI (AD-28) — Notification-Settings preview screen composed from
// ~/ui (A6 settings archetype). Pure presentational component: renders the
// server-built NotificationSettingsVM passed as a prop; toggles run through
// injected action callbacks (M014) implemented fetcher-side by the hosting
// route. Final Subframe optics land as a tracked design-nachzug once David's
// D-P3 ships.
import { useTranslation } from "react-i18next";
import type { NotificationSettingChannel, NotificationSettingsVM } from "@hivegrid/view-models";
import { Alert } from "~/ui/components/Alert";
import { Switch } from "~/ui/components/Switch";
export type NotificationSettingsActions = {
onTogglePreference: (input: { category: string; channel: NotificationSettingChannel; enabled: boolean }) => void;
/** Master switch: true = turn ALL emails off (writes every category). */
onSetEmailMaster: (disableAllEmails: boolean) => void;
};
export type NotificationSettingsPageProps = {
vm: NotificationSettingsVM;
/** Plain-text result of the last save action (null = nothing saved yet). */
saveState: { ok: boolean; errorText?: string } | null;
actions: NotificationSettingsActions;
};
export function NotificationSettingsPage({ vm, saveState, actions }: NotificationSettingsPageProps) {
const { t } = useTranslation();
// Loading / not-ready: keep the marker so the shell + e2e see a stable surface.
if (vm.status !== "ready" || !vm.data) {
return <div className="flex w-full flex-col gap-6 p-6" data-ui-id="ui.settings.notifications.page" />;
}
const { groups, allEmailsDisabled } = vm.data;
return (
<div className="mx-auto flex w-full max-w-3xl flex-col gap-6 p-6" data-ui-id="ui.settings.notifications.page">
{/* Header: title + subtitle (0px rhythm) */}
<div className="flex flex-col gap-0">
<span className="text-heading-2 font-heading-2 text-text-neutral-primary">{t("settings.notifications.heading")}</span>
<span className="text-body-default-regular-150 font-body-default-regular-150 text-text-neutral-secondary">
{t("settings.notifications.description")}
</span>
</div>
{saveState ? (
<div data-ui-id="ui.settings.notifications.saveState">
{saveState.ok ? (
<Alert variant="success" title={t("settings.notifications.saved")} />
) : (
<Alert variant="error" title={saveState.errorText ?? t("settings.notifications.errors.invalidPreferenceAction")} />
)}
</div>
) : null}
{/* Master switch: all emails off (card surface, 16px padding) */}
<div
className="flex flex-wrap items-center justify-between gap-4 rounded-md border border-solid border-border-default bg-surface-neutral-primary p-4"
data-ui-id="ui.settings.notifications.master.email"
>
<div className="flex flex-col gap-0">
<span className="text-body-default-medium-0 font-body-default-medium-0 text-text-neutral-primary">
{t("settings.notifications.master.heading")}
</span>
<span className="text-body-small-regular-150 font-body-small-regular-150 text-text-neutral-secondary">
{t("settings.notifications.master.description")}
</span>
</div>
<label className="flex items-center gap-2">
<span className="text-body-default-regular-0 font-body-default-regular-0 text-text-neutral-primary">
{t("settings.notifications.master.disableAllEmails")}
</span>
<Switch
checked={allEmailsDisabled}
onCheckedChange={(checked: boolean) => actions.onSetEmailMaster(checked)}
data-ui-id="ui.settings.notifications.master.switch"
/>
</label>
</div>
{/* Event types grouped per module (A6) */}
<div className="flex flex-col gap-4">
{groups.map((group) => (
<div
key={group.module}
className="flex flex-col rounded-md border border-solid border-border-default bg-surface-neutral-primary"
data-ui-id={`ui.settings.notifications.module.${group.module}`}
>
<span className="border-b border-solid border-border-default px-4 py-2 text-body-small-medium-0 font-body-small-medium-0 uppercase text-text-neutral-tertiary">
{t(group.moduleLabelKey)}
</span>
{group.categories.map((category) => (
<div
key={category.category}
className="flex flex-wrap items-center justify-between gap-4 p-4"
data-ui-id={`ui.settings.notifications.category.${category.category}`}
>
<div className="flex flex-col gap-0">
<span className="text-body-default-medium-0 font-body-default-medium-0 text-text-neutral-primary">
{t(category.labelKey)}
</span>
<span className="text-body-small-regular-150 font-body-small-regular-150 text-text-neutral-secondary">
{t("settings.notifications.categoryDescription", { category: String(t(category.labelKey)).toLowerCase() })}
</span>
</div>
<div className="flex flex-wrap items-center gap-4">
<ChannelToggle
label={t("settings.notifications.channels.inApp")}
checked={category.channels.IN_APP}
uiId={`ui.settings.notifications.preference.${category.category}.in_app`}
onChange={(enabled) => actions.onTogglePreference({ category: category.category, channel: "IN_APP", enabled })}
/>
<ChannelToggle
label={t("settings.notifications.channels.email")}
checked={category.channels.EMAIL}
uiId={`ui.settings.notifications.preference.${category.category}.email`}
onChange={(enabled) => actions.onTogglePreference({ category: category.category, channel: "EMAIL", enabled })}
/>
</div>
</div>
))}
</div>
))}
</div>
</div>
);
}
function ChannelToggle({
label,
checked,
uiId,
onChange,
}: {
label: string;
checked: boolean;
uiId: string;
onChange: (enabled: boolean) => void;
}) {
return (
<label className="flex items-center gap-2" data-ui-id={uiId}>
<span className="text-body-default-regular-0 font-body-default-regular-0 text-text-neutral-primary">{label}</span>
<Switch checked={checked} onCheckedChange={onChange} />
</label>
);
}