Spaces:
Sleeping
Sleeping
axeronis commited on
Commit ·
b5b0f8b
1
Parent(s): 506bd65
fix: Repair NotificationBell.tsx syntax error
Browse files- frontend/components/NotificationBell.tsx +104 -125
frontend/components/NotificationBell.tsx
CHANGED
|
@@ -80,6 +80,29 @@ export default function NotificationBell() {
|
|
| 80 |
fetchUnreadCount()
|
| 81 |
}
|
| 82 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 83 |
const markAllRead = async () => {
|
| 84 |
const token = localStorage.getItem('auth_token')
|
| 85 |
await fetch(`${process.env.NEXT_PUBLIC_API_URL}/api/v1/notifications/mark-all-read`, {
|
|
@@ -112,137 +135,93 @@ export default function NotificationBell() {
|
|
| 112 |
{/* Dropdown */}
|
| 113 |
<AnimatePresence>
|
| 114 |
{isOpen && (
|
| 115 |
-
const getIcon = (type: string) => {
|
| 116 |
-
switch (type) {
|
| 117 |
-
case 'order': return '🛍️';
|
| 118 |
-
case 'booking': return '📅';
|
| 119 |
-
case 'lead_heat': return '🔥';
|
| 120 |
-
case 'message': return '💬';
|
| 121 |
-
default: return '🔔';
|
| 122 |
-
}
|
| 123 |
-
}
|
| 124 |
|
| 125 |
-
const formatTime = (dateStr: string) => {
|
| 126 |
-
const date = new Date(dateStr)
|
| 127 |
-
const now = new Date()
|
| 128 |
-
const diffMs = now.getTime() - date.getTime()
|
| 129 |
-
const diffMins = Math.round(diffMs / 60000)
|
| 130 |
-
const diffHrs = Math.round(diffMs / 3600000)
|
| 131 |
-
|
| 132 |
-
if (diffMins < 1) return 'Только что'
|
| 133 |
-
if (diffMins < 60) return `${diffMins} мин. назад`
|
| 134 |
-
if (diffHrs < 24) return `${diffHrs} ч. назад`
|
| 135 |
-
return date.toLocaleDateString('ru-RU', {day: 'numeric', month: 'short' })
|
| 136 |
-
}
|
| 137 |
|
| 138 |
-
|
| 139 |
-
|
| 140 |
-
|
| 141 |
-
|
| 142 |
-
|
| 143 |
-
className="
|
| 144 |
-
id="notification-bell"
|
| 145 |
>
|
| 146 |
-
|
| 147 |
-
|
| 148 |
-
<
|
| 149 |
-
|
| 150 |
-
|
| 151 |
-
|
| 152 |
-
|
| 153 |
-
|
| 154 |
-
|
| 155 |
-
|
| 156 |
-
|
| 157 |
-
|
| 158 |
-
|
| 159 |
-
|
| 160 |
-
|
| 161 |
-
|
| 162 |
-
|
| 163 |
-
|
| 164 |
-
|
| 165 |
-
|
| 166 |
-
|
| 167 |
-
|
| 168 |
-
|
| 169 |
-
|
| 170 |
-
|
| 171 |
-
|
|
|
|
|
|
|
| 172 |
<button
|
| 173 |
-
|
| 174 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 175 |
>
|
| 176 |
-
|
| 177 |
-
|
| 178 |
-
|
| 179 |
-
|
| 180 |
-
|
| 181 |
-
|
| 182 |
-
|
| 183 |
-
|
| 184 |
-
|
| 185 |
-
|
| 186 |
-
|
| 187 |
-
|
| 188 |
-
|
| 189 |
-
|
| 190 |
-
|
| 191 |
-
|
| 192 |
-
|
| 193 |
-
|
| 194 |
-
|
| 195 |
-
|
| 196 |
-
|
| 197 |
-
|
| 198 |
-
onClick={() => handleNotificationClick(notification)}
|
| 199 |
-
className={cn(
|
| 200 |
-
"w-full p-4 text-left hover:bg-slate-50 transition-all duration-200 group relative",
|
| 201 |
-
!notification.is_read ? "bg-indigo-50/50" : "bg-white"
|
| 202 |
-
)}
|
| 203 |
-
>
|
| 204 |
-
{!notification.is_read && (
|
| 205 |
-
<div className="absolute left-0 top-0 bottom-0 w-1 bg-indigo-500" />
|
| 206 |
-
)}
|
| 207 |
-
|
| 208 |
-
<div className="flex gap-3">
|
| 209 |
-
{/* Icon */}
|
| 210 |
-
<div className={cn(
|
| 211 |
-
"w-10 h-10 rounded-full flex items-center justify-center flex-shrink-0 text-lg shadow-sm group-hover:scale-110 transition-transform",
|
| 212 |
-
notification.type === 'booking' ? "bg-purple-100" :
|
| 213 |
-
notification.type === 'order' ? "bg-emerald-100" :
|
| 214 |
-
notification.type === 'message' ? "bg-blue-100" :
|
| 215 |
-
"bg-orange-100"
|
| 216 |
)}>
|
| 217 |
-
{
|
| 218 |
-
</
|
| 219 |
-
|
| 220 |
-
|
| 221 |
-
<
|
| 222 |
-
<div className="flex justify-between items-start mb-0.5">
|
| 223 |
-
<h4 className={cn(
|
| 224 |
-
"text-sm font-medium truncate pr-2",
|
| 225 |
-
!notification.is_read ? "text-slate-900" : "text-slate-700"
|
| 226 |
-
)}>
|
| 227 |
-
{notification.title}
|
| 228 |
-
</h4>
|
| 229 |
-
<span className="text-[10px] text-slate-400 whitespace-nowrap flex-shrink-0 mt-1">
|
| 230 |
-
{formatTime(notification.created_at)}
|
| 231 |
-
</span>
|
| 232 |
-
</div>
|
| 233 |
-
<p className="text-xs text-slate-500 line-clamp-2 leading-relaxed">
|
| 234 |
-
{notification.message}
|
| 235 |
-
</p>
|
| 236 |
-
</div>
|
| 237 |
</div>
|
| 238 |
-
|
| 239 |
-
|
| 240 |
-
|
| 241 |
-
|
|
|
|
|
|
|
|
|
|
| 242 |
</div>
|
| 243 |
-
|
| 244 |
-
|
| 245 |
-
</
|
| 246 |
-
|
| 247 |
-
|
|
|
|
|
|
|
| 248 |
}
|
|
|
|
| 80 |
fetchUnreadCount()
|
| 81 |
}
|
| 82 |
|
| 83 |
+
const getIcon = (type: string) => {
|
| 84 |
+
switch (type) {
|
| 85 |
+
case 'order': return '🛍️';
|
| 86 |
+
case 'booking': return '📅';
|
| 87 |
+
case 'lead_heat': return '🔥';
|
| 88 |
+
case 'message': return '💬';
|
| 89 |
+
default: return '🔔';
|
| 90 |
+
}
|
| 91 |
+
}
|
| 92 |
+
|
| 93 |
+
const formatTime = (dateStr: string) => {
|
| 94 |
+
const date = new Date(dateStr)
|
| 95 |
+
const now = new Date()
|
| 96 |
+
const diffMs = now.getTime() - date.getTime()
|
| 97 |
+
const diffMins = Math.round(diffMs / 60000)
|
| 98 |
+
const diffHrs = Math.round(diffMs / 3600000)
|
| 99 |
+
|
| 100 |
+
if (diffMins < 1) return 'Только что'
|
| 101 |
+
if (diffMins < 60) return `${diffMins} мин. назад`
|
| 102 |
+
if (diffHrs < 24) return `${diffHrs} ч. назад`
|
| 103 |
+
return date.toLocaleDateString('ru-RU', { day: 'numeric', month: 'short' })
|
| 104 |
+
}
|
| 105 |
+
|
| 106 |
const markAllRead = async () => {
|
| 107 |
const token = localStorage.getItem('auth_token')
|
| 108 |
await fetch(`${process.env.NEXT_PUBLIC_API_URL}/api/v1/notifications/mark-all-read`, {
|
|
|
|
| 135 |
{/* Dropdown */}
|
| 136 |
<AnimatePresence>
|
| 137 |
{isOpen && (
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 138 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 139 |
|
| 140 |
+
<motion.div
|
| 141 |
+
initial={{ opacity: 0, scale: 0.95, y: 10 }}
|
| 142 |
+
animate={{ opacity: 1, scale: 1, y: 0 }}
|
| 143 |
+
exit={{ opacity: 0, scale: 0.95, y: 10 }}
|
| 144 |
+
transition={{ duration: 0.2 }}
|
| 145 |
+
className="absolute right-0 mt-3 w-80 sm:w-96 bg-white rounded-2xl shadow-xl border border-slate-100 overflow-hidden z-50 origin-top-right"
|
|
|
|
| 146 |
>
|
| 147 |
+
{/* Header */}
|
| 148 |
+
<div className="px-4 py-3 border-b border-slate-100 flex items-center justify-between bg-white/50 backdrop-blur-sm">
|
| 149 |
+
<h3 className="font-semibold text-slate-900">Уведомления</h3>
|
| 150 |
+
{unreadCount > 0 && (
|
| 151 |
+
<button
|
| 152 |
+
onClick={markAllRead}
|
| 153 |
+
className="text-xs text-indigo-600 hover:text-indigo-700 font-medium px-2 py-1 rounded hover:bg-indigo-50 transition-colors"
|
| 154 |
+
>
|
| 155 |
+
Прочитать все
|
| 156 |
+
</button>
|
| 157 |
+
)}
|
| 158 |
+
</div>
|
| 159 |
+
|
| 160 |
+
{/* Notifications List */}
|
| 161 |
+
<div className="max-h-[28rem] overflow-y-auto custom-scrollbar">
|
| 162 |
+
{loading && notifications.length === 0 ? (
|
| 163 |
+
<div className="p-8 text-center text-slate-400">
|
| 164 |
+
<div className="animate-spin w-6 h-6 border-2 border-indigo-500 border-t-transparent rounded-full mx-auto mb-2" />
|
| 165 |
+
Загрузка...
|
| 166 |
+
</div>
|
| 167 |
+
) : notifications.length === 0 ? (
|
| 168 |
+
<div className="py-12 px-8 text-center text-slate-400">
|
| 169 |
+
<Bell className="w-12 h-12 mx-auto mb-3 opacity-20" />
|
| 170 |
+
<p className="text-sm">Нет новых уведомлений</p>
|
| 171 |
+
</div>
|
| 172 |
+
) : (
|
| 173 |
+
<div className="divide-y divide-slate-50">
|
| 174 |
+
{notifications.map((notification) => (
|
| 175 |
<button
|
| 176 |
+
key={notification.id}
|
| 177 |
+
onClick={() => handleNotificationClick(notification)}
|
| 178 |
+
className={cn(
|
| 179 |
+
"w-full p-4 text-left hover:bg-slate-50 transition-all duration-200 group relative",
|
| 180 |
+
!notification.is_read ? "bg-indigo-50/50" : "bg-white"
|
| 181 |
+
)}
|
| 182 |
>
|
| 183 |
+
{!notification.is_read && (
|
| 184 |
+
<div className="absolute left-0 top-0 bottom-0 w-1 bg-indigo-500" />
|
| 185 |
+
)}
|
| 186 |
+
|
| 187 |
+
<div className="flex gap-3">
|
| 188 |
+
{/* Icon */}
|
| 189 |
+
<div className={cn(
|
| 190 |
+
"w-10 h-10 rounded-full flex items-center justify-center flex-shrink-0 text-lg shadow-sm group-hover:scale-110 transition-transform",
|
| 191 |
+
notification.type === 'booking' ? "bg-purple-100" :
|
| 192 |
+
notification.type === 'order' ? "bg-emerald-100" :
|
| 193 |
+
notification.type === 'message' ? "bg-blue-100" :
|
| 194 |
+
"bg-orange-100"
|
| 195 |
+
)}>
|
| 196 |
+
{getIcon(notification.type)}
|
| 197 |
+
</div>
|
| 198 |
+
|
| 199 |
+
{/* Content */}
|
| 200 |
+
<div className="flex-1 min-w-0 pt-0.5">
|
| 201 |
+
<div className="flex justify-between items-start mb-0.5">
|
| 202 |
+
<h4 className={cn(
|
| 203 |
+
"text-sm font-medium truncate pr-2",
|
| 204 |
+
!notification.is_read ? "text-slate-900" : "text-slate-700"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 205 |
)}>
|
| 206 |
+
{notification.title}
|
| 207 |
+
</h4>
|
| 208 |
+
<span className="text-[10px] text-slate-400 whitespace-nowrap flex-shrink-0 mt-1">
|
| 209 |
+
{formatTime(notification.created_at)}
|
| 210 |
+
</span>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 211 |
</div>
|
| 212 |
+
<p className="text-xs text-slate-500 line-clamp-2 leading-relaxed">
|
| 213 |
+
{notification.message}
|
| 214 |
+
</p>
|
| 215 |
+
</div>
|
| 216 |
+
</div>
|
| 217 |
+
</button>
|
| 218 |
+
))}
|
| 219 |
</div>
|
| 220 |
+
)}
|
| 221 |
+
</div>
|
| 222 |
+
</motion.div>
|
| 223 |
+
)}
|
| 224 |
+
</AnimatePresence>
|
| 225 |
+
</div>
|
| 226 |
+
)
|
| 227 |
}
|