feat: role-based notification settings, push via DB trigger

This commit is contained in:
root 2026-05-22 11:11:01 +00:00
parent f099cf20d8
commit 5f88b2ca65
2 changed files with 13 additions and 7 deletions

View File

@ -4,16 +4,21 @@ import { usePushNotifications } from "../../hooks/usePushNotifications";
import { Panel } from "../UI/Panel";
import { Bell, Settings } from "../UI/Icons";
const NOTIF_TYPES = [
{ key: "order_status_change", label: "Изменение статуса заказа", description: "Уведомления когда меняется статус заказа" },
{ key: "driver_assigned", label: "Назначение водителя", description: "Уведомления когда вам назначается заказ" },
{ key: "delivery_problem", label: "Проблемы с доставкой", description: "Уведомления об отменах и проблемах" },
const ALL_NOTIF_TYPES = [
{ key: "order_status_change", label: "Изменение статуса", description: "Статус заказа или доставки изменился", roles: ["manager", "logistician", "driver", "admin"] },
{ key: "driver_assigned", label: "Назначение на заказ", description: "Вам назначили заказ или доставку", roles: ["driver"] },
{ key: "driver_unassigned", label: "Снятие с заказа", description: "Вас сняли с заказа или доставки", roles: ["driver"] },
{ key: "delivery_problem", label: "Проблемы и отмены", description: "Отмена, проблема, невозможность дозвониться", roles: ["manager", "logistician", "admin"] },
{ key: "new_order", label: "Новый заказ", description: "Создан новый заказ в системе", roles: ["manager", "logistician", "admin"] },
{ key: "group_status_change", label: "Изменение группы доставки", description: "Статус группы доставки обновлён", roles: ["logistician", "manager", "admin"] },
];
export function NotificationSettings({ userId, onBack }) {
export function NotificationSettings({ userId, userRole, onBack }) {
const { prefs, isLoading: prefsLoading, updatePref } = useNotificationPreferences(userId);
const { isSupported, isSubscribed, isLoading: pushLoading, subscribe, unsubscribe } = usePushNotifications(userId);
const role = userRole || "manager";
const visibleTypes = ALL_NOTIF_TYPES.filter((t) => t.roles.includes(role));
const loading = prefsLoading || pushLoading;
return (
@ -71,7 +76,7 @@ export function NotificationSettings({ userId, onBack }) {
Что уведомлять
</h3>
<div className="space-y-3">
{NOTIF_TYPES.map(({ key, label, description }) => (
{visibleTypes.map(({ key, label, description }) => (
<label key={key} className="flex items-start justify-between gap-3">
<div>
<p className="text-sm font-medium">{label}</p>

View File

@ -31,6 +31,7 @@ export const AppShell = ({
<div className="mx-auto max-w-2xl">
<NotificationSettings
userId={user?.id}
userRole={user?.role}
onBack={() => setShowNotifSettings(false)}
/>
</div>