Spaces:
Sleeping

axeronis commited on
Commit
b5b0f8b
·
1 Parent(s): 506bd65

fix: Repair NotificationBell.tsx syntax error

Browse files
Files changed (1) hide show
  1. 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
- return (
139
- <div className="relative">
140
- {/* Bell Icon */}
141
- <button
142
- onClick={handleClick}
143
- className="relative p-2 hover:bg-indigo-50 text-slate-500 hover:text-indigo-600 rounded-lg transition-colors"
144
- id="notification-bell"
145
  >
146
- <Bell className="w-6 h-6" />
147
- {unreadCount > 0 && (
148
- <motion.span
149
- initial={{ scale: 0 }}
150
- animate={{ scale: 1 }}
151
- className="absolute top-1 right-1 bg-red-500 text-white text-[10px] rounded-full w-4 h-4 flex items-center justify-center font-bold border-2 border-white"
152
- >
153
- {unreadCount > 9 ? '9' : unreadCount}
154
- </motion.span>
155
- )}
156
- </button>
157
-
158
- {/* Dropdown */}
159
- <AnimatePresence>
160
- {isOpen && (
161
- <motion.div
162
- initial={{ opacity: 0, scale: 0.95, y: 10 }}
163
- animate={{ opacity: 1, scale: 1, y: 0 }}
164
- exit={{ opacity: 0, scale: 0.95, y: 10 }}
165
- transition={{ duration: 0.2 }}
166
- 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"
167
- >
168
- {/* Header */}
169
- <div className="px-4 py-3 border-b border-slate-100 flex items-center justify-between bg-white/50 backdrop-blur-sm">
170
- <h3 className="font-semibold text-slate-900">Уведомления</h3>
171
- {unreadCount > 0 && (
 
 
172
  <button
173
- onClick={markAllRead}
174
- className="text-xs text-indigo-600 hover:text-indigo-700 font-medium px-2 py-1 rounded hover:bg-indigo-50 transition-colors"
 
 
 
 
175
  >
176
- Прочитать все
177
- </button>
178
- )}
179
- </div>
180
-
181
- {/* Notifications List */}
182
- <div className="max-h-[28rem] overflow-y-auto custom-scrollbar">
183
- {loading && notifications.length === 0 ? (
184
- <div className="p-8 text-center text-slate-400">
185
- <div className="animate-spin w-6 h-6 border-2 border-indigo-500 border-t-transparent rounded-full mx-auto mb-2" />
186
- Загрузка...
187
- </div>
188
- ) : notifications.length === 0 ? (
189
- <div className="py-12 px-8 text-center text-slate-400">
190
- <Bell className="w-12 h-12 mx-auto mb-3 opacity-20" />
191
- <p className="text-sm">Нет новых уведомлений</p>
192
- </div>
193
- ) : (
194
- <div className="divide-y divide-slate-50">
195
- {notifications.map((notification) => (
196
- <button
197
- key={notification.id}
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
- {getIcon(notification.type)}
218
- </div>
219
-
220
- {/* Content */}
221
- <div className="flex-1 min-w-0 pt-0.5">
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
- </button>
239
- ))}
240
- </div>
241
- )}
 
 
 
242
  </div>
243
- </motion.div>
244
- )}
245
- </AnimatePresence>
246
- </div>
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
  }