Compare commits
14 Commits
6c8c8b78b6
...
f61c506fdb
| Author | SHA1 | Date | |
|---|---|---|---|
| f61c506fdb | |||
| 38ebd2bbd1 | |||
| 83c9cd8fb7 | |||
| 8014dcd602 | |||
| f39e7da33c | |||
| ea841d0d39 | |||
| a431711ff0 | |||
| 8208b3b27b | |||
| e4804128f6 | |||
| 978d69eea3 | |||
| 4932974579 | |||
| e45281f5ed | |||
| 9de59cacfa | |||
| a08644dde3 |
2528
package-lock.json
generated
2528
package-lock.json
generated
File diff suppressed because it is too large
Load Diff
20
package.json
20
package.json
@@ -6,20 +6,30 @@
|
|||||||
"scripts": {
|
"scripts": {
|
||||||
"dev": "vite",
|
"dev": "vite",
|
||||||
"build": "tsc && vite build",
|
"build": "tsc && vite build",
|
||||||
"preview": "vite preview"
|
"preview": "vite preview",
|
||||||
|
"test": "vitest run",
|
||||||
|
"test:watch": "vitest",
|
||||||
|
"test:ui": "vitest --ui"
|
||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
|
"axios": "^1.6.7",
|
||||||
|
"dayjs": "^1.11.10",
|
||||||
"react": "^18.3.1",
|
"react": "^18.3.1",
|
||||||
"react-dom": "^18.3.1",
|
"react-dom": "^18.3.1",
|
||||||
"react-router-dom": "^6.22.0",
|
"react-router-dom": "^6.22.0"
|
||||||
"axios": "^1.6.7",
|
|
||||||
"dayjs": "^1.11.10"
|
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
|
"@testing-library/dom": "^10.4.1",
|
||||||
|
"@testing-library/jest-dom": "^6.9.1",
|
||||||
|
"@testing-library/react": "^16.3.2",
|
||||||
|
"@testing-library/user-event": "^14.6.1",
|
||||||
"@types/react": "^18.3.1",
|
"@types/react": "^18.3.1",
|
||||||
"@types/react-dom": "^18.3.0",
|
"@types/react-dom": "^18.3.0",
|
||||||
"@vitejs/plugin-react": "^4.2.1",
|
"@vitejs/plugin-react": "^4.2.1",
|
||||||
|
"@vitest/ui": "^4.1.2",
|
||||||
|
"jsdom": "^29.0.1",
|
||||||
"typescript": "^5.4.0",
|
"typescript": "^5.4.0",
|
||||||
"vite": "^5.1.0"
|
"vite": "^5.1.0",
|
||||||
|
"vitest": "^4.1.2"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
21
src/App.tsx
21
src/App.tsx
@@ -14,9 +14,10 @@ import MilestoneDetailPage from '@/pages/MilestoneDetailPage'
|
|||||||
import NotificationsPage from '@/pages/NotificationsPage'
|
import NotificationsPage from '@/pages/NotificationsPage'
|
||||||
import RoleEditorPage from '@/pages/RoleEditorPage'
|
import RoleEditorPage from '@/pages/RoleEditorPage'
|
||||||
import MonitorPage from '@/pages/MonitorPage'
|
import MonitorPage from '@/pages/MonitorPage'
|
||||||
import ProposesPage from '@/pages/ProposesPage'
|
import ProposalsPage from '@/pages/ProposalsPage'
|
||||||
import ProposeDetailPage from '@/pages/ProposeDetailPage'
|
import ProposalDetailPage from '@/pages/ProposalDetailPage'
|
||||||
import UsersPage from '@/pages/UsersPage'
|
import UsersPage from '@/pages/UsersPage'
|
||||||
|
import CalendarPage from '@/pages/CalendarPage'
|
||||||
import SupportDetailPage from '@/pages/SupportDetailPage'
|
import SupportDetailPage from '@/pages/SupportDetailPage'
|
||||||
import MeetingDetailPage from '@/pages/MeetingDetailPage'
|
import MeetingDetailPage from '@/pages/MeetingDetailPage'
|
||||||
import axios from 'axios'
|
import axios from 'axios'
|
||||||
@@ -111,15 +112,19 @@ export default function App() {
|
|||||||
<Routes>
|
<Routes>
|
||||||
<Route path="/" element={<DashboardPage />} />
|
<Route path="/" element={<DashboardPage />} />
|
||||||
<Route path="/tasks" element={<TasksPage />} />
|
<Route path="/tasks" element={<TasksPage />} />
|
||||||
<Route path="/tasks/:id" element={<TaskDetailPage />} />
|
<Route path="/tasks/:taskCode" element={<TaskDetailPage />} />
|
||||||
<Route path="/projects" element={<ProjectsPage />} />
|
<Route path="/projects" element={<ProjectsPage />} />
|
||||||
<Route path="/projects/:id" element={<ProjectDetailPage />} />
|
<Route path="/projects/:id" element={<ProjectDetailPage />} />
|
||||||
<Route path="/milestones" element={<MilestonesPage />} />
|
<Route path="/milestones" element={<MilestonesPage />} />
|
||||||
<Route path="/milestones/:id" element={<MilestoneDetailPage />} />
|
<Route path="/milestones/:milestoneCode" element={<MilestoneDetailPage />} />
|
||||||
<Route path="/proposes" element={<ProposesPage />} />
|
<Route path="/proposals" element={<ProposalsPage />} />
|
||||||
<Route path="/proposes/:id" element={<ProposeDetailPage />} />
|
<Route path="/proposals/:proposalCode" element={<ProposalDetailPage />} />
|
||||||
<Route path="/meetings/:meetingId" element={<MeetingDetailPage />} />
|
<Route path="/calendar" element={<CalendarPage />} />
|
||||||
<Route path="/supports/:supportId" element={<SupportDetailPage />} />
|
{/* Legacy routes for backward compatibility */}
|
||||||
|
<Route path="/proposes" element={<ProposalsPage />} />
|
||||||
|
<Route path="/proposes/:proposalCode" element={<ProposalDetailPage />} />
|
||||||
|
<Route path="/meetings/:meetingCode" element={<MeetingDetailPage />} />
|
||||||
|
<Route path="/supports/:supportCode" element={<SupportDetailPage />} />
|
||||||
<Route path="/notifications" element={<NotificationsPage />} />
|
<Route path="/notifications" element={<NotificationsPage />} />
|
||||||
<Route path="/roles" element={<RoleEditorPage />} />
|
<Route path="/roles" element={<RoleEditorPage />} />
|
||||||
<Route path="/users" element={<UsersPage />} />
|
<Route path="/users" element={<UsersPage />} />
|
||||||
|
|||||||
@@ -3,7 +3,7 @@ import api from '@/services/api'
|
|||||||
import type { Milestone, Project, Task } from '@/types'
|
import type { Milestone, Project, Task } from '@/types'
|
||||||
|
|
||||||
const TASK_TYPES = [
|
const TASK_TYPES = [
|
||||||
{ value: 'story', label: 'Story', subtypes: ['improvement', 'refactor'] }, // P9.6: 'feature' removed — must come from propose accept
|
// P9.6: 'story' removed — all story/* types are restricted; must come from Proposal Accept workflow
|
||||||
{ value: 'issue', label: 'Issue', subtypes: ['infrastructure', 'performance', 'regression', 'security', 'user_experience', 'defect'] },
|
{ value: 'issue', label: 'Issue', subtypes: ['infrastructure', 'performance', 'regression', 'security', 'user_experience', 'defect'] },
|
||||||
// P7.1: 'task' type removed — defect subtype migrated to issue/defect
|
// P7.1: 'task' type removed — defect subtype migrated to issue/defect
|
||||||
{ value: 'test', label: 'Test', subtypes: ['regression', 'security', 'smoke', 'stress'] },
|
{ value: 'test', label: 'Test', subtypes: ['regression', 'security', 'smoke', 'stress'] },
|
||||||
@@ -18,8 +18,8 @@ type Props = {
|
|||||||
onClose: () => void
|
onClose: () => void
|
||||||
onCreated?: (task: Task) => void | Promise<void>
|
onCreated?: (task: Task) => void | Promise<void>
|
||||||
onSaved?: (task: Task) => void | Promise<void>
|
onSaved?: (task: Task) => void | Promise<void>
|
||||||
initialProjectId?: number
|
initialProjectCode?: string
|
||||||
initialMilestoneId?: number
|
initialMilestoneCode?: string
|
||||||
lockProject?: boolean
|
lockProject?: boolean
|
||||||
lockMilestone?: boolean
|
lockMilestone?: boolean
|
||||||
task?: Task | null
|
task?: Task | null
|
||||||
@@ -28,8 +28,8 @@ type Props = {
|
|||||||
type FormState = {
|
type FormState = {
|
||||||
title: string
|
title: string
|
||||||
description: string
|
description: string
|
||||||
project_id: number
|
project_code: string
|
||||||
milestone_id: number
|
milestone_code: string
|
||||||
task_type: string
|
task_type: string
|
||||||
task_subtype: string
|
task_subtype: string
|
||||||
priority: string
|
priority: string
|
||||||
@@ -37,11 +37,11 @@ type FormState = {
|
|||||||
reporter_id: number
|
reporter_id: number
|
||||||
}
|
}
|
||||||
|
|
||||||
const makeInitialForm = (projectId = 0, milestoneId = 0): FormState => ({
|
const makeInitialForm = (projectCode = '', milestoneCode = ''): FormState => ({
|
||||||
title: '',
|
title: '',
|
||||||
description: '',
|
description: '',
|
||||||
project_id: projectId,
|
project_code: projectCode,
|
||||||
milestone_id: milestoneId,
|
milestone_code: milestoneCode,
|
||||||
task_type: 'issue', // P7.1: default changed from 'task' to 'issue'
|
task_type: 'issue', // P7.1: default changed from 'task' to 'issue'
|
||||||
task_subtype: '',
|
task_subtype: '',
|
||||||
priority: 'medium',
|
priority: 'medium',
|
||||||
@@ -54,8 +54,8 @@ export default function CreateTaskModal({
|
|||||||
onClose,
|
onClose,
|
||||||
onCreated,
|
onCreated,
|
||||||
onSaved,
|
onSaved,
|
||||||
initialProjectId,
|
initialProjectCode,
|
||||||
initialMilestoneId,
|
initialMilestoneCode,
|
||||||
lockProject = false,
|
lockProject = false,
|
||||||
lockMilestone = false,
|
lockMilestone = false,
|
||||||
task,
|
task,
|
||||||
@@ -63,7 +63,7 @@ export default function CreateTaskModal({
|
|||||||
const [projects, setProjects] = useState<Project[]>([])
|
const [projects, setProjects] = useState<Project[]>([])
|
||||||
const [milestones, setMilestones] = useState<Milestone[]>([])
|
const [milestones, setMilestones] = useState<Milestone[]>([])
|
||||||
const [saving, setSaving] = useState(false)
|
const [saving, setSaving] = useState(false)
|
||||||
const [form, setForm] = useState<FormState>(makeInitialForm(initialProjectId, initialMilestoneId))
|
const [form, setForm] = useState<FormState>(makeInitialForm(initialProjectCode, initialMilestoneCode))
|
||||||
|
|
||||||
const isEdit = Boolean(task)
|
const isEdit = Boolean(task)
|
||||||
const currentType = useMemo(
|
const currentType = useMemo(
|
||||||
@@ -72,18 +72,18 @@ export default function CreateTaskModal({
|
|||||||
)
|
)
|
||||||
const subtypes = currentType.subtypes || []
|
const subtypes = currentType.subtypes || []
|
||||||
|
|
||||||
const loadMilestones = async (projectId: number, preferredMilestoneId?: number) => {
|
const loadMilestones = async (projectCode: string, preferredMilestoneCode?: string) => {
|
||||||
if (!projectId) {
|
if (!projectCode) {
|
||||||
setMilestones([])
|
setMilestones([])
|
||||||
setForm((f) => ({ ...f, milestone_id: 0 }))
|
setForm((f) => ({ ...f, milestone_code: '' }))
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
const { data } = await api.get<Milestone[]>(`/milestones?project_id=${projectId}`)
|
const { data } = await api.get<Milestone[]>(`/milestones?project_code=${projectCode}`)
|
||||||
setMilestones(data)
|
setMilestones(data)
|
||||||
const hasPreferred = preferredMilestoneId && data.some((m) => m.id === preferredMilestoneId)
|
const hasPreferred = preferredMilestoneCode && data.some((m) => m.milestone_code === preferredMilestoneCode)
|
||||||
const nextMilestoneId = hasPreferred ? preferredMilestoneId! : (data[0]?.id || 0)
|
const nextMilestoneCode = hasPreferred ? preferredMilestoneCode! : (data[0]?.milestone_code || '')
|
||||||
setForm((f) => ({ ...f, milestone_id: nextMilestoneId }))
|
setForm((f) => ({ ...f, milestone_code: nextMilestoneCode }))
|
||||||
}
|
}
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
@@ -93,30 +93,30 @@ export default function CreateTaskModal({
|
|||||||
const { data } = await api.get<Project[]>('/projects')
|
const { data } = await api.get<Project[]>('/projects')
|
||||||
setProjects(data)
|
setProjects(data)
|
||||||
|
|
||||||
const chosenProjectId = task?.project_id || initialProjectId || data[0]?.id || 0
|
const chosenProjectCode = task?.project_code || initialProjectCode || data[0]?.project_code || ''
|
||||||
const chosenMilestoneId = task?.milestone_id || initialMilestoneId || 0
|
const chosenMilestoneCode = task?.milestone_code || initialMilestoneCode || ''
|
||||||
|
|
||||||
setForm(task ? {
|
setForm(task ? {
|
||||||
title: task.title,
|
title: task.title,
|
||||||
description: task.description || '',
|
description: task.description || '',
|
||||||
project_id: task.project_id,
|
project_code: task.project_code || '',
|
||||||
milestone_id: task.milestone_id || 0,
|
milestone_code: task.milestone_code || '',
|
||||||
task_type: task.task_type,
|
task_type: task.task_type,
|
||||||
task_subtype: task.task_subtype || '',
|
task_subtype: task.task_subtype || '',
|
||||||
priority: task.priority,
|
priority: task.priority,
|
||||||
tags: task.tags || '',
|
tags: task.tags || '',
|
||||||
reporter_id: task.reporter_id,
|
reporter_id: task.reporter_id,
|
||||||
} : makeInitialForm(chosenProjectId, chosenMilestoneId))
|
} : makeInitialForm(chosenProjectCode, chosenMilestoneCode))
|
||||||
|
|
||||||
await loadMilestones(chosenProjectId, chosenMilestoneId)
|
await loadMilestones(chosenProjectCode, chosenMilestoneCode)
|
||||||
}
|
}
|
||||||
|
|
||||||
init().catch(console.error)
|
init().catch(console.error)
|
||||||
}, [isOpen, initialProjectId, initialMilestoneId, task])
|
}, [isOpen, initialProjectCode, initialMilestoneCode, task])
|
||||||
|
|
||||||
const handleProjectChange = async (projectId: number) => {
|
const handleProjectChange = async (projectCode: string) => {
|
||||||
setForm((f) => ({ ...f, project_id: projectId, milestone_id: 0 }))
|
setForm((f) => ({ ...f, project_code: projectCode, milestone_code: '' }))
|
||||||
await loadMilestones(projectId)
|
await loadMilestones(projectCode)
|
||||||
}
|
}
|
||||||
|
|
||||||
const handleTypeChange = (taskType: string) => {
|
const handleTypeChange = (taskType: string) => {
|
||||||
@@ -125,7 +125,7 @@ export default function CreateTaskModal({
|
|||||||
|
|
||||||
const submit = async (e: React.FormEvent) => {
|
const submit = async (e: React.FormEvent) => {
|
||||||
e.preventDefault()
|
e.preventDefault()
|
||||||
if (!form.milestone_id) {
|
if (!form.milestone_code) {
|
||||||
alert('Please select a milestone')
|
alert('Please select a milestone')
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
@@ -136,7 +136,7 @@ export default function CreateTaskModal({
|
|||||||
setSaving(true)
|
setSaving(true)
|
||||||
try {
|
try {
|
||||||
const { data } = isEdit
|
const { data } = isEdit
|
||||||
? await api.patch<Task>(`/tasks/${task!.id}`, payload)
|
? await api.patch<Task>(`/tasks/${task!.task_code}`, payload)
|
||||||
: await api.post<Task>('/tasks', payload)
|
: await api.post<Task>('/tasks', payload)
|
||||||
await onCreated?.(data)
|
await onCreated?.(data)
|
||||||
await onSaved?.(data)
|
await onSaved?.(data)
|
||||||
@@ -181,12 +181,12 @@ export default function CreateTaskModal({
|
|||||||
Project
|
Project
|
||||||
<select
|
<select
|
||||||
data-testid="project-select"
|
data-testid="project-select"
|
||||||
value={form.project_id}
|
value={form.project_code}
|
||||||
onChange={(e) => handleProjectChange(Number(e.target.value))}
|
onChange={(e) => handleProjectChange(e.target.value)}
|
||||||
disabled={lockProject}
|
disabled={lockProject}
|
||||||
>
|
>
|
||||||
{projects.map((p) => (
|
{projects.map((p) => (
|
||||||
<option key={p.id} value={p.id}>{p.name}</option>
|
<option key={p.id} value={p.project_code || ''}>{p.name}</option>
|
||||||
))}
|
))}
|
||||||
</select>
|
</select>
|
||||||
</label>
|
</label>
|
||||||
@@ -195,13 +195,13 @@ export default function CreateTaskModal({
|
|||||||
Milestone
|
Milestone
|
||||||
<select
|
<select
|
||||||
data-testid="milestone-select"
|
data-testid="milestone-select"
|
||||||
value={form.milestone_id}
|
value={form.milestone_code}
|
||||||
onChange={(e) => setForm({ ...form, milestone_id: Number(e.target.value) })}
|
onChange={(e) => setForm({ ...form, milestone_code: e.target.value })}
|
||||||
disabled={lockMilestone}
|
disabled={lockMilestone}
|
||||||
>
|
>
|
||||||
{milestones.length === 0 && <option value={0}>No milestones available</option>}
|
{milestones.length === 0 && <option value={0}>No milestones available</option>}
|
||||||
{milestones.map((m) => (
|
{milestones.map((m) => (
|
||||||
<option key={m.id} value={m.id}>{m.title}</option>
|
<option key={m.id} value={m.milestone_code || ''}>{m.title}</option>
|
||||||
))}
|
))}
|
||||||
</select>
|
</select>
|
||||||
</label>
|
</label>
|
||||||
|
|||||||
@@ -7,14 +7,14 @@ type Props = {
|
|||||||
onClose: () => void
|
onClose: () => void
|
||||||
onSaved?: (milestone: Milestone) => void | Promise<void>
|
onSaved?: (milestone: Milestone) => void | Promise<void>
|
||||||
milestone?: Milestone | null
|
milestone?: Milestone | null
|
||||||
initialProjectId?: number
|
initialProjectCode?: string
|
||||||
lockProject?: boolean
|
lockProject?: boolean
|
||||||
}
|
}
|
||||||
|
|
||||||
type FormState = {
|
type FormState = {
|
||||||
title: string
|
title: string
|
||||||
description: string
|
description: string
|
||||||
project_id: number
|
project_code: string
|
||||||
status: string
|
status: string
|
||||||
due_date: string
|
due_date: string
|
||||||
planned_release_date: string
|
planned_release_date: string
|
||||||
@@ -23,7 +23,7 @@ type FormState = {
|
|||||||
const emptyForm: FormState = {
|
const emptyForm: FormState = {
|
||||||
title: '',
|
title: '',
|
||||||
description: '',
|
description: '',
|
||||||
project_id: 0,
|
project_code: '',
|
||||||
status: 'open',
|
status: 'open',
|
||||||
due_date: '',
|
due_date: '',
|
||||||
planned_release_date: '',
|
planned_release_date: '',
|
||||||
@@ -31,7 +31,7 @@ const emptyForm: FormState = {
|
|||||||
|
|
||||||
const toDateInput = (value?: string | null) => (value ? String(value).slice(0, 10) : '')
|
const toDateInput = (value?: string | null) => (value ? String(value).slice(0, 10) : '')
|
||||||
|
|
||||||
export default function MilestoneFormModal({ isOpen, onClose, onSaved, milestone, initialProjectId, lockProject = false }: Props) {
|
export default function MilestoneFormModal({ isOpen, onClose, onSaved, milestone, initialProjectCode, lockProject = false }: Props) {
|
||||||
const [projects, setProjects] = useState<Project[]>([])
|
const [projects, setProjects] = useState<Project[]>([])
|
||||||
const [saving, setSaving] = useState(false)
|
const [saving, setSaving] = useState(false)
|
||||||
const [form, setForm] = useState<FormState>(emptyForm)
|
const [form, setForm] = useState<FormState>(emptyForm)
|
||||||
@@ -42,11 +42,11 @@ export default function MilestoneFormModal({ isOpen, onClose, onSaved, milestone
|
|||||||
const init = async () => {
|
const init = async () => {
|
||||||
const { data } = await api.get<Project[]>('/projects')
|
const { data } = await api.get<Project[]>('/projects')
|
||||||
setProjects(data)
|
setProjects(data)
|
||||||
const defaultProjectId = milestone?.project_id || initialProjectId || data[0]?.id || 0
|
const defaultProjectCode = milestone?.project_code || initialProjectCode || data[0]?.project_code || ''
|
||||||
setForm({
|
setForm({
|
||||||
title: milestone?.title || '',
|
title: milestone?.title || '',
|
||||||
description: milestone?.description || '',
|
description: milestone?.description || '',
|
||||||
project_id: defaultProjectId,
|
project_code: defaultProjectCode,
|
||||||
status: milestone?.status || 'open',
|
status: milestone?.status || 'open',
|
||||||
due_date: toDateInput(milestone?.due_date),
|
due_date: toDateInput(milestone?.due_date),
|
||||||
planned_release_date: toDateInput(milestone?.planned_release_date),
|
planned_release_date: toDateInput(milestone?.planned_release_date),
|
||||||
@@ -54,7 +54,7 @@ export default function MilestoneFormModal({ isOpen, onClose, onSaved, milestone
|
|||||||
}
|
}
|
||||||
|
|
||||||
init().catch(console.error)
|
init().catch(console.error)
|
||||||
}, [isOpen, milestone, initialProjectId])
|
}, [isOpen, milestone, initialProjectCode])
|
||||||
|
|
||||||
const submit = async (e: React.FormEvent) => {
|
const submit = async (e: React.FormEvent) => {
|
||||||
e.preventDefault()
|
e.preventDefault()
|
||||||
@@ -63,13 +63,13 @@ export default function MilestoneFormModal({ isOpen, onClose, onSaved, milestone
|
|||||||
const payload = {
|
const payload = {
|
||||||
title: form.title,
|
title: form.title,
|
||||||
description: form.description || null,
|
description: form.description || null,
|
||||||
project_id: form.project_id,
|
project_code: form.project_code,
|
||||||
status: form.status,
|
status: form.status,
|
||||||
due_date: form.due_date || null,
|
due_date: form.due_date || null,
|
||||||
planned_release_date: form.planned_release_date || null,
|
planned_release_date: form.planned_release_date || null,
|
||||||
}
|
}
|
||||||
if (milestone) {
|
if (milestone) {
|
||||||
const { data } = await api.patch<Milestone>(`/milestones/${milestone.id}`, payload)
|
const { data } = await api.patch<Milestone>(`/milestones/${milestone.milestone_code}`, payload)
|
||||||
await onSaved?.(data)
|
await onSaved?.(data)
|
||||||
} else {
|
} else {
|
||||||
const { data } = await api.post<Milestone>('/milestones', payload)
|
const { data } = await api.post<Milestone>('/milestones', payload)
|
||||||
@@ -116,8 +116,8 @@ export default function MilestoneFormModal({ isOpen, onClose, onSaved, milestone
|
|||||||
<div className="task-create-grid">
|
<div className="task-create-grid">
|
||||||
<label>
|
<label>
|
||||||
Project
|
Project
|
||||||
<select value={form.project_id} onChange={(e) => setForm((f) => ({ ...f, project_id: Number(e.target.value) }))} disabled={lockProject}>
|
<select value={form.project_code} onChange={(e) => setForm((f) => ({ ...f, project_code: e.target.value }))} disabled={lockProject}>
|
||||||
{projects.map((p) => <option key={p.id} value={p.id}>{p.name}</option>)}
|
{projects.map((p) => <option key={p.id} value={p.project_code || ''}>{p.name}</option>)}
|
||||||
</select>
|
</select>
|
||||||
</label>
|
</label>
|
||||||
|
|
||||||
|
|||||||
@@ -32,7 +32,8 @@ export default function Sidebar({ user, onLogout }: Props) {
|
|||||||
const links = user ? [
|
const links = user ? [
|
||||||
{ to: '/', icon: '📊', label: 'Dashboard' },
|
{ to: '/', icon: '📊', label: 'Dashboard' },
|
||||||
{ to: '/projects', icon: '📁', label: 'Projects' },
|
{ to: '/projects', icon: '📁', label: 'Projects' },
|
||||||
{ to: '/proposes', icon: '💡', label: 'Proposes' },
|
{ to: '/proposals', icon: '💡', label: 'Proposals' },
|
||||||
|
{ to: '/calendar', icon: '📅', label: 'Calendar' },
|
||||||
{ to: '/notifications', icon: '🔔', label: 'Notifications' + (unreadCount > 0 ? ' (' + unreadCount + ')' : '') },
|
{ to: '/notifications', icon: '🔔', label: 'Notifications' + (unreadCount > 0 ? ' (' + unreadCount + ')' : '') },
|
||||||
{ to: '/monitor', icon: '📡', label: 'Monitor' },
|
{ to: '/monitor', icon: '📡', label: 'Monitor' },
|
||||||
...(user.is_admin ? [
|
...(user.is_admin ? [
|
||||||
|
|||||||
851
src/pages/CalendarPage.tsx
Normal file
851
src/pages/CalendarPage.tsx
Normal file
@@ -0,0 +1,851 @@
|
|||||||
|
import { useState, useEffect } from 'react'
|
||||||
|
import api from '@/services/api'
|
||||||
|
import dayjs from 'dayjs'
|
||||||
|
|
||||||
|
// Types for Calendar entities
|
||||||
|
type SlotType = 'work' | 'on_call' | 'entertainment' | 'system'
|
||||||
|
type EventType = 'job' | 'entertainment' | 'system_event'
|
||||||
|
type SlotStatus = 'not_started' | 'ongoing' | 'deferred' | 'skipped' | 'paused' | 'finished' | 'aborted'
|
||||||
|
|
||||||
|
interface TimeSlotResponse {
|
||||||
|
slot_id: string // real int id or "plan-{planId}-{date}" for virtual
|
||||||
|
date: string
|
||||||
|
slot_type: SlotType
|
||||||
|
estimated_duration: number
|
||||||
|
scheduled_at: string // HH:mm
|
||||||
|
started_at: string | null
|
||||||
|
attended: boolean
|
||||||
|
actual_duration: number | null
|
||||||
|
event_type: EventType | null
|
||||||
|
event_data: Record<string, any> | null
|
||||||
|
priority: number
|
||||||
|
status: SlotStatus
|
||||||
|
plan_id: number | null
|
||||||
|
is_virtual: boolean
|
||||||
|
created_at: string | null
|
||||||
|
updated_at: string | null
|
||||||
|
}
|
||||||
|
|
||||||
|
interface DayViewResponse {
|
||||||
|
date: string
|
||||||
|
user_id: number
|
||||||
|
slots: TimeSlotResponse[]
|
||||||
|
}
|
||||||
|
|
||||||
|
interface SchedulePlanResponse {
|
||||||
|
id: number
|
||||||
|
slot_type: SlotType
|
||||||
|
estimated_duration: number
|
||||||
|
event_type: string | null
|
||||||
|
event_data: Record<string, any> | null
|
||||||
|
at_time: string
|
||||||
|
on_day: string | null
|
||||||
|
on_week: number | null
|
||||||
|
on_month: string | null
|
||||||
|
is_active: boolean
|
||||||
|
created_at: string
|
||||||
|
updated_at: string | null
|
||||||
|
}
|
||||||
|
|
||||||
|
interface PlanListResponse {
|
||||||
|
plans: SchedulePlanResponse[]
|
||||||
|
}
|
||||||
|
|
||||||
|
type Weekday = 'sun' | 'mon' | 'tue' | 'wed' | 'thu' | 'fri' | 'sat'
|
||||||
|
type MonthName = 'jan' | 'feb' | 'mar' | 'apr' | 'may' | 'jun' | 'jul' | 'aug' | 'sep' | 'oct' | 'nov' | 'dec'
|
||||||
|
|
||||||
|
interface WorkloadWarning {
|
||||||
|
period: string
|
||||||
|
slot_type: string
|
||||||
|
current: number
|
||||||
|
minimum: number
|
||||||
|
message: string
|
||||||
|
}
|
||||||
|
|
||||||
|
interface ScheduleResponse {
|
||||||
|
slot: TimeSlotResponse
|
||||||
|
warnings: WorkloadWarning[]
|
||||||
|
}
|
||||||
|
|
||||||
|
const SLOT_TYPES: { value: SlotType; label: string }[] = [
|
||||||
|
{ value: 'work', label: 'Work' },
|
||||||
|
{ value: 'on_call', label: 'On Call' },
|
||||||
|
{ value: 'entertainment', label: 'Entertainment' },
|
||||||
|
{ value: 'system', label: 'System' },
|
||||||
|
]
|
||||||
|
|
||||||
|
const EVENT_TYPES: { value: EventType; label: string }[] = [
|
||||||
|
{ value: 'job', label: 'Job' },
|
||||||
|
{ value: 'entertainment', label: 'Entertainment' },
|
||||||
|
{ value: 'system_event', label: 'System Event' },
|
||||||
|
]
|
||||||
|
|
||||||
|
const WEEKDAYS: { value: Weekday; label: string }[] = [
|
||||||
|
{ value: 'sun', label: 'Sunday' },
|
||||||
|
{ value: 'mon', label: 'Monday' },
|
||||||
|
{ value: 'tue', label: 'Tuesday' },
|
||||||
|
{ value: 'wed', label: 'Wednesday' },
|
||||||
|
{ value: 'thu', label: 'Thursday' },
|
||||||
|
{ value: 'fri', label: 'Friday' },
|
||||||
|
{ value: 'sat', label: 'Saturday' },
|
||||||
|
]
|
||||||
|
|
||||||
|
const MONTHS: { value: MonthName; label: string }[] = [
|
||||||
|
{ value: 'jan', label: 'January' },
|
||||||
|
{ value: 'feb', label: 'February' },
|
||||||
|
{ value: 'mar', label: 'March' },
|
||||||
|
{ value: 'apr', label: 'April' },
|
||||||
|
{ value: 'may', label: 'May' },
|
||||||
|
{ value: 'jun', label: 'June' },
|
||||||
|
{ value: 'jul', label: 'July' },
|
||||||
|
{ value: 'aug', label: 'August' },
|
||||||
|
{ value: 'sep', label: 'September' },
|
||||||
|
{ value: 'oct', label: 'October' },
|
||||||
|
{ value: 'nov', label: 'November' },
|
||||||
|
{ value: 'dec', label: 'December' },
|
||||||
|
]
|
||||||
|
|
||||||
|
const SLOT_TYPE_ICONS: Record<string, string> = {
|
||||||
|
work: '💼',
|
||||||
|
on_call: '📞',
|
||||||
|
entertainment: '🎮',
|
||||||
|
system: '⚙️',
|
||||||
|
}
|
||||||
|
|
||||||
|
const STATUS_CLASSES: Record<string, string> = {
|
||||||
|
not_started: 'status-open',
|
||||||
|
ongoing: 'status-undergoing',
|
||||||
|
deferred: 'status-pending',
|
||||||
|
skipped: 'status-closed',
|
||||||
|
paused: 'status-pending',
|
||||||
|
finished: 'status-completed',
|
||||||
|
aborted: 'status-closed',
|
||||||
|
}
|
||||||
|
|
||||||
|
export default function CalendarPage() {
|
||||||
|
const [selectedDate, setSelectedDate] = useState(dayjs().format('YYYY-MM-DD'))
|
||||||
|
const [slots, setSlots] = useState<TimeSlotResponse[]>([])
|
||||||
|
const [plans, setPlans] = useState<SchedulePlanResponse[]>([])
|
||||||
|
const [loading, setLoading] = useState(false)
|
||||||
|
const [activeTab, setActiveTab] = useState<'daily' | 'plans'>('daily')
|
||||||
|
const [error, setError] = useState('')
|
||||||
|
|
||||||
|
// Create/Edit slot modal state
|
||||||
|
const [showSlotModal, setShowSlotModal] = useState(false)
|
||||||
|
const [editingSlot, setEditingSlot] = useState<TimeSlotResponse | null>(null)
|
||||||
|
const [slotForm, setSlotForm] = useState({
|
||||||
|
slot_type: 'work' as SlotType,
|
||||||
|
scheduled_at: '09:00',
|
||||||
|
estimated_duration: 25,
|
||||||
|
event_type: '' as string,
|
||||||
|
event_data_code: '',
|
||||||
|
event_data_event: '',
|
||||||
|
priority: 50,
|
||||||
|
})
|
||||||
|
const [slotSaving, setSlotSaving] = useState(false)
|
||||||
|
const [warnings, setWarnings] = useState<WorkloadWarning[]>([])
|
||||||
|
const [showPlanModal, setShowPlanModal] = useState(false)
|
||||||
|
const [editingPlan, setEditingPlan] = useState<SchedulePlanResponse | null>(null)
|
||||||
|
const [planSaving, setPlanSaving] = useState(false)
|
||||||
|
const [planForm, setPlanForm] = useState({
|
||||||
|
slot_type: 'work' as SlotType,
|
||||||
|
estimated_duration: 25,
|
||||||
|
at_time: '09:00',
|
||||||
|
on_day: '' as Weekday | '',
|
||||||
|
on_week: '' as string,
|
||||||
|
on_month: '' as MonthName | '',
|
||||||
|
event_type: '' as string,
|
||||||
|
event_data_code: '',
|
||||||
|
event_data_event: '',
|
||||||
|
})
|
||||||
|
|
||||||
|
const fetchSlots = async (date: string) => {
|
||||||
|
setLoading(true)
|
||||||
|
setError('')
|
||||||
|
try {
|
||||||
|
const { data } = await api.get<DayViewResponse>(`/calendar/day?date=${date}`)
|
||||||
|
setSlots(Array.isArray(data?.slots) ? data.slots : [])
|
||||||
|
} catch (err: any) {
|
||||||
|
setError(err.response?.data?.detail || 'Failed to load calendar')
|
||||||
|
setSlots([])
|
||||||
|
} finally {
|
||||||
|
setLoading(false)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
const fetchPlans = async () => {
|
||||||
|
try {
|
||||||
|
const { data } = await api.get<PlanListResponse>('/calendar/plans')
|
||||||
|
setPlans(Array.isArray(data?.plans) ? data.plans : [])
|
||||||
|
} catch (err: any) {
|
||||||
|
console.error('Failed to load plans:', err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
fetchSlots(selectedDate)
|
||||||
|
fetchPlans()
|
||||||
|
}, [])
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
if (activeTab === 'daily') {
|
||||||
|
fetchSlots(selectedDate)
|
||||||
|
}
|
||||||
|
}, [selectedDate])
|
||||||
|
|
||||||
|
const handleDateChange = (e: React.ChangeEvent<HTMLInputElement>) => {
|
||||||
|
setSelectedDate(e.target.value)
|
||||||
|
}
|
||||||
|
|
||||||
|
const goToday = () => setSelectedDate(dayjs().format('YYYY-MM-DD'))
|
||||||
|
const goPrev = () => setSelectedDate(dayjs(selectedDate).subtract(1, 'day').format('YYYY-MM-DD'))
|
||||||
|
const goNext = () => setSelectedDate(dayjs(selectedDate).add(1, 'day').format('YYYY-MM-DD'))
|
||||||
|
|
||||||
|
const formatPlanSchedule = (plan: SchedulePlanResponse) => {
|
||||||
|
const parts: string[] = [`at ${plan.at_time}`]
|
||||||
|
if (plan.on_day) parts.push(`on ${plan.on_day}`)
|
||||||
|
if (plan.on_week) parts.push(`week ${plan.on_week}`)
|
||||||
|
if (plan.on_month) parts.push(`in ${plan.on_month}`)
|
||||||
|
return parts.join(' · ')
|
||||||
|
}
|
||||||
|
|
||||||
|
// --- Slot create/edit ---
|
||||||
|
const openCreateSlotModal = () => {
|
||||||
|
setEditingSlot(null)
|
||||||
|
setSlotForm({
|
||||||
|
slot_type: 'work',
|
||||||
|
scheduled_at: '09:00',
|
||||||
|
estimated_duration: 25,
|
||||||
|
event_type: '',
|
||||||
|
event_data_code: '',
|
||||||
|
event_data_event: '',
|
||||||
|
priority: 50,
|
||||||
|
})
|
||||||
|
setWarnings([])
|
||||||
|
setError('')
|
||||||
|
setShowSlotModal(true)
|
||||||
|
}
|
||||||
|
|
||||||
|
const openEditSlotModal = (slot: TimeSlotResponse) => {
|
||||||
|
setEditingSlot(slot)
|
||||||
|
setSlotForm({
|
||||||
|
slot_type: slot.slot_type,
|
||||||
|
scheduled_at: slot.scheduled_at,
|
||||||
|
estimated_duration: slot.estimated_duration,
|
||||||
|
event_type: slot.event_type || '',
|
||||||
|
event_data_code: slot.event_data?.code || '',
|
||||||
|
event_data_event: slot.event_data?.event || '',
|
||||||
|
priority: slot.priority,
|
||||||
|
})
|
||||||
|
setWarnings([])
|
||||||
|
setError('')
|
||||||
|
setShowSlotModal(true)
|
||||||
|
}
|
||||||
|
|
||||||
|
const buildEventData = () => {
|
||||||
|
if (!slotForm.event_type) return null
|
||||||
|
if (slotForm.event_type === 'job') {
|
||||||
|
return slotForm.event_data_code ? { type: 'Task', code: slotForm.event_data_code } : null
|
||||||
|
}
|
||||||
|
if (slotForm.event_type === 'system_event') {
|
||||||
|
return slotForm.event_data_event ? { event: slotForm.event_data_event } : null
|
||||||
|
}
|
||||||
|
return null
|
||||||
|
}
|
||||||
|
|
||||||
|
const buildPlanEventData = () => {
|
||||||
|
if (!planForm.event_type) return null
|
||||||
|
if (planForm.event_type === 'job') {
|
||||||
|
return planForm.event_data_code ? { type: 'Task', code: planForm.event_data_code } : null
|
||||||
|
}
|
||||||
|
if (planForm.event_type === 'system_event') {
|
||||||
|
return planForm.event_data_event ? { event: planForm.event_data_event } : null
|
||||||
|
}
|
||||||
|
return null
|
||||||
|
}
|
||||||
|
|
||||||
|
const openCreatePlanModal = () => {
|
||||||
|
setEditingPlan(null)
|
||||||
|
setPlanForm({
|
||||||
|
slot_type: 'work',
|
||||||
|
estimated_duration: 25,
|
||||||
|
at_time: '09:00',
|
||||||
|
on_day: '',
|
||||||
|
on_week: '',
|
||||||
|
on_month: '',
|
||||||
|
event_type: '',
|
||||||
|
event_data_code: '',
|
||||||
|
event_data_event: '',
|
||||||
|
})
|
||||||
|
setError('')
|
||||||
|
setShowPlanModal(true)
|
||||||
|
}
|
||||||
|
|
||||||
|
const openEditPlanModal = (plan: SchedulePlanResponse) => {
|
||||||
|
setEditingPlan(plan)
|
||||||
|
setPlanForm({
|
||||||
|
slot_type: plan.slot_type,
|
||||||
|
estimated_duration: plan.estimated_duration,
|
||||||
|
at_time: plan.at_time.slice(0, 5),
|
||||||
|
on_day: (plan.on_day?.toLowerCase() as Weekday | undefined) || '',
|
||||||
|
on_week: plan.on_week ? String(plan.on_week) : '',
|
||||||
|
on_month: (plan.on_month?.toLowerCase() as MonthName | undefined) || '',
|
||||||
|
event_type: plan.event_type || '',
|
||||||
|
event_data_code: plan.event_data?.code || '',
|
||||||
|
event_data_event: plan.event_data?.event || '',
|
||||||
|
})
|
||||||
|
setError('')
|
||||||
|
setShowPlanModal(true)
|
||||||
|
}
|
||||||
|
|
||||||
|
const handleSavePlan = async () => {
|
||||||
|
setPlanSaving(true)
|
||||||
|
setError('')
|
||||||
|
try {
|
||||||
|
const payload: any = {
|
||||||
|
slot_type: planForm.slot_type,
|
||||||
|
estimated_duration: planForm.estimated_duration,
|
||||||
|
at_time: planForm.at_time,
|
||||||
|
on_day: planForm.on_day || null,
|
||||||
|
on_week: planForm.on_week ? Number(planForm.on_week) : null,
|
||||||
|
on_month: planForm.on_month || null,
|
||||||
|
event_type: planForm.event_type || null,
|
||||||
|
event_data: buildPlanEventData(),
|
||||||
|
}
|
||||||
|
|
||||||
|
if (editingPlan) {
|
||||||
|
await api.patch(`/calendar/plans/${editingPlan.id}`, payload)
|
||||||
|
} else {
|
||||||
|
await api.post('/calendar/plans', payload)
|
||||||
|
}
|
||||||
|
|
||||||
|
setShowPlanModal(false)
|
||||||
|
fetchPlans()
|
||||||
|
if (activeTab === 'daily') {
|
||||||
|
fetchSlots(selectedDate)
|
||||||
|
}
|
||||||
|
} catch (err: any) {
|
||||||
|
setError(err.response?.data?.detail || 'Save plan failed')
|
||||||
|
} finally {
|
||||||
|
setPlanSaving(false)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
const handleSaveSlot = async () => {
|
||||||
|
setSlotSaving(true)
|
||||||
|
setError('')
|
||||||
|
setWarnings([])
|
||||||
|
try {
|
||||||
|
const payload: any = {
|
||||||
|
slot_type: slotForm.slot_type,
|
||||||
|
scheduled_at: slotForm.scheduled_at,
|
||||||
|
estimated_duration: slotForm.estimated_duration,
|
||||||
|
priority: slotForm.priority,
|
||||||
|
event_type: slotForm.event_type || null,
|
||||||
|
event_data: buildEventData(),
|
||||||
|
}
|
||||||
|
|
||||||
|
let response: any
|
||||||
|
if (editingSlot) {
|
||||||
|
// Edit existing slot
|
||||||
|
if (editingSlot.is_virtual) {
|
||||||
|
response = await api.patch(`/calendar/slots/virtual/${editingSlot.slot_id}`, payload)
|
||||||
|
} else if (editingSlot.slot_id) {
|
||||||
|
response = await api.patch(`/calendar/slots/${editingSlot.slot_id}`, payload)
|
||||||
|
} else {
|
||||||
|
throw new Error('Missing slot identifier for edit')
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
// Create new slot
|
||||||
|
payload.date = selectedDate
|
||||||
|
response = await api.post('/calendar/slots', payload)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Check for warnings in response
|
||||||
|
if (response.data?.warnings && response.data.warnings.length > 0) {
|
||||||
|
setWarnings(response.data.warnings)
|
||||||
|
}
|
||||||
|
|
||||||
|
setShowSlotModal(false)
|
||||||
|
fetchSlots(selectedDate)
|
||||||
|
} catch (err: any) {
|
||||||
|
const detail = err.response?.data?.detail
|
||||||
|
if (typeof detail === 'string' && detail.toLowerCase().includes('overlap')) {
|
||||||
|
setError(`⚠️ Overlap conflict: ${detail}`)
|
||||||
|
} else if (detail && typeof detail === 'object') {
|
||||||
|
const message = typeof detail.message === 'string' ? detail.message : 'Save failed'
|
||||||
|
const conflicts = Array.isArray(detail.conflicts) ? detail.conflicts : []
|
||||||
|
if (conflicts.length > 0) {
|
||||||
|
const summary = conflicts
|
||||||
|
.map((conflict: any) => `${conflict.slot_type || 'slot'} at ${conflict.scheduled_at || 'unknown time'}`)
|
||||||
|
.join(', ')
|
||||||
|
setError(`⚠️ ${message}: ${summary}`)
|
||||||
|
} else {
|
||||||
|
setError(`⚠️ ${message}`)
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
setError(detail || 'Save failed')
|
||||||
|
}
|
||||||
|
} finally {
|
||||||
|
setSlotSaving(false)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// --- Slot cancel ---
|
||||||
|
const handleCancelSlot = async (slot: TimeSlotResponse) => {
|
||||||
|
if (!confirm(`Cancel this ${slot.slot_type} slot at ${slot.scheduled_at}?`)) return
|
||||||
|
setError('')
|
||||||
|
try {
|
||||||
|
if (slot.is_virtual) {
|
||||||
|
await api.post(`/calendar/slots/virtual/${slot.slot_id}/cancel`)
|
||||||
|
} else if (slot.slot_id) {
|
||||||
|
await api.post(`/calendar/slots/${slot.slot_id}/cancel`)
|
||||||
|
} else {
|
||||||
|
throw new Error('Missing slot identifier for cancel')
|
||||||
|
}
|
||||||
|
fetchSlots(selectedDate)
|
||||||
|
} catch (err: any) {
|
||||||
|
setError(err.response?.data?.detail || 'Cancel failed')
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// --- Plan cancel ---
|
||||||
|
const handleCancelPlan = async (plan: SchedulePlanResponse) => {
|
||||||
|
if (!confirm(`Cancel plan #${plan.id}? This won't affect past materialized slots.`)) return
|
||||||
|
setError('')
|
||||||
|
try {
|
||||||
|
await api.post(`/calendar/plans/${plan.id}/cancel`)
|
||||||
|
fetchPlans()
|
||||||
|
} catch (err: any) {
|
||||||
|
setError(err.response?.data?.detail || 'Cancel plan failed')
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Check if a date is in the past
|
||||||
|
const isPastDate = dayjs(selectedDate).isBefore(dayjs().startOf('day'))
|
||||||
|
|
||||||
|
return (
|
||||||
|
<div className="calendar-page">
|
||||||
|
<div className="page-header" style={{ display: 'flex', justifyContent: 'space-between', alignItems: 'center', marginBottom: 16 }}>
|
||||||
|
<h2>📅 Calendar</h2>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
{/* Tab switcher */}
|
||||||
|
<div style={{ display: 'flex', gap: 8, marginBottom: 16 }}>
|
||||||
|
<button
|
||||||
|
className={activeTab === 'daily' ? 'btn-primary' : 'btn-secondary'}
|
||||||
|
onClick={() => setActiveTab('daily')}
|
||||||
|
>
|
||||||
|
Daily View
|
||||||
|
</button>
|
||||||
|
<button
|
||||||
|
className={activeTab === 'plans' ? 'btn-primary' : 'btn-secondary'}
|
||||||
|
onClick={() => setActiveTab('plans')}
|
||||||
|
>
|
||||||
|
Plans ({plans.length})
|
||||||
|
</button>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
{error && <div className="error-message" style={{ color: 'var(--danger)', marginBottom: 12 }}>{error}</div>}
|
||||||
|
|
||||||
|
{/* Workload warnings banner */}
|
||||||
|
{warnings.length > 0 && (
|
||||||
|
<div style={{ background: 'var(--warning-bg, #fff3cd)', border: '1px solid var(--warning-border, #ffc107)', borderRadius: 8, padding: 12, marginBottom: 12 }}>
|
||||||
|
<strong>⚠️ Workload Warnings:</strong>
|
||||||
|
<ul style={{ margin: '4px 0 0 16px', padding: 0 }}>
|
||||||
|
{warnings.map((w, i) => (
|
||||||
|
<li key={i}>{w.message} ({w.period} {w.slot_type}: {w.current}/{w.minimum} min)</li>
|
||||||
|
))}
|
||||||
|
</ul>
|
||||||
|
</div>
|
||||||
|
)}
|
||||||
|
|
||||||
|
{activeTab === 'daily' && (
|
||||||
|
<>
|
||||||
|
{/* Date navigation */}
|
||||||
|
<div style={{ display: 'flex', alignItems: 'center', gap: 8, marginBottom: 16 }}>
|
||||||
|
<button className="btn-secondary" onClick={goPrev}>◀</button>
|
||||||
|
<input
|
||||||
|
type="date"
|
||||||
|
value={selectedDate}
|
||||||
|
onChange={handleDateChange}
|
||||||
|
style={{ fontSize: '1rem', padding: '4px 8px' }}
|
||||||
|
/>
|
||||||
|
<button className="btn-secondary" onClick={goNext}>▶</button>
|
||||||
|
<button className="btn-transition" onClick={goToday}>Today</button>
|
||||||
|
{!isPastDate && (
|
||||||
|
<button className="btn-primary" onClick={openCreateSlotModal} style={{ marginLeft: 'auto' }}>+ New Slot</button>
|
||||||
|
)}
|
||||||
|
</div>
|
||||||
|
|
||||||
|
{/* Deferred slots notice */}
|
||||||
|
{slots.some(s => s.status === 'deferred') && (
|
||||||
|
<div style={{ background: 'var(--warning-bg, #fff3cd)', border: '1px solid var(--warning-border, #ffc107)', borderRadius: 8, padding: 10, marginBottom: 12, fontSize: '0.9rem' }}>
|
||||||
|
⏳ Some slots are <strong>deferred</strong> — they were postponed due to scheduling conflicts or agent unavailability.
|
||||||
|
</div>
|
||||||
|
)}
|
||||||
|
|
||||||
|
{/* Slot list */}
|
||||||
|
{loading ? (
|
||||||
|
<div className="loading">Loading...</div>
|
||||||
|
) : slots.length === 0 ? (
|
||||||
|
<div className="empty" style={{ padding: '40px 0', color: 'var(--text-secondary)', textAlign: 'center' }}>
|
||||||
|
No slots scheduled for {dayjs(selectedDate).format('MMMM D, YYYY')}.
|
||||||
|
</div>
|
||||||
|
) : (
|
||||||
|
<div className="milestone-grid">
|
||||||
|
{slots.map((slot) => (
|
||||||
|
<div
|
||||||
|
key={slot.slot_id}
|
||||||
|
className="milestone-card"
|
||||||
|
style={{ opacity: slot.is_virtual ? 0.8 : 1 }}
|
||||||
|
>
|
||||||
|
<div className="milestone-card-header" style={{ display: 'flex', alignItems: 'center', gap: 8, flexWrap: 'wrap' }}>
|
||||||
|
<span style={{ fontSize: '1.2rem' }}>{SLOT_TYPE_ICONS[slot.slot_type] || '📋'}</span>
|
||||||
|
<span className="badge">{slot.slot_type.replace('_', ' ')}</span>
|
||||||
|
<span className={`badge ${STATUS_CLASSES[slot.status] || ''}`}>{slot.status.replace('_', ' ')}</span>
|
||||||
|
{slot.is_virtual && <span className="badge" style={{ background: 'var(--text-secondary)', color: 'white', fontSize: '0.7rem' }}>plan</span>}
|
||||||
|
<span style={{ marginLeft: 'auto', fontWeight: 600 }}>{slot.scheduled_at}</span>
|
||||||
|
</div>
|
||||||
|
<div style={{ marginTop: 8, display: 'flex', gap: 16, fontSize: '0.9rem', color: 'var(--text-secondary)' }}>
|
||||||
|
<span>⏱ {slot.estimated_duration} min</span>
|
||||||
|
<span>⚡ Priority: {slot.priority}</span>
|
||||||
|
{slot.event_type && <span>📌 {slot.event_type.replace('_', ' ')}</span>}
|
||||||
|
</div>
|
||||||
|
{slot.event_data && slot.event_data.code && (
|
||||||
|
<div style={{ marginTop: 4, fontSize: '0.85rem', color: 'var(--text-secondary)' }}>
|
||||||
|
🔗 {slot.event_data.code}
|
||||||
|
</div>
|
||||||
|
)}
|
||||||
|
{slot.event_data && slot.event_data.event && (
|
||||||
|
<div style={{ marginTop: 4, fontSize: '0.85rem', color: 'var(--text-secondary)' }}>
|
||||||
|
📣 {slot.event_data.event}
|
||||||
|
</div>
|
||||||
|
)}
|
||||||
|
{/* Action buttons for non-past, modifiable slots */}
|
||||||
|
{!isPastDate && (slot.status === 'not_started' || slot.status === 'deferred') && (
|
||||||
|
<div style={{ marginTop: 8, display: 'flex', gap: 6 }}>
|
||||||
|
<button
|
||||||
|
className="btn-transition"
|
||||||
|
style={{ padding: '4px 10px', fontSize: '0.8rem' }}
|
||||||
|
onClick={() => openEditSlotModal(slot)}
|
||||||
|
>
|
||||||
|
✏️ Edit
|
||||||
|
</button>
|
||||||
|
<button
|
||||||
|
className="btn-danger"
|
||||||
|
style={{ padding: '4px 10px', fontSize: '0.8rem' }}
|
||||||
|
onClick={() => handleCancelSlot(slot)}
|
||||||
|
>
|
||||||
|
❌ Cancel
|
||||||
|
</button>
|
||||||
|
</div>
|
||||||
|
)}
|
||||||
|
</div>
|
||||||
|
))}
|
||||||
|
</div>
|
||||||
|
)}
|
||||||
|
</>
|
||||||
|
)}
|
||||||
|
|
||||||
|
{activeTab === 'plans' && (
|
||||||
|
<>
|
||||||
|
<div style={{ display: 'flex', justifyContent: 'flex-end', marginBottom: 16 }}>
|
||||||
|
<button className="btn-primary" onClick={openCreatePlanModal}>+ New Plan</button>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div className="milestone-grid">
|
||||||
|
{plans.length === 0 ? (
|
||||||
|
<div className="empty" style={{ padding: '40px 0', color: 'var(--text-secondary)', textAlign: 'center' }}>
|
||||||
|
No schedule plans configured.
|
||||||
|
</div>
|
||||||
|
) : (
|
||||||
|
plans.map((plan) => (
|
||||||
|
<div key={plan.id} className="milestone-card">
|
||||||
|
<div className="milestone-card-header" style={{ display: 'flex', alignItems: 'center', gap: 8, flexWrap: 'wrap' }}>
|
||||||
|
<span style={{ fontSize: '1.2rem' }}>{SLOT_TYPE_ICONS[plan.slot_type] || '📋'}</span>
|
||||||
|
<span className="badge">{plan.slot_type.replace('_', ' ')}</span>
|
||||||
|
{!plan.is_active && <span className="badge status-closed">inactive</span>}
|
||||||
|
<span style={{ marginLeft: 'auto', fontWeight: 600 }}>Plan #{plan.id}</span>
|
||||||
|
</div>
|
||||||
|
<div style={{ marginTop: 8, fontSize: '0.9rem', color: 'var(--text-secondary)' }}>
|
||||||
|
<div>🔄 {formatPlanSchedule(plan)}</div>
|
||||||
|
<div>⏱ {plan.estimated_duration} min</div>
|
||||||
|
{plan.event_type && <div>📌 {plan.event_type.replace('_', ' ')}</div>}
|
||||||
|
</div>
|
||||||
|
{plan.is_active && (
|
||||||
|
<div style={{ marginTop: 8, display: 'flex', gap: 8 }}>
|
||||||
|
<button
|
||||||
|
className="btn-transition"
|
||||||
|
style={{ padding: '4px 10px', fontSize: '0.8rem' }}
|
||||||
|
onClick={() => openEditPlanModal(plan)}
|
||||||
|
>
|
||||||
|
✏️ Edit Plan
|
||||||
|
</button>
|
||||||
|
<button
|
||||||
|
className="btn-danger"
|
||||||
|
style={{ padding: '4px 10px', fontSize: '0.8rem' }}
|
||||||
|
onClick={() => handleCancelPlan(plan)}
|
||||||
|
>
|
||||||
|
❌ Cancel Plan
|
||||||
|
</button>
|
||||||
|
</div>
|
||||||
|
)}
|
||||||
|
</div>
|
||||||
|
))
|
||||||
|
)}
|
||||||
|
</div>
|
||||||
|
</>
|
||||||
|
)}
|
||||||
|
|
||||||
|
{/* Create/Edit Slot Modal */}
|
||||||
|
{showSlotModal && (
|
||||||
|
<div className="modal-overlay" onClick={() => setShowSlotModal(false)}>
|
||||||
|
<div className="modal" onClick={(e) => e.stopPropagation()}>
|
||||||
|
<h3>{editingSlot ? 'Edit Slot' : 'New Slot'}</h3>
|
||||||
|
<p style={{ color: 'var(--text-secondary)', fontSize: '0.9rem' }}>
|
||||||
|
Date: <strong>{dayjs(selectedDate).format('MMMM D, YYYY')}</strong>
|
||||||
|
</p>
|
||||||
|
|
||||||
|
<label style={{ display: 'block', marginBottom: 8 }}>
|
||||||
|
<strong>Slot Type</strong>
|
||||||
|
<select
|
||||||
|
value={slotForm.slot_type}
|
||||||
|
onChange={(e) => setSlotForm({ ...slotForm, slot_type: e.target.value as SlotType })}
|
||||||
|
style={{ width: '100%', marginTop: 4 }}
|
||||||
|
>
|
||||||
|
{SLOT_TYPES.map((t) => (
|
||||||
|
<option key={t.value} value={t.value}>{t.label}</option>
|
||||||
|
))}
|
||||||
|
</select>
|
||||||
|
</label>
|
||||||
|
|
||||||
|
<label style={{ display: 'block', marginBottom: 8 }}>
|
||||||
|
<strong>Scheduled At</strong>
|
||||||
|
<input
|
||||||
|
type="time"
|
||||||
|
value={slotForm.scheduled_at}
|
||||||
|
onChange={(e) => setSlotForm({ ...slotForm, scheduled_at: e.target.value })}
|
||||||
|
style={{ width: '100%', marginTop: 4 }}
|
||||||
|
/>
|
||||||
|
</label>
|
||||||
|
|
||||||
|
<label style={{ display: 'block', marginBottom: 8 }}>
|
||||||
|
<strong>Estimated Duration (minutes, 1–50)</strong>
|
||||||
|
<input
|
||||||
|
type="number"
|
||||||
|
min={1}
|
||||||
|
max={50}
|
||||||
|
value={slotForm.estimated_duration}
|
||||||
|
onChange={(e) => setSlotForm({ ...slotForm, estimated_duration: Number(e.target.value) })}
|
||||||
|
style={{ width: '100%', marginTop: 4 }}
|
||||||
|
/>
|
||||||
|
</label>
|
||||||
|
|
||||||
|
<label style={{ display: 'block', marginBottom: 8 }}>
|
||||||
|
<strong>Priority (0–99)</strong>
|
||||||
|
<input
|
||||||
|
type="number"
|
||||||
|
min={0}
|
||||||
|
max={99}
|
||||||
|
value={slotForm.priority}
|
||||||
|
onChange={(e) => setSlotForm({ ...slotForm, priority: Number(e.target.value) })}
|
||||||
|
style={{ width: '100%', marginTop: 4 }}
|
||||||
|
/>
|
||||||
|
</label>
|
||||||
|
|
||||||
|
<label style={{ display: 'block', marginBottom: 8 }}>
|
||||||
|
<strong>Event Type</strong>
|
||||||
|
<select
|
||||||
|
value={slotForm.event_type}
|
||||||
|
onChange={(e) => setSlotForm({ ...slotForm, event_type: e.target.value })}
|
||||||
|
style={{ width: '100%', marginTop: 4 }}
|
||||||
|
>
|
||||||
|
<option value="">None</option>
|
||||||
|
{EVENT_TYPES.map((t) => (
|
||||||
|
<option key={t.value} value={t.value}>{t.label}</option>
|
||||||
|
))}
|
||||||
|
</select>
|
||||||
|
</label>
|
||||||
|
|
||||||
|
{slotForm.event_type === 'job' && (
|
||||||
|
<label style={{ display: 'block', marginBottom: 8 }}>
|
||||||
|
<strong>Job Code</strong>
|
||||||
|
<input
|
||||||
|
type="text"
|
||||||
|
value={slotForm.event_data_code}
|
||||||
|
onChange={(e) => setSlotForm({ ...slotForm, event_data_code: e.target.value })}
|
||||||
|
placeholder="e.g. TASK-42"
|
||||||
|
style={{ width: '100%', marginTop: 4 }}
|
||||||
|
/>
|
||||||
|
</label>
|
||||||
|
)}
|
||||||
|
|
||||||
|
{slotForm.event_type === 'system_event' && (
|
||||||
|
<label style={{ display: 'block', marginBottom: 8 }}>
|
||||||
|
<strong>System Event</strong>
|
||||||
|
<select
|
||||||
|
value={slotForm.event_data_event}
|
||||||
|
onChange={(e) => setSlotForm({ ...slotForm, event_data_event: e.target.value })}
|
||||||
|
style={{ width: '100%', marginTop: 4 }}
|
||||||
|
>
|
||||||
|
<option value="">Select event</option>
|
||||||
|
<option value="ScheduleToday">Schedule Today</option>
|
||||||
|
<option value="SummaryToday">Summary Today</option>
|
||||||
|
<option value="ScheduledGatewayRestart">Scheduled Gateway Restart</option>
|
||||||
|
</select>
|
||||||
|
</label>
|
||||||
|
)}
|
||||||
|
|
||||||
|
<div style={{ marginTop: 12, display: 'flex', gap: 8 }}>
|
||||||
|
<button
|
||||||
|
className="btn-primary"
|
||||||
|
onClick={handleSaveSlot}
|
||||||
|
disabled={slotSaving}
|
||||||
|
>
|
||||||
|
{slotSaving ? 'Saving...' : 'Save'}
|
||||||
|
</button>
|
||||||
|
<button className="btn-back" onClick={() => setShowSlotModal(false)}>Cancel</button>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
)}
|
||||||
|
|
||||||
|
{showPlanModal && (
|
||||||
|
<div className="modal-overlay" onClick={() => setShowPlanModal(false)}>
|
||||||
|
<div className="modal" onClick={(e) => e.stopPropagation()}>
|
||||||
|
<h3>{editingPlan ? 'Edit Plan' : 'New Plan'}</h3>
|
||||||
|
|
||||||
|
<label style={{ display: 'block', marginBottom: 8 }}>
|
||||||
|
<strong>Slot Type</strong>
|
||||||
|
<select
|
||||||
|
value={planForm.slot_type}
|
||||||
|
onChange={(e) => setPlanForm({ ...planForm, slot_type: e.target.value as SlotType })}
|
||||||
|
style={{ width: '100%', marginTop: 4 }}
|
||||||
|
>
|
||||||
|
{SLOT_TYPES.map((t) => (
|
||||||
|
<option key={t.value} value={t.value}>{t.label}</option>
|
||||||
|
))}
|
||||||
|
</select>
|
||||||
|
</label>
|
||||||
|
|
||||||
|
<label style={{ display: 'block', marginBottom: 8 }}>
|
||||||
|
<strong>At Time</strong>
|
||||||
|
<input
|
||||||
|
type="time"
|
||||||
|
value={planForm.at_time}
|
||||||
|
onChange={(e) => setPlanForm({ ...planForm, at_time: e.target.value })}
|
||||||
|
style={{ width: '100%', marginTop: 4 }}
|
||||||
|
/>
|
||||||
|
</label>
|
||||||
|
|
||||||
|
<label style={{ display: 'block', marginBottom: 8 }}>
|
||||||
|
<strong>Estimated Duration (minutes, 1–50)</strong>
|
||||||
|
<input
|
||||||
|
type="number"
|
||||||
|
min={1}
|
||||||
|
max={50}
|
||||||
|
value={planForm.estimated_duration}
|
||||||
|
onChange={(e) => setPlanForm({ ...planForm, estimated_duration: Number(e.target.value) })}
|
||||||
|
style={{ width: '100%', marginTop: 4 }}
|
||||||
|
/>
|
||||||
|
</label>
|
||||||
|
|
||||||
|
<label style={{ display: 'block', marginBottom: 8 }}>
|
||||||
|
<strong>On Day (optional)</strong>
|
||||||
|
<select
|
||||||
|
value={planForm.on_day}
|
||||||
|
onChange={(e) => setPlanForm({ ...planForm, on_day: e.target.value as Weekday | '' })}
|
||||||
|
style={{ width: '100%', marginTop: 4 }}
|
||||||
|
>
|
||||||
|
<option value="">Every day</option>
|
||||||
|
{WEEKDAYS.map((d) => (
|
||||||
|
<option key={d.value} value={d.value}>{d.label}</option>
|
||||||
|
))}
|
||||||
|
</select>
|
||||||
|
</label>
|
||||||
|
|
||||||
|
<label style={{ display: 'block', marginBottom: 8 }}>
|
||||||
|
<strong>On Week (optional)</strong>
|
||||||
|
<select
|
||||||
|
value={planForm.on_week}
|
||||||
|
onChange={(e) => setPlanForm({ ...planForm, on_week: e.target.value })}
|
||||||
|
style={{ width: '100%', marginTop: 4 }}
|
||||||
|
>
|
||||||
|
<option value="">Every matching week</option>
|
||||||
|
<option value="1">1</option>
|
||||||
|
<option value="2">2</option>
|
||||||
|
<option value="3">3</option>
|
||||||
|
<option value="4">4</option>
|
||||||
|
</select>
|
||||||
|
</label>
|
||||||
|
|
||||||
|
<label style={{ display: 'block', marginBottom: 8 }}>
|
||||||
|
<strong>On Month (optional)</strong>
|
||||||
|
<select
|
||||||
|
value={planForm.on_month}
|
||||||
|
onChange={(e) => setPlanForm({ ...planForm, on_month: e.target.value as MonthName | '' })}
|
||||||
|
style={{ width: '100%', marginTop: 4 }}
|
||||||
|
>
|
||||||
|
<option value="">Every month</option>
|
||||||
|
{MONTHS.map((m) => (
|
||||||
|
<option key={m.value} value={m.value}>{m.label}</option>
|
||||||
|
))}
|
||||||
|
</select>
|
||||||
|
</label>
|
||||||
|
|
||||||
|
<label style={{ display: 'block', marginBottom: 8 }}>
|
||||||
|
<strong>Event Type</strong>
|
||||||
|
<select
|
||||||
|
value={planForm.event_type}
|
||||||
|
onChange={(e) => setPlanForm({ ...planForm, event_type: e.target.value })}
|
||||||
|
style={{ width: '100%', marginTop: 4 }}
|
||||||
|
>
|
||||||
|
<option value="">None</option>
|
||||||
|
{EVENT_TYPES.map((t) => (
|
||||||
|
<option key={t.value} value={t.value}>{t.label}</option>
|
||||||
|
))}
|
||||||
|
</select>
|
||||||
|
</label>
|
||||||
|
|
||||||
|
{planForm.event_type === 'job' && (
|
||||||
|
<label style={{ display: 'block', marginBottom: 8 }}>
|
||||||
|
<strong>Job Code</strong>
|
||||||
|
<input
|
||||||
|
type="text"
|
||||||
|
value={planForm.event_data_code}
|
||||||
|
onChange={(e) => setPlanForm({ ...planForm, event_data_code: e.target.value })}
|
||||||
|
placeholder="e.g. TASK-42"
|
||||||
|
style={{ width: '100%', marginTop: 4 }}
|
||||||
|
/>
|
||||||
|
</label>
|
||||||
|
)}
|
||||||
|
|
||||||
|
{planForm.event_type === 'system_event' && (
|
||||||
|
<label style={{ display: 'block', marginBottom: 8 }}>
|
||||||
|
<strong>System Event</strong>
|
||||||
|
<select
|
||||||
|
value={planForm.event_data_event}
|
||||||
|
onChange={(e) => setPlanForm({ ...planForm, event_data_event: e.target.value })}
|
||||||
|
style={{ width: '100%', marginTop: 4 }}
|
||||||
|
>
|
||||||
|
<option value="">Select event</option>
|
||||||
|
<option value="ScheduleToday">Schedule Today</option>
|
||||||
|
<option value="SummaryToday">Summary Today</option>
|
||||||
|
<option value="ScheduledGatewayRestart">Scheduled Gateway Restart</option>
|
||||||
|
</select>
|
||||||
|
</label>
|
||||||
|
)}
|
||||||
|
|
||||||
|
<div style={{ marginTop: 12, display: 'flex', gap: 8 }}>
|
||||||
|
<button className="btn-primary" onClick={handleSavePlan} disabled={planSaving}>
|
||||||
|
{planSaving ? 'Saving...' : 'Save Plan'}
|
||||||
|
</button>
|
||||||
|
<button className="btn-back" onClick={() => setShowPlanModal(false)}>Cancel</button>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
)}
|
||||||
|
</div>
|
||||||
|
)
|
||||||
|
}
|
||||||
@@ -4,7 +4,7 @@ import api from '@/services/api'
|
|||||||
import type { Project, Milestone } from '@/types'
|
import type { Project, Milestone } from '@/types'
|
||||||
|
|
||||||
const TASK_TYPES = [
|
const TASK_TYPES = [
|
||||||
{ value: 'story', label: 'Story', subtypes: ['improvement', 'refactor'] }, // P9.6: 'feature' removed — must come from propose accept
|
// P9.6: 'story' removed — all story/* types are restricted; must come from Proposal Accept workflow
|
||||||
{ value: 'issue', label: 'Issue', subtypes: ['infrastructure', 'performance', 'regression', 'security', 'user_experience', 'defect'] },
|
{ value: 'issue', label: 'Issue', subtypes: ['infrastructure', 'performance', 'regression', 'security', 'user_experience', 'defect'] },
|
||||||
// P7.1: 'task' type removed — defect subtype migrated to issue/defect
|
// P7.1: 'task' type removed — defect subtype migrated to issue/defect
|
||||||
{ value: 'test', label: 'Test', subtypes: ['regression', 'security', 'smoke', 'stress'] },
|
{ value: 'test', label: 'Test', subtypes: ['regression', 'security', 'smoke', 'stress'] },
|
||||||
@@ -19,7 +19,7 @@ export default function CreateTaskPage() {
|
|||||||
const [projects, setProjects] = useState<Project[]>([])
|
const [projects, setProjects] = useState<Project[]>([])
|
||||||
const [milestones, setMilestones] = useState<Milestone[]>([])
|
const [milestones, setMilestones] = useState<Milestone[]>([])
|
||||||
const [form, setForm] = useState({
|
const [form, setForm] = useState({
|
||||||
title: '', description: '', project_id: 0, milestone_id: 0, task_type: 'issue', // P7.1: default changed from 'task' to 'issue'
|
title: '', description: '', project_code: '', milestone_code: '', task_type: 'issue', // P7.1: default changed from 'task' to 'issue'
|
||||||
task_subtype: '', priority: 'medium', tags: '', reporter_id: 1,
|
task_subtype: '', priority: 'medium', tags: '', reporter_id: 1,
|
||||||
})
|
})
|
||||||
|
|
||||||
@@ -27,21 +27,21 @@ export default function CreateTaskPage() {
|
|||||||
api.get<Project[]>('/projects').then(({ data }) => {
|
api.get<Project[]>('/projects').then(({ data }) => {
|
||||||
setProjects(data)
|
setProjects(data)
|
||||||
if (data.length) {
|
if (data.length) {
|
||||||
setForm((f) => ({ ...f, project_id: data[0].id }))
|
setForm((f) => ({ ...f, project_code: data[0].project_code || '' }))
|
||||||
// Load milestones for the first project
|
// Load milestones for the first project
|
||||||
api.get<Milestone[]>(`/milestones?project_id=${data[0].id}`).then(({ data: ms }) => {
|
api.get<Milestone[]>(`/milestones?project_code=${data[0].project_code}`).then(({ data: ms }) => {
|
||||||
setMilestones(ms)
|
setMilestones(ms)
|
||||||
if (ms.length) setForm((f) => ({ ...f, milestone_id: ms[0].id }))
|
if (ms.length) setForm((f) => ({ ...f, milestone_code: ms[0].milestone_code || '' }))
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
}, [])
|
}, [])
|
||||||
|
|
||||||
const handleProjectChange = (projectId: number) => {
|
const handleProjectChange = (projectCode: string) => {
|
||||||
setForm(f => ({ ...f, project_id: projectId, milestone_id: 0 }))
|
setForm(f => ({ ...f, project_code: projectCode, milestone_code: '' }))
|
||||||
api.get<Milestone[]>(`/milestones?project_id=${projectId}`).then(({ data: ms }) => {
|
api.get<Milestone[]>(`/milestones?project_code=${projectCode}`).then(({ data: ms }) => {
|
||||||
setMilestones(ms)
|
setMilestones(ms)
|
||||||
if (ms.length) setForm((f) => ({ ...f, milestone_id: ms[0].id }))
|
if (ms.length) setForm((f) => ({ ...f, milestone_code: ms[0].milestone_code || '' }))
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -54,7 +54,7 @@ export default function CreateTaskPage() {
|
|||||||
|
|
||||||
const submit = async (e: React.FormEvent) => {
|
const submit = async (e: React.FormEvent) => {
|
||||||
e.preventDefault()
|
e.preventDefault()
|
||||||
if (!form.milestone_id) {
|
if (!form.milestone_code) {
|
||||||
alert('Please select a milestone')
|
alert('Please select a milestone')
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
@@ -71,14 +71,14 @@ export default function CreateTaskPage() {
|
|||||||
<label>Title <input data-testid="task-title-input" required value={form.title} onChange={(e) => setForm({ ...form, title: e.target.value })} /></label>
|
<label>Title <input data-testid="task-title-input" required value={form.title} onChange={(e) => setForm({ ...form, title: e.target.value })} /></label>
|
||||||
<label>Description <textarea data-testid="task-description-input" value={form.description} onChange={(e) => setForm({ ...form, description: e.target.value })} /></label>
|
<label>Description <textarea data-testid="task-description-input" value={form.description} onChange={(e) => setForm({ ...form, description: e.target.value })} /></label>
|
||||||
<label>Projects
|
<label>Projects
|
||||||
<select data-testid="project-select" value={form.project_id} onChange={(e) => handleProjectChange(Number(e.target.value))}>
|
<select data-testid="project-select" value={form.project_code} onChange={(e) => handleProjectChange(e.target.value)}>
|
||||||
{projects.map((p) => <option key={p.id} value={p.id}>{p.name}</option>)}
|
{projects.map((p) => <option key={p.id} value={p.project_code || ''}>{p.name}</option>)}
|
||||||
</select>
|
</select>
|
||||||
</label>
|
</label>
|
||||||
<label>Milestone
|
<label>Milestone
|
||||||
<select data-testid="milestone-select" value={form.milestone_id} onChange={(e) => setForm({ ...form, milestone_id: Number(e.target.value) })}>
|
<select data-testid="milestone-select" value={form.milestone_code} onChange={(e) => setForm({ ...form, milestone_code: e.target.value })}>
|
||||||
{milestones.length === 0 && <option value={0}>No milestones available</option>}
|
{milestones.length === 0 && <option value="">No milestones available</option>}
|
||||||
{milestones.map((m) => <option key={m.id} value={m.id}>{m.title}</option>)}
|
{milestones.map((m) => <option key={m.id} value={m.milestone_code || ''}>{m.title}</option>)}
|
||||||
</select>
|
</select>
|
||||||
</label>
|
</label>
|
||||||
<label>Type
|
<label>Type
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
import { useState, useEffect } from 'react'
|
import { useState, useEffect } from 'react'
|
||||||
|
import { Link } from 'react-router-dom'
|
||||||
import api from '@/services/api'
|
import api from '@/services/api'
|
||||||
import type { DashboardStats, Task } from '@/types'
|
import type { DashboardStats, Task } from '@/types'
|
||||||
|
|
||||||
@@ -60,8 +61,8 @@ export default function DashboardPage() {
|
|||||||
<tbody>
|
<tbody>
|
||||||
{(stats.recent_tasks || []).map((i) => (
|
{(stats.recent_tasks || []).map((i) => (
|
||||||
<tr key={i.id}>
|
<tr key={i.id}>
|
||||||
<td>{i.task_code || `#${i.id}`}</td>
|
<td>{i.task_code || '—'}</td>
|
||||||
<td><a href={`/tasks/${i.task_code || i.id}`}>{i.title}</a></td>
|
<td>{i.task_code ? <Link to={`/tasks/${i.task_code}`}>{i.title}</Link> : i.title}</td>
|
||||||
<td><span className={`badge status-${i.status}`}>{i.status}</span></td>
|
<td><span className={`badge status-${i.status}`}>{i.status}</span></td>
|
||||||
<td><span className={`badge priority-${i.priority}`}>{i.priority}</span></td>
|
<td><span className={`badge priority-${i.priority}`}>{i.priority}</span></td>
|
||||||
<td>{i.task_type}</td><td>{i.task_subtype || "-"}</td>
|
<td>{i.task_type}</td><td>{i.task_subtype || "-"}</td>
|
||||||
|
|||||||
@@ -29,7 +29,7 @@ interface MeetingItem {
|
|||||||
const STATUS_OPTIONS = ['scheduled', 'in_progress', 'completed', 'cancelled']
|
const STATUS_OPTIONS = ['scheduled', 'in_progress', 'completed', 'cancelled']
|
||||||
|
|
||||||
export default function MeetingDetailPage() {
|
export default function MeetingDetailPage() {
|
||||||
const { meetingId } = useParams()
|
const { meetingCode } = useParams()
|
||||||
const navigate = useNavigate()
|
const navigate = useNavigate()
|
||||||
const { user } = useAuth()
|
const { user } = useAuth()
|
||||||
const [meeting, setMeeting] = useState<MeetingItem | null>(null)
|
const [meeting, setMeeting] = useState<MeetingItem | null>(null)
|
||||||
@@ -46,7 +46,7 @@ export default function MeetingDetailPage() {
|
|||||||
|
|
||||||
const fetchMeeting = async () => {
|
const fetchMeeting = async () => {
|
||||||
try {
|
try {
|
||||||
const { data } = await api.get<MeetingItem>(`/meetings/${meetingId}`)
|
const { data } = await api.get<MeetingItem>(`/meetings/${meetingCode}`)
|
||||||
setMeeting(data)
|
setMeeting(data)
|
||||||
setEditForm({
|
setEditForm({
|
||||||
title: data.title,
|
title: data.title,
|
||||||
@@ -63,14 +63,14 @@ export default function MeetingDetailPage() {
|
|||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
fetchMeeting()
|
fetchMeeting()
|
||||||
}, [meetingId])
|
}, [meetingCode])
|
||||||
|
|
||||||
const handleAttend = async () => {
|
const handleAttend = async () => {
|
||||||
if (!meeting) return
|
if (!meeting) return
|
||||||
setSaving(true)
|
setSaving(true)
|
||||||
setMessage('')
|
setMessage('')
|
||||||
try {
|
try {
|
||||||
const { data } = await api.post<MeetingItem>(`/meetings/${meetingId}/attend`)
|
const { data } = await api.post<MeetingItem>(`/meetings/${meetingCode}/attend`)
|
||||||
setMeeting(data)
|
setMeeting(data)
|
||||||
setMessage('You have joined this meeting')
|
setMessage('You have joined this meeting')
|
||||||
} catch (err: any) {
|
} catch (err: any) {
|
||||||
@@ -85,7 +85,7 @@ export default function MeetingDetailPage() {
|
|||||||
setSaving(true)
|
setSaving(true)
|
||||||
setMessage('')
|
setMessage('')
|
||||||
try {
|
try {
|
||||||
const { data } = await api.patch<MeetingItem>(`/meetings/${meetingId}`, {
|
const { data } = await api.patch<MeetingItem>(`/meetings/${meetingCode}`, {
|
||||||
status: newStatus,
|
status: newStatus,
|
||||||
})
|
})
|
||||||
setMeeting(data)
|
setMeeting(data)
|
||||||
@@ -117,7 +117,7 @@ export default function MeetingDetailPage() {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
const { data } = await api.patch<MeetingItem>(`/meetings/${meetingId}`, payload)
|
const { data } = await api.patch<MeetingItem>(`/meetings/${meetingCode}`, payload)
|
||||||
setMeeting(data)
|
setMeeting(data)
|
||||||
setEditMode(false)
|
setEditMode(false)
|
||||||
setMessage('Meeting updated')
|
setMessage('Meeting updated')
|
||||||
@@ -133,7 +133,7 @@ export default function MeetingDetailPage() {
|
|||||||
if (!confirm(`Delete meeting ${meeting.meeting_code || meeting.id}? This cannot be undone.`)) return
|
if (!confirm(`Delete meeting ${meeting.meeting_code || meeting.id}? This cannot be undone.`)) return
|
||||||
setSaving(true)
|
setSaving(true)
|
||||||
try {
|
try {
|
||||||
await api.delete(`/meetings/${meetingId}`)
|
await api.delete(`/meetings/${meetingCode}`)
|
||||||
navigate(-1)
|
navigate(-1)
|
||||||
} catch (err: any) {
|
} catch (err: any) {
|
||||||
setMessage(err.response?.data?.detail || 'Failed to delete meeting')
|
setMessage(err.response?.data?.detail || 'Failed to delete meeting')
|
||||||
|
|||||||
@@ -24,7 +24,7 @@ interface MilestoneTask {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export default function MilestoneDetailPage() {
|
export default function MilestoneDetailPage() {
|
||||||
const { id } = useParams()
|
const { milestoneCode } = useParams()
|
||||||
const navigate = useNavigate()
|
const navigate = useNavigate()
|
||||||
const { user } = useAuth()
|
const { user } = useAuth()
|
||||||
const [milestone, setMilestone] = useState<Milestone | null>(null)
|
const [milestone, setMilestone] = useState<Milestone | null>(null)
|
||||||
@@ -49,7 +49,8 @@ export default function MilestoneDetailPage() {
|
|||||||
const [preflight, setPreflight] = useState<{ freeze?: { allowed: boolean; reason: string | null }; start?: { allowed: boolean; reason: string | null } } | null>(null)
|
const [preflight, setPreflight] = useState<{ freeze?: { allowed: boolean; reason: string | null }; start?: { allowed: boolean; reason: string | null } } | null>(null)
|
||||||
|
|
||||||
const fetchMilestone = () => {
|
const fetchMilestone = () => {
|
||||||
api.get<Milestone>(`/milestones/${id}`).then(({ data }) => {
|
if (!milestoneCode) return
|
||||||
|
api.get<Milestone>(`/milestones/${milestoneCode}`).then(({ data }) => {
|
||||||
setMilestone(data)
|
setMilestone(data)
|
||||||
if (data.project_id) {
|
if (data.project_id) {
|
||||||
api.get<Project>(`/projects/${data.project_id}`).then(({ data: proj }) => {
|
api.get<Project>(`/projects/${data.project_id}`).then(({ data: proj }) => {
|
||||||
@@ -57,40 +58,44 @@ export default function MilestoneDetailPage() {
|
|||||||
setProjectCode(proj.project_code || '')
|
setProjectCode(proj.project_code || '')
|
||||||
})
|
})
|
||||||
api.get<ProjectMember[]>(`/projects/${data.project_id}/members`).then(({ data }) => setMembers(data)).catch(() => {})
|
api.get<ProjectMember[]>(`/projects/${data.project_id}/members`).then(({ data }) => setMembers(data)).catch(() => {})
|
||||||
fetchPreflight(data.project_id, data.id)
|
if (data.project_code && data.milestone_code) {
|
||||||
|
fetchPreflight(data.project_code, data.milestone_code)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (data.milestone_code) {
|
||||||
|
api.get<MilestoneProgress>(`/milestones/${data.milestone_code}/progress`).then(({ data: prog }) => setProgress(prog)).catch(() => {})
|
||||||
}
|
}
|
||||||
api.get<MilestoneProgress>(`/milestones/${data.id}/progress`).then(({ data: prog }) => setProgress(prog)).catch(() => {})
|
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
const fetchPreflight = (projectId: number, milestoneId: number) => {
|
const fetchPreflight = (projectCode: string, milestoneCode: string) => {
|
||||||
api.get(`/projects/${projectId}/milestones/${milestoneId}/actions/preflight`)
|
api.get(`/projects/${projectCode}/milestones/${milestoneCode}/actions/preflight`)
|
||||||
.then(({ data }) => setPreflight(data))
|
.then(({ data }) => setPreflight(data))
|
||||||
.catch(() => setPreflight(null))
|
.catch(() => setPreflight(null))
|
||||||
}
|
}
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
fetchMilestone()
|
fetchMilestone()
|
||||||
}, [id])
|
}, [milestoneCode])
|
||||||
|
|
||||||
const refreshMilestoneItems = () => {
|
const refreshMilestoneItems = () => {
|
||||||
if (!projectCode || !milestone) return
|
if (!projectCode || !milestone?.milestone_code) return
|
||||||
api.get<MilestoneTask[]>(`/tasks/${projectCode}/${milestone.id}`).then(({ data }) => setTasks(data)).catch(() => {})
|
api.get<MilestoneTask[]>(`/tasks/${projectCode}/${milestone.milestone_code}`).then(({ data }) => setTasks(data)).catch(() => {})
|
||||||
api.get<any[]>(`/supports/${projectCode}/${milestone.id}`).then(({ data }) => setSupports(data)).catch(() => {})
|
api.get<any[]>(`/supports/${projectCode}/${milestone.milestone_code}`).then(({ data }) => setSupports(data)).catch(() => {})
|
||||||
api.get<any[]>(`/meetings/${projectCode}/${milestone.id}`).then(({ data }) => setMeetings(data)).catch(() => {})
|
api.get<any[]>(`/meetings/${projectCode}/${milestone.milestone_code}`).then(({ data }) => setMeetings(data)).catch(() => {})
|
||||||
}
|
}
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
refreshMilestoneItems()
|
refreshMilestoneItems()
|
||||||
}, [projectCode, milestone?.id])
|
}, [projectCode, milestone?.milestone_code])
|
||||||
|
|
||||||
const createItem = async (type: 'supports' | 'meetings') => {
|
const createItem = async (type: 'supports' | 'meetings') => {
|
||||||
if (!newTitle.trim() || !projectCode || !milestone) return
|
if (!newTitle.trim() || !projectCode || !milestone?.milestone_code) return
|
||||||
const payload = {
|
const payload = {
|
||||||
title: newTitle,
|
title: newTitle,
|
||||||
description: newDesc || null,
|
description: newDesc || null,
|
||||||
}
|
}
|
||||||
await api.post(`/${type}/${projectCode}/${milestone.id}`, payload)
|
await api.post(`/${type}/${projectCode}/${milestone.milestone_code}`, payload)
|
||||||
setNewTitle('')
|
setNewTitle('')
|
||||||
setNewDesc('')
|
setNewDesc('')
|
||||||
setShowCreateSupport(false)
|
setShowCreateSupport(false)
|
||||||
@@ -119,10 +124,12 @@ export default function MilestoneDetailPage() {
|
|||||||
setActionLoading(action)
|
setActionLoading(action)
|
||||||
setActionError(null)
|
setActionError(null)
|
||||||
try {
|
try {
|
||||||
await api.post(`/projects/${project.id}/milestones/${milestone.id}/actions/${action}`, body ?? {})
|
await api.post(`/projects/${project.project_code}/milestones/${milestone.milestone_code}/actions/${action}`, body ?? {})
|
||||||
fetchMilestone()
|
fetchMilestone()
|
||||||
refreshMilestoneItems()
|
refreshMilestoneItems()
|
||||||
fetchPreflight(project.id, milestone.id)
|
if (project.project_code && milestone.milestone_code) {
|
||||||
|
fetchPreflight(project.project_code, milestone.milestone_code)
|
||||||
|
}
|
||||||
} catch (err: any) {
|
} catch (err: any) {
|
||||||
const detail = err?.response?.data?.detail
|
const detail = err?.response?.data?.detail
|
||||||
setActionError(typeof detail === 'string' ? detail : `${action} failed`)
|
setActionError(typeof detail === 'string' ? detail : `${action} failed`)
|
||||||
@@ -142,8 +149,8 @@ export default function MilestoneDetailPage() {
|
|||||||
if (!milestone) return <div className="loading">Loading...</div>
|
if (!milestone) return <div className="loading">Loading...</div>
|
||||||
|
|
||||||
const renderTaskRow = (t: MilestoneTask) => (
|
const renderTaskRow = (t: MilestoneTask) => (
|
||||||
<tr key={t.id} className="clickable" onClick={() => navigate(`/tasks/${t.task_code || t.id}`)}>
|
<tr key={t.id} className={t.task_code ? 'clickable' : ''} onClick={() => t.task_code && navigate(`/tasks/${t.task_code}`)}>
|
||||||
<td>{t.task_code || t.id}</td>
|
<td>{t.task_code || '—'}</td>
|
||||||
<td className="task-title">{t.title}</td>
|
<td className="task-title">{t.title}</td>
|
||||||
<td><span className={`badge status-${t.task_status || t.status}`}>{t.task_status || t.status}</span></td>
|
<td><span className={`badge status-${t.task_status || t.status}`}>{t.task_status || t.status}</span></td>
|
||||||
<td>{t.estimated_effort || '-'}</td>
|
<td>{t.estimated_effort || '-'}</td>
|
||||||
@@ -297,8 +304,8 @@ export default function MilestoneDetailPage() {
|
|||||||
<CreateTaskModal
|
<CreateTaskModal
|
||||||
isOpen={showCreateTask}
|
isOpen={showCreateTask}
|
||||||
onClose={() => setShowCreateTask(false)}
|
onClose={() => setShowCreateTask(false)}
|
||||||
initialProjectId={milestone.project_id}
|
initialProjectCode={milestone.project_code || ''}
|
||||||
initialMilestoneId={milestone.id}
|
initialMilestoneCode={milestone.milestone_code || ''}
|
||||||
lockProject
|
lockProject
|
||||||
lockMilestone
|
lockMilestone
|
||||||
onCreated={() => {
|
onCreated={() => {
|
||||||
@@ -356,8 +363,8 @@ export default function MilestoneDetailPage() {
|
|||||||
<thead><tr><th>Code</th><th>Title</th><th>Status</th><th>Priority</th></tr></thead>
|
<thead><tr><th>Code</th><th>Title</th><th>Status</th><th>Priority</th></tr></thead>
|
||||||
<tbody>
|
<tbody>
|
||||||
{supports.map((i) => (
|
{supports.map((i) => (
|
||||||
<tr key={i.id} className="clickable" onClick={() => navigate(`/supports/${i.support_code || i.id}`)}>
|
<tr key={i.id} className={i.support_code ? 'clickable' : ''} onClick={() => i.support_code && navigate(`/supports/${i.support_code}`)}>
|
||||||
<td>{i.support_code || i.id}</td>
|
<td>{i.support_code || '—'}</td>
|
||||||
<td className="task-title">{i.title}</td>
|
<td className="task-title">{i.title}</td>
|
||||||
<td><span className={`badge status-${i.status}`}>{i.status}</span></td>
|
<td><span className={`badge status-${i.status}`}>{i.status}</span></td>
|
||||||
<td><span className={`badge priority-${i.priority}`}>{i.priority}</span></td>
|
<td><span className={`badge priority-${i.priority}`}>{i.priority}</span></td>
|
||||||
@@ -373,8 +380,8 @@ export default function MilestoneDetailPage() {
|
|||||||
<thead><tr><th>Code</th><th>Title</th><th>Status</th><th>Priority</th></tr></thead>
|
<thead><tr><th>Code</th><th>Title</th><th>Status</th><th>Priority</th></tr></thead>
|
||||||
<tbody>
|
<tbody>
|
||||||
{meetings.map((i) => (
|
{meetings.map((i) => (
|
||||||
<tr key={i.id} className="clickable" onClick={() => navigate(`/meetings/${i.meeting_code || i.id}`)}>
|
<tr key={i.id} className={i.meeting_code ? 'clickable' : ''} onClick={() => i.meeting_code && navigate(`/meetings/${i.meeting_code}`)}>
|
||||||
<td>{i.meeting_code || i.id}</td>
|
<td>{i.meeting_code || '—'}</td>
|
||||||
<td className="task-title">{i.title}</td>
|
<td className="task-title">{i.title}</td>
|
||||||
<td><span className={`badge status-${i.status}`}>{i.status}</span></td>
|
<td><span className={`badge status-${i.status}`}>{i.status}</span></td>
|
||||||
<td><span className={`badge priority-${i.priority}`}>{i.priority}</span></td>
|
<td><span className={`badge priority-${i.priority}`}>{i.priority}</span></td>
|
||||||
|
|||||||
@@ -13,7 +13,7 @@ export default function MilestonesPage() {
|
|||||||
const navigate = useNavigate()
|
const navigate = useNavigate()
|
||||||
|
|
||||||
const fetchMilestones = () => {
|
const fetchMilestones = () => {
|
||||||
const params = projectFilter ? `?project_id=${projectFilter}` : ''
|
const params = projectFilter ? `?project_code=${projectFilter}` : ''
|
||||||
api.get<Milestone[]>(`/milestones${params}`).then(({ data }) => setMilestones(data))
|
api.get<Milestone[]>(`/milestones${params}`).then(({ data }) => setMilestones(data))
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -35,21 +35,21 @@ export default function MilestonesPage() {
|
|||||||
<div className="filters">
|
<div className="filters">
|
||||||
<select value={projectFilter} onChange={(e) => setProjectFilter(e.target.value)}>
|
<select value={projectFilter} onChange={(e) => setProjectFilter(e.target.value)}>
|
||||||
<option value="">All projects</option>
|
<option value="">All projects</option>
|
||||||
{projects.map((p) => <option key={p.id} value={p.id}>{p.name}</option>)}
|
{projects.map((p) => <option key={p.id} value={p.project_code || ''}>{p.name}</option>)}
|
||||||
</select>
|
</select>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<MilestoneFormModal
|
<MilestoneFormModal
|
||||||
isOpen={showCreate}
|
isOpen={showCreate}
|
||||||
onClose={() => setShowCreate(false)}
|
onClose={() => setShowCreate(false)}
|
||||||
initialProjectId={projectFilter ? Number(projectFilter) : undefined}
|
initialProjectCode={projectFilter || undefined}
|
||||||
lockProject={Boolean(projectFilter)}
|
lockProject={Boolean(projectFilter)}
|
||||||
onSaved={() => fetchMilestones()}
|
onSaved={() => fetchMilestones()}
|
||||||
/>
|
/>
|
||||||
|
|
||||||
<div className="milestone-grid">
|
<div className="milestone-grid">
|
||||||
{milestones.map((ms) => (
|
{milestones.map((ms) => (
|
||||||
<div key={ms.id} className="milestone-card" onClick={() => navigate(`/milestones/${ms.milestone_code || ms.id}`)}>
|
<div key={ms.id} className="milestone-card" onClick={() => ms.milestone_code && navigate(`/milestones/${ms.milestone_code}`)}>
|
||||||
<div className="milestone-card-header">
|
<div className="milestone-card-header">
|
||||||
<span className={`badge status-${ms.status}`}>{ms.status}</span>
|
<span className={`badge status-${ms.status}`}>{ms.status}</span>
|
||||||
<h3>{ms.title}</h3>{ms.milestone_code && <span className="badge" style={{ marginLeft: 8, fontSize: '0.75em' }}>{ms.milestone_code}</span>}
|
<h3>{ms.title}</h3>{ms.milestone_code && <span className="badge" style={{ marginLeft: 8, fontSize: '0.75em' }}>{ms.milestone_code}</span>}
|
||||||
|
|||||||
@@ -52,7 +52,7 @@ export default function NotificationsPage() {
|
|||||||
className={`notification-item ${n.is_read ? 'read' : 'unread'}`}
|
className={`notification-item ${n.is_read ? 'read' : 'unread'}`}
|
||||||
onClick={() => {
|
onClick={() => {
|
||||||
if (!n.is_read) markRead(n.id)
|
if (!n.is_read) markRead(n.id)
|
||||||
if (n.task_id) navigate(`/tasks/${n.task_id}`)
|
if (n.task_code) navigate(`/tasks/${n.task_code}`)
|
||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
<div className="notification-dot">{n.is_read ? '' : '●'}</div>
|
<div className="notification-dot">{n.is_read ? '' : '●'}</div>
|
||||||
|
|||||||
@@ -114,7 +114,7 @@ export default function ProjectDetailPage() {
|
|||||||
{canEditProject && <button className="btn-sm" onClick={() => setShowMilestoneModal(true)}>+ New</button>}
|
{canEditProject && <button className="btn-sm" onClick={() => setShowMilestoneModal(true)}>+ New</button>}
|
||||||
</h3>
|
</h3>
|
||||||
{milestones.map((ms) => (
|
{milestones.map((ms) => (
|
||||||
<div key={ms.id} className="milestone-item" onClick={() => navigate(`/milestones/${ms.milestone_code || ms.id}`)}>
|
<div key={ms.id} className="milestone-item" onClick={() => ms.milestone_code && navigate(`/milestones/${ms.milestone_code}`)}>
|
||||||
<span className={`badge status-${ms.status === 'open' ? 'open' : ms.status === 'closed' ? 'closed' : 'in_progress'}`}>{ms.status}</span>
|
<span className={`badge status-${ms.status === 'open' ? 'open' : ms.status === 'closed' ? 'closed' : 'in_progress'}`}>{ms.status}</span>
|
||||||
<span className="milestone-title">{ms.title}</span>
|
<span className="milestone-title">{ms.title}</span>
|
||||||
{ms.due_date && <span className="text-dim"> · Due {dayjs(ms.due_date).format('YYYY-MM-DD')}</span>}
|
{ms.due_date && <span className="text-dim"> · Due {dayjs(ms.due_date).format('YYYY-MM-DD')}</span>}
|
||||||
@@ -136,7 +136,7 @@ export default function ProjectDetailPage() {
|
|||||||
<MilestoneFormModal
|
<MilestoneFormModal
|
||||||
isOpen={showMilestoneModal}
|
isOpen={showMilestoneModal}
|
||||||
onClose={() => setShowMilestoneModal(false)}
|
onClose={() => setShowMilestoneModal(false)}
|
||||||
initialProjectId={project.id}
|
initialProjectCode={project.project_code || ''}
|
||||||
lockProject
|
lockProject
|
||||||
onSaved={() => fetchProject()}
|
onSaved={() => fetchProject()}
|
||||||
/>
|
/>
|
||||||
|
|||||||
465
src/pages/ProposalDetailPage.tsx
Normal file
465
src/pages/ProposalDetailPage.tsx
Normal file
@@ -0,0 +1,465 @@
|
|||||||
|
import { useState, useEffect } from 'react'
|
||||||
|
import { useParams, useNavigate, useSearchParams } from 'react-router-dom'
|
||||||
|
import api from '@/services/api'
|
||||||
|
import type { Proposal, Milestone, Essential, EssentialType } from '@/types'
|
||||||
|
import dayjs from 'dayjs'
|
||||||
|
import CopyableCode from '@/components/CopyableCode'
|
||||||
|
|
||||||
|
export default function ProposalDetailPage() {
|
||||||
|
const { proposalCode } = useParams()
|
||||||
|
const [searchParams] = useSearchParams()
|
||||||
|
const projectCode = searchParams.get('project_code')
|
||||||
|
const navigate = useNavigate()
|
||||||
|
|
||||||
|
const [proposal, setProposal] = useState<Proposal | null>(null)
|
||||||
|
const [milestones, setMilestones] = useState<Milestone[]>([])
|
||||||
|
const [showAccept, setShowAccept] = useState(false)
|
||||||
|
const [selectedMilestone, setSelectedMilestone] = useState<string>('')
|
||||||
|
const [actionLoading, setActionLoading] = useState(false)
|
||||||
|
const [error, setError] = useState('')
|
||||||
|
|
||||||
|
// Edit state
|
||||||
|
const [showEdit, setShowEdit] = useState(false)
|
||||||
|
const [editTitle, setEditTitle] = useState('')
|
||||||
|
const [editDescription, setEditDescription] = useState('')
|
||||||
|
const [editLoading, setEditLoading] = useState(false)
|
||||||
|
|
||||||
|
// Essential state
|
||||||
|
const [essentials, setEssentials] = useState<Essential[]>([])
|
||||||
|
const [loadingEssentials, setLoadingEssentials] = useState(false)
|
||||||
|
|
||||||
|
// Essential create/edit state
|
||||||
|
const [showEssentialModal, setShowEssentialModal] = useState(false)
|
||||||
|
const [editingEssential, setEditingEssential] = useState<Essential | null>(null)
|
||||||
|
const [essentialTitle, setEssentialTitle] = useState('')
|
||||||
|
const [essentialType, setEssentialType] = useState<EssentialType>('feature')
|
||||||
|
const [essentialDesc, setEssentialDesc] = useState('')
|
||||||
|
const [essentialLoading, setEssentialLoading] = useState(false)
|
||||||
|
|
||||||
|
const fetchProposal = () => {
|
||||||
|
if (!projectCode || !proposalCode) return
|
||||||
|
api.get<Proposal>(`/projects/${projectCode}/proposals/${proposalCode}`).then(({ data }) => setProposal(data))
|
||||||
|
}
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
fetchProposal()
|
||||||
|
}, [proposalCode, projectCode])
|
||||||
|
|
||||||
|
const loadMilestones = () => {
|
||||||
|
if (!projectCode) return
|
||||||
|
api.get<Milestone[]>(`/milestones?project_code=${projectCode}`)
|
||||||
|
.then(({ data }) => setMilestones(data.filter((m) => m.status === 'open')))
|
||||||
|
}
|
||||||
|
|
||||||
|
const fetchEssentials = () => {
|
||||||
|
if (!projectCode || !proposalCode) return
|
||||||
|
setLoadingEssentials(true)
|
||||||
|
api.get<Essential[]>(`/projects/${projectCode}/proposals/${proposalCode}/essentials`)
|
||||||
|
.then(({ data }) => setEssentials(data))
|
||||||
|
.finally(() => setLoadingEssentials(false))
|
||||||
|
}
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
fetchEssentials()
|
||||||
|
}, [proposalCode, projectCode])
|
||||||
|
|
||||||
|
const handleAccept = async () => {
|
||||||
|
if (!selectedMilestone || !projectCode || !proposalCode) return
|
||||||
|
setActionLoading(true)
|
||||||
|
setError('')
|
||||||
|
try {
|
||||||
|
await api.post(`/projects/${projectCode}/proposals/${proposalCode}/accept`, { milestone_code: selectedMilestone })
|
||||||
|
setShowAccept(false)
|
||||||
|
fetchProposal()
|
||||||
|
} catch (err: any) {
|
||||||
|
setError(err.response?.data?.detail || 'Accept failed')
|
||||||
|
} finally {
|
||||||
|
setActionLoading(false)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
const handleReject = async () => {
|
||||||
|
if (!projectCode || !proposalCode) return
|
||||||
|
const reason = prompt('Reject reason (optional):')
|
||||||
|
setActionLoading(true)
|
||||||
|
setError('')
|
||||||
|
try {
|
||||||
|
await api.post(`/projects/${projectCode}/proposals/${proposalCode}/reject`, { reason: reason || undefined })
|
||||||
|
fetchProposal()
|
||||||
|
} catch (err: any) {
|
||||||
|
setError(err.response?.data?.detail || 'Reject failed')
|
||||||
|
} finally {
|
||||||
|
setActionLoading(false)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
const openEditModal = () => {
|
||||||
|
if (!proposal) return
|
||||||
|
setEditTitle(proposal.title)
|
||||||
|
setEditDescription(proposal.description || '')
|
||||||
|
setError('')
|
||||||
|
setShowEdit(true)
|
||||||
|
}
|
||||||
|
|
||||||
|
const handleEdit = async () => {
|
||||||
|
if (!projectCode || !proposalCode) return
|
||||||
|
setEditLoading(true)
|
||||||
|
setError('')
|
||||||
|
try {
|
||||||
|
await api.patch(`/projects/${projectCode}/proposals/${proposalCode}`, {
|
||||||
|
title: editTitle,
|
||||||
|
description: editDescription,
|
||||||
|
})
|
||||||
|
setShowEdit(false)
|
||||||
|
fetchProposal()
|
||||||
|
} catch (err: any) {
|
||||||
|
setError(err.response?.data?.detail || 'Update failed')
|
||||||
|
} finally {
|
||||||
|
setEditLoading(false)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
const handleReopen = async () => {
|
||||||
|
if (!projectCode || !proposalCode) return
|
||||||
|
setActionLoading(true)
|
||||||
|
setError('')
|
||||||
|
try {
|
||||||
|
await api.post(`/projects/${projectCode}/proposals/${proposalCode}/reopen`)
|
||||||
|
fetchProposal()
|
||||||
|
} catch (err: any) {
|
||||||
|
setError(err.response?.data?.detail || 'Reopen failed')
|
||||||
|
} finally {
|
||||||
|
setActionLoading(false)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Essential handlers
|
||||||
|
const openEssentialModal = (essential?: Essential) => {
|
||||||
|
if (essential) {
|
||||||
|
setEditingEssential(essential)
|
||||||
|
setEssentialTitle(essential.title)
|
||||||
|
setEssentialType(essential.type)
|
||||||
|
setEssentialDesc(essential.description || '')
|
||||||
|
} else {
|
||||||
|
setEditingEssential(null)
|
||||||
|
setEssentialTitle('')
|
||||||
|
setEssentialType('feature')
|
||||||
|
setEssentialDesc('')
|
||||||
|
}
|
||||||
|
setError('')
|
||||||
|
setShowEssentialModal(true)
|
||||||
|
}
|
||||||
|
|
||||||
|
const handleSaveEssential = async () => {
|
||||||
|
if (!projectCode || !proposalCode) return
|
||||||
|
setEssentialLoading(true)
|
||||||
|
setError('')
|
||||||
|
try {
|
||||||
|
if (editingEssential) {
|
||||||
|
await api.patch(`/projects/${projectCode}/proposals/${proposalCode}/essentials/${editingEssential.essential_code}`, {
|
||||||
|
title: essentialTitle,
|
||||||
|
type: essentialType,
|
||||||
|
description: essentialDesc || null,
|
||||||
|
})
|
||||||
|
} else {
|
||||||
|
await api.post(`/projects/${projectCode}/proposals/${proposalCode}/essentials`, {
|
||||||
|
title: essentialTitle,
|
||||||
|
type: essentialType,
|
||||||
|
description: essentialDesc || null,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
setShowEssentialModal(false)
|
||||||
|
fetchEssentials()
|
||||||
|
} catch (err: any) {
|
||||||
|
setError(err.response?.data?.detail || 'Save failed')
|
||||||
|
} finally {
|
||||||
|
setEssentialLoading(false)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
const handleDeleteEssential = async (essentialCode: string) => {
|
||||||
|
if (!projectCode || !proposalCode) return
|
||||||
|
if (!confirm('Are you sure you want to delete this Essential?')) return
|
||||||
|
setEssentialLoading(true)
|
||||||
|
try {
|
||||||
|
await api.delete(`/projects/${projectCode}/proposals/${proposalCode}/essentials/${essentialCode}`)
|
||||||
|
fetchEssentials()
|
||||||
|
} catch (err: any) {
|
||||||
|
setError(err.response?.data?.detail || 'Delete failed')
|
||||||
|
} finally {
|
||||||
|
setEssentialLoading(false)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!proposal) return <div className="loading">Loading...</div>
|
||||||
|
|
||||||
|
const statusBadgeClass = (s: string) => {
|
||||||
|
if (s === 'open') return 'status-open'
|
||||||
|
if (s === 'accepted') return 'status-completed'
|
||||||
|
if (s === 'rejected') return 'status-closed'
|
||||||
|
return ''
|
||||||
|
}
|
||||||
|
|
||||||
|
return (
|
||||||
|
<div className="task-detail">
|
||||||
|
<button className="btn-back" onClick={() => navigate(-1)}>← Back</button>
|
||||||
|
|
||||||
|
<div className="task-header">
|
||||||
|
<h2>
|
||||||
|
💡 {proposal.title}
|
||||||
|
{proposal.proposal_code && <span style={{ marginLeft: 8 }}><CopyableCode code={proposal.proposal_code} /></span>}
|
||||||
|
</h2>
|
||||||
|
<span className={`badge ${statusBadgeClass(proposal.status)}`} style={{ fontSize: '1rem' }}>
|
||||||
|
{proposal.status}
|
||||||
|
</span>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
{error && <div className="error-message" style={{ color: 'var(--danger)', marginBottom: 12 }}>{error}</div>}
|
||||||
|
|
||||||
|
<div className="section">
|
||||||
|
<h3>Details</h3>
|
||||||
|
<div className="detail-grid">
|
||||||
|
<div><strong>Proposal Code:</strong> {proposal.proposal_code ? <CopyableCode code={proposal.proposal_code} /> : '—'}</div>
|
||||||
|
<div><strong>Status:</strong> {proposal.status}</div>
|
||||||
|
<div><strong>Created By:</strong> {proposal.created_by_username || (proposal.created_by_id ? `User #${proposal.created_by_id}` : '—')}</div>
|
||||||
|
<div><strong>Created:</strong> {dayjs(proposal.created_at).format('YYYY-MM-DD HH:mm')}</div>
|
||||||
|
<div><strong>Updated:</strong> {proposal.updated_at ? dayjs(proposal.updated_at).format('YYYY-MM-DD HH:mm') : '—'}</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div className="section">
|
||||||
|
<h3>Description</h3>
|
||||||
|
<p style={{ whiteSpace: 'pre-wrap' }}>{proposal.description || 'No description'}</p>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
{/* Essentials section */}
|
||||||
|
<div className="section">
|
||||||
|
<div style={{ display: 'flex', justifyContent: 'space-between', alignItems: 'center', marginBottom: 12 }}>
|
||||||
|
<h3>Essentials ({essentials.length})</h3>
|
||||||
|
{proposal.status === 'open' && (
|
||||||
|
<button className="btn-primary" onClick={() => openEssentialModal()}>+ New Essential</button>
|
||||||
|
)}
|
||||||
|
</div>
|
||||||
|
{loadingEssentials ? (
|
||||||
|
<div className="loading">Loading...</div>
|
||||||
|
) : essentials.length === 0 ? (
|
||||||
|
<div className="empty" style={{ padding: '20px 0', color: 'var(--text-secondary)' }}>
|
||||||
|
No essentials yet. {proposal.status === 'open' ? 'Add one to define deliverables for this proposal.' : ''}
|
||||||
|
</div>
|
||||||
|
) : (
|
||||||
|
<div className="milestone-grid">
|
||||||
|
{essentials.map((e) => (
|
||||||
|
<div key={e.id} className="milestone-card">
|
||||||
|
<div className="milestone-card-header" style={{ display: 'flex', alignItems: 'center', gap: 8, flexWrap: 'wrap' }}>
|
||||||
|
<span className="badge">{e.type}</span>
|
||||||
|
{e.essential_code && <span className="badge"><CopyableCode code={e.essential_code} /></span>}
|
||||||
|
<h4 style={{ margin: 0, flex: 1 }}>{e.title}</h4>
|
||||||
|
{proposal.status === 'open' && (
|
||||||
|
<div style={{ display: 'flex', gap: 4 }}>
|
||||||
|
<button
|
||||||
|
className="btn-transition"
|
||||||
|
style={{ padding: '4px 8px', fontSize: '0.8rem' }}
|
||||||
|
onClick={() => openEssentialModal(e)}
|
||||||
|
>
|
||||||
|
Edit
|
||||||
|
</button>
|
||||||
|
<button
|
||||||
|
className="btn-danger"
|
||||||
|
style={{ padding: '4px 8px', fontSize: '0.8rem' }}
|
||||||
|
onClick={() => handleDeleteEssential(e.essential_code)}
|
||||||
|
>
|
||||||
|
Delete
|
||||||
|
</button>
|
||||||
|
</div>
|
||||||
|
)}
|
||||||
|
</div>
|
||||||
|
{e.description && (
|
||||||
|
<p style={{ marginTop: 8, color: 'var(--text-secondary)', whiteSpace: 'pre-wrap' }}>{e.description}</p>
|
||||||
|
)}
|
||||||
|
</div>
|
||||||
|
))}
|
||||||
|
</div>
|
||||||
|
)}
|
||||||
|
</div>
|
||||||
|
|
||||||
|
{/* Generated tasks (shown when accepted) */}
|
||||||
|
{proposal.status === 'accepted' && proposal.generated_tasks && proposal.generated_tasks.length > 0 && (
|
||||||
|
<div className="section">
|
||||||
|
<h3>Generated Tasks</h3>
|
||||||
|
<div className="milestone-grid">
|
||||||
|
{proposal.generated_tasks.map((gt) => (
|
||||||
|
<div
|
||||||
|
key={gt.task_id}
|
||||||
|
className="milestone-card"
|
||||||
|
onClick={() => gt.task_code && navigate(`/tasks/${gt.task_code}`)}
|
||||||
|
style={{ cursor: 'pointer' }}
|
||||||
|
>
|
||||||
|
<div className="milestone-card-header">
|
||||||
|
<span className="badge">{gt.task_type}/{gt.task_subtype}</span>
|
||||||
|
{gt.task_code && <span className="badge">{gt.task_code}</span>}
|
||||||
|
<h3>{gt.title}</h3>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
))}
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
)}
|
||||||
|
|
||||||
|
{/* Action buttons */}
|
||||||
|
<div className="section" style={{ display: 'flex', gap: 8, flexWrap: 'wrap' }}>
|
||||||
|
{proposal.status === 'open' && (
|
||||||
|
<>
|
||||||
|
<button
|
||||||
|
className="btn-transition"
|
||||||
|
onClick={openEditModal}
|
||||||
|
>
|
||||||
|
✏️ Edit
|
||||||
|
</button>
|
||||||
|
<button
|
||||||
|
className="btn-primary"
|
||||||
|
disabled={actionLoading}
|
||||||
|
onClick={() => { loadMilestones(); setShowAccept(true) }}
|
||||||
|
>
|
||||||
|
✅ Accept
|
||||||
|
</button>
|
||||||
|
<button
|
||||||
|
className="btn-danger"
|
||||||
|
disabled={actionLoading}
|
||||||
|
onClick={handleReject}
|
||||||
|
>
|
||||||
|
❌ Reject
|
||||||
|
</button>
|
||||||
|
</>
|
||||||
|
)}
|
||||||
|
{proposal.status === 'rejected' && (
|
||||||
|
<button
|
||||||
|
className="btn-transition"
|
||||||
|
disabled={actionLoading}
|
||||||
|
onClick={handleReopen}
|
||||||
|
>
|
||||||
|
🔄 Reopen
|
||||||
|
</button>
|
||||||
|
)}
|
||||||
|
</div>
|
||||||
|
|
||||||
|
{/* Edit modal */}
|
||||||
|
{showEdit && (
|
||||||
|
<div className="modal-overlay" onClick={() => setShowEdit(false)}>
|
||||||
|
<div className="modal" onClick={(e) => e.stopPropagation()}>
|
||||||
|
<h3>Edit Proposal</h3>
|
||||||
|
<label style={{ display: 'block', marginBottom: 8 }}>
|
||||||
|
<strong>Title</strong>
|
||||||
|
<input
|
||||||
|
type="text"
|
||||||
|
value={editTitle}
|
||||||
|
onChange={(e) => setEditTitle(e.target.value)}
|
||||||
|
style={{ width: '100%', marginTop: 4 }}
|
||||||
|
/>
|
||||||
|
</label>
|
||||||
|
<label style={{ display: 'block', marginBottom: 8 }}>
|
||||||
|
<strong>Description</strong>
|
||||||
|
<textarea
|
||||||
|
value={editDescription}
|
||||||
|
onChange={(e) => setEditDescription(e.target.value)}
|
||||||
|
rows={6}
|
||||||
|
style={{ width: '100%', marginTop: 4 }}
|
||||||
|
/>
|
||||||
|
</label>
|
||||||
|
<div style={{ marginTop: 12, display: 'flex', gap: 8 }}>
|
||||||
|
<button
|
||||||
|
className="btn-primary"
|
||||||
|
onClick={handleEdit}
|
||||||
|
disabled={!editTitle.trim() || editLoading}
|
||||||
|
>
|
||||||
|
{editLoading ? 'Saving...' : 'Save'}
|
||||||
|
</button>
|
||||||
|
<button className="btn-back" onClick={() => setShowEdit(false)}>Cancel</button>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
)}
|
||||||
|
|
||||||
|
{/* Accept modal with milestone selector */}
|
||||||
|
{showAccept && (
|
||||||
|
<div className="modal-overlay" onClick={() => setShowAccept(false)}>
|
||||||
|
<div className="modal" onClick={(e) => e.stopPropagation()}>
|
||||||
|
<h3>Accept Proposal</h3>
|
||||||
|
<p>Select an <strong>open</strong> milestone to generate story tasks in:</p>
|
||||||
|
<select
|
||||||
|
value={selectedMilestone}
|
||||||
|
onChange={(e) => setSelectedMilestone(e.target.value)}
|
||||||
|
>
|
||||||
|
<option value="">— Select milestone —</option>
|
||||||
|
{milestones.map((ms) => (
|
||||||
|
<option key={ms.id} value={ms.milestone_code || ''}>{ms.title}</option>
|
||||||
|
))}
|
||||||
|
</select>
|
||||||
|
{milestones.length === 0 && (
|
||||||
|
<p style={{ color: 'var(--danger)', marginTop: 8 }}>No open milestones available.</p>
|
||||||
|
)}
|
||||||
|
<div style={{ marginTop: 12, display: 'flex', gap: 8 }}>
|
||||||
|
<button
|
||||||
|
className="btn-primary"
|
||||||
|
onClick={handleAccept}
|
||||||
|
disabled={!selectedMilestone || actionLoading}
|
||||||
|
>
|
||||||
|
{actionLoading ? 'Accepting...' : 'Confirm Accept'}
|
||||||
|
</button>
|
||||||
|
<button className="btn-back" onClick={() => setShowAccept(false)}>Cancel</button>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
)}
|
||||||
|
{/* Essential create/edit modal */}
|
||||||
|
{showEssentialModal && (
|
||||||
|
<div className="modal-overlay" onClick={() => setShowEssentialModal(false)}>
|
||||||
|
<div className="modal" onClick={(e) => e.stopPropagation()}>
|
||||||
|
<h3>{editingEssential ? 'Edit Essential' : 'New Essential'}</h3>
|
||||||
|
<label style={{ display: 'block', marginBottom: 8 }}>
|
||||||
|
<strong>Title</strong>
|
||||||
|
<input
|
||||||
|
type="text"
|
||||||
|
value={essentialTitle}
|
||||||
|
onChange={(e) => setEssentialTitle(e.target.value)}
|
||||||
|
style={{ width: '100%', marginTop: 4 }}
|
||||||
|
placeholder="Essential title"
|
||||||
|
/>
|
||||||
|
</label>
|
||||||
|
<label style={{ display: 'block', marginBottom: 8 }}>
|
||||||
|
<strong>Type</strong>
|
||||||
|
<select
|
||||||
|
value={essentialType}
|
||||||
|
onChange={(e) => setEssentialType(e.target.value as EssentialType)}
|
||||||
|
style={{ width: '100%', marginTop: 4 }}
|
||||||
|
>
|
||||||
|
<option value="feature">Feature</option>
|
||||||
|
<option value="improvement">Improvement</option>
|
||||||
|
<option value="refactor">Refactor</option>
|
||||||
|
</select>
|
||||||
|
</label>
|
||||||
|
<label style={{ display: 'block', marginBottom: 8 }}>
|
||||||
|
<strong>Description</strong>
|
||||||
|
<textarea
|
||||||
|
value={essentialDesc}
|
||||||
|
onChange={(e) => setEssentialDesc(e.target.value)}
|
||||||
|
rows={4}
|
||||||
|
style={{ width: '100%', marginTop: 4 }}
|
||||||
|
placeholder="Description (optional)"
|
||||||
|
/>
|
||||||
|
</label>
|
||||||
|
<div style={{ marginTop: 12, display: 'flex', gap: 8 }}>
|
||||||
|
<button
|
||||||
|
className="btn-primary"
|
||||||
|
onClick={handleSaveEssential}
|
||||||
|
disabled={!essentialTitle.trim() || essentialLoading}
|
||||||
|
>
|
||||||
|
{essentialLoading ? 'Saving...' : 'Save'}
|
||||||
|
</button>
|
||||||
|
<button className="btn-back" onClick={() => setShowEssentialModal(false)}>Cancel</button>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
)}
|
||||||
|
</div>
|
||||||
|
)
|
||||||
|
}
|
||||||
@@ -1,11 +1,11 @@
|
|||||||
import { useState, useEffect } from 'react'
|
import { useState, useEffect } from 'react'
|
||||||
import { useNavigate } from 'react-router-dom'
|
import { useNavigate } from 'react-router-dom'
|
||||||
import api from '@/services/api'
|
import api from '@/services/api'
|
||||||
import type { Propose, Project } from '@/types'
|
import type { Proposal, Project } from '@/types'
|
||||||
import dayjs from 'dayjs'
|
import dayjs from 'dayjs'
|
||||||
|
|
||||||
export default function ProposesPage() {
|
export default function ProposalsPage() {
|
||||||
const [proposes, setProposes] = useState<Propose[]>([])
|
const [proposals, setProposals] = useState<Proposal[]>([])
|
||||||
const [projects, setProjects] = useState<Project[]>([])
|
const [projects, setProjects] = useState<Project[]>([])
|
||||||
const [projectFilter, setProjectFilter] = useState('')
|
const [projectFilter, setProjectFilter] = useState('')
|
||||||
const [showCreate, setShowCreate] = useState(false)
|
const [showCreate, setShowCreate] = useState(false)
|
||||||
@@ -14,32 +14,32 @@ export default function ProposesPage() {
|
|||||||
const [creating, setCreating] = useState(false)
|
const [creating, setCreating] = useState(false)
|
||||||
const navigate = useNavigate()
|
const navigate = useNavigate()
|
||||||
|
|
||||||
const fetchProposes = () => {
|
const fetchProposals = () => {
|
||||||
if (!projectFilter) {
|
if (!projectFilter) {
|
||||||
setProposes([])
|
setProposals([])
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
api.get<Propose[]>(`/projects/${projectFilter}/proposes`).then(({ data }) => setProposes(data))
|
api.get<Proposal[]>(`/projects/${projectFilter}/proposals`).then(({ data }) => setProposals(data))
|
||||||
}
|
}
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
api.get<Project[]>('/projects').then(({ data }) => setProjects(data))
|
api.get<Project[]>('/projects').then(({ data }) => setProjects(data))
|
||||||
}, [])
|
}, [])
|
||||||
|
|
||||||
useEffect(() => { fetchProposes() }, [projectFilter])
|
useEffect(() => { fetchProposals() }, [projectFilter])
|
||||||
|
|
||||||
const handleCreate = async () => {
|
const handleCreate = async () => {
|
||||||
if (!newTitle.trim() || !projectFilter) return
|
if (!newTitle.trim() || !projectFilter) return
|
||||||
setCreating(true)
|
setCreating(true)
|
||||||
try {
|
try {
|
||||||
await api.post(`/projects/${projectFilter}/proposes`, {
|
await api.post(`/projects/${projectFilter}/proposals`, {
|
||||||
title: newTitle.trim(),
|
title: newTitle.trim(),
|
||||||
description: newDesc.trim() || null,
|
description: newDesc.trim() || null,
|
||||||
})
|
})
|
||||||
setNewTitle('')
|
setNewTitle('')
|
||||||
setNewDesc('')
|
setNewDesc('')
|
||||||
setShowCreate(false)
|
setShowCreate(false)
|
||||||
fetchProposes()
|
fetchProposals()
|
||||||
} finally {
|
} finally {
|
||||||
setCreating(false)
|
setCreating(false)
|
||||||
}
|
}
|
||||||
@@ -55,45 +55,44 @@ export default function ProposesPage() {
|
|||||||
return (
|
return (
|
||||||
<div className="milestones-page">
|
<div className="milestones-page">
|
||||||
<div className="page-header">
|
<div className="page-header">
|
||||||
<h2>💡 Proposes ({proposes.length})</h2>
|
<h2>💡 Proposals ({proposals.length})</h2>
|
||||||
<button className="btn-primary" disabled={!projectFilter} onClick={() => setShowCreate(true)}>
|
<button className="btn-primary" disabled={!projectFilter} onClick={() => setShowCreate(true)}>
|
||||||
+ New Propose
|
+ New Proposal
|
||||||
</button>
|
</button>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div className="filters">
|
<div className="filters">
|
||||||
<select value={projectFilter} onChange={(e) => setProjectFilter(e.target.value)}>
|
<select value={projectFilter} onChange={(e) => setProjectFilter(e.target.value)}>
|
||||||
<option value="">Select a project</option>
|
<option value="">Select a project</option>
|
||||||
{projects.map((p) => <option key={p.id} value={p.id}>{p.name}</option>)}
|
{projects.map((p) => <option key={p.id} value={p.project_code || ''}>{p.name}</option>)}
|
||||||
</select>
|
</select>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
{!projectFilter && <p className="empty">Please select a project to view proposes.</p>}
|
{!projectFilter && <p className="empty">Please select a project to view proposals.</p>}
|
||||||
|
|
||||||
<div className="milestone-grid">
|
<div className="milestone-grid">
|
||||||
{proposes.map((pr) => (
|
{proposals.map((pr) => (
|
||||||
<div key={pr.id} className="milestone-card" onClick={() => navigate(`/proposes/${pr.propose_code || pr.id}?project_id=${pr.project_id}`)}>
|
<div key={pr.id} className="milestone-card" onClick={() => pr.proposal_code && pr.project_code && navigate(`/proposals/${pr.proposal_code}?project_code=${pr.project_code}`)}>
|
||||||
<div className="milestone-card-header">
|
<div className="milestone-card-header">
|
||||||
<span className={`badge ${statusBadgeClass(pr.status)}`}>{pr.status}</span>
|
<span className={`badge ${statusBadgeClass(pr.status)}`}>{pr.status}</span>
|
||||||
{pr.propose_code && <span className="badge">{pr.propose_code}</span>}
|
{pr.proposal_code && <span className="badge">{pr.proposal_code}</span>}
|
||||||
<h3>{pr.title}</h3>
|
<h3>{pr.title}</h3>
|
||||||
</div>
|
</div>
|
||||||
<p className="project-desc">{pr.description || 'No description'}</p>
|
<p className="project-desc">{pr.description || 'No description'}</p>
|
||||||
<div className="project-meta">
|
<div className="project-meta">
|
||||||
{pr.feat_task_id && <span>Task: {pr.feat_task_id}</span>}
|
|
||||||
<span>Created {dayjs(pr.created_at).format('YYYY-MM-DD')}</span>
|
<span>Created {dayjs(pr.created_at).format('YYYY-MM-DD')}</span>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
))}
|
))}
|
||||||
{projectFilter && proposes.length === 0 && <p className="empty">No proposes</p>}
|
{projectFilter && proposals.length === 0 && <p className="empty">No proposals</p>}
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
{showCreate && (
|
{showCreate && (
|
||||||
<div className="modal-overlay" onClick={() => setShowCreate(false)}>
|
<div className="modal-overlay" onClick={() => setShowCreate(false)}>
|
||||||
<div className="modal" onClick={(e) => e.stopPropagation()}>
|
<div className="modal" onClick={(e) => e.stopPropagation()}>
|
||||||
<h3>New Propose</h3>
|
<h3>New Proposal</h3>
|
||||||
<label>Title</label>
|
<label>Title</label>
|
||||||
<input value={newTitle} onChange={(e) => setNewTitle(e.target.value)} placeholder="Propose title" />
|
<input value={newTitle} onChange={(e) => setNewTitle(e.target.value)} placeholder="Proposal title" />
|
||||||
<label>Description</label>
|
<label>Description</label>
|
||||||
<textarea value={newDesc} onChange={(e) => setNewDesc(e.target.value)} placeholder="Description (optional)" rows={4} />
|
<textarea value={newDesc} onChange={(e) => setNewDesc(e.target.value)} placeholder="Description (optional)" rows={4} />
|
||||||
<div style={{ marginTop: 12, display: 'flex', gap: 8 }}>
|
<div style={{ marginTop: 12, display: 'flex', gap: 8 }}>
|
||||||
@@ -1,266 +0,0 @@
|
|||||||
import { useState, useEffect } from 'react'
|
|
||||||
import { useParams, useNavigate, useSearchParams } from 'react-router-dom'
|
|
||||||
import api from '@/services/api'
|
|
||||||
import type { Propose, Milestone } from '@/types'
|
|
||||||
import dayjs from 'dayjs'
|
|
||||||
import CopyableCode from '@/components/CopyableCode'
|
|
||||||
|
|
||||||
export default function ProposeDetailPage() {
|
|
||||||
const { id } = useParams()
|
|
||||||
const [searchParams] = useSearchParams()
|
|
||||||
const projectId = searchParams.get('project_id')
|
|
||||||
const navigate = useNavigate()
|
|
||||||
|
|
||||||
const [propose, setPropose] = useState<Propose | null>(null)
|
|
||||||
const [milestones, setMilestones] = useState<Milestone[]>([])
|
|
||||||
const [showAccept, setShowAccept] = useState(false)
|
|
||||||
const [selectedMilestone, setSelectedMilestone] = useState<number | ''>('')
|
|
||||||
const [actionLoading, setActionLoading] = useState(false)
|
|
||||||
const [error, setError] = useState('')
|
|
||||||
|
|
||||||
// Edit state (P10.7)
|
|
||||||
const [showEdit, setShowEdit] = useState(false)
|
|
||||||
const [editTitle, setEditTitle] = useState('')
|
|
||||||
const [editDescription, setEditDescription] = useState('')
|
|
||||||
const [editLoading, setEditLoading] = useState(false)
|
|
||||||
|
|
||||||
const fetchPropose = () => {
|
|
||||||
if (!projectId) return
|
|
||||||
api.get<Propose>(`/projects/${projectId}/proposes/${id}`).then(({ data }) => setPropose(data))
|
|
||||||
}
|
|
||||||
|
|
||||||
useEffect(() => {
|
|
||||||
fetchPropose()
|
|
||||||
}, [id, projectId])
|
|
||||||
|
|
||||||
const loadMilestones = () => {
|
|
||||||
if (!projectId) return
|
|
||||||
api.get<Milestone[]>(`/milestones?project_id=${projectId}`)
|
|
||||||
.then(({ data }) => setMilestones(data.filter((m) => m.status === 'open')))
|
|
||||||
}
|
|
||||||
|
|
||||||
const handleAccept = async () => {
|
|
||||||
if (!selectedMilestone || !projectId) return
|
|
||||||
setActionLoading(true)
|
|
||||||
setError('')
|
|
||||||
try {
|
|
||||||
await api.post(`/projects/${projectId}/proposes/${id}/accept`, { milestone_id: selectedMilestone })
|
|
||||||
setShowAccept(false)
|
|
||||||
fetchPropose()
|
|
||||||
} catch (err: any) {
|
|
||||||
setError(err.response?.data?.detail || 'Accept failed')
|
|
||||||
} finally {
|
|
||||||
setActionLoading(false)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
const handleReject = async () => {
|
|
||||||
if (!projectId) return
|
|
||||||
const reason = prompt('Reject reason (optional):')
|
|
||||||
setActionLoading(true)
|
|
||||||
setError('')
|
|
||||||
try {
|
|
||||||
await api.post(`/projects/${projectId}/proposes/${id}/reject`, { reason: reason || undefined })
|
|
||||||
fetchPropose()
|
|
||||||
} catch (err: any) {
|
|
||||||
setError(err.response?.data?.detail || 'Reject failed')
|
|
||||||
} finally {
|
|
||||||
setActionLoading(false)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
const openEditModal = () => {
|
|
||||||
if (!propose) return
|
|
||||||
setEditTitle(propose.title)
|
|
||||||
setEditDescription(propose.description || '')
|
|
||||||
setError('')
|
|
||||||
setShowEdit(true)
|
|
||||||
}
|
|
||||||
|
|
||||||
const handleEdit = async () => {
|
|
||||||
if (!projectId) return
|
|
||||||
setEditLoading(true)
|
|
||||||
setError('')
|
|
||||||
try {
|
|
||||||
await api.patch(`/projects/${projectId}/proposes/${id}`, {
|
|
||||||
title: editTitle,
|
|
||||||
description: editDescription,
|
|
||||||
})
|
|
||||||
setShowEdit(false)
|
|
||||||
fetchPropose()
|
|
||||||
} catch (err: any) {
|
|
||||||
setError(err.response?.data?.detail || 'Update failed')
|
|
||||||
} finally {
|
|
||||||
setEditLoading(false)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
const handleReopen = async () => {
|
|
||||||
if (!projectId) return
|
|
||||||
setActionLoading(true)
|
|
||||||
setError('')
|
|
||||||
try {
|
|
||||||
await api.post(`/projects/${projectId}/proposes/${id}/reopen`)
|
|
||||||
fetchPropose()
|
|
||||||
} catch (err: any) {
|
|
||||||
setError(err.response?.data?.detail || 'Reopen failed')
|
|
||||||
} finally {
|
|
||||||
setActionLoading(false)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!propose) return <div className="loading">Loading...</div>
|
|
||||||
|
|
||||||
const statusBadgeClass = (s: string) => {
|
|
||||||
if (s === 'open') return 'status-open'
|
|
||||||
if (s === 'accepted') return 'status-completed'
|
|
||||||
if (s === 'rejected') return 'status-closed'
|
|
||||||
return ''
|
|
||||||
}
|
|
||||||
|
|
||||||
return (
|
|
||||||
<div className="task-detail">
|
|
||||||
<button className="btn-back" onClick={() => navigate(-1)}>← Back</button>
|
|
||||||
|
|
||||||
<div className="task-header">
|
|
||||||
<h2>
|
|
||||||
💡 {propose.title}
|
|
||||||
{propose.propose_code && <span style={{ marginLeft: 8 }}><CopyableCode code={propose.propose_code} /></span>}
|
|
||||||
</h2>
|
|
||||||
<span className={`badge ${statusBadgeClass(propose.status)}`} style={{ fontSize: '1rem' }}>
|
|
||||||
{propose.status}
|
|
||||||
</span>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
{error && <div className="error-message" style={{ color: 'var(--danger)', marginBottom: 12 }}>{error}</div>}
|
|
||||||
|
|
||||||
<div className="section">
|
|
||||||
<h3>Details</h3>
|
|
||||||
<div className="detail-grid">
|
|
||||||
<div><strong>Propose Code:</strong> {propose.propose_code ? <CopyableCode code={propose.propose_code} /> : '—'}</div>
|
|
||||||
<div><strong>Status:</strong> {propose.status}</div>
|
|
||||||
<div><strong>Created By:</strong> {propose.created_by_username || (propose.created_by_id ? `User #${propose.created_by_id}` : '—')}</div>
|
|
||||||
<div><strong>Created:</strong> {dayjs(propose.created_at).format('YYYY-MM-DD HH:mm')}</div>
|
|
||||||
<div><strong>Updated:</strong> {propose.updated_at ? dayjs(propose.updated_at).format('YYYY-MM-DD HH:mm') : '—'}</div>
|
|
||||||
<div><strong>Feature Task:</strong> {propose.feat_task_id || '—'}</div>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div className="section">
|
|
||||||
<h3>Description</h3>
|
|
||||||
<p style={{ whiteSpace: 'pre-wrap' }}>{propose.description || 'No description'}</p>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
{/* Action buttons */}
|
|
||||||
<div className="section" style={{ display: 'flex', gap: 8, flexWrap: 'wrap' }}>
|
|
||||||
{propose.status === 'open' && (
|
|
||||||
<>
|
|
||||||
<button
|
|
||||||
className="btn-transition"
|
|
||||||
onClick={openEditModal}
|
|
||||||
>
|
|
||||||
✏️ Edit
|
|
||||||
</button>
|
|
||||||
<button
|
|
||||||
className="btn-primary"
|
|
||||||
disabled={actionLoading}
|
|
||||||
onClick={() => { loadMilestones(); setShowAccept(true) }}
|
|
||||||
>
|
|
||||||
✅ Accept
|
|
||||||
</button>
|
|
||||||
<button
|
|
||||||
className="btn-danger"
|
|
||||||
disabled={actionLoading}
|
|
||||||
onClick={handleReject}
|
|
||||||
>
|
|
||||||
❌ Reject
|
|
||||||
</button>
|
|
||||||
</>
|
|
||||||
)}
|
|
||||||
{propose.status === 'accepted' && propose.feat_task_id && (
|
|
||||||
<button className="btn-transition" onClick={() => navigate(`/tasks/${propose.feat_task_id}`)}>
|
|
||||||
📋 View Generated Task
|
|
||||||
</button>
|
|
||||||
)}
|
|
||||||
{propose.status === 'rejected' && (
|
|
||||||
<button
|
|
||||||
className="btn-transition"
|
|
||||||
disabled={actionLoading}
|
|
||||||
onClick={handleReopen}
|
|
||||||
>
|
|
||||||
🔄 Reopen
|
|
||||||
</button>
|
|
||||||
)}
|
|
||||||
</div>
|
|
||||||
|
|
||||||
{/* Edit modal (P10.7 — only reachable when open) */}
|
|
||||||
{showEdit && (
|
|
||||||
<div className="modal-overlay" onClick={() => setShowEdit(false)}>
|
|
||||||
<div className="modal" onClick={(e) => e.stopPropagation()}>
|
|
||||||
<h3>Edit Propose</h3>
|
|
||||||
<label style={{ display: 'block', marginBottom: 8 }}>
|
|
||||||
<strong>Title</strong>
|
|
||||||
<input
|
|
||||||
type="text"
|
|
||||||
value={editTitle}
|
|
||||||
onChange={(e) => setEditTitle(e.target.value)}
|
|
||||||
style={{ width: '100%', marginTop: 4 }}
|
|
||||||
/>
|
|
||||||
</label>
|
|
||||||
<label style={{ display: 'block', marginBottom: 8 }}>
|
|
||||||
<strong>Description</strong>
|
|
||||||
<textarea
|
|
||||||
value={editDescription}
|
|
||||||
onChange={(e) => setEditDescription(e.target.value)}
|
|
||||||
rows={6}
|
|
||||||
style={{ width: '100%', marginTop: 4 }}
|
|
||||||
/>
|
|
||||||
</label>
|
|
||||||
<div style={{ marginTop: 12, display: 'flex', gap: 8 }}>
|
|
||||||
<button
|
|
||||||
className="btn-primary"
|
|
||||||
onClick={handleEdit}
|
|
||||||
disabled={!editTitle.trim() || editLoading}
|
|
||||||
>
|
|
||||||
{editLoading ? 'Saving...' : 'Save'}
|
|
||||||
</button>
|
|
||||||
<button className="btn-back" onClick={() => setShowEdit(false)}>Cancel</button>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
)}
|
|
||||||
|
|
||||||
{/* Accept modal with milestone selector */}
|
|
||||||
{showAccept && (
|
|
||||||
<div className="modal-overlay" onClick={() => setShowAccept(false)}>
|
|
||||||
<div className="modal" onClick={(e) => e.stopPropagation()}>
|
|
||||||
<h3>Accept Propose</h3>
|
|
||||||
<p>Select an <strong>open</strong> milestone to create a feature story task in:</p>
|
|
||||||
<select
|
|
||||||
value={selectedMilestone}
|
|
||||||
onChange={(e) => setSelectedMilestone(Number(e.target.value))}
|
|
||||||
>
|
|
||||||
<option value="">— Select milestone —</option>
|
|
||||||
{milestones.map((ms) => (
|
|
||||||
<option key={ms.id} value={ms.id}>{ms.title}</option>
|
|
||||||
))}
|
|
||||||
</select>
|
|
||||||
{milestones.length === 0 && (
|
|
||||||
<p style={{ color: 'var(--danger)', marginTop: 8 }}>No open milestones available.</p>
|
|
||||||
)}
|
|
||||||
<div style={{ marginTop: 12, display: 'flex', gap: 8 }}>
|
|
||||||
<button
|
|
||||||
className="btn-primary"
|
|
||||||
onClick={handleAccept}
|
|
||||||
disabled={!selectedMilestone || actionLoading}
|
|
||||||
>
|
|
||||||
{actionLoading ? 'Accepting...' : 'Confirm Accept'}
|
|
||||||
</button>
|
|
||||||
<button className="btn-back" onClick={() => setShowAccept(false)}>Cancel</button>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
)}
|
|
||||||
</div>
|
|
||||||
)
|
|
||||||
}
|
|
||||||
@@ -27,7 +27,7 @@ const STATUS_OPTIONS = ['open', 'in_progress', 'resolved', 'closed']
|
|||||||
const PRIORITY_OPTIONS = ['low', 'medium', 'high', 'critical']
|
const PRIORITY_OPTIONS = ['low', 'medium', 'high', 'critical']
|
||||||
|
|
||||||
export default function SupportDetailPage() {
|
export default function SupportDetailPage() {
|
||||||
const { supportId } = useParams()
|
const { supportCode } = useParams()
|
||||||
const navigate = useNavigate()
|
const navigate = useNavigate()
|
||||||
const { user } = useAuth()
|
const { user } = useAuth()
|
||||||
const [support, setSupport] = useState<SupportItem | null>(null)
|
const [support, setSupport] = useState<SupportItem | null>(null)
|
||||||
@@ -40,7 +40,7 @@ export default function SupportDetailPage() {
|
|||||||
|
|
||||||
const fetchSupport = async () => {
|
const fetchSupport = async () => {
|
||||||
try {
|
try {
|
||||||
const { data } = await api.get<SupportItem>(`/supports/${supportId}`)
|
const { data } = await api.get<SupportItem>(`/supports/${supportCode}`)
|
||||||
setSupport(data)
|
setSupport(data)
|
||||||
setEditForm({
|
setEditForm({
|
||||||
title: data.title,
|
title: data.title,
|
||||||
@@ -56,14 +56,14 @@ export default function SupportDetailPage() {
|
|||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
fetchSupport()
|
fetchSupport()
|
||||||
}, [supportId])
|
}, [supportCode])
|
||||||
|
|
||||||
const handleTake = async () => {
|
const handleTake = async () => {
|
||||||
if (!support) return
|
if (!support) return
|
||||||
setSaving(true)
|
setSaving(true)
|
||||||
setMessage('')
|
setMessage('')
|
||||||
try {
|
try {
|
||||||
const { data } = await api.post<SupportItem>(`/supports/${supportId}/take`)
|
const { data } = await api.post<SupportItem>(`/supports/${supportCode}/take`)
|
||||||
setSupport(data)
|
setSupport(data)
|
||||||
setMessage('You have taken this support ticket')
|
setMessage('You have taken this support ticket')
|
||||||
} catch (err: any) {
|
} catch (err: any) {
|
||||||
@@ -78,7 +78,7 @@ export default function SupportDetailPage() {
|
|||||||
setSaving(true)
|
setSaving(true)
|
||||||
setMessage('')
|
setMessage('')
|
||||||
try {
|
try {
|
||||||
const { data } = await api.post<SupportItem>(`/supports/${supportId}/transition`, {
|
const { data } = await api.post<SupportItem>(`/supports/${supportCode}/transition`, {
|
||||||
status: transitionStatus,
|
status: transitionStatus,
|
||||||
})
|
})
|
||||||
setSupport(data)
|
setSupport(data)
|
||||||
@@ -106,7 +106,7 @@ export default function SupportDetailPage() {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
const { data } = await api.patch<SupportItem>(`/supports/${supportId}`, payload)
|
const { data } = await api.patch<SupportItem>(`/supports/${supportCode}`, payload)
|
||||||
setSupport(data)
|
setSupport(data)
|
||||||
setEditMode(false)
|
setEditMode(false)
|
||||||
setMessage('Support ticket updated')
|
setMessage('Support ticket updated')
|
||||||
@@ -122,7 +122,7 @@ export default function SupportDetailPage() {
|
|||||||
if (!confirm(`Delete support ticket ${support.support_code || support.id}? This cannot be undone.`)) return
|
if (!confirm(`Delete support ticket ${support.support_code || support.id}? This cannot be undone.`)) return
|
||||||
setSaving(true)
|
setSaving(true)
|
||||||
try {
|
try {
|
||||||
await api.delete(`/supports/${supportId}`)
|
await api.delete(`/supports/${supportCode}`)
|
||||||
navigate(-1)
|
navigate(-1)
|
||||||
} catch (err: any) {
|
} catch (err: any) {
|
||||||
setMessage(err.response?.data?.detail || 'Failed to delete support ticket')
|
setMessage(err.response?.data?.detail || 'Failed to delete support ticket')
|
||||||
|
|||||||
@@ -8,7 +8,7 @@ import CreateTaskModal from '@/components/CreateTaskModal'
|
|||||||
import CopyableCode from '@/components/CopyableCode'
|
import CopyableCode from '@/components/CopyableCode'
|
||||||
|
|
||||||
export default function TaskDetailPage() {
|
export default function TaskDetailPage() {
|
||||||
const { id } = useParams()
|
const { taskCode } = useParams()
|
||||||
const navigate = useNavigate()
|
const navigate = useNavigate()
|
||||||
const { user } = useAuth()
|
const { user } = useAuth()
|
||||||
const [task, setTask] = useState<Task | null>(null)
|
const [task, setTask] = useState<Task | null>(null)
|
||||||
@@ -26,27 +26,30 @@ export default function TaskDetailPage() {
|
|||||||
const [closeReason, setCloseReason] = useState('')
|
const [closeReason, setCloseReason] = useState('')
|
||||||
|
|
||||||
const refreshTask = async () => {
|
const refreshTask = async () => {
|
||||||
const { data } = await api.get<Task>(`/tasks/${id}`)
|
if (!taskCode) return
|
||||||
|
const { data } = await api.get<Task>(`/tasks/${taskCode}`)
|
||||||
setTask(data)
|
setTask(data)
|
||||||
if (data.project_id) {
|
if (data.project_id) {
|
||||||
api.get<Project>(`/projects/${data.project_id}`).then(({ data }) => setProject(data)).catch(() => {})
|
api.get<Project>(`/projects/${data.project_id}`).then(({ data }) => setProject(data)).catch(() => {})
|
||||||
api.get<ProjectMember[]>(`/projects/${data.project_id}/members`).then(({ data }) => setMembers(data)).catch(() => {})
|
api.get<ProjectMember[]>(`/projects/${data.project_id}/members`).then(({ data }) => setMembers(data)).catch(() => {})
|
||||||
}
|
}
|
||||||
if (data.milestone_id) {
|
if (data.milestone_code) {
|
||||||
api.get<Milestone>(`/milestones/${data.milestone_id}`).then(({ data }) => setMilestone(data)).catch(() => {})
|
api.get<Milestone>(`/milestones/${data.milestone_code}`).then(({ data }) => setMilestone(data)).catch(() => {})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
refreshTask().catch(console.error)
|
refreshTask().catch(console.error)
|
||||||
api.get<Comment[]>(`/tasks/${id}/comments`).then(({ data }) => setComments(data))
|
if (taskCode) {
|
||||||
}, [id])
|
api.get<Comment[]>(`/tasks/${taskCode}/comments`).then(({ data }) => setComments(data))
|
||||||
|
}
|
||||||
|
}, [taskCode])
|
||||||
|
|
||||||
const addComment = async () => {
|
const addComment = async () => {
|
||||||
if (!newComment.trim() || !task) return
|
if (!newComment.trim() || !task) return
|
||||||
await api.post('/comments', { content: newComment, task_id: task.id, author_id: 1 })
|
await api.post('/comments', { content: newComment, task_id: task.id, author_id: 1 })
|
||||||
setNewComment('')
|
setNewComment('')
|
||||||
const { data } = await api.get<Comment[]>(`/tasks/${id}/comments`)
|
const { data } = await api.get<Comment[]>(`/tasks/${taskCode}/comments`)
|
||||||
setComments(data)
|
setComments(data)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -54,10 +57,10 @@ export default function TaskDetailPage() {
|
|||||||
setActionLoading(actionName)
|
setActionLoading(actionName)
|
||||||
setActionError(null)
|
setActionError(null)
|
||||||
try {
|
try {
|
||||||
await api.post(`/tasks/${id}/transition?new_status=${newStatus}`, body || {})
|
await api.post(`/tasks/${taskCode}/transition?new_status=${newStatus}`, body || {})
|
||||||
await refreshTask()
|
await refreshTask()
|
||||||
// refresh comments too (finish adds one via backend)
|
// refresh comments too (finish adds one via backend)
|
||||||
const { data } = await api.get<Comment[]>(`/tasks/${id}/comments`)
|
const { data } = await api.get<Comment[]>(`/tasks/${taskCode}/comments`)
|
||||||
setComments(data)
|
setComments(data)
|
||||||
} catch (err: any) {
|
} catch (err: any) {
|
||||||
setActionError(err?.response?.data?.detail || err?.message || 'Action failed')
|
setActionError(err?.response?.data?.detail || err?.message || 'Action failed')
|
||||||
|
|||||||
@@ -64,8 +64,8 @@ export default function TasksPage() {
|
|||||||
</thead>
|
</thead>
|
||||||
<tbody>
|
<tbody>
|
||||||
{tasks.map((t) => (
|
{tasks.map((t) => (
|
||||||
<tr key={t.id} onClick={() => navigate(`/tasks/${t.task_code || t.id}`)} className="clickable">
|
<tr key={t.id} onClick={() => t.task_code && navigate(`/tasks/${t.task_code}`)} className={t.task_code ? 'clickable' : ''}>
|
||||||
<td>{t.task_code || t.id}</td>
|
<td>{t.task_code || '—'}</td>
|
||||||
<td className="task-title">{t.title}</td>
|
<td className="task-title">{t.title}</td>
|
||||||
<td><span className="badge" style={{ backgroundColor: statusColors[t.status] || '#ccc' }}>{t.status}</span></td>
|
<td><span className="badge" style={{ backgroundColor: statusColors[t.status] || '#ccc' }}>{t.status}</span></td>
|
||||||
<td><span className={`badge priority-${t.priority}`}>{t.priority}</span></td>
|
<td><span className={`badge priority-${t.priority}`}>{t.priority}</span></td>
|
||||||
|
|||||||
317
src/test/calendar.test.tsx
Normal file
317
src/test/calendar.test.tsx
Normal file
@@ -0,0 +1,317 @@
|
|||||||
|
import { describe, it, expect, vi, beforeEach, afterEach } from 'vitest'
|
||||||
|
import { render, screen, waitFor, fireEvent, cleanup } from '@testing-library/react'
|
||||||
|
import userEvent from '@testing-library/user-event'
|
||||||
|
import CalendarPage from '@/pages/CalendarPage'
|
||||||
|
|
||||||
|
const mockGet = vi.fn()
|
||||||
|
const mockPost = vi.fn()
|
||||||
|
|
||||||
|
vi.mock('@/services/api', () => ({
|
||||||
|
default: {
|
||||||
|
get: (...args: any[]) => mockGet(...args),
|
||||||
|
post: (...args: any[]) => mockPost(...args),
|
||||||
|
},
|
||||||
|
}))
|
||||||
|
|
||||||
|
type Slot = {
|
||||||
|
slot_id: string
|
||||||
|
date: string
|
||||||
|
slot_type: 'work' | 'on_call' | 'entertainment' | 'system'
|
||||||
|
estimated_duration: number
|
||||||
|
scheduled_at: string
|
||||||
|
started_at: string | null
|
||||||
|
attended: boolean
|
||||||
|
actual_duration: number | null
|
||||||
|
event_type: 'job' | 'entertainment' | 'system_event' | null
|
||||||
|
event_data: Record<string, any> | null
|
||||||
|
priority: number
|
||||||
|
status: 'not_started' | 'ongoing' | 'deferred' | 'skipped' | 'paused' | 'finished' | 'aborted'
|
||||||
|
plan_id: number | null
|
||||||
|
is_virtual: boolean
|
||||||
|
created_at: string | null
|
||||||
|
updated_at: string | null
|
||||||
|
}
|
||||||
|
|
||||||
|
type Plan = {
|
||||||
|
id: number
|
||||||
|
slot_type: 'work' | 'on_call' | 'entertainment' | 'system'
|
||||||
|
estimated_duration: number
|
||||||
|
event_type: string | null
|
||||||
|
event_data: Record<string, any> | null
|
||||||
|
at_time: string
|
||||||
|
on_day: string | null
|
||||||
|
on_week: number | null
|
||||||
|
on_month: string | null
|
||||||
|
is_active: boolean
|
||||||
|
created_at: string
|
||||||
|
updated_at: string | null
|
||||||
|
}
|
||||||
|
|
||||||
|
const slots: Slot[] = [
|
||||||
|
{
|
||||||
|
slot_id: '1',
|
||||||
|
date: '2026-04-01',
|
||||||
|
slot_type: 'work',
|
||||||
|
estimated_duration: 25,
|
||||||
|
scheduled_at: '09:00',
|
||||||
|
started_at: null,
|
||||||
|
attended: false,
|
||||||
|
actual_duration: null,
|
||||||
|
event_type: 'job',
|
||||||
|
event_data: { type: 'Task', code: 'TASK-1' },
|
||||||
|
priority: 50,
|
||||||
|
status: 'not_started',
|
||||||
|
plan_id: null,
|
||||||
|
is_virtual: false,
|
||||||
|
created_at: '2026-04-01T00:00:00Z',
|
||||||
|
updated_at: '2026-04-01T00:00:00Z',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
slot_id: 'plan-5-2026-04-01',
|
||||||
|
date: '2026-04-01',
|
||||||
|
slot_type: 'on_call',
|
||||||
|
estimated_duration: 30,
|
||||||
|
scheduled_at: '14:00',
|
||||||
|
started_at: null,
|
||||||
|
attended: false,
|
||||||
|
actual_duration: null,
|
||||||
|
event_type: null,
|
||||||
|
event_data: null,
|
||||||
|
priority: 70,
|
||||||
|
status: 'deferred',
|
||||||
|
plan_id: 5,
|
||||||
|
is_virtual: true,
|
||||||
|
created_at: null,
|
||||||
|
updated_at: null,
|
||||||
|
},
|
||||||
|
]
|
||||||
|
|
||||||
|
const plans: Plan[] = [
|
||||||
|
{
|
||||||
|
id: 5,
|
||||||
|
slot_type: 'on_call',
|
||||||
|
estimated_duration: 30,
|
||||||
|
event_type: null,
|
||||||
|
event_data: null,
|
||||||
|
at_time: '14:00',
|
||||||
|
on_day: 'Mon',
|
||||||
|
on_week: null,
|
||||||
|
on_month: null,
|
||||||
|
is_active: true,
|
||||||
|
created_at: '2026-03-01T00:00:00Z',
|
||||||
|
updated_at: null,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
id: 6,
|
||||||
|
slot_type: 'work',
|
||||||
|
estimated_duration: 50,
|
||||||
|
event_type: 'system_event',
|
||||||
|
event_data: { event: 'ScheduleToday' },
|
||||||
|
at_time: '08:00',
|
||||||
|
on_day: 'Tue',
|
||||||
|
on_week: 1,
|
||||||
|
on_month: null,
|
||||||
|
is_active: false,
|
||||||
|
created_at: '2026-03-01T00:00:00Z',
|
||||||
|
updated_at: null,
|
||||||
|
},
|
||||||
|
]
|
||||||
|
|
||||||
|
function setupApi(options?: {
|
||||||
|
slots?: Slot[]
|
||||||
|
plans?: Plan[]
|
||||||
|
dayError?: string
|
||||||
|
postImpl?: (url: string, payload?: any) => any
|
||||||
|
}) {
|
||||||
|
const currentSlots = options?.slots ?? slots
|
||||||
|
const currentPlans = options?.plans ?? plans
|
||||||
|
|
||||||
|
mockGet.mockImplementation((url: string) => {
|
||||||
|
if (url.startsWith('/calendar/day')) {
|
||||||
|
if (options?.dayError) {
|
||||||
|
return Promise.reject({ response: { data: { detail: options.dayError } } })
|
||||||
|
}
|
||||||
|
return Promise.resolve({ data: currentSlots })
|
||||||
|
}
|
||||||
|
if (url === '/calendar/plans') {
|
||||||
|
return Promise.resolve({ data: currentPlans })
|
||||||
|
}
|
||||||
|
return Promise.reject(new Error(`Unhandled GET ${url}`))
|
||||||
|
})
|
||||||
|
|
||||||
|
mockPost.mockImplementation((url: string, payload?: any) => {
|
||||||
|
if (options?.postImpl) return options.postImpl(url, payload)
|
||||||
|
return Promise.resolve({ data: {} })
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
describe('CalendarPage', () => {
|
||||||
|
beforeEach(() => {
|
||||||
|
vi.clearAllMocks()
|
||||||
|
setupApi()
|
||||||
|
vi.spyOn(window, 'confirm').mockReturnValue(true)
|
||||||
|
})
|
||||||
|
|
||||||
|
afterEach(() => {
|
||||||
|
cleanup()
|
||||||
|
vi.restoreAllMocks()
|
||||||
|
})
|
||||||
|
|
||||||
|
it('renders daily slots, deferred notice, and virtual-plan badge', async () => {
|
||||||
|
render(<CalendarPage />)
|
||||||
|
|
||||||
|
expect(await screen.findByText('09:00')).toBeInTheDocument()
|
||||||
|
expect(screen.getByText('14:00')).toBeInTheDocument()
|
||||||
|
expect(screen.getAllByText(/deferred/i).length).toBeGreaterThan(0)
|
||||||
|
expect(screen.getByText(/agent unavailability/i)).toBeInTheDocument()
|
||||||
|
expect(screen.getByText(/TASK-1/i)).toBeInTheDocument()
|
||||||
|
expect(screen.getByText(/^plan$/i)).toBeInTheDocument()
|
||||||
|
expect(screen.getByText(/Priority: 50/i)).toBeInTheDocument()
|
||||||
|
})
|
||||||
|
|
||||||
|
it('renders plans tab content', async () => {
|
||||||
|
render(<CalendarPage />)
|
||||||
|
|
||||||
|
await screen.findByText('09:00')
|
||||||
|
await userEvent.click(screen.getByRole('button', { name: /Plans \(2\)/i }))
|
||||||
|
|
||||||
|
expect(await screen.findByText(/Plan #5/i)).toBeInTheDocument()
|
||||||
|
expect(screen.getByText(/Plan #6/i)).toBeInTheDocument()
|
||||||
|
expect(screen.getByText(/at 14:00 · on Mon/i)).toBeInTheDocument()
|
||||||
|
expect(screen.getByText(/inactive/i)).toBeInTheDocument()
|
||||||
|
})
|
||||||
|
|
||||||
|
it('opens create modal and toggles event-specific fields', async () => {
|
||||||
|
render(<CalendarPage />)
|
||||||
|
|
||||||
|
await screen.findByText('09:00')
|
||||||
|
await userEvent.click(screen.getByRole('button', { name: /\+ New Slot/i }))
|
||||||
|
|
||||||
|
expect(screen.getByRole('heading', { name: /New Slot/i })).toBeInTheDocument()
|
||||||
|
|
||||||
|
const selects = screen.getAllByRole('combobox')
|
||||||
|
const eventTypeSelect = selects[1]
|
||||||
|
|
||||||
|
fireEvent.change(eventTypeSelect, { target: { value: 'job' } })
|
||||||
|
expect(screen.getByLabelText(/Job Code/i)).toBeInTheDocument()
|
||||||
|
|
||||||
|
fireEvent.change(eventTypeSelect, { target: { value: 'system_event' } })
|
||||||
|
expect(screen.getByLabelText(/System Event/i)).toBeInTheDocument()
|
||||||
|
})
|
||||||
|
|
||||||
|
it('submits new slot and displays workload warnings', async () => {
|
||||||
|
setupApi({
|
||||||
|
postImpl: (url: string) => {
|
||||||
|
if (url === '/calendar/schedule') {
|
||||||
|
return Promise.resolve({
|
||||||
|
data: {
|
||||||
|
slot: slots[0],
|
||||||
|
warnings: [
|
||||||
|
{
|
||||||
|
period: 'daily',
|
||||||
|
slot_type: 'work',
|
||||||
|
current: 25,
|
||||||
|
minimum: 120,
|
||||||
|
message: 'Daily work minimum not met',
|
||||||
|
},
|
||||||
|
],
|
||||||
|
},
|
||||||
|
})
|
||||||
|
}
|
||||||
|
return Promise.resolve({ data: {} })
|
||||||
|
},
|
||||||
|
})
|
||||||
|
|
||||||
|
render(<CalendarPage />)
|
||||||
|
|
||||||
|
await screen.findByText('09:00')
|
||||||
|
await userEvent.click(screen.getByRole('button', { name: /\+ New Slot/i }))
|
||||||
|
await userEvent.click(screen.getByRole('button', { name: /^Save$/i }))
|
||||||
|
|
||||||
|
await waitFor(() => {
|
||||||
|
expect(mockPost).toHaveBeenCalledWith(
|
||||||
|
'/calendar/schedule',
|
||||||
|
expect.objectContaining({
|
||||||
|
slot_type: 'work',
|
||||||
|
scheduled_at: '09:00',
|
||||||
|
estimated_duration: 25,
|
||||||
|
priority: 50,
|
||||||
|
date: '2026-04-01',
|
||||||
|
}),
|
||||||
|
)
|
||||||
|
})
|
||||||
|
|
||||||
|
expect(await screen.findByText(/Workload Warnings/i)).toBeInTheDocument()
|
||||||
|
expect(screen.getByText(/Daily work minimum not met/i)).toBeInTheDocument()
|
||||||
|
})
|
||||||
|
|
||||||
|
it('shows overlap error when save fails with overlap detail', async () => {
|
||||||
|
setupApi({
|
||||||
|
postImpl: (url: string) => {
|
||||||
|
if (url === '/calendar/schedule') {
|
||||||
|
return Promise.reject({
|
||||||
|
response: { data: { detail: 'Slot overlap with existing slot at 09:00' } },
|
||||||
|
})
|
||||||
|
}
|
||||||
|
return Promise.resolve({ data: {} })
|
||||||
|
},
|
||||||
|
})
|
||||||
|
|
||||||
|
render(<CalendarPage />)
|
||||||
|
|
||||||
|
await screen.findByText('09:00')
|
||||||
|
await userEvent.click(screen.getByRole('button', { name: /\+ New Slot/i }))
|
||||||
|
await userEvent.click(screen.getByRole('button', { name: /^Save$/i }))
|
||||||
|
|
||||||
|
expect(await screen.findByText(/Overlap conflict/i)).toBeInTheDocument()
|
||||||
|
})
|
||||||
|
|
||||||
|
it('opens edit modal with existing slot values and submits edit request', async () => {
|
||||||
|
setupApi({
|
||||||
|
postImpl: (url: string) => {
|
||||||
|
if (url.startsWith('/calendar/edit')) {
|
||||||
|
return Promise.resolve({ data: { slot: slots[0], warnings: [] } })
|
||||||
|
}
|
||||||
|
return Promise.resolve({ data: {} })
|
||||||
|
},
|
||||||
|
})
|
||||||
|
|
||||||
|
render(<CalendarPage />)
|
||||||
|
|
||||||
|
await screen.findByText('09:00')
|
||||||
|
await userEvent.click(screen.getAllByRole('button', { name: /✏️ Edit/i })[0])
|
||||||
|
|
||||||
|
expect(screen.getByRole('heading', { name: /Edit Slot/i })).toBeInTheDocument()
|
||||||
|
expect((screen.getAllByRole('combobox')[0] as HTMLSelectElement).value).toBe('work')
|
||||||
|
expect((document.querySelector('input[type="time"]') as HTMLInputElement).value).toBe('09:00')
|
||||||
|
|
||||||
|
await userEvent.click(screen.getByRole('button', { name: /^Save$/i }))
|
||||||
|
|
||||||
|
await waitFor(() => {
|
||||||
|
expect(mockPost).toHaveBeenCalledWith(
|
||||||
|
expect.stringContaining('/calendar/edit?date=2026-04-01&slot_id=1'),
|
||||||
|
expect.objectContaining({ slot_type: 'work' }),
|
||||||
|
)
|
||||||
|
})
|
||||||
|
})
|
||||||
|
|
||||||
|
it('cancels a slot after confirmation', async () => {
|
||||||
|
render(<CalendarPage />)
|
||||||
|
|
||||||
|
await screen.findByText('09:00')
|
||||||
|
await userEvent.click(screen.getAllByRole('button', { name: /❌ Cancel/i })[0])
|
||||||
|
|
||||||
|
await waitFor(() => {
|
||||||
|
expect(window.confirm).toHaveBeenCalled()
|
||||||
|
expect(mockPost).toHaveBeenCalledWith('/calendar/cancel?date=2026-04-01&slot_id=1')
|
||||||
|
})
|
||||||
|
})
|
||||||
|
|
||||||
|
it('shows fetch error banner when day loading fails', async () => {
|
||||||
|
setupApi({ dayError: 'Failed to load calendar' })
|
||||||
|
|
||||||
|
render(<CalendarPage />)
|
||||||
|
|
||||||
|
expect(await screen.findByText(/Failed to load calendar/i)).toBeInTheDocument()
|
||||||
|
})
|
||||||
|
})
|
||||||
525
src/test/proposal-essential.test.tsx
Normal file
525
src/test/proposal-essential.test.tsx
Normal file
@@ -0,0 +1,525 @@
|
|||||||
|
import { describe, it, expect, vi, beforeEach, afterEach } from 'vitest'
|
||||||
|
import { render, screen, waitFor, fireEvent, cleanup } from '@testing-library/react'
|
||||||
|
import userEvent from '@testing-library/user-event'
|
||||||
|
import ProposalDetailPage from '@/pages/ProposalDetailPage'
|
||||||
|
import { MemoryRouter, Routes, Route } from 'react-router-dom'
|
||||||
|
|
||||||
|
const mockGet = vi.fn()
|
||||||
|
const mockPost = vi.fn()
|
||||||
|
const mockPatch = vi.fn()
|
||||||
|
const mockDelete = vi.fn()
|
||||||
|
|
||||||
|
vi.mock('@/services/api', () => ({
|
||||||
|
default: {
|
||||||
|
get: (...args: any[]) => mockGet(...args),
|
||||||
|
post: (...args: any[]) => mockPost(...args),
|
||||||
|
patch: (...args: any[]) => mockPatch(...args),
|
||||||
|
delete: (...args: any[]) => mockDelete(...args),
|
||||||
|
},
|
||||||
|
}))
|
||||||
|
|
||||||
|
const mockNavigate = vi.fn()
|
||||||
|
vi.mock('react-router-dom', async () => {
|
||||||
|
const actual = await vi.importActual('react-router-dom')
|
||||||
|
return {
|
||||||
|
...actual,
|
||||||
|
useNavigate: () => mockNavigate,
|
||||||
|
useParams: () => ({ id: '1' }),
|
||||||
|
useSearchParams: () => [new URLSearchParams('?project_id=1'), vi.fn()],
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
|
type Essential = {
|
||||||
|
id: number
|
||||||
|
essential_code: string
|
||||||
|
proposal_id: number
|
||||||
|
type: 'feature' | 'improvement' | 'refactor'
|
||||||
|
title: string
|
||||||
|
description: string | null
|
||||||
|
created_by_id: number | null
|
||||||
|
created_at: string
|
||||||
|
updated_at: string | null
|
||||||
|
}
|
||||||
|
|
||||||
|
type Proposal = {
|
||||||
|
id: number
|
||||||
|
proposal_code: string | null
|
||||||
|
title: string
|
||||||
|
description: string | null
|
||||||
|
status: 'open' | 'accepted' | 'rejected'
|
||||||
|
project_id: number
|
||||||
|
created_by_id: number | null
|
||||||
|
created_by_username: string | null
|
||||||
|
feat_task_id: string | null
|
||||||
|
essentials: Essential[] | null
|
||||||
|
generated_tasks: any[] | null
|
||||||
|
created_at: string
|
||||||
|
updated_at: string | null
|
||||||
|
}
|
||||||
|
|
||||||
|
type Milestone = {
|
||||||
|
id: number
|
||||||
|
title: string
|
||||||
|
status: 'open' | 'freeze' | 'undergoing' | 'completed' | 'closed'
|
||||||
|
}
|
||||||
|
|
||||||
|
const mockProposal: Proposal = {
|
||||||
|
id: 1,
|
||||||
|
proposal_code: 'PROP-001',
|
||||||
|
title: 'Test Proposal',
|
||||||
|
description: 'Test description',
|
||||||
|
status: 'open',
|
||||||
|
project_id: 1,
|
||||||
|
created_by_id: 1,
|
||||||
|
created_by_username: 'admin',
|
||||||
|
feat_task_id: null,
|
||||||
|
essentials: [],
|
||||||
|
generated_tasks: null,
|
||||||
|
created_at: '2026-03-01T00:00:00Z',
|
||||||
|
updated_at: null,
|
||||||
|
}
|
||||||
|
|
||||||
|
const mockEssentials: Essential[] = [
|
||||||
|
{
|
||||||
|
id: 1,
|
||||||
|
essential_code: 'ESS-001',
|
||||||
|
proposal_id: 1,
|
||||||
|
type: 'feature',
|
||||||
|
title: 'Feature Essential',
|
||||||
|
description: 'A feature essential',
|
||||||
|
created_by_id: 1,
|
||||||
|
created_at: '2026-03-01T00:00:00Z',
|
||||||
|
updated_at: null,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
id: 2,
|
||||||
|
essential_code: 'ESS-002',
|
||||||
|
proposal_id: 1,
|
||||||
|
type: 'improvement',
|
||||||
|
title: 'Improvement Essential',
|
||||||
|
description: null,
|
||||||
|
created_by_id: 1,
|
||||||
|
created_at: '2026-03-01T00:00:00Z',
|
||||||
|
updated_at: null,
|
||||||
|
},
|
||||||
|
]
|
||||||
|
|
||||||
|
const mockMilestones: Milestone[] = [
|
||||||
|
{ id: 1, title: 'Milestone 1', status: 'open' },
|
||||||
|
{ id: 2, title: 'Milestone 2', status: 'open' },
|
||||||
|
]
|
||||||
|
|
||||||
|
function setupApi(options?: {
|
||||||
|
proposal?: Proposal
|
||||||
|
essentials?: Essential[]
|
||||||
|
milestones?: Milestone[]
|
||||||
|
error?: string
|
||||||
|
}) {
|
||||||
|
const proposal = options?.proposal ?? mockProposal
|
||||||
|
const essentials = options?.essentials ?? mockEssentials
|
||||||
|
const milestones = options?.milestones ?? mockMilestones
|
||||||
|
|
||||||
|
mockGet.mockImplementation((url: string) => {
|
||||||
|
if (url.includes('/proposals/1') && !url.includes('/essentials')) {
|
||||||
|
if (options?.error) {
|
||||||
|
return Promise.reject({ response: { data: { detail: options.error } } })
|
||||||
|
}
|
||||||
|
return Promise.resolve({ data: proposal })
|
||||||
|
}
|
||||||
|
if (url.includes('/essentials')) {
|
||||||
|
return Promise.resolve({ data: essentials })
|
||||||
|
}
|
||||||
|
if (url.includes('/milestones')) {
|
||||||
|
return Promise.resolve({ data: milestones })
|
||||||
|
}
|
||||||
|
return Promise.reject(new Error(`Unhandled GET ${url}`))
|
||||||
|
})
|
||||||
|
|
||||||
|
mockPost.mockResolvedValue({ data: {} })
|
||||||
|
mockPatch.mockResolvedValue({ data: {} })
|
||||||
|
mockDelete.mockResolvedValue({ data: {} })
|
||||||
|
}
|
||||||
|
|
||||||
|
describe('ProposalDetailPage', () => {
|
||||||
|
beforeEach(() => {
|
||||||
|
vi.clearAllMocks()
|
||||||
|
setupApi()
|
||||||
|
vi.spyOn(window, 'confirm').mockReturnValue(true)
|
||||||
|
})
|
||||||
|
|
||||||
|
afterEach(() => {
|
||||||
|
cleanup()
|
||||||
|
vi.restoreAllMocks()
|
||||||
|
})
|
||||||
|
|
||||||
|
describe('Essential List Display', () => {
|
||||||
|
it('renders essentials section with count', async () => {
|
||||||
|
render(<ProposalDetailPage />)
|
||||||
|
|
||||||
|
await waitFor(() => {
|
||||||
|
expect(screen.getByText('Essentials (2)')).toBeInTheDocument()
|
||||||
|
})
|
||||||
|
})
|
||||||
|
|
||||||
|
it('displays essential cards with type badges', async () => {
|
||||||
|
render(<ProposalDetailPage />)
|
||||||
|
|
||||||
|
await waitFor(() => {
|
||||||
|
expect(screen.getByText('Feature Essential')).toBeInTheDocument()
|
||||||
|
})
|
||||||
|
|
||||||
|
expect(screen.getByText('Improvement Essential')).toBeInTheDocument()
|
||||||
|
expect(screen.getByText('feature')).toBeInTheDocument()
|
||||||
|
expect(screen.getByText('improvement')).toBeInTheDocument()
|
||||||
|
})
|
||||||
|
|
||||||
|
it('displays essential codes', async () => {
|
||||||
|
render(<ProposalDetailPage />)
|
||||||
|
|
||||||
|
await waitFor(() => {
|
||||||
|
expect(screen.getByText('ESS-001')).toBeInTheDocument()
|
||||||
|
})
|
||||||
|
|
||||||
|
expect(screen.getByText('ESS-002')).toBeInTheDocument()
|
||||||
|
})
|
||||||
|
|
||||||
|
it('displays essential descriptions when available', async () => {
|
||||||
|
render(<ProposalDetailPage />)
|
||||||
|
|
||||||
|
await waitFor(() => {
|
||||||
|
expect(screen.getByText('A feature essential')).toBeInTheDocument()
|
||||||
|
})
|
||||||
|
})
|
||||||
|
|
||||||
|
it('shows empty state when no essentials', async () => {
|
||||||
|
setupApi({ essentials: [] })
|
||||||
|
render(<ProposalDetailPage />)
|
||||||
|
|
||||||
|
await waitFor(() => {
|
||||||
|
expect(screen.getByText('Essentials (0)')).toBeInTheDocument()
|
||||||
|
})
|
||||||
|
|
||||||
|
expect(screen.getByText(/No essentials yet/)).toBeInTheDocument()
|
||||||
|
expect(screen.getByText(/Add one to define deliverables/)).toBeInTheDocument()
|
||||||
|
})
|
||||||
|
|
||||||
|
it('shows loading state for essentials', async () => {
|
||||||
|
mockGet.mockImplementation((url: string) => {
|
||||||
|
if (url.includes('/proposals/1') && !url.includes('/essentials')) {
|
||||||
|
return Promise.resolve({ data: mockProposal })
|
||||||
|
}
|
||||||
|
if (url.includes('/essentials')) {
|
||||||
|
return new Promise(() => {}) // Never resolve
|
||||||
|
}
|
||||||
|
return Promise.reject(new Error(`Unhandled GET ${url}`))
|
||||||
|
})
|
||||||
|
|
||||||
|
render(<ProposalDetailPage />)
|
||||||
|
|
||||||
|
await waitFor(() => {
|
||||||
|
expect(screen.getByText(/Loading/i)).toBeInTheDocument()
|
||||||
|
})
|
||||||
|
})
|
||||||
|
})
|
||||||
|
|
||||||
|
describe('Essential Create/Edit Forms', () => {
|
||||||
|
it('opens create essential modal', async () => {
|
||||||
|
render(<ProposalDetailPage />)
|
||||||
|
|
||||||
|
await waitFor(() => {
|
||||||
|
expect(screen.getByText('+ New Essential')).toBeInTheDocument()
|
||||||
|
})
|
||||||
|
|
||||||
|
await userEvent.click(screen.getByText('+ New Essential'))
|
||||||
|
|
||||||
|
expect(screen.getByRole('heading', { name: 'New Essential' })).toBeInTheDocument()
|
||||||
|
expect(screen.getByPlaceholderText('Essential title')).toBeInTheDocument()
|
||||||
|
expect(screen.getByText('Feature')).toBeInTheDocument()
|
||||||
|
expect(screen.getByText('Improvement')).toBeInTheDocument()
|
||||||
|
expect(screen.getByText('Refactor')).toBeInTheDocument()
|
||||||
|
})
|
||||||
|
|
||||||
|
it('creates new essential', async () => {
|
||||||
|
render(<ProposalDetailPage />)
|
||||||
|
|
||||||
|
await waitFor(() => {
|
||||||
|
expect(screen.getByText('+ New Essential')).toBeInTheDocument()
|
||||||
|
})
|
||||||
|
|
||||||
|
await userEvent.click(screen.getByText('+ New Essential'))
|
||||||
|
|
||||||
|
await userEvent.type(screen.getByPlaceholderText('Essential title'), 'New Test Essential')
|
||||||
|
fireEvent.change(screen.getAllByRole('combobox')[0], { target: { value: 'refactor' } })
|
||||||
|
await userEvent.type(screen.getByPlaceholderText('Description (optional)'), 'Test description')
|
||||||
|
|
||||||
|
await userEvent.click(screen.getByRole('button', { name: 'Save' }))
|
||||||
|
|
||||||
|
await waitFor(() => {
|
||||||
|
expect(mockPost).toHaveBeenCalledWith(
|
||||||
|
'/projects/1/proposals/1/essentials',
|
||||||
|
expect.objectContaining({
|
||||||
|
title: 'New Test Essential',
|
||||||
|
type: 'refactor',
|
||||||
|
description: 'Test description',
|
||||||
|
})
|
||||||
|
)
|
||||||
|
})
|
||||||
|
})
|
||||||
|
|
||||||
|
it('opens edit essential modal with pre-filled data', async () => {
|
||||||
|
render(<ProposalDetailPage />)
|
||||||
|
|
||||||
|
await waitFor(() => {
|
||||||
|
expect(screen.getByText('Feature Essential')).toBeInTheDocument()
|
||||||
|
})
|
||||||
|
|
||||||
|
const editButtons = screen.getAllByRole('button', { name: 'Edit' })
|
||||||
|
await userEvent.click(editButtons[0])
|
||||||
|
|
||||||
|
expect(screen.getByRole('heading', { name: 'Edit Essential' })).toBeInTheDocument()
|
||||||
|
|
||||||
|
const titleInput = screen.getByDisplayValue('Feature Essential')
|
||||||
|
expect(titleInput).toBeInTheDocument()
|
||||||
|
|
||||||
|
const descriptionInput = screen.getByDisplayValue('A feature essential')
|
||||||
|
expect(descriptionInput).toBeInTheDocument()
|
||||||
|
})
|
||||||
|
|
||||||
|
it('updates essential', async () => {
|
||||||
|
render(<ProposalDetailPage />)
|
||||||
|
|
||||||
|
await waitFor(() => {
|
||||||
|
expect(screen.getByText('Feature Essential')).toBeInTheDocument()
|
||||||
|
})
|
||||||
|
|
||||||
|
const editButtons = screen.getAllByRole('button', { name: 'Edit' })
|
||||||
|
await userEvent.click(editButtons[0])
|
||||||
|
|
||||||
|
const titleInput = screen.getByDisplayValue('Feature Essential')
|
||||||
|
await userEvent.clear(titleInput)
|
||||||
|
await userEvent.type(titleInput, 'Updated Essential Title')
|
||||||
|
|
||||||
|
await userEvent.click(screen.getByRole('button', { name: 'Save' }))
|
||||||
|
|
||||||
|
await waitFor(() => {
|
||||||
|
expect(mockPatch).toHaveBeenCalledWith(
|
||||||
|
'/projects/1/proposals/1/essentials/1',
|
||||||
|
expect.objectContaining({
|
||||||
|
title: 'Updated Essential Title',
|
||||||
|
type: 'feature',
|
||||||
|
description: 'A feature essential',
|
||||||
|
})
|
||||||
|
)
|
||||||
|
})
|
||||||
|
})
|
||||||
|
|
||||||
|
it('deletes essential after confirmation', async () => {
|
||||||
|
render(<ProposalDetailPage />)
|
||||||
|
|
||||||
|
await waitFor(() => {
|
||||||
|
expect(screen.getByText('Feature Essential')).toBeInTheDocument()
|
||||||
|
})
|
||||||
|
|
||||||
|
const deleteButtons = screen.getAllByRole('button', { name: 'Delete' })
|
||||||
|
await userEvent.click(deleteButtons[0])
|
||||||
|
|
||||||
|
await waitFor(() => {
|
||||||
|
expect(window.confirm).toHaveBeenCalledWith('Are you sure you want to delete this Essential?')
|
||||||
|
})
|
||||||
|
|
||||||
|
await waitFor(() => {
|
||||||
|
expect(mockDelete).toHaveBeenCalledWith('/projects/1/proposals/1/essentials/1')
|
||||||
|
})
|
||||||
|
})
|
||||||
|
|
||||||
|
it('disables save button when title is empty', async () => {
|
||||||
|
render(<ProposalDetailPage />)
|
||||||
|
|
||||||
|
await waitFor(() => {
|
||||||
|
expect(screen.getByText('+ New Essential')).toBeInTheDocument()
|
||||||
|
})
|
||||||
|
|
||||||
|
await userEvent.click(screen.getByText('+ New Essential'))
|
||||||
|
|
||||||
|
const saveButton = screen.getByRole('button', { name: 'Save' })
|
||||||
|
expect(saveButton).toBeDisabled()
|
||||||
|
|
||||||
|
await userEvent.type(screen.getByPlaceholderText('Essential title'), 'Some Title')
|
||||||
|
expect(saveButton).toBeEnabled()
|
||||||
|
|
||||||
|
await userEvent.clear(screen.getByPlaceholderText('Essential title'))
|
||||||
|
expect(saveButton).toBeDisabled()
|
||||||
|
})
|
||||||
|
})
|
||||||
|
|
||||||
|
describe('Accept with Milestone Selection', () => {
|
||||||
|
it('opens accept modal with milestone selector', async () => {
|
||||||
|
render(<ProposalDetailPage />)
|
||||||
|
|
||||||
|
const acceptButton = await screen.findByRole('button', { name: /accept/i })
|
||||||
|
await userEvent.click(acceptButton)
|
||||||
|
|
||||||
|
expect(screen.getByRole('heading', { name: 'Accept Proposal' })).toBeInTheDocument()
|
||||||
|
expect(screen.getByText(/milestone to generate story tasks/i)).toBeInTheDocument()
|
||||||
|
expect(screen.getByRole('combobox')).toBeInTheDocument()
|
||||||
|
})
|
||||||
|
|
||||||
|
it('disables confirm button without milestone selection', async () => {
|
||||||
|
render(<ProposalDetailPage />)
|
||||||
|
|
||||||
|
const acceptButton = await screen.findByRole('button', { name: /accept/i })
|
||||||
|
await userEvent.click(acceptButton)
|
||||||
|
|
||||||
|
const confirmButton = screen.getByRole('button', { name: 'Confirm Accept' })
|
||||||
|
expect(confirmButton).toBeDisabled()
|
||||||
|
})
|
||||||
|
|
||||||
|
it('enables confirm button after milestone selection', async () => {
|
||||||
|
render(<ProposalDetailPage />)
|
||||||
|
|
||||||
|
const acceptButton = await screen.findByRole('button', { name: /accept/i })
|
||||||
|
await userEvent.click(acceptButton)
|
||||||
|
|
||||||
|
const select = screen.getByRole('combobox')
|
||||||
|
fireEvent.change(select, { target: { value: '1' } })
|
||||||
|
|
||||||
|
const confirmButton = screen.getByRole('button', { name: 'Confirm Accept' })
|
||||||
|
expect(confirmButton).toBeEnabled()
|
||||||
|
})
|
||||||
|
|
||||||
|
it('calls accept API with selected milestone', async () => {
|
||||||
|
render(<ProposalDetailPage />)
|
||||||
|
|
||||||
|
const acceptButton = await screen.findByRole('button', { name: /accept/i })
|
||||||
|
await userEvent.click(acceptButton)
|
||||||
|
|
||||||
|
const select = screen.getByRole('combobox')
|
||||||
|
fireEvent.change(select, { target: { value: '1' } })
|
||||||
|
|
||||||
|
await userEvent.click(screen.getByRole('button', { name: 'Confirm Accept' }))
|
||||||
|
|
||||||
|
await waitFor(() => {
|
||||||
|
expect(mockPost).toHaveBeenCalledWith(
|
||||||
|
'/projects/1/proposals/1/accept',
|
||||||
|
{ milestone_id: 1 }
|
||||||
|
)
|
||||||
|
})
|
||||||
|
})
|
||||||
|
|
||||||
|
it('shows warning when no open milestones available', async () => {
|
||||||
|
setupApi({ milestones: [] })
|
||||||
|
render(<ProposalDetailPage />)
|
||||||
|
|
||||||
|
const acceptButton = await screen.findByRole('button', { name: /accept/i })
|
||||||
|
await userEvent.click(acceptButton)
|
||||||
|
|
||||||
|
expect(screen.getByText('No open milestones available.')).toBeInTheDocument()
|
||||||
|
})
|
||||||
|
|
||||||
|
it('displays generated tasks after accept', async () => {
|
||||||
|
const acceptedProposal: Proposal = {
|
||||||
|
...mockProposal,
|
||||||
|
status: 'accepted',
|
||||||
|
generated_tasks: [
|
||||||
|
{ task_id: 1, task_code: 'TASK-001', title: 'Story Task 1', task_type: 'story', task_subtype: 'feature' },
|
||||||
|
{ task_id: 2, task_code: 'TASK-002', title: 'Story Task 2', task_type: 'story', task_subtype: 'improvement' },
|
||||||
|
],
|
||||||
|
}
|
||||||
|
setupApi({ proposal: acceptedProposal })
|
||||||
|
|
||||||
|
render(<ProposalDetailPage />)
|
||||||
|
|
||||||
|
await waitFor(() => {
|
||||||
|
expect(screen.getByText('Generated Tasks')).toBeInTheDocument()
|
||||||
|
})
|
||||||
|
|
||||||
|
expect(screen.getByText('Story Task 1')).toBeInTheDocument()
|
||||||
|
expect(screen.getByText('Story Task 2')).toBeInTheDocument()
|
||||||
|
expect(screen.getByText('story/feature')).toBeInTheDocument()
|
||||||
|
expect(screen.getByText('story/improvement')).toBeInTheDocument()
|
||||||
|
})
|
||||||
|
})
|
||||||
|
|
||||||
|
describe('Story Creation Restriction UI', () => {
|
||||||
|
it('hides essential controls for accepted proposal', async () => {
|
||||||
|
const acceptedProposal: Proposal = {
|
||||||
|
...mockProposal,
|
||||||
|
status: 'accepted',
|
||||||
|
essentials: mockEssentials,
|
||||||
|
}
|
||||||
|
setupApi({ proposal: acceptedProposal })
|
||||||
|
|
||||||
|
render(<ProposalDetailPage />)
|
||||||
|
|
||||||
|
await screen.findByText('Feature Essential')
|
||||||
|
expect(screen.queryByText('+ New Essential')).not.toBeInTheDocument()
|
||||||
|
})
|
||||||
|
|
||||||
|
it('hides edit/delete buttons for essentials when proposal is accepted', async () => {
|
||||||
|
const acceptedProposal: Proposal = {
|
||||||
|
...mockProposal,
|
||||||
|
status: 'accepted',
|
||||||
|
essentials: mockEssentials,
|
||||||
|
}
|
||||||
|
setupApi({ proposal: acceptedProposal })
|
||||||
|
|
||||||
|
render(<ProposalDetailPage />)
|
||||||
|
|
||||||
|
await waitFor(() => {
|
||||||
|
expect(screen.getByText('Feature Essential')).toBeInTheDocument()
|
||||||
|
})
|
||||||
|
|
||||||
|
const deleteButtons = screen.queryAllByRole('button', { name: 'Delete' })
|
||||||
|
expect(deleteButtons.length).toBe(0)
|
||||||
|
})
|
||||||
|
|
||||||
|
it('hides edit/delete buttons for rejected proposal', async () => {
|
||||||
|
const rejectedProposal: Proposal = {
|
||||||
|
...mockProposal,
|
||||||
|
status: 'rejected',
|
||||||
|
essentials: mockEssentials,
|
||||||
|
}
|
||||||
|
setupApi({ proposal: rejectedProposal })
|
||||||
|
|
||||||
|
render(<ProposalDetailPage />)
|
||||||
|
|
||||||
|
await screen.findByRole('button', { name: /reopen/i })
|
||||||
|
expect(screen.queryByText('+ New Essential')).not.toBeInTheDocument()
|
||||||
|
})
|
||||||
|
})
|
||||||
|
|
||||||
|
describe('Error Handling', () => {
|
||||||
|
it('displays error message on essential create failure', async () => {
|
||||||
|
mockPost.mockRejectedValue({ response: { data: { detail: 'Failed to create essential' } } })
|
||||||
|
|
||||||
|
render(<ProposalDetailPage />)
|
||||||
|
|
||||||
|
await waitFor(() => {
|
||||||
|
expect(screen.getByText('+ New Essential')).toBeInTheDocument()
|
||||||
|
})
|
||||||
|
|
||||||
|
await userEvent.click(screen.getByText('+ New Essential'))
|
||||||
|
await userEvent.type(screen.getByPlaceholderText('Essential title'), 'Test')
|
||||||
|
await userEvent.click(screen.getByRole('button', { name: 'Save' }))
|
||||||
|
|
||||||
|
await waitFor(() => {
|
||||||
|
expect(screen.getByText('Failed to create essential')).toBeInTheDocument()
|
||||||
|
})
|
||||||
|
})
|
||||||
|
|
||||||
|
it('displays error message on accept failure', async () => {
|
||||||
|
mockPost.mockRejectedValue({ response: { data: { detail: 'Accept failed: milestone required' } } })
|
||||||
|
|
||||||
|
render(<ProposalDetailPage />)
|
||||||
|
|
||||||
|
const acceptButton = await screen.findByRole('button', { name: /accept/i })
|
||||||
|
await userEvent.click(acceptButton)
|
||||||
|
fireEvent.change(screen.getByRole('combobox'), { target: { value: '1' } })
|
||||||
|
await userEvent.click(screen.getByRole('button', { name: 'Confirm Accept' }))
|
||||||
|
|
||||||
|
await waitFor(() => {
|
||||||
|
expect(screen.getByText('Accept failed: milestone required')).toBeInTheDocument()
|
||||||
|
})
|
||||||
|
})
|
||||||
|
})
|
||||||
|
})
|
||||||
58
src/test/setup.ts
Normal file
58
src/test/setup.ts
Normal file
@@ -0,0 +1,58 @@
|
|||||||
|
import '@testing-library/jest-dom'
|
||||||
|
import { vi } from 'vitest'
|
||||||
|
|
||||||
|
// Mock localStorage
|
||||||
|
const localStorageMock = {
|
||||||
|
getItem: vi.fn((key: string) => {
|
||||||
|
if (key === 'token') return 'mock-token'
|
||||||
|
if (key === 'HF_BACKEND_BASE_URL') return 'http://localhost:8000'
|
||||||
|
return null
|
||||||
|
}),
|
||||||
|
setItem: vi.fn(),
|
||||||
|
removeItem: vi.fn(),
|
||||||
|
clear: vi.fn(),
|
||||||
|
}
|
||||||
|
vi.stubGlobal('localStorage', localStorageMock)
|
||||||
|
|
||||||
|
// Mock window.location
|
||||||
|
Object.defineProperty(window, 'location', {
|
||||||
|
configurable: true,
|
||||||
|
value: Object.defineProperties({}, {
|
||||||
|
pathname: { value: '/calendar', writable: true },
|
||||||
|
href: { value: 'http://localhost/calendar', writable: true },
|
||||||
|
assign: { value: vi.fn(), writable: true },
|
||||||
|
replace: { value: vi.fn(), writable: true },
|
||||||
|
}) as any,
|
||||||
|
})
|
||||||
|
|
||||||
|
// Mock matchMedia
|
||||||
|
Object.defineProperty(window, 'matchMedia', {
|
||||||
|
writable: true,
|
||||||
|
value: vi.fn().mockImplementation((query: string) => ({
|
||||||
|
matches: false,
|
||||||
|
media: query,
|
||||||
|
onchange: null,
|
||||||
|
addListener: vi.fn(),
|
||||||
|
removeListener: vi.fn(),
|
||||||
|
addEventListener: vi.fn(),
|
||||||
|
removeEventListener: vi.fn(),
|
||||||
|
dispatchEvent: vi.fn(),
|
||||||
|
})),
|
||||||
|
})
|
||||||
|
|
||||||
|
// Mock ResizeObserver
|
||||||
|
class ResizeObserverMock {
|
||||||
|
observe() {}
|
||||||
|
unobserve() {}
|
||||||
|
disconnect() {}
|
||||||
|
}
|
||||||
|
vi.stubGlobal('ResizeObserver', ResizeObserverMock)
|
||||||
|
|
||||||
|
// Mock IntersectionObserver
|
||||||
|
class IntersectionObserverMock {
|
||||||
|
constructor() {}
|
||||||
|
observe() {}
|
||||||
|
unobserve() {}
|
||||||
|
disconnect() {}
|
||||||
|
}
|
||||||
|
vi.stubGlobal('IntersectionObserver', IntersectionObserverMock)
|
||||||
@@ -36,6 +36,8 @@ export interface ProjectMember {
|
|||||||
export interface Task {
|
export interface Task {
|
||||||
id: number
|
id: number
|
||||||
task_code: string | null
|
task_code: string | null
|
||||||
|
project_code?: string | null
|
||||||
|
milestone_code?: string | null
|
||||||
title: string
|
title: string
|
||||||
description: string | null
|
description: string | null
|
||||||
task_type: 'issue' | 'maintenance' | 'research' | 'review' | 'story' | 'test' | 'resolution' // P7.1: 'task' removed
|
task_type: 'issue' | 'maintenance' | 'research' | 'review' | 'story' | 'test' | 'resolution' // P7.1: 'task' removed
|
||||||
@@ -69,6 +71,7 @@ export interface Comment {
|
|||||||
export interface Milestone {
|
export interface Milestone {
|
||||||
id: number
|
id: number
|
||||||
milestone_code: string | null
|
milestone_code: string | null
|
||||||
|
project_code?: string | null
|
||||||
title: string
|
title: string
|
||||||
description: string | null
|
description: string | null
|
||||||
status: 'open' | 'freeze' | 'undergoing' | 'completed' | 'closed'
|
status: 'open' | 'freeze' | 'undergoing' | 'completed' | 'closed'
|
||||||
@@ -106,6 +109,7 @@ export interface Notification {
|
|||||||
message: string
|
message: string
|
||||||
is_read: boolean
|
is_read: boolean
|
||||||
task_id: number | null
|
task_id: number | null
|
||||||
|
task_code?: string | null
|
||||||
created_at: string
|
created_at: string
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -127,16 +131,44 @@ export interface DashboardStats {
|
|||||||
recent_tasks: Task[]
|
recent_tasks: Task[]
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface Propose {
|
export interface Proposal {
|
||||||
id: number
|
id: number
|
||||||
propose_code: string | null
|
proposal_code: string | null
|
||||||
title: string
|
title: string
|
||||||
description: string | null
|
description: string | null
|
||||||
status: 'open' | 'accepted' | 'rejected'
|
status: 'open' | 'accepted' | 'rejected'
|
||||||
project_id: number
|
project_id: number
|
||||||
|
project_code?: string | null
|
||||||
created_by_id: number | null
|
created_by_id: number | null
|
||||||
created_by_username: string | null
|
created_by_username: string | null
|
||||||
feat_task_id: string | null
|
feat_task_id: string | null
|
||||||
|
essentials: Essential[] | null
|
||||||
|
generated_tasks: GeneratedTask[] | null
|
||||||
|
created_at: string
|
||||||
|
updated_at: string | null
|
||||||
|
}
|
||||||
|
|
||||||
|
/** @deprecated Use Proposal instead */
|
||||||
|
export type Propose = Proposal
|
||||||
|
|
||||||
|
export interface GeneratedTask {
|
||||||
|
task_id: number
|
||||||
|
task_code: string | null
|
||||||
|
title: string
|
||||||
|
task_type: string
|
||||||
|
task_subtype: string | null
|
||||||
|
}
|
||||||
|
|
||||||
|
export type EssentialType = 'feature' | 'improvement' | 'refactor'
|
||||||
|
|
||||||
|
export interface Essential {
|
||||||
|
id: number
|
||||||
|
essential_code: string
|
||||||
|
proposal_id: number
|
||||||
|
type: EssentialType
|
||||||
|
title: string
|
||||||
|
description: string | null
|
||||||
|
created_by_id: number | null
|
||||||
created_at: string
|
created_at: string
|
||||||
updated_at: string | null
|
updated_at: string | null
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -19,4 +19,11 @@ export default defineConfig({
|
|||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
test: {
|
||||||
|
globals: true,
|
||||||
|
environment: 'jsdom',
|
||||||
|
setupFiles: './src/test/setup.ts',
|
||||||
|
css: true,
|
||||||
|
include: ['src/test/**/*.test.{ts,tsx}'],
|
||||||
|
},
|
||||||
})
|
})
|
||||||
|
|||||||
Reference in New Issue
Block a user