1 line
14 KiB
JavaScript
1 line
14 KiB
JavaScript
(globalThis.TURBOPACK||(globalThis.TURBOPACK=[])).push(["object"==typeof document?document.currentScript:void 0,83089,e=>{"use strict";var t=e.i(43476),a=e.i(71645),s=e.i(94327),l=e.i(56322);let n=["NEW_RESERVATION","RESERVATION_CANCELLED","PAYMENT_RECEIVED","SUBSCRIPTION_TRIAL_ENDING","MAINTENANCE_DUE","OFFER_EXPIRING"],r=["EMAIL","SMS","WHATSAPP","IN_APP","PUSH"],i={EMAIL:"bg-blue-100 text-blue-700 dark:bg-blue-900/40 dark:text-blue-300",SMS:"bg-green-100 text-green-700 dark:bg-green-900/40 dark:text-green-300",WHATSAPP:"bg-teal-100 text-teal-700 dark:bg-teal-900/40 dark:text-teal-300",IN_APP:"bg-purple-100 text-purple-700 dark:bg-purple-900/40 dark:text-purple-300",PUSH:"bg-orange-100 text-orange-700 dark:bg-orange-900/40 dark:text-orange-300"},d={PENDING:"bg-yellow-100 text-yellow-700 dark:bg-yellow-900/40 dark:text-yellow-300",SENT:"bg-green-100 text-green-700 dark:bg-green-900/40 dark:text-green-300",DELIVERED:"bg-green-100 text-green-700 dark:bg-green-900/40 dark:text-green-300",FAILED:"bg-red-100 text-red-700 dark:bg-red-900/40 dark:text-red-300",READ:"bg-slate-100 text-slate-600 dark:bg-slate-800 dark:text-slate-400"};e.s(["default",0,function(){let{language:e}=(0,l.useDashboardI18n)(),[c,o]=(0,a.useState)([]),[x,p]=(0,a.useState)([]),[u,h]=(0,a.useState)({}),[m,N]=(0,a.useState)("inbox"),[b,f]=(0,a.useState)(!0),[E,g]=(0,a.useState)(!1),[y,A]=(0,a.useState)(!1),[v,k]=(0,a.useState)(!1),[S,j]=(0,a.useState)(null),[I,w]=(0,a.useState)(""),[R,P]=(0,a.useState)(""),D={en:{title:"Notifications",subtitle:"Track in-app alerts, audit delivery history, and control preferences for your team account.",inbox:"Inbox",history:"History",preferences:"Preferences",markAllRead:"Mark all as read",loading:"Loading notifications…",empty:"No notifications yet.",read:"Read",markRead:"Mark as read",event:"Event",channel:"Channel",status:"Status",sentAt:"Sent at",date:"Date",allChannels:"All channels",allStatuses:"All statuses",savePreferences:"Save preferences",saving:"Saving…",failedLoad:"Failed to load notifications",failedSave:"Failed to save preferences",noHistory:"No notification history found.",channels:{EMAIL:"Email",SMS:"SMS",WHATSAPP:"WhatsApp",IN_APP:"In-app",PUSH:"Push"},statuses:{PENDING:"Pending",SENT:"Sent",DELIVERED:"Delivered",FAILED:"Failed",READ:"Read"},events:{NEW_RESERVATION:"New reservation",RESERVATION_CANCELLED:"Reservation cancelled",PAYMENT_RECEIVED:"Payment received",SUBSCRIPTION_TRIAL_ENDING:"Trial ending",MAINTENANCE_DUE:"Maintenance due",OFFER_EXPIRING:"Offer expiring",BOOKING_CONFIRMED:"Booking confirmed",VEHICLE_MAINTENANCE_DUE:"Vehicle maintenance due"}},fr:{title:"Notifications",subtitle:"Suivez les alertes, auditez l'historique de diffusion et gérez les préférences de votre équipe.",inbox:"Boîte de réception",history:"Historique",preferences:"Préférences",markAllRead:"Tout marquer comme lu",loading:"Chargement des notifications…",empty:"Aucune notification pour le moment.",read:"Lu",markRead:"Marquer comme lu",event:"Événement",channel:"Canal",status:"Statut",sentAt:"Envoyé le",date:"Date",allChannels:"Tous les canaux",allStatuses:"Tous les statuts",savePreferences:"Enregistrer les préférences",saving:"Enregistrement…",failedLoad:"Échec du chargement des notifications",failedSave:"Échec de l'enregistrement des préférences",noHistory:"Aucun historique de notification trouvé.",channels:{EMAIL:"Email",SMS:"SMS",WHATSAPP:"WhatsApp",IN_APP:"Dans l'application",PUSH:"Push"},statuses:{PENDING:"En attente",SENT:"Envoyé",DELIVERED:"Délivré",FAILED:"Échoué",READ:"Lu"},events:{NEW_RESERVATION:"Nouvelle réservation",RESERVATION_CANCELLED:"Réservation annulée",PAYMENT_RECEIVED:"Paiement reçu",SUBSCRIPTION_TRIAL_ENDING:"Fin d'essai proche",MAINTENANCE_DUE:"Maintenance due",OFFER_EXPIRING:"Offre expirante",BOOKING_CONFIRMED:"Réservation confirmée",VEHICLE_MAINTENANCE_DUE:"Maintenance véhicule due"}},ar:{title:"الإشعارات",subtitle:"تابع التنبيهات وراجع سجل الإرسال وتحكم في التفضيلات لحساب فريقك.",inbox:"صندوق الوارد",history:"السجل",preferences:"التفضيلات",markAllRead:"تحديد الكل كمقروء",loading:"جارٍ تحميل الإشعارات…",empty:"لا توجد إشعارات حالياً.",read:"مقروء",markRead:"تحديد كمقروء",event:"الحدث",channel:"القناة",status:"الحالة",sentAt:"وقت الإرسال",date:"التاريخ",allChannels:"جميع القنوات",allStatuses:"جميع الحالات",savePreferences:"حفظ التفضيلات",saving:"جارٍ الحفظ…",failedLoad:"فشل تحميل الإشعارات",failedSave:"فشل حفظ التفضيلات",noHistory:"لا يوجد سجل إشعارات.",channels:{EMAIL:"البريد",SMS:"رسائل",WHATSAPP:"واتساب",IN_APP:"داخل التطبيق",PUSH:"إشعار فوري"},statuses:{PENDING:"قيد الانتظار",SENT:"مرسل",DELIVERED:"تم التسليم",FAILED:"فشل",READ:"مقروء"},events:{NEW_RESERVATION:"حجز جديد",RESERVATION_CANCELLED:"إلغاء حجز",PAYMENT_RECEIVED:"تم استلام الدفع",SUBSCRIPTION_TRIAL_ENDING:"اقتراب نهاية التجربة",MAINTENANCE_DUE:"صيانة مستحقة",OFFER_EXPIRING:"عرض على وشك الانتهاء",BOOKING_CONFIRMED:"تأكيد الحجز",VEHICLE_MAINTENANCE_DUE:"صيانة المركبة مستحقة"}}}[e];async function T(){f(!0),j(null);try{let[e,t]=await Promise.all([(0,s.apiFetch)("/notifications/company"),(0,s.apiFetch)("/notifications/company/preferences")]);o(e);let a=Object.fromEntries(t.map(e=>[`${e.notificationType}:${e.channel}`,e.enabled]));h(a)}catch(e){j(e.message??D.failedLoad)}finally{f(!1)}}async function C(){g(!0),j(null);try{let e=new URLSearchParams;I&&e.set("channel",I),R&&e.set("status",R);let t=e.toString(),a=await (0,s.apiFetch)(`/notifications/history${t?`?${t}`:""}`);p(a),A(!0)}catch(e){j(e.message??D.failedLoad)}finally{g(!1)}}async function _(e){await (0,s.apiFetch)(`/notifications/company/${e}/read`,{method:"POST"}),o(t=>t.map(t=>t.id===e?{...t,readAt:new Date().toISOString()}:t)),window.dispatchEvent(new Event("notifications:updated"))}async function L(){await (0,s.apiFetch)("/notifications/company/read-all",{method:"POST"}),o(e=>e.map(e=>({...e,readAt:e.readAt??new Date().toISOString()}))),window.dispatchEvent(new Event("notifications:updated"))}async function O(){k(!0),j(null);try{let e=Object.entries(u).map(([e,t])=>{let[a,s]=e.split(":");return{notificationType:a,channel:s,enabled:t}});await (0,s.apiFetch)("/notifications/company/preferences",{method:"PATCH",body:JSON.stringify(e)})}catch(e){j(e.message??D.failedSave)}finally{k(!1)}}function M(e){return D.events[e]??e.replaceAll("_"," ")}return(0,a.useEffect)(()=>{T()},[]),(0,a.useEffect)(()=>{"history"===m&&C()},[m,I,R]),(0,t.jsxs)("div",{className:"space-y-6",children:[(0,t.jsxs)("div",{className:"flex flex-wrap items-center justify-between gap-4",children:[(0,t.jsxs)("div",{children:[(0,t.jsx)("h1",{className:"text-2xl font-semibold text-slate-900 dark:text-slate-100",children:D.title}),(0,t.jsx)("p",{className:"mt-1 text-sm text-slate-500 dark:text-slate-400",children:D.subtitle})]}),(0,t.jsxs)("div",{className:"flex items-center gap-2",children:[(0,t.jsx)("button",{type:"button",onClick:()=>N("inbox"),className:"inbox"===m?"btn-primary":"btn-secondary",children:D.inbox}),(0,t.jsx)("button",{type:"button",onClick:()=>N("history"),className:"history"===m?"btn-primary":"btn-secondary",children:D.history}),(0,t.jsx)("button",{type:"button",onClick:()=>N("preferences"),className:"preferences"===m?"btn-primary":"btn-secondary",children:D.preferences})]})]}),S?(0,t.jsx)("div",{className:"card p-4 text-sm text-red-600 dark:text-red-400",children:S}):null,"inbox"===m?(0,t.jsxs)("div",{className:"space-y-4",children:[(0,t.jsx)("div",{className:"flex justify-end",children:(0,t.jsx)("button",{type:"button",onClick:L,className:"btn-secondary",children:D.markAllRead})}),b?(0,t.jsx)("div",{className:"card p-6 text-sm text-slate-500",children:D.loading}):null,b||0!==c.length?null:(0,t.jsx)("div",{className:"card p-6 text-sm text-slate-500",children:D.empty}),b?null:c.map(e=>(0,t.jsxs)("article",{className:"card p-6",children:[(0,t.jsxs)("div",{className:"flex flex-wrap items-start justify-between gap-3",children:[(0,t.jsxs)("div",{children:[(0,t.jsx)("p",{className:"text-xs font-semibold uppercase tracking-[0.16em] text-slate-500 dark:text-slate-400",children:M(e.type)}),(0,t.jsx)("h2",{className:"mt-2 text-lg font-semibold text-slate-900 dark:text-slate-100",children:e.title})]}),e.readAt?(0,t.jsx)("span",{className:"rounded-full bg-slate-100 px-3 py-1 text-xs font-semibold text-slate-600 dark:bg-slate-800 dark:text-slate-400",children:D.read}):(0,t.jsx)("button",{type:"button",onClick:()=>_(e.id),className:"btn-secondary",children:D.markRead})]}),(0,t.jsx)("p",{className:"mt-3 text-sm leading-7 text-slate-600 dark:text-slate-300",children:e.body}),(0,t.jsx)("p",{className:"mt-4 text-xs text-slate-400",children:new Date(e.createdAt).toLocaleString()})]},e.id))]}):null,"history"===m?(0,t.jsxs)("div",{className:"space-y-4",children:[(0,t.jsxs)("div",{className:"flex flex-wrap items-center gap-3",children:[(0,t.jsxs)("select",{value:I,onChange:e=>w(e.target.value),className:"rounded-xl border border-slate-200 bg-white px-3 py-2 text-sm text-slate-700 shadow-sm focus:border-blue-500 focus:outline-none focus:ring-1 focus:ring-blue-500 dark:border-blue-900 dark:bg-blue-950 dark:text-slate-200",children:[(0,t.jsx)("option",{value:"",children:D.allChannels}),r.map(e=>(0,t.jsx)("option",{value:e,children:D.channels[e]??e},e))]}),(0,t.jsxs)("select",{value:R,onChange:e=>P(e.target.value),className:"rounded-xl border border-slate-200 bg-white px-3 py-2 text-sm text-slate-700 shadow-sm focus:border-blue-500 focus:outline-none focus:ring-1 focus:ring-blue-500 dark:border-blue-900 dark:bg-blue-950 dark:text-slate-200",children:[(0,t.jsx)("option",{value:"",children:D.allStatuses}),Object.keys(D.statuses).map(e=>(0,t.jsx)("option",{value:e,children:D.statuses[e]},e))]})]}),E?(0,t.jsx)("div",{className:"card p-6 text-sm text-slate-500",children:D.loading}):y&&0===x.length?(0,t.jsx)("div",{className:"card p-6 text-sm text-slate-500",children:D.noHistory}):(0,t.jsx)("div",{className:"card overflow-hidden",children:(0,t.jsx)("div",{className:"overflow-x-auto",children:(0,t.jsxs)("table",{className:"min-w-full text-sm",children:[(0,t.jsx)("thead",{className:"bg-slate-50 dark:bg-blue-950",children:(0,t.jsxs)("tr",{children:[(0,t.jsx)("th",{className:"whitespace-nowrap px-4 py-3 text-left text-xs font-semibold uppercase tracking-wider text-slate-500 dark:text-slate-400",children:D.date}),(0,t.jsx)("th",{className:"whitespace-nowrap px-4 py-3 text-left text-xs font-semibold uppercase tracking-wider text-slate-500 dark:text-slate-400",children:D.event}),(0,t.jsx)("th",{className:"whitespace-nowrap px-4 py-3 text-left text-xs font-semibold uppercase tracking-wider text-slate-500 dark:text-slate-400",children:D.channel}),(0,t.jsx)("th",{className:"whitespace-nowrap px-4 py-3 text-left text-xs font-semibold uppercase tracking-wider text-slate-500 dark:text-slate-400",children:D.title??"Title"}),(0,t.jsx)("th",{className:"whitespace-nowrap px-4 py-3 text-left text-xs font-semibold uppercase tracking-wider text-slate-500 dark:text-slate-400",children:D.status}),(0,t.jsx)("th",{className:"whitespace-nowrap px-4 py-3 text-left text-xs font-semibold uppercase tracking-wider text-slate-500 dark:text-slate-400",children:D.sentAt})]})}),(0,t.jsx)("tbody",{className:"divide-y divide-slate-100 dark:divide-blue-900/50",children:x.map(e=>(0,t.jsxs)("tr",{className:"hover:bg-slate-50/60 dark:hover:bg-blue-900/20",children:[(0,t.jsx)("td",{className:"whitespace-nowrap px-4 py-3 text-xs text-slate-500 dark:text-slate-400",children:new Date(e.createdAt).toLocaleString()}),(0,t.jsx)("td",{className:"whitespace-nowrap px-4 py-3 text-xs font-medium text-slate-700 dark:text-slate-300",children:M(e.type)}),(0,t.jsx)("td",{className:"px-4 py-3",children:(0,t.jsx)("span",{className:`inline-flex items-center rounded-full px-2 py-0.5 text-xs font-semibold ${i[e.channel]??"bg-slate-100 text-slate-600"}`,children:D.channels[e.channel]??e.channel})}),(0,t.jsxs)("td",{className:"max-w-[260px] px-4 py-3",children:[(0,t.jsx)("p",{className:"truncate text-sm font-medium text-slate-800 dark:text-slate-200",children:e.title}),(0,t.jsx)("p",{className:"truncate text-xs text-slate-400 dark:text-slate-500",children:e.body})]}),(0,t.jsx)("td",{className:"px-4 py-3",children:(0,t.jsx)("span",{className:`inline-flex items-center rounded-full px-2 py-0.5 text-xs font-semibold ${d[e.status]??"bg-slate-100 text-slate-600"}`,children:D.statuses[e.status]??e.status})}),(0,t.jsx)("td",{className:"whitespace-nowrap px-4 py-3 text-xs text-slate-500 dark:text-slate-400",children:e.sentAt?new Date(e.sentAt).toLocaleString():"—"})]},e.id))})]})})})]}):null,"preferences"===m?(0,t.jsxs)("div",{className:"card overflow-hidden",children:[(0,t.jsx)("div",{className:"overflow-x-auto",children:(0,t.jsxs)("table",{className:"min-w-full text-sm",children:[(0,t.jsx)("thead",{className:"bg-slate-50 dark:bg-blue-950",children:(0,t.jsxs)("tr",{children:[(0,t.jsx)("th",{className:"px-4 py-3 text-left font-semibold text-slate-600 dark:text-slate-300",children:D.event}),r.map(e=>(0,t.jsx)("th",{className:"px-4 py-3 text-center font-semibold text-slate-600 dark:text-slate-300",children:D.channels[e]??e.replace("_"," ")},e))]})}),(0,t.jsx)("tbody",{children:n.map(e=>(0,t.jsxs)("tr",{className:"border-t border-slate-100 dark:border-blue-900/50",children:[(0,t.jsx)("td",{className:"px-4 py-3 font-medium text-slate-900 dark:text-slate-200",children:D.events[e]??e.replaceAll("_"," ")}),r.map(a=>(0,t.jsx)("td",{className:"px-4 py-3 text-center",children:(0,t.jsx)("input",{type:"checkbox",checked:u[`${e}:${a}`]??!0,onChange:t=>{var s;return s=t.target.checked,void h(t=>({...t,[`${e}:${a}`]:s}))},className:"h-4 w-4 rounded border-slate-300 text-blue-600"})},`${e}-${a}`))]},e))})]})}),(0,t.jsx)("div",{className:"flex justify-end border-t border-slate-100 dark:border-blue-900/50 p-4",children:(0,t.jsx)("button",{type:"button",onClick:O,disabled:v,className:"btn-primary",children:v?D.saving:D.savePreferences})})]}):null]})}])}]); |