FR-6.1/6.2: Sandra recebe push quando pedido entra em pending_approval; Rafael recebe quando pedido é aprovado ou recusado. Service worker registrado em background (PWA-ready via public/sw.js). FR-6.3: Badge na Topbar busca GET /notifications/pending-count (supervisores veem count de pending_approval; reps veem 0). Intervalo de 30s. FR-6.4: Botão Compartilhar no OrderDetailPage para pedidos approved/invoiced (apenas reps). Usa navigator.share() com texto formatado para WhatsApp. Infra: modelo PushSubscription (Prisma), NotificationsModule (subscribe/ unsubscribe/pending-count + PushService VAPID), VAPID keys em .env, integração no OrdersService (create → supervisores, approve/reject → repId). Co-Authored-By: Claude Sonnet 4.6 (1M context) <noreply@anthropic.com>
23 lines
643 B
JavaScript
23 lines
643 B
JavaScript
// Service Worker SAR — C6 Web Push
|
|
// Recebe push events e exibe notificação nativa. Clique abre a URL do payload.
|
|
|
|
self.addEventListener('push', (event) => {
|
|
const data = event.data?.json() ?? {};
|
|
event.waitUntil(
|
|
self.registration.showNotification(data.title ?? 'SAR', {
|
|
body: data.body ?? '',
|
|
icon: '/sar-icon.png',
|
|
badge: '/sar-icon.png',
|
|
data: data.url ? { url: data.url } : undefined,
|
|
}),
|
|
);
|
|
});
|
|
|
|
self.addEventListener('notificationclick', (event) => {
|
|
event.notification.close();
|
|
const url = event.notification.data?.url;
|
|
if (url) {
|
|
event.waitUntil(clients.openWindow(url));
|
|
}
|
|
});
|