Spaces:
Sleeping

axeronis commited on
Commit
ac8e2ed
·
1 Parent(s): b0ebfb2

feat: add timezone/region UI selector in account settings page

Browse files
frontend/app/settings/account/page.tsx CHANGED
@@ -1,10 +1,37 @@
1
  'use client'
2
 
3
- import { useState } from 'react'
4
  import { motion } from 'framer-motion'
5
- import { User, Building, Camera, Save, Loader2, Mail, Shield, Lock, Trash2, AlertTriangle } from 'lucide-react'
6
  import { useAuth } from '@/contexts/AuthContext'
7
  import { useToast } from '@/contexts/ToastContext'
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
8
 
9
  export default function AccountSettingsPage() {
10
  const { user } = useAuth()
@@ -14,11 +41,30 @@ export default function AccountSettingsPage() {
14
  const [fullName, setFullName] = useState(user?.full_name || '')
15
  const [phone, setPhone] = useState('')
16
 
 
 
 
 
 
17
  // Password
18
  const [currentPassword, setCurrentPassword] = useState('')
19
  const [newPassword, setNewPassword] = useState('')
20
  const [confirmPassword, setConfirmPassword] = useState('')
21
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
22
  const handleSave = async () => {
23
  setIsLoading(true)
24
  await new Promise(resolve => setTimeout(resolve, 1000))
@@ -26,6 +72,17 @@ export default function AccountSettingsPage() {
26
  toast.success('Успех!', 'Изменения сохранены')
27
  }
28
 
 
 
 
 
 
 
 
 
 
 
 
29
  const handlePasswordChange = async () => {
30
  if (newPassword !== confirmPassword) {
31
  toast.error('Ошибка', 'Пароли не совпадают')
@@ -138,6 +195,72 @@ export default function AccountSettingsPage() {
138
  </div>
139
  </motion.div>
140
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
141
  {/* Security Card */}
142
  <motion.div
143
  initial={{ opacity: 0, y: 20 }}
@@ -238,3 +361,4 @@ export default function AccountSettingsPage() {
238
  </div>
239
  )
240
  }
 
 
1
  'use client'
2
 
3
+ import { useState, useEffect } from 'react'
4
  import { motion } from 'framer-motion'
5
+ import { User, Building, Camera, Save, Loader2, Mail, Shield, Lock, Trash2, AlertTriangle, Globe, Clock } from 'lucide-react'
6
  import { useAuth } from '@/contexts/AuthContext'
7
  import { useToast } from '@/contexts/ToastContext'
8
+ import { tenantApi } from '@/lib/api'
9
+
10
+ // Popular timezones for CIS region
11
+ const TIMEZONES = [
12
+ { value: 'Asia/Bishkek', label: 'Бишкек (UTC+6)', offset: '+6' },
13
+ { value: 'Asia/Almaty', label: 'Алматы (UTC+6)', offset: '+6' },
14
+ { value: 'Asia/Tashkent', label: 'Ташкент (UTC+5)', offset: '+5' },
15
+ { value: 'Europe/Moscow', label: 'Москва (UTC+3)', offset: '+3' },
16
+ { value: 'Asia/Yekaterinburg', label: 'Екатеринбург (UTC+5)', offset: '+5' },
17
+ { value: 'Asia/Novosibirsk', label: 'Новосибирск (UTC+7)', offset: '+7' },
18
+ { value: 'Asia/Krasnoyarsk', label: 'Красноярск (UTC+7)', offset: '+7' },
19
+ { value: 'Asia/Irkutsk', label: 'Иркутск (UTC+8)', offset: '+8' },
20
+ { value: 'Asia/Vladivostok', label: 'Владивосток (UTC+10)', offset: '+10' },
21
+ { value: 'Asia/Dubai', label: 'Дубай (UTC+4)', offset: '+4' },
22
+ { value: 'Europe/Kiev', label: 'Киев (UTC+2)', offset: '+2' },
23
+ { value: 'Europe/Minsk', label: 'Минск (UTC+3)', offset: '+3' },
24
+ ]
25
+
26
+ const REGIONS = [
27
+ { value: 'kg', label: '🇰🇬 Кыргызстан' },
28
+ { value: 'ru', label: '🇷🇺 Россия' },
29
+ { value: 'kz', label: '🇰🇿 Казахстан' },
30
+ { value: 'uz', label: '🇺🇿 Узбекистан' },
31
+ { value: 'ae', label: '🇦🇪 ОАЭ' },
32
+ { value: 'ua', label: '🇺🇦 Украина' },
33
+ { value: 'by', label: '🇧🇾 Беларусь' },
34
+ ]
35
 
36
  export default function AccountSettingsPage() {
37
  const { user } = useAuth()
 
41
  const [fullName, setFullName] = useState(user?.full_name || '')
42
  const [phone, setPhone] = useState('')
43
 
44
+ // Timezone settings
45
+ const [timezone, setTimezone] = useState('Asia/Bishkek')
46
+ const [region, setRegion] = useState('kg')
47
+ const [isSavingTimezone, setIsSavingTimezone] = useState(false)
48
+
49
  // Password
50
  const [currentPassword, setCurrentPassword] = useState('')
51
  const [newPassword, setNewPassword] = useState('')
52
  const [confirmPassword, setConfirmPassword] = useState('')
53
 
54
+ // Load current timezone from tenant
55
+ useEffect(() => {
56
+ const loadSettings = async () => {
57
+ try {
58
+ const tenant = await tenantApi.getCurrent()
59
+ if (tenant.timezone) setTimezone(tenant.timezone)
60
+ if (tenant.region) setRegion(tenant.region)
61
+ } catch (err) {
62
+ console.error('Failed to load timezone settings:', err)
63
+ }
64
+ }
65
+ loadSettings()
66
+ }, [])
67
+
68
  const handleSave = async () => {
69
  setIsLoading(true)
70
  await new Promise(resolve => setTimeout(resolve, 1000))
 
72
  toast.success('Успех!', 'Изменения сохранены')
73
  }
74
 
75
+ const handleSaveTimezone = async () => {
76
+ setIsSavingTimezone(true)
77
+ try {
78
+ await tenantApi.update({ timezone, region })
79
+ toast.success('Сохранено!', 'Часовой пояс обновлён')
80
+ } catch (err) {
81
+ toast.error('Ошибка', 'Не удалось сохранить настройки')
82
+ }
83
+ setIsSavingTimezone(false)
84
+ }
85
+
86
  const handlePasswordChange = async () => {
87
  if (newPassword !== confirmPassword) {
88
  toast.error('Ошибка', 'Пароли не совпадают')
 
195
  </div>
196
  </motion.div>
197
 
198
+ {/* Timezone Card - NEW */}
199
+ <motion.div
200
+ initial={{ opacity: 0, y: 20 }}
201
+ animate={{ opacity: 1, y: 0 }}
202
+ transition={{ delay: 0.05 }}
203
+ className="bg-[#1E1F2E] rounded-xl border border-white/10 overflow-hidden"
204
+ >
205
+ <div className="p-6 border-b border-white/10">
206
+ <h2 className="text-lg font-semibold text-white flex items-center gap-2">
207
+ <Globe className="w-5 h-5 text-indigo-400" />
208
+ Часовой пояс и регион
209
+ </h2>
210
+ <p className="text-sm text-slate-400 mt-1">
211
+ Используется для расчёта дат при записи на консу��ьтации
212
+ </p>
213
+ </div>
214
+
215
+ <div className="p-6">
216
+ <div className="grid grid-cols-1 md:grid-cols-2 gap-4">
217
+ <div>
218
+ <label className="block text-sm font-medium text-slate-400 mb-2 flex items-center gap-2">
219
+ <Clock className="w-4 h-4" />
220
+ Часовой пояс
221
+ </label>
222
+ <select
223
+ value={timezone}
224
+ onChange={(e) => setTimezone(e.target.value)}
225
+ className="w-full px-4 py-3 bg-white/5 border border-white/10 rounded-xl text-white focus:ring-2 focus:ring-indigo-500/50 focus:border-indigo-500 transition outline-none appearance-none cursor-pointer"
226
+ >
227
+ {TIMEZONES.map((tz) => (
228
+ <option key={tz.value} value={tz.value} className="bg-[#1E1F2E] text-white">
229
+ {tz.label}
230
+ </option>
231
+ ))}
232
+ </select>
233
+ </div>
234
+ <div>
235
+ <label className="block text-sm font-medium text-slate-400 mb-2 flex items-center gap-2">
236
+ <Globe className="w-4 h-4" />
237
+ Регион
238
+ </label>
239
+ <select
240
+ value={region}
241
+ onChange={(e) => setRegion(e.target.value)}
242
+ className="w-full px-4 py-3 bg-white/5 border border-white/10 rounded-xl text-white focus:ring-2 focus:ring-indigo-500/50 focus:border-indigo-500 transition outline-none appearance-none cursor-pointer"
243
+ >
244
+ {REGIONS.map((r) => (
245
+ <option key={r.value} value={r.value} className="bg-[#1E1F2E] text-white">
246
+ {r.label}
247
+ </option>
248
+ ))}
249
+ </select>
250
+ </div>
251
+ </div>
252
+
253
+ <button
254
+ onClick={handleSaveTimezone}
255
+ disabled={isSavingTimezone}
256
+ className="mt-6 w-full flex items-center justify-center gap-2 px-6 py-3 bg-white/10 hover:bg-white/15 text-white font-semibold rounded-xl transition disabled:opacity-50 border border-white/10"
257
+ >
258
+ {isSavingTimezone ? <Loader2 className="w-5 h-5 animate-spin" /> : <Save className="w-5 h-5" />}
259
+ Сохранить часовой пояс
260
+ </button>
261
+ </div>
262
+ </motion.div>
263
+
264
  {/* Security Card */}
265
  <motion.div
266
  initial={{ opacity: 0, y: 20 }}
 
361
  </div>
362
  )
363
  }
364
+