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:
76
src/pages/MilestoneDetailPage.tsx
Normal file
76
src/pages/MilestoneDetailPage.tsx
Normal 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>
|
||||
)
|
||||
}
|
||||
87
src/pages/MilestonesPage.tsx
Normal file
87
src/pages/MilestonesPage.tsx
Normal 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>
|
||||
)
|
||||
}
|
||||
69
src/pages/NotificationsPage.tsx
Normal file
69
src/pages/NotificationsPage.tsx
Normal 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>
|
||||
)
|
||||
}
|
||||
105
src/pages/ProjectDetailPage.tsx
Normal file
105
src/pages/ProjectDetailPage.tsx
Normal 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>
|
||||
)
|
||||
}
|
||||
64
src/pages/ProjectsPage.tsx
Normal file
64
src/pages/ProjectsPage.tsx
Normal 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>
|
||||
)
|
||||
}
|
||||
Reference in New Issue
Block a user