Spaces:
Running

axeronis commited on
Commit
6661747
·
1 Parent(s): 7e00cd6

improve: UX/UI for PaymentMethods and KnowledgeFiles

Browse files
frontend/components/knowledge/KnowledgeFilesManager.tsx CHANGED
@@ -4,13 +4,13 @@ import { useState } from 'react'
4
  import { useQuery, useMutation, useQueryClient } from '@tanstack/react-query'
5
  import { knowledgeApi } from '@/lib/api'
6
  import { useToast } from '@/contexts/ToastContext'
7
- import { Plus, Trash2, Edit2, FileText, Image as ImageIcon, Video, Link as LinkIcon, Loader2, Save, X, Tag, Calendar, GitBranch, Sparkles, QrCode, Mic } from 'lucide-react'
8
  import { motion, AnimatePresence } from 'framer-motion'
9
 
10
  interface KnowledgeFile {
11
  id: string
12
  name: string
13
- file_type: 'document' | 'image' | 'video' | 'link' | 'qr' | 'audio'
14
  file_url?: string
15
  external_link?: string
16
  thumbnail_url?: string
@@ -26,12 +26,10 @@ interface KnowledgeFile {
26
  }
27
 
28
  const FILE_TYPES = [
29
- { value: 'document', label: 'Документ (PDF)', icon: FileText },
30
- { value: 'image', label: 'Изображение', icon: ImageIcon },
31
- { value: 'video', label: 'Видео', icon: Video },
32
- { value: 'link', label: 'Ссылка', icon: LinkIcon },
33
- { value: 'qr', label: 'QR-код', icon: QrCode },
34
- { value: 'audio', label: 'Аудио', icon: Mic }
35
  ]
36
 
37
  const SEND_CONDITIONS = [
@@ -290,25 +288,114 @@ export function KnowledgeFilesManager() {
290
  </div>
291
  </div>
292
 
293
- {formData.file_type === 'link' ? (
 
294
  <div>
295
- <label className="text-sm font-medium text-slate-400 mb-1 block">Внешняя ссылка</label>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
296
  <input
297
  type="url"
298
- value={formData.external_link}
299
- onChange={e => setFormData({ ...formData, external_link: e.target.value })}
300
- placeholder="https://youtube.com/..."
301
  className="w-full px-3 py-2 bg-white/5 border border-white/10 rounded-lg text-white"
302
  />
 
303
  </div>
304
- ) : (
 
 
 
305
  <div>
306
- <label className="text-sm font-medium text-slate-400 mb-1 block">URL файла</label>
307
  <input
308
  type="url"
309
- value={formData.file_url}
310
- onChange={e => setFormData({ ...formData, file_url: e.target.value })}
311
- placeholder="https://storage.example.com/file.pdf"
312
  className="w-full px-3 py-2 bg-white/5 border border-white/10 rounded-lg text-white"
313
  />
314
  </div>
 
4
  import { useQuery, useMutation, useQueryClient } from '@tanstack/react-query'
5
  import { knowledgeApi } from '@/lib/api'
6
  import { useToast } from '@/contexts/ToastContext'
7
+ import { Plus, Trash2, Edit2, FileText, Image as ImageIcon, Video, Link as LinkIcon, Loader2, Save, X, Tag, Calendar, GitBranch, Sparkles, Upload } from 'lucide-react'
8
  import { motion, AnimatePresence } from 'framer-motion'
9
 
10
  interface KnowledgeFile {
11
  id: string
12
  name: string
13
+ file_type: 'document' | 'image' | 'video' | 'link'
14
  file_url?: string
15
  external_link?: string
16
  thumbnail_url?: string
 
26
  }
27
 
28
  const FILE_TYPES = [
29
+ { value: 'document', label: 'Документ (PDF)', icon: FileText, desc: 'PDF, инструкции, гайды' },
30
+ { value: 'image', label: 'Изображение', icon: ImageIcon, desc: 'Фото, схемы, картинки' },
31
+ { value: 'video', label: 'Видео', icon: Video, desc: 'YouTube, Vimeo или прямая ссылка' },
32
+ { value: 'link', label: 'Ссылка', icon: LinkIcon, desc: 'Любая внешняя ссылка' }
 
 
33
  ]
34
 
35
  const SEND_CONDITIONS = [
 
288
  </div>
289
  </div>
290
 
291
+ {/* Document - Upload or URL */}
292
+ {formData.file_type === 'document' && (
293
  <div>
294
+ <label className="text-sm font-medium text-slate-400 mb-2 block">Документ (PDF)</label>
295
+
296
+ {/* Upload button */}
297
+ <label className="flex items-center justify-center gap-2 p-4 border-2 border-dashed border-white/20 rounded-xl cursor-pointer hover:border-emerald-500/50 hover:bg-emerald-500/5 transition-all mb-3">
298
+ <Upload className="w-5 h-5 text-slate-400" />
299
+ <span className="text-slate-400">Загрузить PDF</span>
300
+ <input
301
+ type="file"
302
+ accept=".pdf,.doc,.docx"
303
+ className="hidden"
304
+ onChange={async (e) => {
305
+ const file = e.target.files?.[0]
306
+ if (file) {
307
+ toast.info('Загрузка файлов скоро будет доступна. Пока используйте URL.')
308
+ }
309
+ }}
310
+ />
311
+ </label>
312
+
313
+ {/* URL fallback */}
314
+ <div className="relative">
315
+ <span className="absolute left-3 top-1/2 -translate-y-1/2 text-xs text-slate-500">или URL:</span>
316
+ <input
317
+ type="url"
318
+ value={formData.file_url}
319
+ onChange={e => setFormData({ ...formData, file_url: e.target.value })}
320
+ placeholder="https://..."
321
+ className="w-full pl-16 pr-3 py-2 bg-white/5 border border-white/10 rounded-lg text-white text-sm"
322
+ />
323
+ </div>
324
+ </div>
325
+ )}
326
+
327
+ {/* Image - Upload or URL */}
328
+ {formData.file_type === 'image' && (
329
+ <div>
330
+ <label className="text-sm font-medium text-slate-400 mb-2 block">Изображение</label>
331
+
332
+ {/* Upload button */}
333
+ <label className="flex items-center justify-center gap-2 p-4 border-2 border-dashed border-white/20 rounded-xl cursor-pointer hover:border-emerald-500/50 hover:bg-emerald-500/5 transition-all mb-3">
334
+ <Upload className="w-5 h-5 text-slate-400" />
335
+ <span className="text-slate-400">Загрузить изображение</span>
336
+ <input
337
+ type="file"
338
+ accept="image/*"
339
+ className="hidden"
340
+ onChange={async (e) => {
341
+ const file = e.target.files?.[0]
342
+ if (file) {
343
+ toast.info('Загрузка файлов скоро будет доступна. Пока используйте URL.')
344
+ }
345
+ }}
346
+ />
347
+ </label>
348
+
349
+ {/* URL fallback */}
350
+ <div className="relative">
351
+ <span className="absolute left-3 top-1/2 -translate-y-1/2 text-xs text-slate-500">или URL:</span>
352
+ <input
353
+ type="url"
354
+ value={formData.file_url}
355
+ onChange={e => setFormData({ ...formData, file_url: e.target.value })}
356
+ placeholder="https://..."
357
+ className="w-full pl-16 pr-3 py-2 bg-white/5 border border-white/10 rounded-lg text-white text-sm"
358
+ />
359
+ </div>
360
+
361
+ {/* Preview */}
362
+ {formData.file_url && (
363
+ <div className="mt-3 p-2 bg-white/5 rounded-lg">
364
+ <img
365
+ src={formData.file_url}
366
+ alt="Preview"
367
+ className="max-h-32 mx-auto rounded"
368
+ onError={(e) => (e.target as HTMLImageElement).style.display = 'none'}
369
+ />
370
+ </div>
371
+ )}
372
+ </div>
373
+ )}
374
+
375
+ {/* Video - URL only */}
376
+ {formData.file_type === 'video' && (
377
+ <div>
378
+ <label className="text-sm font-medium text-slate-400 mb-1 block">Ссылка на видео</label>
379
  <input
380
  type="url"
381
+ value={formData.file_url}
382
+ onChange={e => setFormData({ ...formData, file_url: e.target.value })}
383
+ placeholder="https://youtube.com/... или прямая ссылка"
384
  className="w-full px-3 py-2 bg-white/5 border border-white/10 rounded-lg text-white"
385
  />
386
+ <p className="text-xs text-slate-500 mt-1">YouTube, Vimeo или прямая ссылка на видеофайл</p>
387
  </div>
388
+ )}
389
+
390
+ {/* Link - External URL */}
391
+ {formData.file_type === 'link' && (
392
  <div>
393
+ <label className="text-sm font-medium text-slate-400 mb-1 block">Внешняя ссылка</label>
394
  <input
395
  type="url"
396
+ value={formData.external_link}
397
+ onChange={e => setFormData({ ...formData, external_link: e.target.value })}
398
+ placeholder="https://..."
399
  className="w-full px-3 py-2 bg-white/5 border border-white/10 rounded-lg text-white"
400
  />
401
  </div>
frontend/components/knowledge/PaymentMethodsManager.tsx CHANGED
@@ -4,7 +4,7 @@ import { useState } from 'react'
4
  import { useQuery, useMutation, useQueryClient } from '@tanstack/react-query'
5
  import { knowledgeApi } from '@/lib/api'
6
  import { useToast } from '@/contexts/ToastContext'
7
- import { Plus, Trash2, Edit2, CreditCard, Link as LinkIcon, QrCode, Image as ImageIcon, Loader2, Save, X } from 'lucide-react'
8
  import { motion, AnimatePresence } from 'framer-motion'
9
 
10
  interface PaymentMethod {
@@ -20,10 +20,9 @@ interface PaymentMethod {
20
  }
21
 
22
  const PAYMENT_TYPES = [
23
- { value: 'requisites', label: 'Реквизиты', icon: CreditCard },
24
- { value: 'link', label: 'Ссылка на оплату', icon: LinkIcon },
25
- { value: 'qr_code', label: 'QR-код', icon: QrCode },
26
- { value: 'image', label: 'Изображение', icon: ImageIcon }
27
  ]
28
 
29
  const SEND_CONDITIONS = [
@@ -233,8 +232,8 @@ export function PaymentMethodsManager() {
233
  key={type.value}
234
  onClick={() => setFormData({ ...formData, payment_type: type.value })}
235
  className={`flex items-center gap-2 p-2 rounded-lg border ${formData.payment_type === type.value
236
- ? 'bg-indigo-500/20 border-indigo-500 text-indigo-400'
237
- : 'bg-white/5 border-white/10 text-slate-300'
238
  }`}
239
  >
240
  <type.icon className="w-4 h-4" />
@@ -270,16 +269,51 @@ export function PaymentMethodsManager() {
270
  </div>
271
  )}
272
 
273
- {(formData.payment_type === 'qr_code' || formData.payment_type === 'image') && (
274
  <div>
275
- <label className="text-sm font-medium text-slate-400 mb-1 block">URL изображения</label>
276
- <input
277
- type="url"
278
- value={formData.image_url}
279
- onChange={e => setFormData({ ...formData, image_url: e.target.value })}
280
- placeholder="https://..."
281
- className="w-full px-3 py-2 bg-white/5 border border-white/10 rounded-lg text-white"
282
- />
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
283
  </div>
284
  )}
285
 
 
4
  import { useQuery, useMutation, useQueryClient } from '@tanstack/react-query'
5
  import { knowledgeApi } from '@/lib/api'
6
  import { useToast } from '@/contexts/ToastContext'
7
+ import { Plus, Trash2, Edit2, CreditCard, Link as LinkIcon, Image as ImageIcon, Loader2, Save, X, Upload } from 'lucide-react'
8
  import { motion, AnimatePresence } from 'framer-motion'
9
 
10
  interface PaymentMethod {
 
20
  }
21
 
22
  const PAYMENT_TYPES = [
23
+ { value: 'requisites', label: 'Реквизиты', icon: CreditCard, desc: 'Номер карты, ФИО получателя' },
24
+ { value: 'link', label: 'Ссылка на оплату', icon: LinkIcon, desc: 'Прямая ссылка на оплату' },
25
+ { value: 'image', label: 'Изображение / QR', icon: ImageIcon, desc: 'QR-код или фото реквизитов' }
 
26
  ]
27
 
28
  const SEND_CONDITIONS = [
 
232
  key={type.value}
233
  onClick={() => setFormData({ ...formData, payment_type: type.value })}
234
  className={`flex items-center gap-2 p-2 rounded-lg border ${formData.payment_type === type.value
235
+ ? 'bg-indigo-500/20 border-indigo-500 text-indigo-400'
236
+ : 'bg-white/5 border-white/10 text-slate-300'
237
  }`}
238
  >
239
  <type.icon className="w-4 h-4" />
 
269
  </div>
270
  )}
271
 
272
+ {formData.payment_type === 'image' && (
273
  <div>
274
+ <label className="text-sm font-medium text-slate-400 mb-2 block">Изображение (QR-код или фото)</label>
275
+
276
+ {/* Upload button */}
277
+ <label className="flex items-center justify-center gap-2 p-4 border-2 border-dashed border-white/20 rounded-xl cursor-pointer hover:border-indigo-500/50 hover:bg-indigo-500/5 transition-all mb-3">
278
+ <Upload className="w-5 h-5 text-slate-400" />
279
+ <span className="text-slate-400">Загрузить изображение</span>
280
+ <input
281
+ type="file"
282
+ accept="image/*"
283
+ className="hidden"
284
+ onChange={async (e) => {
285
+ const file = e.target.files?.[0]
286
+ if (file) {
287
+ // For now, show a placeholder - in production would upload to storage
288
+ toast.info('Загрузка файлов скоро будет доступна. Пока используйте URL.')
289
+ }
290
+ }}
291
+ />
292
+ </label>
293
+
294
+ {/* URL fallback */}
295
+ <div className="relative">
296
+ <span className="absolute left-3 top-1/2 -translate-y-1/2 text-xs text-slate-500">или URL:</span>
297
+ <input
298
+ type="url"
299
+ value={formData.image_url}
300
+ onChange={e => setFormData({ ...formData, image_url: e.target.value })}
301
+ placeholder="https://..."
302
+ className="w-full pl-16 pr-3 py-2 bg-white/5 border border-white/10 rounded-lg text-white text-sm"
303
+ />
304
+ </div>
305
+
306
+ {/* Preview */}
307
+ {formData.image_url && (
308
+ <div className="mt-3 p-2 bg-white/5 rounded-lg">
309
+ <img
310
+ src={formData.image_url}
311
+ alt="Preview"
312
+ className="max-h-32 mx-auto rounded"
313
+ onError={(e) => (e.target as HTMLImageElement).style.display = 'none'}
314
+ />
315
+ </div>
316
+ )}
317
  </div>
318
  )}
319