feat: role-based notification settings, push via DB trigger
This commit is contained in:
parent
f099cf20d8
commit
5f88b2ca65
|
|
@ -4,16 +4,21 @@ import { usePushNotifications } from "../../hooks/usePushNotifications";
|
||||||
import { Panel } from "../UI/Panel";
|
import { Panel } from "../UI/Panel";
|
||||||
import { Bell, Settings } from "../UI/Icons";
|
import { Bell, Settings } from "../UI/Icons";
|
||||||
|
|
||||||
const NOTIF_TYPES = [
|
const ALL_NOTIF_TYPES = [
|
||||||
{ key: "order_status_change", label: "Изменение статуса заказа", description: "Уведомления когда меняется статус заказа" },
|
{ key: "order_status_change", label: "Изменение статуса", description: "Статус заказа или доставки изменился", roles: ["manager", "logistician", "driver", "admin"] },
|
||||||
{ key: "driver_assigned", label: "Назначение водителя", description: "Уведомления когда вам назначается заказ" },
|
{ key: "driver_assigned", label: "Назначение на заказ", description: "Вам назначили заказ или доставку", roles: ["driver"] },
|
||||||
{ key: "delivery_problem", label: "Проблемы с доставкой", description: "Уведомления об отменах и проблемах" },
|
{ 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 { prefs, isLoading: prefsLoading, updatePref } = useNotificationPreferences(userId);
|
||||||
const { isSupported, isSubscribed, isLoading: pushLoading, subscribe, unsubscribe } = usePushNotifications(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;
|
const loading = prefsLoading || pushLoading;
|
||||||
|
|
||||||
return (
|
return (
|
||||||
|
|
@ -71,7 +76,7 @@ export function NotificationSettings({ userId, onBack }) {
|
||||||
Что уведомлять
|
Что уведомлять
|
||||||
</h3>
|
</h3>
|
||||||
<div className="space-y-3">
|
<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">
|
<label key={key} className="flex items-start justify-between gap-3">
|
||||||
<div>
|
<div>
|
||||||
<p className="text-sm font-medium">{label}</p>
|
<p className="text-sm font-medium">{label}</p>
|
||||||
|
|
@ -96,4 +101,4 @@ export function NotificationSettings({ userId, onBack }) {
|
||||||
</Panel>
|
</Panel>
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
@ -31,6 +31,7 @@ export const AppShell = ({
|
||||||
<div className="mx-auto max-w-2xl">
|
<div className="mx-auto max-w-2xl">
|
||||||
<NotificationSettings
|
<NotificationSettings
|
||||||
userId={user?.id}
|
userId={user?.id}
|
||||||
|
userRole={user?.role}
|
||||||
onBack={() => setShowNotifSettings(false)}
|
onBack={() => setShowNotifSettings(false)}
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue