feat: add calendar event deletion with confirmation
All checks were successful
Deploy / deploy (push) Successful in 4m37s

This commit is contained in:
Cosmo
2026-04-22 18:28:13 +00:00
parent 000e25ddb1
commit 4874466985
2 changed files with 77 additions and 2 deletions

View File

@@ -1,6 +1,6 @@
'use client'
import { useState, useEffect } from 'react'
import { ChevronLeft, ChevronRight, Plus, X, Clock, MapPin } from 'lucide-react'
import { ChevronLeft, ChevronRight, Plus, X, Clock, MapPin, Trash2 } from 'lucide-react'
interface CalendarEvent {
id: string
@@ -102,6 +102,8 @@ export default function CalendarTab() {
const [loading, setLoading] = useState(true)
const [selectedEvent, setSelectedEvent] = useState<CalendarEvent | null>(null)
const [showAddModal, setShowAddModal] = useState(false)
const [deleting, setDeleting] = useState(false)
const [confirmDelete, setConfirmDelete] = useState(false)
const [addDate, setAddDate] = useState<string>('')
useEffect(() => {
@@ -112,6 +114,23 @@ export default function CalendarTab() {
.catch(() => setLoading(false))
}, [year, month])
const deleteEvent = async (event: CalendarEvent) => {
setDeleting(true)
try {
const r = await fetch(`/api/calendar?eventId=${event.id}`, { method: 'DELETE' })
const d = await r.json()
if (d.error) throw new Error(d.error)
setEvents(prev => prev.filter(e => e.id !== event.id))
setSelectedEvent(null)
setConfirmDelete(false)
} catch (e: any) {
alert(e.message || 'Ошибка удаления')
} finally {
setDeleting(false)
}
}
// Upcoming events (next 30 days)
const upcoming = events
.filter(e => new Date(e.start) >= new Date())
@@ -273,7 +292,7 @@ export default function CalendarTab() {
{/* Event detail modal */}
{selectedEvent && (
<div style={{ position: 'fixed', inset: 0, background: 'rgba(0,0,0,0.6)', zIndex: 100, display: 'flex', alignItems: 'center', justifyContent: 'center', padding: 20 }} onClick={() => setSelectedEvent(null)}>
<div style={{ position: 'fixed', inset: 0, background: 'rgba(0,0,0,0.6)', zIndex: 100, display: 'flex', alignItems: 'center', justifyContent: 'center', padding: 20 }} onClick={() => { setSelectedEvent(null); setConfirmDelete(false) }}>
<div style={{ background: 'var(--bg)', border: '1px solid rgba(255,255,255,0.1)', borderRadius: 20, padding: 24, maxWidth: 360, width: '100%', boxShadow: '0 20px 60px rgba(0,0,0,0.5)' }} onClick={e => e.stopPropagation()}>
<div style={{ display: 'flex', justifyContent: 'space-between', alignItems: 'flex-start', marginBottom: 16 }}>
<div style={{ width: 4, height: 40, borderRadius: 2, background: selectedEvent.color, marginRight: 12, flexShrink: 0, marginTop: 2 }} />
@@ -299,6 +318,34 @@ export default function CalendarTab() {
{selectedEvent.description && (
<div style={{ fontSize: 13, color: 'var(--text-secondary)', marginTop: 4, lineHeight: 1.5 }}>{selectedEvent.description}</div>
)}
{/* Delete button */}
<div style={{ marginTop: 8, borderTop: '1px solid rgba(255,255,255,0.08)', paddingTop: 12 }}>
{!confirmDelete ? (
<button
onClick={() => setConfirmDelete(true)}
style={{ display: 'flex', alignItems: 'center', gap: 6, padding: '8px 14px', borderRadius: 10, background: 'rgba(239,68,68,0.1)', border: '1px solid rgba(239,68,68,0.3)', color: '#f87171', fontSize: 13, fontWeight: 600, cursor: 'pointer', touchAction: 'manipulation', width: '100%', justifyContent: 'center' }}
>
<Trash2 size={14} />
Удалить событие
</button>
) : (
<div style={{ display: 'flex', gap: 8 }}>
<button
onClick={() => deleteEvent(selectedEvent)}
disabled={deleting}
style={{ flex: 1, padding: '8px 14px', borderRadius: 10, background: deleting ? 'rgba(239,68,68,0.15)' : 'rgba(239,68,68,0.25)', border: '1px solid rgba(239,68,68,0.5)', color: '#f87171', fontSize: 13, fontWeight: 600, cursor: deleting ? 'default' : 'pointer', touchAction: 'manipulation' }}
>
{deleting ? 'Удаление...' : 'Да, удалить'}
</button>
<button
onClick={() => setConfirmDelete(false)}
style={{ flex: 1, padding: '8px 14px', borderRadius: 10, background: 'rgba(255,255,255,0.06)', border: '1px solid rgba(255,255,255,0.1)', color: 'var(--text-secondary)', fontSize: 13, fontWeight: 600, cursor: 'pointer', touchAction: 'manipulation' }}
>
Отмена
</button>
</div>
)}
</div>
</div>
</div>
</div>