fix: correct token read in upload + remove upload button, keep drop zone

- api.upload.photo used wrong localStorage key ('access_token' vs 'hotelsync-session')
- Removed standalone 'Загрузить фото' button — drop zone handles click+drag
- Added '+' thumbnail button to add more photos when gallery is non-empty
- Show spinner inline during upload instead of disabled button

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
2026-03-23 13:05:08 +03:00
parent c0945e7264
commit 95809851fb
2 changed files with 13 additions and 5 deletions

View File

@@ -347,7 +347,7 @@ export const api = {
// ── File Upload ─────────────────────────────────────────────────────────── // ── File Upload ───────────────────────────────────────────────────────────
upload: { upload: {
photo: async (file: File, folder: 'categories' | 'rooms' | 'hotels' | 'guests' = 'rooms'): Promise<string> => { photo: async (file: File, folder: 'categories' | 'rooms' | 'hotels' | 'guests' = 'rooms'): Promise<string> => {
const token = localStorage.getItem('access_token') const token = getToken()
const fd = new FormData() const fd = new FormData()
fd.append('file', file) fd.append('file', file)
const res = await fetch(`${BASE}/api/upload?folder=${folder}`, { const res = await fetch(`${BASE}/api/upload?folder=${folder}`, {

View File

@@ -250,6 +250,12 @@ function CategoryForm({ category, onClose, onSave }: CategoryFormProps) {
<img src={p} alt="" className="w-full h-full object-cover" /> <img src={p} alt="" className="w-full h-full object-cover" />
</button> </button>
))} ))}
<button
onClick={() => fileRef.current?.click()}
className="w-14 h-14 rounded-lg border-2 border-dashed border-slate-300 dark:border-slate-600 flex items-center justify-center text-slate-400 hover:border-brand-400 hover:text-brand-500 shrink-0 transition-colors"
>
<Plus size={18} />
</button>
</div> </div>
</div> </div>
) : ( ) : (
@@ -271,10 +277,12 @@ function CategoryForm({ category, onClose, onSave }: CategoryFormProps) {
</div> </div>
)} )}
<input ref={fileRef} type="file" accept="image/*" multiple className="hidden" onChange={handlePhotoUpload} /> <input ref={fileRef} type="file" accept="image/*" multiple className="hidden" onChange={handlePhotoUpload} />
<button onClick={() => fileRef.current?.click()} className="btn-secondary w-full justify-center" disabled={uploading}> {uploading && (
{uploading ? <Loader2 size={14} className="animate-spin" /> : <ImagePlus size={14} />} <div className="flex items-center justify-center gap-2 text-sm text-slate-500 py-1">
{uploading ? 'Загрузка...' : 'Загрузить фото'} <Loader2 size={14} className="animate-spin" />
</button> Загрузка...
</div>
)}
</> </>
)} )}
</div> </div>