From 5f88b2ca65754de445f442f16b02e991a8e8c193 Mon Sep 17 00:00:00 2001 From: root Date: Fri, 22 May 2026 11:11:01 +0000 Subject: [PATCH] feat: role-based notification settings, push via DB trigger --- .../notifications/NotificationSettings.jsx | 19 ++++++++++++------- src/layouts/AppShell.jsx | 1 + 2 files changed, 13 insertions(+), 7 deletions(-) diff --git a/src/components/notifications/NotificationSettings.jsx b/src/components/notifications/NotificationSettings.jsx index aae93de..c12b605 100644 --- a/src/components/notifications/NotificationSettings.jsx +++ b/src/components/notifications/NotificationSettings.jsx @@ -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 }) { Что уведомлять
- {NOTIF_TYPES.map(({ key, label, description }) => ( + {visibleTypes.map(({ key, label, description }) => (