feat(m4): project & member management with tests and e2e
- ProjectRepository, ProjectMemberRepository, minimal NotificationRepository - ProjectService: create/update/archive/delete project, add/remove member, permission checks (isMember/admin), member-added notification, getDashboard skeleton, getMyProjects, getMemberRole - projectValidator, API services factory - API routes: projects CRUD, members list/add/remove - Screens: dashboard (project list + create form), project overview, members, settings; layout (Header/Sidebar/ProjectNav) and project components - Unit tests (Project/ProjectMember repositories, ProjectService), integration project-member-permission, e2e project-management
This commit is contained in:
84
components/project/AddMemberForm.tsx
Normal file
84
components/project/AddMemberForm.tsx
Normal file
@ -0,0 +1,84 @@
|
||||
'use client';
|
||||
|
||||
import { useState, type FormEvent } from 'react';
|
||||
import { useRouter } from 'next/navigation';
|
||||
|
||||
export function AddMemberForm({ projectId }: { projectId: number }) {
|
||||
const router = useRouter();
|
||||
const [email, setEmail] = useState('');
|
||||
const [role, setRole] = useState('member');
|
||||
const [error, setError] = useState<string | null>(null);
|
||||
const [loading, setLoading] = useState(false);
|
||||
|
||||
async function onSubmit(event: FormEvent<HTMLFormElement>) {
|
||||
event.preventDefault();
|
||||
setLoading(true);
|
||||
setError(null);
|
||||
|
||||
const res = await fetch(`/api/projects/${projectId}/members`, {
|
||||
method: 'POST',
|
||||
headers: { 'Content-Type': 'application/json' },
|
||||
body: JSON.stringify({ email, role }),
|
||||
});
|
||||
|
||||
if (res.ok) {
|
||||
setEmail('');
|
||||
router.refresh();
|
||||
return;
|
||||
}
|
||||
|
||||
const body = (await res.json().catch(() => null)) as {
|
||||
error?: { message?: string };
|
||||
} | null;
|
||||
setError(body?.error?.message ?? 'メンバー追加に失敗しました');
|
||||
setLoading(false);
|
||||
}
|
||||
|
||||
return (
|
||||
<form
|
||||
onSubmit={onSubmit}
|
||||
className="flex flex-col gap-2 rounded border bg-white p-4 sm:flex-row sm:items-end"
|
||||
>
|
||||
<div className="flex-1">
|
||||
<label htmlFor="member-email" className="block text-sm font-medium">
|
||||
追加するユーザーのメールアドレス
|
||||
</label>
|
||||
<input
|
||||
id="member-email"
|
||||
type="email"
|
||||
value={email}
|
||||
onChange={(e) => setEmail(e.target.value)}
|
||||
className="mt-1 w-full rounded border px-3 py-2"
|
||||
required
|
||||
/>
|
||||
</div>
|
||||
<div>
|
||||
<label htmlFor="member-role" className="block text-sm font-medium">
|
||||
ロール
|
||||
</label>
|
||||
<select
|
||||
id="member-role"
|
||||
value={role}
|
||||
onChange={(e) => setRole(e.target.value)}
|
||||
className="mt-1 rounded border px-3 py-2"
|
||||
>
|
||||
<option value="member">member</option>
|
||||
<option value="admin">admin</option>
|
||||
<option value="guest">guest</option>
|
||||
</select>
|
||||
</div>
|
||||
<button
|
||||
type="submit"
|
||||
disabled={loading}
|
||||
className="rounded bg-blue-600 px-4 py-2 font-medium text-white hover:bg-blue-700 disabled:opacity-50"
|
||||
>
|
||||
{loading ? '追加中...' : 'メンバー追加'}
|
||||
</button>
|
||||
{error && (
|
||||
<p className="text-sm text-red-600" role="alert">
|
||||
{error}
|
||||
</p>
|
||||
)}
|
||||
</form>
|
||||
);
|
||||
}
|
||||
85
components/project/CreateProjectForm.tsx
Normal file
85
components/project/CreateProjectForm.tsx
Normal file
@ -0,0 +1,85 @@
|
||||
'use client';
|
||||
|
||||
import { useState, type FormEvent } from 'react';
|
||||
import { useRouter } from 'next/navigation';
|
||||
|
||||
export function CreateProjectForm() {
|
||||
const router = useRouter();
|
||||
const [name, setName] = useState('');
|
||||
const [description, setDescription] = useState('');
|
||||
const [error, setError] = useState<string | null>(null);
|
||||
const [loading, setLoading] = useState(false);
|
||||
|
||||
async function onSubmit(event: FormEvent<HTMLFormElement>) {
|
||||
event.preventDefault();
|
||||
setLoading(true);
|
||||
setError(null);
|
||||
|
||||
const res = await fetch('/api/projects', {
|
||||
method: 'POST',
|
||||
headers: { 'Content-Type': 'application/json' },
|
||||
body: JSON.stringify({ name, description: description || undefined }),
|
||||
});
|
||||
|
||||
if (res.ok) {
|
||||
const data = (await res.json()) as { project: { id: number } };
|
||||
router.push(`/projects/${data.project.id}`);
|
||||
return;
|
||||
}
|
||||
|
||||
const body = (await res.json().catch(() => null)) as {
|
||||
error?: { message?: string };
|
||||
} | null;
|
||||
setError(body?.error?.message ?? 'プロジェクトの作成に失敗しました');
|
||||
setLoading(false);
|
||||
}
|
||||
|
||||
return (
|
||||
<form
|
||||
onSubmit={onSubmit}
|
||||
className="flex flex-col gap-2 rounded-lg border bg-white p-4 shadow-sm sm:flex-row sm:items-end"
|
||||
>
|
||||
<div className="flex-1">
|
||||
<label htmlFor="project-name" className="block text-sm font-medium">
|
||||
プロジェクト名
|
||||
</label>
|
||||
<input
|
||||
id="project-name"
|
||||
type="text"
|
||||
value={name}
|
||||
onChange={(e) => setName(e.target.value)}
|
||||
className="mt-1 w-full rounded border px-3 py-2"
|
||||
required
|
||||
maxLength={200}
|
||||
/>
|
||||
</div>
|
||||
<div className="flex-1">
|
||||
<label
|
||||
htmlFor="project-description"
|
||||
className="block text-sm font-medium"
|
||||
>
|
||||
説明(任意)
|
||||
</label>
|
||||
<input
|
||||
id="project-description"
|
||||
type="text"
|
||||
value={description}
|
||||
onChange={(e) => setDescription(e.target.value)}
|
||||
className="mt-1 w-full rounded border px-3 py-2"
|
||||
/>
|
||||
</div>
|
||||
<button
|
||||
type="submit"
|
||||
disabled={loading}
|
||||
className="rounded bg-blue-600 px-4 py-2 font-medium text-white hover:bg-blue-700 disabled:opacity-50"
|
||||
>
|
||||
{loading ? '作成中...' : '新規プロジェクト'}
|
||||
</button>
|
||||
{error && (
|
||||
<p className="text-sm text-red-600 sm:full" role="alert">
|
||||
{error}
|
||||
</p>
|
||||
)}
|
||||
</form>
|
||||
);
|
||||
}
|
||||
24
components/project/DashboardWidget.tsx
Normal file
24
components/project/DashboardWidget.tsx
Normal file
@ -0,0 +1,24 @@
|
||||
/**
|
||||
* ダッシュボードの各項目を表示するウィジェットコンテナ。
|
||||
* M4では骨組みのみ。全項目の集計は M13 で完成させる。
|
||||
*/
|
||||
export function DashboardWidget({
|
||||
title,
|
||||
children,
|
||||
empty,
|
||||
}: {
|
||||
title: string;
|
||||
children?: React.ReactNode;
|
||||
empty?: string;
|
||||
}) {
|
||||
return (
|
||||
<section className="rounded-lg border bg-white p-4 shadow-sm">
|
||||
<h2 className="mb-3 text-sm font-semibold text-gray-700">{title}</h2>
|
||||
{children ? (
|
||||
<div className="space-y-2">{children}</div>
|
||||
) : (
|
||||
<p className="text-sm text-gray-400">{empty ?? 'データがありません'}</p>
|
||||
)}
|
||||
</section>
|
||||
);
|
||||
}
|
||||
51
components/project/DeleteProjectButton.tsx
Normal file
51
components/project/DeleteProjectButton.tsx
Normal file
@ -0,0 +1,51 @@
|
||||
'use client';
|
||||
|
||||
import { useState } from 'react';
|
||||
import { useRouter } from 'next/navigation';
|
||||
|
||||
export function DeleteProjectButton({ projectId }: { projectId: number }) {
|
||||
const router = useRouter();
|
||||
const [busy, setBusy] = useState(false);
|
||||
const [error, setError] = useState<string | null>(null);
|
||||
|
||||
async function onDelete() {
|
||||
if (
|
||||
!window.confirm('プロジェクトを削除しますか?この操作は取り消せません。')
|
||||
) {
|
||||
return;
|
||||
}
|
||||
setBusy(true);
|
||||
setError(null);
|
||||
const res = await fetch(`/api/projects/${projectId}`, {
|
||||
method: 'DELETE',
|
||||
});
|
||||
setBusy(false);
|
||||
if (res.ok) {
|
||||
router.push('/dashboard');
|
||||
router.refresh();
|
||||
} else {
|
||||
const body = (await res.json().catch(() => null)) as {
|
||||
error?: { message?: string };
|
||||
} | null;
|
||||
setError(body?.error?.message ?? '削除に失敗しました');
|
||||
}
|
||||
}
|
||||
|
||||
return (
|
||||
<div className="mt-3">
|
||||
<button
|
||||
type="button"
|
||||
onClick={onDelete}
|
||||
disabled={busy}
|
||||
className="rounded bg-red-600 px-4 py-2 text-sm font-medium text-white hover:bg-red-700 disabled:opacity-50"
|
||||
>
|
||||
{busy ? '削除中...' : 'プロジェクトを削除'}
|
||||
</button>
|
||||
{error && (
|
||||
<p className="mt-2 text-sm text-red-600" role="alert">
|
||||
{error}
|
||||
</p>
|
||||
)}
|
||||
</div>
|
||||
);
|
||||
}
|
||||
40
components/project/ProjectCard.tsx
Normal file
40
components/project/ProjectCard.tsx
Normal file
@ -0,0 +1,40 @@
|
||||
import type { Project } from '@/lib/types';
|
||||
|
||||
const STATUS_LABELS: Record<string, string> = {
|
||||
active: 'Active',
|
||||
on_hold: 'On Hold',
|
||||
completed: 'Completed',
|
||||
archived: 'Archived',
|
||||
};
|
||||
|
||||
const STATUS_COLORS: Record<string, string> = {
|
||||
active: 'bg-green-100 text-green-800',
|
||||
on_hold: 'bg-yellow-100 text-yellow-800',
|
||||
completed: 'bg-blue-100 text-blue-800',
|
||||
archived: 'bg-gray-200 text-gray-700',
|
||||
};
|
||||
|
||||
export function ProjectCard({ project }: { project: Project }) {
|
||||
return (
|
||||
<a
|
||||
href={`/projects/${project.id}`}
|
||||
className="block rounded-lg border bg-white p-4 shadow-sm transition hover:shadow-md"
|
||||
>
|
||||
<div className="flex items-center justify-between">
|
||||
<h3 className="font-semibold text-gray-800">{project.name}</h3>
|
||||
<span
|
||||
className={`rounded px-2 py-0.5 text-xs ${
|
||||
STATUS_COLORS[project.status] ?? 'bg-gray-100 text-gray-700'
|
||||
}`}
|
||||
>
|
||||
{STATUS_LABELS[project.status] ?? project.status}
|
||||
</span>
|
||||
</div>
|
||||
{project.description && (
|
||||
<p className="mt-2 line-clamp-2 text-sm text-gray-600">
|
||||
{project.description}
|
||||
</p>
|
||||
)}
|
||||
</a>
|
||||
);
|
||||
}
|
||||
120
components/project/ProjectSettingsForm.tsx
Normal file
120
components/project/ProjectSettingsForm.tsx
Normal file
@ -0,0 +1,120 @@
|
||||
'use client';
|
||||
|
||||
import { useState, type FormEvent } from 'react';
|
||||
import { useRouter } from 'next/navigation';
|
||||
import type { Project } from '@/lib/types';
|
||||
|
||||
export function ProjectSettingsForm({
|
||||
project,
|
||||
canManage,
|
||||
}: {
|
||||
project: Project;
|
||||
canManage: boolean;
|
||||
}) {
|
||||
const router = useRouter();
|
||||
const [name, setName] = useState(project.name);
|
||||
const [description, setDescription] = useState(project.description ?? '');
|
||||
const [status, setStatus] = useState(project.status);
|
||||
const [error, setError] = useState<string | null>(null);
|
||||
const [saved, setSaved] = useState(false);
|
||||
const [loading, setLoading] = useState(false);
|
||||
|
||||
async function onSubmit(event: FormEvent<HTMLFormElement>) {
|
||||
event.preventDefault();
|
||||
setLoading(true);
|
||||
setError(null);
|
||||
setSaved(false);
|
||||
|
||||
const res = await fetch(`/api/projects/${project.id}`, {
|
||||
method: 'PATCH',
|
||||
headers: { 'Content-Type': 'application/json' },
|
||||
body: JSON.stringify({
|
||||
name,
|
||||
description: description || undefined,
|
||||
status,
|
||||
}),
|
||||
});
|
||||
|
||||
setLoading(false);
|
||||
if (res.ok) {
|
||||
setSaved(true);
|
||||
router.refresh();
|
||||
} else {
|
||||
const body = (await res.json().catch(() => null)) as {
|
||||
error?: { message?: string };
|
||||
} | null;
|
||||
setError(body?.error?.message ?? '更新に失敗しました');
|
||||
}
|
||||
}
|
||||
|
||||
if (!canManage) {
|
||||
return (
|
||||
<p className="text-sm text-gray-500">
|
||||
プロジェクトの設定変更には管理者権限が必要です。
|
||||
</p>
|
||||
);
|
||||
}
|
||||
|
||||
return (
|
||||
<form onSubmit={onSubmit} className="space-y-4">
|
||||
<div>
|
||||
<label htmlFor="name" className="block text-sm font-medium">
|
||||
プロジェクト名
|
||||
</label>
|
||||
<input
|
||||
id="name"
|
||||
type="text"
|
||||
value={name}
|
||||
onChange={(e) => setName(e.target.value)}
|
||||
className="mt-1 w-full rounded border px-3 py-2"
|
||||
/>
|
||||
</div>
|
||||
<div>
|
||||
<label htmlFor="description" className="block text-sm font-medium">
|
||||
説明
|
||||
</label>
|
||||
<textarea
|
||||
id="description"
|
||||
value={description}
|
||||
onChange={(e) => setDescription(e.target.value)}
|
||||
className="mt-1 w-full rounded border px-3 py-2"
|
||||
/>
|
||||
</div>
|
||||
<div>
|
||||
<label htmlFor="status" className="block text-sm font-medium">
|
||||
ステータス
|
||||
</label>
|
||||
<select
|
||||
id="status"
|
||||
value={status}
|
||||
onChange={(e) =>
|
||||
setStatus(
|
||||
e.target.value as 'active' | 'on_hold' | 'completed' | 'archived'
|
||||
)
|
||||
}
|
||||
className="mt-1 rounded border px-3 py-2"
|
||||
>
|
||||
<option value="active">active</option>
|
||||
<option value="on_hold">on_hold</option>
|
||||
<option value="completed">completed</option>
|
||||
<option value="archived">archived</option>
|
||||
</select>
|
||||
</div>
|
||||
{error && (
|
||||
<p className="text-sm text-red-600" role="alert">
|
||||
{error}
|
||||
</p>
|
||||
)}
|
||||
{saved && (
|
||||
<p className="text-sm text-green-600">プロジェクトを更新しました</p>
|
||||
)}
|
||||
<button
|
||||
type="submit"
|
||||
disabled={loading}
|
||||
className="rounded bg-blue-600 px-4 py-2 font-medium text-white hover:bg-blue-700 disabled:opacity-50"
|
||||
>
|
||||
{loading ? '保存中...' : '保存'}
|
||||
</button>
|
||||
</form>
|
||||
);
|
||||
}
|
||||
41
components/project/RemoveMemberButton.tsx
Normal file
41
components/project/RemoveMemberButton.tsx
Normal file
@ -0,0 +1,41 @@
|
||||
'use client';
|
||||
|
||||
import { useState } from 'react';
|
||||
import { useRouter } from 'next/navigation';
|
||||
|
||||
export function RemoveMemberButton({
|
||||
projectId,
|
||||
userId,
|
||||
label,
|
||||
disabled = false,
|
||||
}: {
|
||||
projectId: number;
|
||||
userId: number;
|
||||
label: string;
|
||||
disabled?: boolean;
|
||||
}) {
|
||||
const router = useRouter();
|
||||
const [busy, setBusy] = useState(false);
|
||||
|
||||
async function onRemove() {
|
||||
setBusy(true);
|
||||
const res = await fetch(`/api/projects/${projectId}/members/${userId}`, {
|
||||
method: 'DELETE',
|
||||
});
|
||||
setBusy(false);
|
||||
if (res.ok) {
|
||||
router.refresh();
|
||||
}
|
||||
}
|
||||
|
||||
return (
|
||||
<button
|
||||
type="button"
|
||||
onClick={onRemove}
|
||||
disabled={disabled || busy}
|
||||
className="text-xs text-red-600 hover:underline disabled:opacity-50"
|
||||
>
|
||||
{busy ? '削除中...' : label}
|
||||
</button>
|
||||
);
|
||||
}
|
||||
Reference in New Issue
Block a user