feat: remove nginx, add projects/milestones/notifications pages

- Dockerfile: replace nginx with serve for static files
- Fix auth endpoint: /auth/login → /auth/token
- Add ProjectsPage, ProjectDetailPage
- Add MilestonesPage, MilestoneDetailPage with progress bar
- Add NotificationsPage with unread count
- Sidebar: add milestones/notifications nav, live unread badge
- API: configurable VITE_API_BASE for host nginx proxy
- Types: add Milestone, MilestoneProgress, Notification, ProjectMember
This commit is contained in:
zhi
2026-03-06 13:05:19 +00:00
parent 853594f447
commit 54d4c4379a
13 changed files with 529 additions and 25 deletions

View File

@@ -0,0 +1,76 @@
import { useState, useEffect } from 'react'
import { useParams, useNavigate } from 'react-router-dom'
import api from '@/services/api'
import type { Milestone, MilestoneProgress, Issue } from '@/types'
import dayjs from 'dayjs'
export default function MilestoneDetailPage() {
const { id } = useParams()
const navigate = useNavigate()
const [milestone, setMilestone] = useState<Milestone | null>(null)
const [progress, setProgress] = useState<MilestoneProgress | null>(null)
const [issues, setIssues] = useState<Issue[]>([])
useEffect(() => {
api.get<Milestone>(`/milestones/${id}`).then(({ data }) => setMilestone(data))
api.get<MilestoneProgress>(`/milestones/${id}/progress`).then(({ data }) => setProgress(data)).catch(() => {})
api.get<Issue[]>(`/milestones/${id}/issues`).then(({ data }) => setIssues(data)).catch(() => {})
}, [id])
if (!milestone) return <div className="loading">...</div>
return (
<div className="milestone-detail">
<button className="btn-back" onClick={() => navigate('/milestones')}> </button>
<div className="issue-header">
<h2>🏁 {milestone.title}</h2>
<div className="issue-meta">
<span className={`badge status-${milestone.status === 'active' ? 'open' : 'closed'}`}>{milestone.status}</span>
{milestone.due_date && <span className="text-dim"> {dayjs(milestone.due_date).format('YYYY-MM-DD')}</span>}
</div>
</div>
{milestone.description && (
<div className="section">
<h3></h3>
<p>{milestone.description}</p>
</div>
)}
{progress && (
<div className="section">
<h3></h3>
<div className="progress-bar-container">
<div className="progress-bar" style={{ width: `${progress.progress_percent}%` }}>
{progress.progress_percent.toFixed(0)}%
</div>
</div>
<p className="text-dim" style={{ marginTop: 8 }}>
{progress.completed_issues} / {progress.total_issues} issues
</p>
</div>
)}
<div className="section">
<h3>Issues ({issues.length})</h3>
<table>
<thead>
<tr><th>#</th><th></th><th></th><th></th></tr>
</thead>
<tbody>
{issues.map((i) => (
<tr key={i.id} className="clickable" onClick={() => navigate(`/issues/${i.id}`)}>
<td>{i.id}</td>
<td className="issue-title">{i.title}</td>
<td><span className={`badge status-${i.status}`}>{i.status}</span></td>
<td><span className={`badge priority-${i.priority}`}>{i.priority}</span></td>
</tr>
))}
{issues.length === 0 && <tr><td colSpan={4} className="empty"> issue</td></tr>}
</tbody>
</table>
</div>
</div>
)
}

View File

@@ -0,0 +1,87 @@
import { useState, useEffect } from 'react'
import { useNavigate } from 'react-router-dom'
import api from '@/services/api'
import type { Milestone, Project } from '@/types'
import dayjs from 'dayjs'
export default function MilestonesPage() {
const [milestones, setMilestones] = useState<Milestone[]>([])
const [projects, setProjects] = useState<Project[]>([])
const [projectFilter, setProjectFilter] = useState('')
const [showCreate, setShowCreate] = useState(false)
const [form, setForm] = useState({ title: '', description: '', project_id: 0, due_date: '' })
const navigate = useNavigate()
const fetchMilestones = () => {
const params = projectFilter ? `?project_id=${projectFilter}` : ''
api.get<Milestone[]>(`/milestones${params}`).then(({ data }) => setMilestones(data))
}
useEffect(() => {
api.get<Project[]>('/projects').then(({ data }) => {
setProjects(data)
if (data.length) setForm((f) => ({ ...f, project_id: data[0].id }))
})
}, [])
useEffect(() => { fetchMilestones() }, [projectFilter])
const createMilestone = async (e: React.FormEvent) => {
e.preventDefault()
const payload: Record<string, unknown> = { ...form }
if (!form.due_date) delete payload.due_date
await api.post('/milestones', payload)
setShowCreate(false)
fetchMilestones()
}
return (
<div className="milestones-page">
<div className="page-header">
<h2>🏁 ({milestones.length})</h2>
<button className="btn-primary" onClick={() => setShowCreate(!showCreate)}>
{showCreate ? '取消' : '+ 新建里程碑'}
</button>
</div>
<div className="filters">
<select value={projectFilter} onChange={(e) => setProjectFilter(e.target.value)}>
<option value=""></option>
{projects.map((p) => <option key={p.id} value={p.id}>{p.name}</option>)}
</select>
</div>
{showCreate && (
<form className="inline-form" onSubmit={createMilestone}>
<input required placeholder="里程碑标题" value={form.title}
onChange={(e) => setForm({ ...form, title: e.target.value })} />
<input placeholder="描述(可选)" value={form.description}
onChange={(e) => setForm({ ...form, description: e.target.value })} />
<select value={form.project_id} onChange={(e) => setForm({ ...form, project_id: Number(e.target.value) })}>
{projects.map((p) => <option key={p.id} value={p.id}>{p.name}</option>)}
</select>
<input type="date" value={form.due_date}
onChange={(e) => setForm({ ...form, due_date: e.target.value })} />
<button type="submit" className="btn-primary"></button>
</form>
)}
<div className="milestone-grid">
{milestones.map((ms) => (
<div key={ms.id} className="milestone-card" onClick={() => navigate(`/milestones/${ms.id}`)}>
<div className="milestone-card-header">
<span className={`badge status-${ms.status === 'active' ? 'open' : 'closed'}`}>{ms.status}</span>
<h3>{ms.title}</h3>
</div>
<p className="project-desc">{ms.description || '暂无描述'}</p>
<div className="project-meta">
{ms.due_date && <span> {dayjs(ms.due_date).format('YYYY-MM-DD')}</span>}
<span> {dayjs(ms.created_at).format('YYYY-MM-DD')}</span>
</div>
</div>
))}
{milestones.length === 0 && <p className="empty"></p>}
</div>
</div>
)
}

View File

@@ -0,0 +1,69 @@
import { useState, useEffect } from 'react'
import { useNavigate } from 'react-router-dom'
import api from '@/services/api'
import type { Notification } from '@/types'
import dayjs from 'dayjs'
export default function NotificationsPage() {
const [notifications, setNotifications] = useState<Notification[]>([])
const [unreadOnly, setUnreadOnly] = useState(false)
const [unreadCount, setUnreadCount] = useState(0)
const navigate = useNavigate()
const fetchNotifications = () => {
const params = new URLSearchParams()
if (unreadOnly) params.set('unread_only', 'true')
api.get<Notification[]>(`/notifications?${params}`).then(({ data }) => setNotifications(data))
api.get<{ count: number }>('/notifications/count').then(({ data }) => setUnreadCount(data.count)).catch(() => {})
}
useEffect(() => { fetchNotifications() }, [unreadOnly])
const markRead = async (id: number) => {
await api.post(`/notifications/${id}/read`)
fetchNotifications()
}
const markAllRead = async () => {
await api.post('/notifications/read-all')
fetchNotifications()
}
return (
<div className="notifications-page">
<div className="page-header">
<h2>🔔 {unreadCount > 0 && <span className="badge" style={{ background: 'var(--danger)' }}>{unreadCount}</span>}</h2>
{unreadCount > 0 && (
<button className="btn-primary" onClick={markAllRead}></button>
)}
</div>
<div className="filters">
<label className="filter-check">
<input type="checkbox" checked={unreadOnly} onChange={(e) => setUnreadOnly(e.target.checked)} />
</label>
</div>
<div className="notification-list">
{notifications.map((n) => (
<div
key={n.id}
className={`notification-item ${n.is_read ? 'read' : 'unread'}`}
onClick={() => {
if (!n.is_read) markRead(n.id)
if (n.issue_id) navigate(`/issues/${n.issue_id}`)
}}
>
<div className="notification-dot">{n.is_read ? '' : '●'}</div>
<div className="notification-body">
<p>{n.message}</p>
<span className="text-dim">{dayjs(n.created_at).format('MM-DD HH:mm')}</span>
</div>
</div>
))}
{notifications.length === 0 && <p className="empty"></p>}
</div>
</div>
)
}

View File

@@ -0,0 +1,105 @@
import { useState, useEffect } from 'react'
import { useParams, useNavigate } from 'react-router-dom'
import api from '@/services/api'
import type { Project, ProjectMember, Issue, Milestone, PaginatedResponse } from '@/types'
import dayjs from 'dayjs'
export default function ProjectDetailPage() {
const { id } = useParams()
const navigate = useNavigate()
const [project, setProject] = useState<Project | null>(null)
const [members, setMembers] = useState<ProjectMember[]>([])
const [issues, setIssues] = useState<Issue[]>([])
const [milestones, setMilestones] = useState<Milestone[]>([])
const [editing, setEditing] = useState(false)
const [editForm, setEditForm] = useState({ name: '', description: '' })
useEffect(() => {
api.get<Project>(`/projects/${id}`).then(({ data }) => {
setProject(data)
setEditForm({ name: data.name, description: data.description || '' })
})
api.get<ProjectMember[]>(`/projects/${id}/members`).then(({ data }) => setMembers(data))
api.get<PaginatedResponse<Issue>>(`/issues?project_id=${id}&page_size=10`).then(({ data }) => setIssues(data.items))
api.get<Milestone[]>(`/milestones?project_id=${id}`).then(({ data }) => setMilestones(data))
}, [id])
const updateProject = async (e: React.FormEvent) => {
e.preventDefault()
const { data } = await api.patch<Project>(`/projects/${id}`, editForm)
setProject(data)
setEditing(false)
}
if (!project) return <div className="loading">...</div>
return (
<div className="project-detail">
<button className="btn-back" onClick={() => navigate('/projects')}> </button>
<div className="issue-header">
{editing ? (
<form className="inline-form" onSubmit={updateProject}>
<input value={editForm.name} onChange={(e) => setEditForm({ ...editForm, name: e.target.value })} required />
<input value={editForm.description} onChange={(e) => setEditForm({ ...editForm, description: e.target.value })} placeholder="描述" />
<button type="submit" className="btn-primary"></button>
<button type="button" className="btn-back" onClick={() => setEditing(false)}></button>
</form>
) : (
<>
<h2>📁 {project.name}</h2>
<p style={{ color: 'var(--text-dim)', marginTop: 4 }}>{project.description || '暂无描述'}</p>
<button className="btn-transition" style={{ marginTop: 8 }} onClick={() => setEditing(true)}></button>
</>
)}
</div>
<div className="section">
<h3> ({members.length})</h3>
{members.length > 0 ? (
<div className="member-list">
{members.map((m) => (
<span key={m.id} className="badge">{`用户 #${m.user_id} (${m.role})`}</span>
))}
</div>
) : (
<p className="empty"></p>
)}
</div>
<div className="section">
<h3> ({milestones.length})</h3>
{milestones.map((ms) => (
<div key={ms.id} className="milestone-item" onClick={() => navigate(`/milestones/${ms.id}`)}>
<span className={`badge status-${ms.status === 'active' ? 'open' : ms.status === 'closed' ? 'closed' : 'in_progress'}`}>{ms.status}</span>
<span className="milestone-title">{ms.title}</span>
{ms.due_date && <span className="text-dim"> · {dayjs(ms.due_date).format('YYYY-MM-DD')}</span>}
</div>
))}
{milestones.length === 0 && <p className="empty"></p>}
</div>
<div className="section">
<div className="page-header">
<h3> Issues</h3>
<button className="btn-primary" onClick={() => navigate('/issues/new')}>+ </button>
</div>
<table>
<thead>
<tr><th>#</th><th></th><th></th><th></th></tr>
</thead>
<tbody>
{issues.map((i) => (
<tr key={i.id} className="clickable" onClick={() => navigate(`/issues/${i.id}`)}>
<td>{i.id}</td>
<td className="issue-title">{i.title}</td>
<td><span className={`badge status-${i.status}`}>{i.status}</span></td>
<td><span className={`badge priority-${i.priority}`}>{i.priority}</span></td>
</tr>
))}
</tbody>
</table>
</div>
</div>
)
}

View File

@@ -0,0 +1,64 @@
import { useState, useEffect } from 'react'
import { useNavigate } from 'react-router-dom'
import api from '@/services/api'
import type { Project } from '@/types'
import dayjs from 'dayjs'
export default function ProjectsPage() {
const [projects, setProjects] = useState<Project[]>([])
const [showCreate, setShowCreate] = useState(false)
const [form, setForm] = useState({ name: '', description: '', owner_id: 1 })
const navigate = useNavigate()
const fetchProjects = () => {
api.get<Project[]>('/projects').then(({ data }) => setProjects(data))
}
useEffect(() => { fetchProjects() }, [])
const createProject = async (e: React.FormEvent) => {
e.preventDefault()
await api.post('/projects', form)
setForm({ name: '', description: '', owner_id: 1 })
setShowCreate(false)
fetchProjects()
}
return (
<div className="projects-page">
<div className="page-header">
<h2>📁 ({projects.length})</h2>
<button className="btn-primary" onClick={() => setShowCreate(!showCreate)}>
{showCreate ? '取消' : '+ 新建项目'}
</button>
</div>
{showCreate && (
<form className="inline-form" onSubmit={createProject}>
<input
required placeholder="项目名称" value={form.name}
onChange={(e) => setForm({ ...form, name: e.target.value })}
/>
<input
placeholder="项目描述(可选)" value={form.description}
onChange={(e) => setForm({ ...form, description: e.target.value })}
/>
<button type="submit" className="btn-primary"></button>
</form>
)}
<div className="project-grid">
{projects.map((p) => (
<div key={p.id} className="project-card" onClick={() => navigate(`/projects/${p.id}`)}>
<h3>{p.name}</h3>
<p className="project-desc">{p.description || '暂无描述'}</p>
<div className="project-meta">
<span> {dayjs(p.created_at).format('YYYY-MM-DD')}</span>
</div>
</div>
))}
{projects.length === 0 && <p className="empty"></p>}
</div>
</div>
)
}