Spaces:
Running
Running
axeronis commited on
Commit ·
40bb82e
1
Parent(s): 5af113e
feat: redesign profile page with improved responsive UI/UX
Browse files- frontend/app/settings/account/page.tsx +328 -237
frontend/app/settings/account/page.tsx
CHANGED
|
@@ -2,8 +2,8 @@
|
|
| 2 |
|
| 3 |
import { useState, useEffect, useRef } from 'react'
|
| 4 |
import { useQuery, useQueryClient } from '@tanstack/react-query'
|
| 5 |
-
import { motion
|
| 6 |
-
import { User, Building2, Camera, Save, Loader2, Mail, Lock, Globe, Clock,
|
| 7 |
import { useAuth } from '@/contexts/AuthContext'
|
| 8 |
import { useToast } from '@/contexts/ToastContext'
|
| 9 |
import { api, tenantsApi, uploadApi } from '@/lib/api'
|
|
@@ -11,30 +11,121 @@ import { cn } from '@/lib/utils'
|
|
| 11 |
|
| 12 |
// Popular timezones for CIS region
|
| 13 |
const TIMEZONES = [
|
| 14 |
-
{ value: 'Asia/Bishkek', label: 'Бишкек
|
| 15 |
-
{ value: 'Asia/Almaty', label: 'Алматы
|
| 16 |
-
{ value: 'Asia/Tashkent', label: 'Ташкент
|
| 17 |
-
{ value: 'Europe/Moscow', label: 'Москва
|
| 18 |
-
{ value: 'Asia/Yekaterinburg', label: 'Екатеринбург
|
| 19 |
-
{ value: 'Asia/Novosibirsk', label: 'Новосибирск
|
| 20 |
-
{ value: 'Asia/Krasnoyarsk', label: 'Красноярск
|
| 21 |
-
{ value: 'Asia/Irkutsk', label: 'Иркутск
|
| 22 |
-
{ value: 'Asia/Vladivostok', label: 'Владивосток
|
| 23 |
-
{ value: 'Asia/Dubai', label: 'Дубай
|
| 24 |
-
{ value: 'Europe/Kiev', label: 'Киев
|
| 25 |
-
{ value: 'Europe/Minsk', label: 'Минск
|
| 26 |
]
|
| 27 |
|
| 28 |
const REGIONS = [
|
| 29 |
-
{ value: 'kg', label: '
|
| 30 |
-
{ value: 'ru', label: '
|
| 31 |
-
{ value: 'kz', label: '
|
| 32 |
-
{ value: 'uz', label: '
|
| 33 |
-
{ value: 'ae', label: '
|
| 34 |
-
{ value: 'ua', label: '
|
| 35 |
-
{ value: 'by', label: '
|
| 36 |
]
|
| 37 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 38 |
export default function AccountSettingsPage() {
|
| 39 |
const { user, setUser } = useAuth()
|
| 40 |
const toast = useToast()
|
|
@@ -85,7 +176,7 @@ export default function AccountSettingsPage() {
|
|
| 85 |
setFormData({
|
| 86 |
full_name: user.full_name || '',
|
| 87 |
email: user.email || '',
|
| 88 |
-
phone: user.phone || '',
|
| 89 |
company_name: tenantData.company_name || tenantData.business_name || '',
|
| 90 |
avatar_url: user.avatar_url || ''
|
| 91 |
})
|
|
@@ -94,34 +185,19 @@ export default function AccountSettingsPage() {
|
|
| 94 |
}
|
| 95 |
}, [tenantData, user])
|
| 96 |
|
| 97 |
-
// Save profile
|
| 98 |
const handleSaveProfile = async () => {
|
| 99 |
setSavingProfile(true)
|
| 100 |
try {
|
| 101 |
-
//
|
| 102 |
-
await api.patch('/api/v1/
|
| 103 |
-
company_name: formData.company_name
|
| 104 |
-
})
|
| 105 |
-
|
| 106 |
-
// Update user (full_name)
|
| 107 |
-
await api.patch('/api/v1/auth/me', {
|
| 108 |
-
full_name: formData.full_name,
|
| 109 |
-
avatar_url: formData.avatar_url
|
| 110 |
-
})
|
| 111 |
|
| 112 |
-
// Update context user
|
| 113 |
if (setUser && user) {
|
| 114 |
-
|
| 115 |
-
...user,
|
| 116 |
-
full_name: formData.full_name,
|
| 117 |
-
avatar_url: formData.avatar_url,
|
| 118 |
-
phone: formData.phone
|
| 119 |
-
}
|
| 120 |
-
setUser(updatedUser)
|
| 121 |
}
|
| 122 |
|
| 123 |
queryClient.invalidateQueries({ queryKey: ['tenant-profile'] })
|
| 124 |
-
toast.success('
|
| 125 |
} catch {
|
| 126 |
toast.error('Ошибка', 'Не удалось сохранить')
|
| 127 |
} finally {
|
|
@@ -129,10 +205,8 @@ export default function AccountSettingsPage() {
|
|
| 129 |
}
|
| 130 |
}
|
| 131 |
|
| 132 |
-
//
|
| 133 |
-
const handleAvatarClick = () =>
|
| 134 |
-
fileInputRef.current?.click()
|
| 135 |
-
}
|
| 136 |
|
| 137 |
const handleFileChange = async (e: React.ChangeEvent<HTMLInputElement>) => {
|
| 138 |
const file = e.target.files?.[0]
|
|
@@ -143,16 +217,11 @@ export default function AccountSettingsPage() {
|
|
| 143 |
const res = await uploadApi.uploadImage(file)
|
| 144 |
if (res.ok) {
|
| 145 |
setFormData(prev => ({ ...prev, avatar_url: res.url }))
|
| 146 |
-
//
|
| 147 |
-
|
| 148 |
-
|
| 149 |
-
})
|
| 150 |
-
if (setUser && user) {
|
| 151 |
-
setUser({ ...user, avatar_url: res.url })
|
| 152 |
-
}
|
| 153 |
-
toast.success('Готово', 'Аватар обновлен')
|
| 154 |
}
|
| 155 |
-
} catch
|
| 156 |
toast.error('Ошибка', 'Не удалось загрузить изображение')
|
| 157 |
} finally {
|
| 158 |
setUploadingAvatar(false)
|
|
@@ -166,9 +235,9 @@ export default function AccountSettingsPage() {
|
|
| 166 |
try {
|
| 167 |
await tenantsApi.update(tenantId, { timezone, region })
|
| 168 |
queryClient.invalidateQueries({ queryKey: ['tenant-profile'] })
|
| 169 |
-
toast.success('Сохранено
|
| 170 |
} catch {
|
| 171 |
-
toast.error('Ошибка', 'Не удалось сохранить
|
| 172 |
}
|
| 173 |
setSavingTimezone(false)
|
| 174 |
}
|
|
@@ -190,7 +259,7 @@ export default function AccountSettingsPage() {
|
|
| 190 |
current_password: passwordData.current_password,
|
| 191 |
new_password: passwordData.new_password
|
| 192 |
})
|
| 193 |
-
toast.success('Успех
|
| 194 |
setPasswordData({ current_password: '', new_password: '', confirm_password: '' })
|
| 195 |
} catch (e: any) {
|
| 196 |
toast.error('Ошибка', e.response?.data?.detail || 'Не удалось изменить пароль')
|
|
@@ -202,50 +271,68 @@ export default function AccountSettingsPage() {
|
|
| 202 |
if (isLoading) {
|
| 203 |
return (
|
| 204 |
<div className="flex items-center justify-center min-h-screen bg-[#0D0E18]">
|
| 205 |
-
<Loader2 className="w-
|
| 206 |
</div>
|
| 207 |
)
|
| 208 |
}
|
| 209 |
|
| 210 |
return (
|
| 211 |
-
<div className="min-h-screen bg-[#
|
| 212 |
-
|
|
|
|
|
|
|
|
|
|
| 213 |
|
| 214 |
-
|
|
|
|
|
|
|
| 215 |
<motion.div
|
| 216 |
initial={{ opacity: 0, y: -20 }}
|
| 217 |
animate={{ opacity: 1, y: 0 }}
|
| 218 |
-
className="mb-
|
| 219 |
>
|
| 220 |
-
<h1 className="text-4xl font-
|
| 221 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 222 |
</motion.div>
|
| 223 |
|
| 224 |
-
<div className="space-y-
|
| 225 |
-
|
| 226 |
-
|
| 227 |
-
|
| 228 |
-
className="
|
| 229 |
-
|
| 230 |
-
<div className="flex flex-col items-center">
|
| 231 |
-
<div className="group relative">
|
| 232 |
<div
|
| 233 |
onClick={handleAvatarClick}
|
| 234 |
-
className=
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 235 |
>
|
| 236 |
{formData.avatar_url ? (
|
| 237 |
-
<img
|
|
|
|
|
|
|
|
|
|
|
|
|
| 238 |
) : (
|
| 239 |
-
<
|
| 240 |
-
{formData.full_name
|
| 241 |
-
</
|
| 242 |
)}
|
| 243 |
|
| 244 |
-
|
|
|
|
| 245 |
{uploadingAvatar ? (
|
| 246 |
-
<Loader2 className="w-
|
| 247 |
) : (
|
| 248 |
-
<Camera className="w-
|
| 249 |
)}
|
| 250 |
</div>
|
| 251 |
</div>
|
|
@@ -257,199 +344,203 @@ export default function AccountSettingsPage() {
|
|
| 257 |
accept="image/*"
|
| 258 |
/>
|
| 259 |
</div>
|
| 260 |
-
<div className="mt-4 text-center">
|
| 261 |
-
<h2 className="text-2xl font-bold text-white">{formData.full_name || 'Ваш профиль'}</h2>
|
| 262 |
-
<p className="text-indigo-400 text-sm font-medium mt-1">{formData.email}</p>
|
| 263 |
-
</div>
|
| 264 |
-
</div>
|
| 265 |
|
| 266 |
-
|
| 267 |
-
|
| 268 |
-
|
| 269 |
-
|
| 270 |
-
|
| 271 |
-
|
| 272 |
-
value={formData.full_name}
|
| 273 |
-
onChange={(e) => setFormData({ ...formData, full_name: e.target.value })}
|
| 274 |
-
className="w-full py-3 bg-transparent border-b border-white/10 focus:border-indigo-500 transition-colors outline-none text-white text-lg placeholder:text-slate-700 font-medium"
|
| 275 |
-
placeholder="Алексей Иванов"
|
| 276 |
-
/>
|
| 277 |
-
</div>
|
| 278 |
-
|
| 279 |
-
<div className="space-y-2">
|
| 280 |
-
<label className="text-xs font-bold uppercase tracking-widest text-slate-500 ml-1">Компания</label>
|
| 281 |
-
<input
|
| 282 |
-
type="text"
|
| 283 |
-
value={formData.company_name}
|
| 284 |
-
onChange={(e) => setFormData({ ...formData, company_name: e.target.value })}
|
| 285 |
-
className="w-full py-3 bg-transparent border-b border-white/10 focus:border-indigo-500 transition-colors outline-none text-white text-lg placeholder:text-slate-700 font-medium"
|
| 286 |
-
placeholder="ООО Ромашка"
|
| 287 |
-
/>
|
| 288 |
-
</div>
|
| 289 |
</div>
|
|
|
|
| 290 |
|
| 291 |
-
|
| 292 |
-
|
| 293 |
-
|
| 294 |
-
|
| 295 |
-
|
| 296 |
-
|
| 297 |
-
|
| 298 |
-
|
| 299 |
-
|
| 300 |
-
|
| 301 |
-
|
| 302 |
-
|
| 303 |
-
|
| 304 |
-
|
| 305 |
-
|
| 306 |
-
|
| 307 |
-
|
| 308 |
-
|
| 309 |
-
|
| 310 |
-
|
| 311 |
-
|
| 312 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 313 |
</div>
|
| 314 |
|
| 315 |
-
|
|
|
|
| 316 |
<button
|
| 317 |
onClick={handleSaveProfile}
|
| 318 |
disabled={savingProfile}
|
| 319 |
-
className=
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 320 |
>
|
| 321 |
-
{savingProfile ?
|
|
|
|
|
|
|
|
|
|
|
|
|
| 322 |
Сохранить изменения
|
| 323 |
</button>
|
| 324 |
</div>
|
| 325 |
-
</
|
| 326 |
|
| 327 |
-
|
| 328 |
-
|
| 329 |
-
|
| 330 |
-
|
| 331 |
-
|
| 332 |
-
|
| 333 |
-
className="space-y-8"
|
| 334 |
-
>
|
| 335 |
-
<div className="flex items-center justify-between">
|
| 336 |
<div>
|
| 337 |
-
<h3 className="text-
|
| 338 |
-
<p className="text-slate-500 text-sm mt-
|
| 339 |
</div>
|
| 340 |
</div>
|
| 341 |
|
| 342 |
-
<div className="grid grid-cols-1
|
| 343 |
-
<
|
| 344 |
-
|
| 345 |
-
|
| 346 |
-
|
| 347 |
-
|
| 348 |
-
|
| 349 |
-
|
| 350 |
-
|
| 351 |
-
|
| 352 |
-
|
| 353 |
-
|
| 354 |
-
|
| 355 |
-
|
| 356 |
-
|
|
|
|
| 357 |
|
| 358 |
-
|
| 359 |
-
|
| 360 |
-
|
| 361 |
-
|
| 362 |
-
|
| 363 |
-
|
| 364 |
-
|
| 365 |
-
|
| 366 |
-
|
| 367 |
-
|
| 368 |
-
|
| 369 |
-
|
| 370 |
-
|
| 371 |
-
|
|
|
|
|
|
|
| 372 |
</div>
|
|
|
|
| 373 |
|
| 374 |
-
|
| 375 |
-
|
| 376 |
-
|
| 377 |
-
className="
|
| 378 |
-
|
| 379 |
-
|
| 380 |
-
|
| 381 |
-
|
| 382 |
-
|
| 383 |
-
|
| 384 |
-
<div className="h-px w-full bg-gradient-to-r from-transparent via-white/10 to-transparent" />
|
| 385 |
-
|
| 386 |
-
<motion.section
|
| 387 |
-
initial={{ opacity: 0 }}
|
| 388 |
-
whileInView={{ opacity: 1 }}
|
| 389 |
-
viewport={{ once: true }}
|
| 390 |
-
className="space-y-8"
|
| 391 |
-
>
|
| 392 |
-
<div>
|
| 393 |
-
<h3 className="text-xl font-bold text-white">Безопасность</h3>
|
| 394 |
-
<p className="text-slate-500 text-sm mt-1">Регулярно меняйте пароль для защиты аккаунта</p>
|
| 395 |
</div>
|
| 396 |
|
| 397 |
-
<div className="space-y-
|
| 398 |
-
<
|
| 399 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 400 |
type="password"
|
| 401 |
-
value={passwordData.
|
| 402 |
-
onChange={(e) => setPasswordData({ ...passwordData,
|
| 403 |
-
|
| 404 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 405 |
/>
|
| 406 |
-
<div className="grid gap-6">
|
| 407 |
-
<input
|
| 408 |
-
type="password"
|
| 409 |
-
value={passwordData.new_password}
|
| 410 |
-
onChange={(e) => setPasswordData({ ...passwordData, new_password: e.target.value })}
|
| 411 |
-
className="w-full py-3 bg-transparent border-b border-white/10 focus:border-indigo-500 transition-colors outline-none text-white font-medium placeholder:text-slate-700"
|
| 412 |
-
placeholder="Новый пароль"
|
| 413 |
-
/>
|
| 414 |
-
<input
|
| 415 |
-
type="password"
|
| 416 |
-
value={passwordData.confirm_password}
|
| 417 |
-
onChange={(e) => setPasswordData({ ...passwordData, confirm_password: e.target.value })}
|
| 418 |
-
className="w-full py-3 bg-transparent border-b border-white/10 focus:border-indigo-500 transition-colors outline-none text-white font-medium placeholder:text-slate-700"
|
| 419 |
-
placeholder="Повторите новый пароль"
|
| 420 |
-
/>
|
| 421 |
-
</div>
|
| 422 |
</div>
|
|
|
|
| 423 |
|
|
|
|
| 424 |
<button
|
| 425 |
onClick={handleChangePassword}
|
| 426 |
disabled={changingPassword || !passwordData.current_password || !passwordData.new_password}
|
| 427 |
-
className=
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 428 |
>
|
| 429 |
-
{changingPassword ? <Loader2 className="w-
|
| 430 |
Сменить пароль
|
| 431 |
</button>
|
| 432 |
</div>
|
| 433 |
-
</
|
| 434 |
-
|
| 435 |
-
|
| 436 |
-
|
| 437 |
-
|
| 438 |
-
|
| 439 |
-
|
| 440 |
-
|
| 441 |
-
|
| 442 |
-
|
| 443 |
-
|
| 444 |
-
|
| 445 |
-
<
|
| 446 |
-
<p className="text-red-500/50 text-xs mt-1">Все ваши данные будут безвозвратно удалены из системы</p>
|
| 447 |
</div>
|
| 448 |
-
<button className=
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 449 |
Удалить аккаунт
|
| 450 |
</button>
|
| 451 |
</div>
|
| 452 |
-
</
|
| 453 |
</div>
|
| 454 |
</div>
|
| 455 |
</div>
|
|
|
|
| 2 |
|
| 3 |
import { useState, useEffect, useRef } from 'react'
|
| 4 |
import { useQuery, useQueryClient } from '@tanstack/react-query'
|
| 5 |
+
import { motion } from 'framer-motion'
|
| 6 |
+
import { User, Building2, Camera, Save, Loader2, Mail, Lock, Globe, Clock, Trash2, Phone, Shield, MapPin, ChevronDown } from 'lucide-react'
|
| 7 |
import { useAuth } from '@/contexts/AuthContext'
|
| 8 |
import { useToast } from '@/contexts/ToastContext'
|
| 9 |
import { api, tenantsApi, uploadApi } from '@/lib/api'
|
|
|
|
| 11 |
|
| 12 |
// Popular timezones for CIS region
|
| 13 |
const TIMEZONES = [
|
| 14 |
+
{ value: 'Asia/Bishkek', label: 'Бишкек', offset: 'UTC+6' },
|
| 15 |
+
{ value: 'Asia/Almaty', label: 'Алматы', offset: 'UTC+6' },
|
| 16 |
+
{ value: 'Asia/Tashkent', label: 'Ташкент', offset: 'UTC+5' },
|
| 17 |
+
{ value: 'Europe/Moscow', label: 'Москва', offset: 'UTC+3' },
|
| 18 |
+
{ value: 'Asia/Yekaterinburg', label: 'Екатеринбург', offset: 'UTC+5' },
|
| 19 |
+
{ value: 'Asia/Novosibirsk', label: 'Новосибирск', offset: 'UTC+7' },
|
| 20 |
+
{ value: 'Asia/Krasnoyarsk', label: 'Красноярск', offset: 'UTC+7' },
|
| 21 |
+
{ value: 'Asia/Irkutsk', label: 'Иркутск', offset: 'UTC+8' },
|
| 22 |
+
{ value: 'Asia/Vladivostok', label: 'Владивосток', offset: 'UTC+10' },
|
| 23 |
+
{ value: 'Asia/Dubai', label: 'Дубай', offset: 'UTC+4' },
|
| 24 |
+
{ value: 'Europe/Kiev', label: 'Киев', offset: 'UTC+2' },
|
| 25 |
+
{ value: 'Europe/Minsk', label: 'Минск', offset: 'UTC+3' },
|
| 26 |
]
|
| 27 |
|
| 28 |
const REGIONS = [
|
| 29 |
+
{ value: 'kg', label: 'Кыргызстан', flag: '🇰🇬' },
|
| 30 |
+
{ value: 'ru', label: 'Россия', flag: '🇷🇺' },
|
| 31 |
+
{ value: 'kz', label: 'Казахстан', flag: '🇰🇿' },
|
| 32 |
+
{ value: 'uz', label: 'Узбекистан', flag: '🇺🇿' },
|
| 33 |
+
{ value: 'ae', label: 'ОАЭ', flag: '🇦🇪' },
|
| 34 |
+
{ value: 'ua', label: 'Украина', flag: '🇺🇦' },
|
| 35 |
+
{ value: 'by', label: 'Беларусь', flag: '🇧🇾' },
|
| 36 |
]
|
| 37 |
|
| 38 |
+
// Card component for consistent styling
|
| 39 |
+
function SettingsCard({ children, className }: { children: React.ReactNode; className?: string }) {
|
| 40 |
+
return (
|
| 41 |
+
<motion.div
|
| 42 |
+
initial={{ opacity: 0, y: 20 }}
|
| 43 |
+
animate={{ opacity: 1, y: 0 }}
|
| 44 |
+
className={cn(
|
| 45 |
+
"bg-white/[0.02] backdrop-blur-sm border border-white/[0.05] rounded-2xl lg:rounded-3xl p-4 sm:p-6 lg:p-8",
|
| 46 |
+
className
|
| 47 |
+
)}
|
| 48 |
+
>
|
| 49 |
+
{children}
|
| 50 |
+
</motion.div>
|
| 51 |
+
)
|
| 52 |
+
}
|
| 53 |
+
|
| 54 |
+
// Input component
|
| 55 |
+
function FormInput({
|
| 56 |
+
label,
|
| 57 |
+
icon: Icon,
|
| 58 |
+
disabled,
|
| 59 |
+
...props
|
| 60 |
+
}: {
|
| 61 |
+
label: string
|
| 62 |
+
icon?: React.ElementType
|
| 63 |
+
disabled?: boolean
|
| 64 |
+
} & React.InputHTMLAttributes<HTMLInputElement>) {
|
| 65 |
+
return (
|
| 66 |
+
<div className="space-y-2">
|
| 67 |
+
<label className="text-xs font-semibold uppercase tracking-wider text-slate-500 flex items-center gap-2">
|
| 68 |
+
{Icon && <Icon className="w-3.5 h-3.5" />}
|
| 69 |
+
{label}
|
| 70 |
+
</label>
|
| 71 |
+
<input
|
| 72 |
+
{...props}
|
| 73 |
+
disabled={disabled}
|
| 74 |
+
className={cn(
|
| 75 |
+
"w-full px-4 py-3.5 bg-white/[0.03] border border-white/[0.08] rounded-xl",
|
| 76 |
+
"text-white placeholder:text-slate-600 font-medium",
|
| 77 |
+
"focus:outline-none focus:border-indigo-500/50 focus:bg-white/[0.05]",
|
| 78 |
+
"transition-all duration-200",
|
| 79 |
+
disabled && "opacity-50 cursor-not-allowed"
|
| 80 |
+
)}
|
| 81 |
+
/>
|
| 82 |
+
</div>
|
| 83 |
+
)
|
| 84 |
+
}
|
| 85 |
+
|
| 86 |
+
// Select component
|
| 87 |
+
function FormSelect({
|
| 88 |
+
label,
|
| 89 |
+
icon: Icon,
|
| 90 |
+
options,
|
| 91 |
+
value,
|
| 92 |
+
onChange
|
| 93 |
+
}: {
|
| 94 |
+
label: string
|
| 95 |
+
icon?: React.ElementType
|
| 96 |
+
options: { value: string; label: string; offset?: string; flag?: string }[]
|
| 97 |
+
value: string
|
| 98 |
+
onChange: (value: string) => void
|
| 99 |
+
}) {
|
| 100 |
+
return (
|
| 101 |
+
<div className="space-y-2">
|
| 102 |
+
<label className="text-xs font-semibold uppercase tracking-wider text-slate-500 flex items-center gap-2">
|
| 103 |
+
{Icon && <Icon className="w-3.5 h-3.5" />}
|
| 104 |
+
{label}
|
| 105 |
+
</label>
|
| 106 |
+
<div className="relative">
|
| 107 |
+
<select
|
| 108 |
+
value={value}
|
| 109 |
+
onChange={(e) => onChange(e.target.value)}
|
| 110 |
+
className={cn(
|
| 111 |
+
"w-full px-4 py-3.5 bg-white/[0.03] border border-white/[0.08] rounded-xl",
|
| 112 |
+
"text-white font-medium appearance-none cursor-pointer",
|
| 113 |
+
"focus:outline-none focus:border-indigo-500/50 focus:bg-white/[0.05]",
|
| 114 |
+
"transition-all duration-200"
|
| 115 |
+
)}
|
| 116 |
+
>
|
| 117 |
+
{options.map((opt) => (
|
| 118 |
+
<option key={opt.value} value={opt.value} className="bg-[#1A1B27] text-white">
|
| 119 |
+
{opt.flag ? `${opt.flag} ${opt.label}` : opt.label} {opt.offset ? `(${opt.offset})` : ''}
|
| 120 |
+
</option>
|
| 121 |
+
))}
|
| 122 |
+
</select>
|
| 123 |
+
<ChevronDown className="absolute right-4 top-1/2 -translate-y-1/2 w-4 h-4 text-slate-500 pointer-events-none" />
|
| 124 |
+
</div>
|
| 125 |
+
</div>
|
| 126 |
+
)
|
| 127 |
+
}
|
| 128 |
+
|
| 129 |
export default function AccountSettingsPage() {
|
| 130 |
const { user, setUser } = useAuth()
|
| 131 |
const toast = useToast()
|
|
|
|
| 176 |
setFormData({
|
| 177 |
full_name: user.full_name || '',
|
| 178 |
email: user.email || '',
|
| 179 |
+
phone: user.phone || '',
|
| 180 |
company_name: tenantData.company_name || tenantData.business_name || '',
|
| 181 |
avatar_url: user.avatar_url || ''
|
| 182 |
})
|
|
|
|
| 185 |
}
|
| 186 |
}, [tenantData, user])
|
| 187 |
|
| 188 |
+
// Save profile
|
| 189 |
const handleSaveProfile = async () => {
|
| 190 |
setSavingProfile(true)
|
| 191 |
try {
|
| 192 |
+
await api.patch('/api/v1/tenants/me', { company_name: formData.company_name })
|
| 193 |
+
await api.patch('/api/v1/auth/me', { full_name: formData.full_name, avatar_url: formData.avatar_url, phone: formData.phone })
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 194 |
|
|
|
|
| 195 |
if (setUser && user) {
|
| 196 |
+
setUser({ ...user, full_name: formData.full_name, avatar_url: formData.avatar_url, phone: formData.phone })
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 197 |
}
|
| 198 |
|
| 199 |
queryClient.invalidateQueries({ queryKey: ['tenant-profile'] })
|
| 200 |
+
toast.success('Сохранено', 'Профиль успешно обновлён')
|
| 201 |
} catch {
|
| 202 |
toast.error('Ошибка', 'Не удалось сохранить')
|
| 203 |
} finally {
|
|
|
|
| 205 |
}
|
| 206 |
}
|
| 207 |
|
| 208 |
+
// Avatar upload
|
| 209 |
+
const handleAvatarClick = () => fileInputRef.current?.click()
|
|
|
|
|
|
|
| 210 |
|
| 211 |
const handleFileChange = async (e: React.ChangeEvent<HTMLInputElement>) => {
|
| 212 |
const file = e.target.files?.[0]
|
|
|
|
| 217 |
const res = await uploadApi.uploadImage(file)
|
| 218 |
if (res.ok) {
|
| 219 |
setFormData(prev => ({ ...prev, avatar_url: res.url }))
|
| 220 |
+
await api.patch('/api/v1/auth/me', { avatar_url: res.url })
|
| 221 |
+
if (setUser && user) setUser({ ...user, avatar_url: res.url })
|
| 222 |
+
toast.success('Го��ово', 'Аватар обновлён')
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 223 |
}
|
| 224 |
+
} catch {
|
| 225 |
toast.error('Ошибка', 'Не удалось загрузить изображение')
|
| 226 |
} finally {
|
| 227 |
setUploadingAvatar(false)
|
|
|
|
| 235 |
try {
|
| 236 |
await tenantsApi.update(tenantId, { timezone, region })
|
| 237 |
queryClient.invalidateQueries({ queryKey: ['tenant-profile'] })
|
| 238 |
+
toast.success('Сохранено', 'Региональные настройки обновлены')
|
| 239 |
} catch {
|
| 240 |
+
toast.error('Ошибка', 'Не удалось сохранить')
|
| 241 |
}
|
| 242 |
setSavingTimezone(false)
|
| 243 |
}
|
|
|
|
| 259 |
current_password: passwordData.current_password,
|
| 260 |
new_password: passwordData.new_password
|
| 261 |
})
|
| 262 |
+
toast.success('Успех', 'Пароль изменён')
|
| 263 |
setPasswordData({ current_password: '', new_password: '', confirm_password: '' })
|
| 264 |
} catch (e: any) {
|
| 265 |
toast.error('Ошибка', e.response?.data?.detail || 'Не удалось изменить пароль')
|
|
|
|
| 271 |
if (isLoading) {
|
| 272 |
return (
|
| 273 |
<div className="flex items-center justify-center min-h-screen bg-[#0D0E18]">
|
| 274 |
+
<Loader2 className="w-10 h-10 animate-spin text-indigo-500" />
|
| 275 |
</div>
|
| 276 |
)
|
| 277 |
}
|
| 278 |
|
| 279 |
return (
|
| 280 |
+
<div className="min-h-screen bg-[#0a0a12] text-slate-300">
|
| 281 |
+
{/* Background gradient */}
|
| 282 |
+
<div className="fixed inset-0 pointer-events-none">
|
| 283 |
+
<div className="absolute top-0 left-1/2 -translate-x-1/2 w-[800px] h-[400px] bg-indigo-500/5 rounded-full blur-[120px]" />
|
| 284 |
+
</div>
|
| 285 |
|
| 286 |
+
{/* Content */}
|
| 287 |
+
<div className="relative z-10 max-w-2xl mx-auto px-4 sm:px-6 py-6 sm:py-10 lg:py-16 pb-24">
|
| 288 |
+
{/* Header */}
|
| 289 |
<motion.div
|
| 290 |
initial={{ opacity: 0, y: -20 }}
|
| 291 |
animate={{ opacity: 1, y: 0 }}
|
| 292 |
+
className="mb-8 sm:mb-12"
|
| 293 |
>
|
| 294 |
+
<h1 className="text-2xl sm:text-3xl lg:text-4xl font-bold text-white tracking-tight">
|
| 295 |
+
Настройки аккаунта
|
| 296 |
+
</h1>
|
| 297 |
+
<p className="text-slate-500 text-sm sm:text-base mt-2">
|
| 298 |
+
Управляйте профилем и безопасностью
|
| 299 |
+
</p>
|
| 300 |
</motion.div>
|
| 301 |
|
| 302 |
+
<div className="space-y-4 sm:space-y-6">
|
| 303 |
+
{/* Profile Card */}
|
| 304 |
+
<SettingsCard>
|
| 305 |
+
{/* Avatar Section */}
|
| 306 |
+
<div className="flex flex-col sm:flex-row items-center gap-4 sm:gap-6 mb-6 sm:mb-8">
|
| 307 |
+
<div className="relative group">
|
|
|
|
|
|
|
| 308 |
<div
|
| 309 |
onClick={handleAvatarClick}
|
| 310 |
+
className={cn(
|
| 311 |
+
"w-20 h-20 sm:w-24 sm:h-24 rounded-2xl overflow-hidden",
|
| 312 |
+
"bg-gradient-to-br from-indigo-500/20 to-purple-600/20",
|
| 313 |
+
"border-2 border-white/[0.08] cursor-pointer",
|
| 314 |
+
"transition-all duration-300 hover:border-indigo-500/50",
|
| 315 |
+
"flex items-center justify-center"
|
| 316 |
+
)}
|
| 317 |
>
|
| 318 |
{formData.avatar_url ? (
|
| 319 |
+
<img
|
| 320 |
+
src={formData.avatar_url}
|
| 321 |
+
alt="Avatar"
|
| 322 |
+
className="w-full h-full object-cover transition-transform duration-500 group-hover:scale-110"
|
| 323 |
+
/>
|
| 324 |
) : (
|
| 325 |
+
<span className="text-2xl sm:text-3xl font-bold text-white">
|
| 326 |
+
{formData.full_name?.charAt(0)?.toUpperCase() || 'U'}
|
| 327 |
+
</span>
|
| 328 |
)}
|
| 329 |
|
| 330 |
+
{/* Hover overlay */}
|
| 331 |
+
<div className="absolute inset-0 bg-black/50 opacity-0 group-hover:opacity-100 transition-opacity flex items-center justify-center rounded-2xl">
|
| 332 |
{uploadingAvatar ? (
|
| 333 |
+
<Loader2 className="w-6 h-6 animate-spin text-white" />
|
| 334 |
) : (
|
| 335 |
+
<Camera className="w-6 h-6 text-white" />
|
| 336 |
)}
|
| 337 |
</div>
|
| 338 |
</div>
|
|
|
|
| 344 |
accept="image/*"
|
| 345 |
/>
|
| 346 |
</div>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 347 |
|
| 348 |
+
<div className="text-center sm:text-left">
|
| 349 |
+
<h2 className="text-lg sm:text-xl font-bold text-white">
|
| 350 |
+
{formData.full_name || 'Ваш профиль'}
|
| 351 |
+
</h2>
|
| 352 |
+
<p className="text-indigo-400 text-sm mt-0.5">{formData.email}</p>
|
| 353 |
+
<p className="text-slate-500 text-xs mt-1">Нажмите на аватар для изменения</p>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 354 |
</div>
|
| 355 |
+
</div>
|
| 356 |
|
| 357 |
+
{/* Form Fields */}
|
| 358 |
+
<div className="grid grid-cols-1 sm:grid-cols-2 gap-4 sm:gap-5">
|
| 359 |
+
<FormInput
|
| 360 |
+
label="Полное имя"
|
| 361 |
+
icon={User}
|
| 362 |
+
type="text"
|
| 363 |
+
value={formData.full_name}
|
| 364 |
+
onChange={(e) => setFormData({ ...formData, full_name: e.target.value })}
|
| 365 |
+
placeholder="Алексей Иванов"
|
| 366 |
+
/>
|
| 367 |
+
<FormInput
|
| 368 |
+
label="Компания"
|
| 369 |
+
icon={Building2}
|
| 370 |
+
type="text"
|
| 371 |
+
value={formData.company_name}
|
| 372 |
+
onChange={(e) => setFormData({ ...formData, company_name: e.target.value })}
|
| 373 |
+
placeholder="ООО Ромашка"
|
| 374 |
+
/>
|
| 375 |
+
<FormInput
|
| 376 |
+
label="Email"
|
| 377 |
+
icon={Mail}
|
| 378 |
+
type="email"
|
| 379 |
+
value={formData.email}
|
| 380 |
+
disabled
|
| 381 |
+
/>
|
| 382 |
+
<FormInput
|
| 383 |
+
label="Телефон"
|
| 384 |
+
icon={Phone}
|
| 385 |
+
type="tel"
|
| 386 |
+
value={formData.phone}
|
| 387 |
+
onChange={(e) => setFormData({ ...formData, phone: e.target.value })}
|
| 388 |
+
placeholder="+7 999 123 45 67"
|
| 389 |
+
/>
|
| 390 |
</div>
|
| 391 |
|
| 392 |
+
{/* Save Button */}
|
| 393 |
+
<div className="mt-6 sm:mt-8">
|
| 394 |
<button
|
| 395 |
onClick={handleSaveProfile}
|
| 396 |
disabled={savingProfile}
|
| 397 |
+
className={cn(
|
| 398 |
+
"w-full sm:w-auto px-8 py-3.5 rounded-xl font-semibold",
|
| 399 |
+
"bg-white text-black",
|
| 400 |
+
"hover:bg-slate-100 active:scale-[0.98]",
|
| 401 |
+
"transition-all duration-200",
|
| 402 |
+
"flex items-center justify-center gap-2.5",
|
| 403 |
+
"disabled:opacity-50 disabled:cursor-not-allowed"
|
| 404 |
+
)}
|
| 405 |
>
|
| 406 |
+
{savingProfile ? (
|
| 407 |
+
<Loader2 className="w-4 h-4 animate-spin" />
|
| 408 |
+
) : (
|
| 409 |
+
<Save className="w-4 h-4" />
|
| 410 |
+
)}
|
| 411 |
Сохранить изменения
|
| 412 |
</button>
|
| 413 |
</div>
|
| 414 |
+
</SettingsCard>
|
| 415 |
|
| 416 |
+
{/* Regional Settings */}
|
| 417 |
+
<SettingsCard>
|
| 418 |
+
<div className="flex items-start gap-4 mb-6">
|
| 419 |
+
<div className="p-2.5 bg-indigo-500/10 rounded-xl">
|
| 420 |
+
<Globe className="w-5 h-5 text-indigo-400" />
|
| 421 |
+
</div>
|
|
|
|
|
|
|
|
|
|
| 422 |
<div>
|
| 423 |
+
<h3 className="text-lg font-semibold text-white">Региональные настройки</h3>
|
| 424 |
+
<p className="text-slate-500 text-sm mt-0.5">Часовой пояс и формат даты</p>
|
| 425 |
</div>
|
| 426 |
</div>
|
| 427 |
|
| 428 |
+
<div className="grid grid-cols-1 sm:grid-cols-2 gap-4 sm:gap-5">
|
| 429 |
+
<FormSelect
|
| 430 |
+
label="Часовой пояс"
|
| 431 |
+
icon={Clock}
|
| 432 |
+
options={TIMEZONES}
|
| 433 |
+
value={timezone}
|
| 434 |
+
onChange={setTimezone}
|
| 435 |
+
/>
|
| 436 |
+
<FormSelect
|
| 437 |
+
label="Страна"
|
| 438 |
+
icon={MapPin}
|
| 439 |
+
options={REGIONS}
|
| 440 |
+
value={region}
|
| 441 |
+
onChange={setRegion}
|
| 442 |
+
/>
|
| 443 |
+
</div>
|
| 444 |
|
| 445 |
+
<div className="mt-6">
|
| 446 |
+
<button
|
| 447 |
+
onClick={handleSaveTimezone}
|
| 448 |
+
disabled={savingTimezone}
|
| 449 |
+
className={cn(
|
| 450 |
+
"px-6 py-2.5 rounded-xl font-medium text-sm",
|
| 451 |
+
"bg-white/[0.05] border border-white/[0.08] text-white",
|
| 452 |
+
"hover:bg-white/[0.08] active:scale-[0.98]",
|
| 453 |
+
"transition-all duration-200",
|
| 454 |
+
"flex items-center gap-2",
|
| 455 |
+
"disabled:opacity-50"
|
| 456 |
+
)}
|
| 457 |
+
>
|
| 458 |
+
{savingTimezone ? <Loader2 className="w-4 h-4 animate-spin" /> : <Save className="w-4 h-4" />}
|
| 459 |
+
Сохранить
|
| 460 |
+
</button>
|
| 461 |
</div>
|
| 462 |
+
</SettingsCard>
|
| 463 |
|
| 464 |
+
{/* Security */}
|
| 465 |
+
<SettingsCard>
|
| 466 |
+
<div className="flex items-start gap-4 mb-6">
|
| 467 |
+
<div className="p-2.5 bg-amber-500/10 rounded-xl">
|
| 468 |
+
<Shield className="w-5 h-5 text-amber-400" />
|
| 469 |
+
</div>
|
| 470 |
+
<div>
|
| 471 |
+
<h3 className="text-lg font-semibold text-white">Безопасность</h3>
|
| 472 |
+
<p className="text-slate-500 text-sm mt-0.5">Смена пароля для защиты аккаунта</p>
|
| 473 |
+
</div>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 474 |
</div>
|
| 475 |
|
| 476 |
+
<div className="space-y-4">
|
| 477 |
+
<FormInput
|
| 478 |
+
label="Текущий пароль"
|
| 479 |
+
icon={Lock}
|
| 480 |
+
type="password"
|
| 481 |
+
value={passwordData.current_password}
|
| 482 |
+
onChange={(e) => setPasswordData({ ...passwordData, current_password: e.target.value })}
|
| 483 |
+
placeholder="••••••••"
|
| 484 |
+
/>
|
| 485 |
+
<div className="grid grid-cols-1 sm:grid-cols-2 gap-4">
|
| 486 |
+
<FormInput
|
| 487 |
+
label="Новый пароль"
|
| 488 |
type="password"
|
| 489 |
+
value={passwordData.new_password}
|
| 490 |
+
onChange={(e) => setPasswordData({ ...passwordData, new_password: e.target.value })}
|
| 491 |
+
placeholder="Минимум 8 символов"
|
| 492 |
+
/>
|
| 493 |
+
<FormInput
|
| 494 |
+
label="Подтверждение"
|
| 495 |
+
type="password"
|
| 496 |
+
value={passwordData.confirm_password}
|
| 497 |
+
onChange={(e) => setPasswordData({ ...passwordData, confirm_password: e.target.value })}
|
| 498 |
+
placeholder="Повторите пароль"
|
| 499 |
/>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 500 |
</div>
|
| 501 |
+
</div>
|
| 502 |
|
| 503 |
+
<div className="mt-6">
|
| 504 |
<button
|
| 505 |
onClick={handleChangePassword}
|
| 506 |
disabled={changingPassword || !passwordData.current_password || !passwordData.new_password}
|
| 507 |
+
className={cn(
|
| 508 |
+
"px-6 py-2.5 rounded-xl font-medium text-sm",
|
| 509 |
+
"bg-white/[0.05] border border-white/[0.08] text-white",
|
| 510 |
+
"hover:bg-white/[0.08] active:scale-[0.98]",
|
| 511 |
+
"transition-all duration-200",
|
| 512 |
+
"flex items-center gap-2",
|
| 513 |
+
"disabled:opacity-30 disabled:cursor-not-allowed"
|
| 514 |
+
)}
|
| 515 |
>
|
| 516 |
+
{changingPassword ? <Loader2 className="w-4 h-4 animate-spin" /> : <Lock className="w-4 h-4" />}
|
| 517 |
Сменить пароль
|
| 518 |
</button>
|
| 519 |
</div>
|
| 520 |
+
</SettingsCard>
|
| 521 |
+
|
| 522 |
+
{/* Danger Zone */}
|
| 523 |
+
<SettingsCard className="border-red-500/20 bg-red-500/[0.02]">
|
| 524 |
+
<div className="flex flex-col sm:flex-row items-start sm:items-center justify-between gap-4">
|
| 525 |
+
<div className="flex items-start gap-4">
|
| 526 |
+
<div className="p-2.5 bg-red-500/10 rounded-xl">
|
| 527 |
+
<Trash2 className="w-5 h-5 text-red-500" />
|
| 528 |
+
</div>
|
| 529 |
+
<div>
|
| 530 |
+
<h3 className="text-base font-semibold text-red-400">Удаление аккаунта</h3>
|
| 531 |
+
<p className="text-red-500/50 text-sm mt-0.5">Все данные будут удалены безвозвратно</p>
|
| 532 |
+
</div>
|
|
|
|
| 533 |
</div>
|
| 534 |
+
<button className={cn(
|
| 535 |
+
"w-full sm:w-auto px-5 py-2.5 rounded-xl font-medium text-sm",
|
| 536 |
+
"border border-red-500/30 text-red-400",
|
| 537 |
+
"hover:bg-red-500 hover:text-white hover:border-transparent",
|
| 538 |
+
"transition-all duration-200"
|
| 539 |
+
)}>
|
| 540 |
Удалить аккаунт
|
| 541 |
</button>
|
| 542 |
</div>
|
| 543 |
+
</SettingsCard>
|
| 544 |
</div>
|
| 545 |
</div>
|
| 546 |
</div>
|