update: projectsmanage
All checks were successful
Build and Release / release (push) Successful in 29s
All checks were successful
Build and Release / release (push) Successful in 29s
This commit is contained in:
@@ -19,6 +19,7 @@ import {
|
|||||||
import Swal from "sweetalert2";
|
import Swal from "sweetalert2";
|
||||||
import { useRouter } from "next/navigation";
|
import { useRouter } from "next/navigation";
|
||||||
import { LIMIT_ITEM_TABLE } from "../../../../../../constant";
|
import { LIMIT_ITEM_TABLE } from "../../../../../../constant";
|
||||||
|
import { ProjectsResponse } from "@/interface/project";
|
||||||
|
|
||||||
const formatDateTimeToISO = (
|
const formatDateTimeToISO = (
|
||||||
dateStr: string,
|
dateStr: string,
|
||||||
@@ -30,19 +31,10 @@ const formatDateTimeToISO = (
|
|||||||
return `${dateStr}T${time}:00.000000+07:00`;
|
return `${dateStr}T${time}:00.000000+07:00`;
|
||||||
};
|
};
|
||||||
|
|
||||||
export interface ProjectsResponse {
|
export default function ProjectsPage(_props: {
|
||||||
status: boolean;
|
params: unknown;
|
||||||
message: string;
|
searchParams: unknown;
|
||||||
data: ProjectItem[];
|
}) {
|
||||||
pagination: {
|
|
||||||
current_page: number;
|
|
||||||
page_size: number;
|
|
||||||
total_records: number;
|
|
||||||
total_pages: number;
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
export default function ProjectsPage() {
|
|
||||||
const router = useRouter();
|
const router = useRouter();
|
||||||
const [page, setPage] = useState<number>(1);
|
const [page, setPage] = useState<number>(1);
|
||||||
const [limitInput, setLimitInput] = useState<string>(
|
const [limitInput, setLimitInput] = useState<string>(
|
||||||
@@ -69,7 +61,7 @@ export default function ProjectsPage() {
|
|||||||
toTime: "",
|
toTime: "",
|
||||||
});
|
});
|
||||||
|
|
||||||
const [tableData, setTableData] = useState<ProjectsResponse | null>(null);
|
const [tableData, setTableData] = useState<ProjectsResponse<ProjectItem> | null>(null);
|
||||||
const [loading, setLoading] = useState<boolean>(true);
|
const [loading, setLoading] = useState<boolean>(true);
|
||||||
|
|
||||||
const [sortBy, setSortBy] = useState<ProjectSortColumn>("created_at");
|
const [sortBy, setSortBy] = useState<ProjectSortColumn>("created_at");
|
||||||
@@ -134,7 +126,7 @@ export default function ProjectsPage() {
|
|||||||
const response = await getProjects(payload);
|
const response = await getProjects(payload);
|
||||||
|
|
||||||
if (response?.status) {
|
if (response?.status) {
|
||||||
setTableData(response as unknown as ProjectsResponse);
|
setTableData(response as unknown as ProjectsResponse<ProjectItem>);
|
||||||
}
|
}
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
toast.error("Lỗi lấy danh sách dự án");
|
toast.error("Lỗi lấy danh sách dự án");
|
||||||
@@ -159,48 +151,9 @@ export default function ProjectsPage() {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
const handleUpdate = async (project: ProjectItem) => {
|
|
||||||
/* Tương tự handleCreate, sử dụng Swal.fire để tạo form cập nhật */
|
|
||||||
toast.info(`Chức năng cập nhật cho dự án "${project.title}"`);
|
|
||||||
};
|
|
||||||
|
|
||||||
const handleDelete = async (id: string) => {
|
|
||||||
const result = await Swal.fire({
|
|
||||||
title: "Xác nhận xóa?",
|
|
||||||
text: "Bạn có chắc chắn muốn xóa dự án này? Hành động này không thể hoàn tác!",
|
|
||||||
icon: "warning",
|
|
||||||
showCancelButton: true,
|
|
||||||
confirmButtonColor: "#ef4444",
|
|
||||||
cancelButtonColor: "#6b7280",
|
|
||||||
confirmButtonText: "Xóa",
|
|
||||||
cancelButtonText: "Hủy",
|
|
||||||
});
|
|
||||||
|
|
||||||
if (result.isConfirmed) {
|
|
||||||
try {
|
|
||||||
// const response = await deleteProject(id);
|
|
||||||
// if (response?.status) {
|
|
||||||
toast.success("Đã xóa dự án thành công.");
|
|
||||||
fetchProjectsData();
|
|
||||||
// } else {
|
|
||||||
// toast.error(response?.message || "Xóa dự án thất bại");
|
|
||||||
// }
|
|
||||||
} catch (error) {
|
|
||||||
toast.error("Đã xảy ra lỗi khi xóa");
|
|
||||||
console.error(error);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
const handleTransferOwner = async (project: ProjectItem) => {
|
|
||||||
/* Sử dụng Swal.fire với input để nhập New Owner ID */
|
|
||||||
toast.info(`Chức năng chuyển quyền sở hữu cho dự án "${project.title}"`);
|
|
||||||
};
|
|
||||||
|
|
||||||
const handleViewDetails = (id: string) => {
|
const handleViewDetails = (id: string) => {
|
||||||
// Điều hướng đến trang chi tiết dự án (quản lý members, commits)
|
router.push(`/projects/${id}`);
|
||||||
// router.push(`/projects/${id}`);
|
|
||||||
toast.info(`Xem chi tiết dự án ID: ${id}`);
|
|
||||||
};
|
};
|
||||||
|
|
||||||
const pagination = tableData?.pagination;
|
const pagination = tableData?.pagination;
|
||||||
@@ -256,9 +209,7 @@ export default function ProjectsPage() {
|
|||||||
onSort={handleSort}
|
onSort={handleSort}
|
||||||
sortBy={sortBy}
|
sortBy={sortBy}
|
||||||
sortOrder={sortOrder}
|
sortOrder={sortOrder}
|
||||||
onUpdate={handleUpdate}
|
|
||||||
onDelete={handleDelete}
|
|
||||||
onTransferOwner={handleTransferOwner}
|
|
||||||
onViewDetails={handleViewDetails}
|
onViewDetails={handleViewDetails}
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
588
src/app/(admin)/(others-pages)/projects/[id]/page.tsx
Normal file
588
src/app/(admin)/(others-pages)/projects/[id]/page.tsx
Normal file
@@ -0,0 +1,588 @@
|
|||||||
|
"use client";
|
||||||
|
|
||||||
|
import { useParams, useRouter } from "next/navigation";
|
||||||
|
import { useEffect, useState } from "react";
|
||||||
|
import Image from "next/image";
|
||||||
|
import { toast } from "sonner";
|
||||||
|
import {
|
||||||
|
getProjectDetailByID,
|
||||||
|
updateProject,
|
||||||
|
transferProjectOwnership,
|
||||||
|
addProjectMember,
|
||||||
|
updateProjectMemberRole,
|
||||||
|
removeProjectMember,
|
||||||
|
deleteProject,
|
||||||
|
} from "@/service/projectService";
|
||||||
|
import { Project } from "@/interface/project";
|
||||||
|
import Swal from "sweetalert2";
|
||||||
|
|
||||||
|
type TabType = "overview" | "members" | "settings";
|
||||||
|
|
||||||
|
export default function ProjectDetailsPage() {
|
||||||
|
const params = useParams();
|
||||||
|
const router = useRouter();
|
||||||
|
const id = params.id as string;
|
||||||
|
|
||||||
|
const [project, setProject] = useState<Project | null>(null);
|
||||||
|
const [loading, setLoading] = useState(true);
|
||||||
|
const [activeTab, setActiveTab] = useState<TabType>("overview");
|
||||||
|
|
||||||
|
const [editForm, setEditForm] = useState({
|
||||||
|
title: "",
|
||||||
|
description: "",
|
||||||
|
status: "PRIVATE" as any,
|
||||||
|
});
|
||||||
|
const [newOwnerId, setNewOwnerId] = useState("");
|
||||||
|
const [newMember, setNewMember] = useState({
|
||||||
|
user_id: "",
|
||||||
|
role: "EDITOR" as any,
|
||||||
|
});
|
||||||
|
|
||||||
|
const fetchProject = async () => {
|
||||||
|
setLoading(true);
|
||||||
|
try {
|
||||||
|
const res = await getProjectDetailByID(id);
|
||||||
|
if (res?.status && res.data) {
|
||||||
|
setProject(res.data);
|
||||||
|
setEditForm({
|
||||||
|
title: res.data.title,
|
||||||
|
description: res.data.description,
|
||||||
|
status: res.data.project_status,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
} catch (error) {
|
||||||
|
toast.error("Lỗi khi tải dữ liệu dự án");
|
||||||
|
} finally {
|
||||||
|
setLoading(false);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
if (id) fetchProject();
|
||||||
|
}, [id]);
|
||||||
|
|
||||||
|
const handleUpdateInfo = async (e: React.FormEvent) => {
|
||||||
|
e.preventDefault();
|
||||||
|
try {
|
||||||
|
await updateProject(id, editForm);
|
||||||
|
toast.success("Cập nhật thông tin thành công!");
|
||||||
|
fetchProject();
|
||||||
|
} catch (error) {
|
||||||
|
toast.error("Cập nhật thất bại");
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
const handleTransferOwnership = async (e: React.FormEvent) => {
|
||||||
|
e.preventDefault();
|
||||||
|
|
||||||
|
const memberName =
|
||||||
|
project?.members?.find((m) => m.user_id === newOwnerId)?.display_name ||
|
||||||
|
"thành viên này";
|
||||||
|
|
||||||
|
const result = await Swal.fire({
|
||||||
|
title: "Chuyển quyền sở hữu?",
|
||||||
|
html: `Bạn có chắc chắn muốn chuyển dự án này cho <b>${memberName}</b>?<br/>Hành động này <b>không thể hoàn tác</b> và bạn sẽ không còn là chủ sở hữu nữa.`,
|
||||||
|
icon: "error",
|
||||||
|
showCancelButton: true,
|
||||||
|
confirmButtonColor: "#238636",
|
||||||
|
cancelButtonColor: "#30363d",
|
||||||
|
confirmButtonText: "Tôi hiểu, chuyển quyền sở hữu",
|
||||||
|
cancelButtonText: "Hủy bỏ",
|
||||||
|
color: "#333",
|
||||||
|
customClass: {
|
||||||
|
popup: "border border-[#30363d] rounded-xl",
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
|
if (result.isConfirmed) {
|
||||||
|
try {
|
||||||
|
const res = await transferProjectOwnership(id, {
|
||||||
|
new_owner_id: newOwnerId,
|
||||||
|
});
|
||||||
|
if (res?.status) {
|
||||||
|
toast.success("Đã chuyển quyền sở hữu thành công!");
|
||||||
|
setNewOwnerId("");
|
||||||
|
fetchProject();
|
||||||
|
} else {
|
||||||
|
toast.error(res?.message || "Chuyển quyền thất bại");
|
||||||
|
}
|
||||||
|
} catch (error) {
|
||||||
|
toast.error("Lỗi hệ thống khi chuyển quyền");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
const handleAddMember = async (e: React.FormEvent) => {
|
||||||
|
e.preventDefault();
|
||||||
|
if (!newMember.user_id) return toast.error("Vui lòng nhập User ID");
|
||||||
|
try {
|
||||||
|
await addProjectMember(id, newMember);
|
||||||
|
toast.success("Thêm thành viên thành công");
|
||||||
|
setNewMember({ user_id: "", role: "EDITOR" });
|
||||||
|
fetchProject();
|
||||||
|
} catch (error) {
|
||||||
|
toast.error("Lỗi thêm thành viên");
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
const handleUpdateRole = async (userId: string, newRole: string) => {
|
||||||
|
try {
|
||||||
|
await updateProjectMemberRole(id, userId, { role: newRole as any });
|
||||||
|
toast.success("Cập nhật quyền thành công");
|
||||||
|
fetchProject();
|
||||||
|
} catch (error) {
|
||||||
|
toast.error("Cập nhật quyền thất bại");
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
const handleRemoveMember = async (userId: string) => {
|
||||||
|
if (!confirm("Xác nhận xóa thành viên này?")) return;
|
||||||
|
try {
|
||||||
|
await removeProjectMember(id, userId);
|
||||||
|
toast.success("Đã xóa thành viên");
|
||||||
|
fetchProject();
|
||||||
|
} catch (error) {
|
||||||
|
toast.error("Xóa thành viên thất bại");
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
const handleDeleteProject = async () => {
|
||||||
|
const result = await Swal.fire({
|
||||||
|
title: "Xác nhận xóa dự án?",
|
||||||
|
text: "Hành động này sẽ xóa vĩnh viễn dự án. Bạn không thể hoàn tác sau khi xác nhận!",
|
||||||
|
icon: "warning",
|
||||||
|
showCancelButton: true,
|
||||||
|
confirmButtonColor: "#d33",
|
||||||
|
cancelButtonColor: "#30363d",
|
||||||
|
confirmButtonText: "Tôi hiểu, xóa dự án này",
|
||||||
|
cancelButtonText: "Hủy",
|
||||||
|
color: "#333",
|
||||||
|
customClass: {
|
||||||
|
popup: "border border-[#30363d] rounded-xl",
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
|
if (result.isConfirmed) {
|
||||||
|
try {
|
||||||
|
const res = await deleteProject(id);
|
||||||
|
if (res?.status) {
|
||||||
|
toast.success("Đã xóa dự án thành công");
|
||||||
|
router.push("/project");
|
||||||
|
} else {
|
||||||
|
toast.error(res?.message || "Xóa dự án thất bại");
|
||||||
|
}
|
||||||
|
} catch (error) {
|
||||||
|
toast.error("Đã xảy ra lỗi khi kết nối máy chủ");
|
||||||
|
console.error(error);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
if (loading)
|
||||||
|
return (
|
||||||
|
<div className="flex justify-center p-20 text-gray-500">
|
||||||
|
Đang tải dữ liệu...
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
if (!project)
|
||||||
|
return (
|
||||||
|
<div className="flex justify-center p-20 text-red-500">
|
||||||
|
Không tìm thấy dự án
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
|
||||||
|
return (
|
||||||
|
<div className="min-h-screen bg-white dark:bg-[#0d1117] text-gray-900 dark:text-[#c9d1d9] font-sans">
|
||||||
|
<div className="pt-8 border-b border-gray-200 dark:border-[#30363d] bg-gray-50 dark:bg-[#0d1117]">
|
||||||
|
<div className="px-6">
|
||||||
|
<div className="flex items-center gap-2 text-xl mb-6">
|
||||||
|
<div className="w-8 h-8 shrink-0 flex items-center justify-center">
|
||||||
|
{project.user?.avatar_url ? (
|
||||||
|
<div className="relative w-8 h-8 rounded-full overflow-hidden border border-gray-200 dark:border-gray-800">
|
||||||
|
<Image
|
||||||
|
src={project.user.avatar_url}
|
||||||
|
alt="avatar"
|
||||||
|
fill
|
||||||
|
className="object-cover rounded-full"
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
) : (
|
||||||
|
<div className="w-8 h-8 rounded-full bg-gray-200 dark:bg-gray-700 flex items-center justify-center border border-gray-300 dark:border-gray-600">
|
||||||
|
<span className="text-[10px] font-bold text-gray-500 dark:text-gray-300 leading-none">
|
||||||
|
{project.user?.display_name?.charAt(0)?.toUpperCase() ||
|
||||||
|
"U"}
|
||||||
|
</span>
|
||||||
|
</div>
|
||||||
|
)}
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<span className="font-medium text-blue-600 dark:text-[#58a6ff] hover:underline cursor-pointer">
|
||||||
|
{project.user?.display_name}
|
||||||
|
</span>
|
||||||
|
<span className="text-gray-400">/</span>
|
||||||
|
<strong className="font-semibold text-blue-600 dark:text-[#58a6ff] hover:underline cursor-pointer">
|
||||||
|
{project.title}
|
||||||
|
</strong>
|
||||||
|
<span className="ml-2 px-2.5 py-0.5 text-xs font-medium rounded-full border border-gray-200 dark:border-[#30363d] text-gray-500 dark:text-[#8b949e]">
|
||||||
|
{project.project_status}
|
||||||
|
</span>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div className="flex gap-4">
|
||||||
|
{[
|
||||||
|
{
|
||||||
|
id: "overview",
|
||||||
|
label: "Overview",
|
||||||
|
icon: "M13 16h-1v-4h-1m1-4h.01M21 12a9 9 0 11-18 0 9 9 0 0118 0z",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
id: "members",
|
||||||
|
label: `Members`,
|
||||||
|
count: project.members?.length || 0,
|
||||||
|
icon: "M12 4.354a4 4 0 110 5.292M15 21H3v-1a6 6 0 0112 0v1zm0 0h6v-1a6 6 0 00-9-5.197M13 7a4 4 0 11-8 0 4 4 0 018 0z",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
id: "settings",
|
||||||
|
label: "Settings",
|
||||||
|
icon: "M10.325 4.317c.426-1.756 2.924-1.756 3.35 0a1.724 1.724 0 002.573 1.066c1.543-.94 3.31.826 2.37 2.37a1.724 1.724 0 001.065 2.572c1.756.426 1.756 2.924 0 3.35a1.724 1.724 0 00-1.066 2.573c.94 1.543-.826 3.31-2.37 2.37a1.724 1.724 0 00-2.572 1.065c-.426 1.756-2.924 1.756-3.35 0a1.724 1.724 0 00-2.573-1.066c-1.543.94-3.31-.826-2.37-2.37a1.724 1.724 0 00-1.065-2.572c-1.756-.426-1.756-2.924 0-3.35a1.724 1.724 0 001.066-2.573c-.94-1.543.826-3.31 2.37-2.37.996.608 2.296.07 2.572-1.065z",
|
||||||
|
},
|
||||||
|
].map((tab) => (
|
||||||
|
<button
|
||||||
|
key={tab.id}
|
||||||
|
onClick={() => setActiveTab(tab.id as TabType)}
|
||||||
|
className={`flex items-center gap-2 px-3 py-2.5 text-sm font-medium border-b-2 transition-colors ${
|
||||||
|
activeTab === tab.id
|
||||||
|
? "border-[#f78166] text-gray-900 dark:text-[#c9d1d9]"
|
||||||
|
: "border-transparent text-gray-500 hover:text-gray-700 dark:hover:text-[#8b949e]"
|
||||||
|
}`}
|
||||||
|
>
|
||||||
|
<svg
|
||||||
|
className="w-4 h-4 opacity-70"
|
||||||
|
fill="none"
|
||||||
|
viewBox="0 0 24 24"
|
||||||
|
stroke="currentColor"
|
||||||
|
>
|
||||||
|
<path
|
||||||
|
strokeLinecap="round"
|
||||||
|
strokeLinejoin="round"
|
||||||
|
strokeWidth={2}
|
||||||
|
d={tab.icon}
|
||||||
|
/>
|
||||||
|
</svg>
|
||||||
|
{tab.label}
|
||||||
|
{tab.count !== undefined && (
|
||||||
|
<span className="ml-1 px-2 py-0.5 text-xs rounded-full bg-gray-200/50 dark:bg-[#21262d] text-gray-600 dark:text-[#c9d1d9]">
|
||||||
|
{tab.count}
|
||||||
|
</span>
|
||||||
|
)}
|
||||||
|
</button>
|
||||||
|
))}
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div className="px-6 py-8">
|
||||||
|
{activeTab === "overview" && (
|
||||||
|
<div className="grid grid-cols-1 md:grid-cols-4 gap-8">
|
||||||
|
<div className="md:col-span-3">
|
||||||
|
<div className="border border-gray-200 dark:border-[#30363d] rounded-xl overflow-hidden ">
|
||||||
|
<div className="bg-gray-50 dark:bg-[#161b22] px-5 py-3 border-b border-gray-200 dark:border-[#30363d] font-semibold text-sm text-gray-800 dark:text-[#c9d1d9]">
|
||||||
|
About
|
||||||
|
</div>
|
||||||
|
<div className="p-6 bg-white dark:bg-[#0d1117] text-[15px] leading-relaxed text-gray-700 dark:text-[#8b949e]">
|
||||||
|
{project.description || (
|
||||||
|
<i className="text-gray-400">
|
||||||
|
Không có mô tả cho dự án này.
|
||||||
|
</i>
|
||||||
|
)}
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div className="md:col-span-1 space-y-6">
|
||||||
|
<div>
|
||||||
|
<h3 className="font-semibold text-sm mb-4 border-b border-gray-200 dark:border-[#30363d] pb-2 text-gray-800 dark:text-[#c9d1d9]">
|
||||||
|
Owner
|
||||||
|
</h3>
|
||||||
|
<div className="flex items-center gap-3">
|
||||||
|
<div className="w-8 h-8 shrink-0 flex items-center justify-center">
|
||||||
|
{project.user?.avatar_url ? (
|
||||||
|
<div className="relative w-8 h-8 rounded-full overflow-hidden border border-gray-200 dark:border-gray-800">
|
||||||
|
<Image
|
||||||
|
src={project.user.avatar_url}
|
||||||
|
alt="avatar"
|
||||||
|
fill
|
||||||
|
className="object-cover rounded-full"
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
) : (
|
||||||
|
<div className="w-8 h-8 rounded-full bg-gray-200 dark:bg-gray-700 flex items-center justify-center border border-gray-300 dark:border-gray-600">
|
||||||
|
<span className="text-[10px] font-bold text-gray-500 dark:text-gray-300 leading-none">
|
||||||
|
{project.user?.display_name
|
||||||
|
?.charAt(0)
|
||||||
|
?.toUpperCase() || "U"}
|
||||||
|
</span>
|
||||||
|
</div>
|
||||||
|
)}
|
||||||
|
</div>
|
||||||
|
<div className="overflow-hidden">
|
||||||
|
<div className="font-semibold text-sm text-gray-800 dark:text-[#c9d1d9] truncate">
|
||||||
|
{project.user?.display_name}
|
||||||
|
</div>
|
||||||
|
<div className="text-xs text-gray-500 dark:text-[#8b949e] truncate">
|
||||||
|
{project.user?.email || "No email"}
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
)}
|
||||||
|
|
||||||
|
{activeTab === "members" && (
|
||||||
|
<div className="max-w-4xl">
|
||||||
|
<h2 className="text-2xl font-normal mb-6 pb-2 border-b border-gray-200 dark:border-[#30363d]">
|
||||||
|
Manage access
|
||||||
|
</h2>
|
||||||
|
|
||||||
|
<form
|
||||||
|
onSubmit={handleAddMember}
|
||||||
|
className="flex flex-col sm:flex-row gap-3 mb-8 p-5 border border-gray-200 dark:border-[#30363d] rounded-xl bg-gray-50 dark:bg-[#161b22] "
|
||||||
|
>
|
||||||
|
<input
|
||||||
|
type="text"
|
||||||
|
placeholder="User ID..."
|
||||||
|
value={newMember.user_id}
|
||||||
|
onChange={(e) =>
|
||||||
|
setNewMember({ ...newMember, user_id: e.target.value })
|
||||||
|
}
|
||||||
|
className="flex-1 px-3 py-2 text-sm rounded-md border border-gray-300 dark:border-[#30363d] bg-white dark:bg-[#0d1117] outline-none focus:ring-2 focus:ring-blue-500/30 focus:border-blue-500 transition-shadow"
|
||||||
|
/>
|
||||||
|
<div className="flex gap-3">
|
||||||
|
<select
|
||||||
|
value={newMember.role}
|
||||||
|
onChange={(e) =>
|
||||||
|
setNewMember({ ...newMember, role: e.target.value as any })
|
||||||
|
}
|
||||||
|
className="px-3 py-2 text-sm rounded-md border border-gray-300 dark:border-[#30363d] bg-white dark:bg-[#0d1117] outline-none focus:ring-2 focus:ring-blue-500/30 focus:border-blue-500 cursor-pointer"
|
||||||
|
>
|
||||||
|
<option value="EDITOR">Editor</option>
|
||||||
|
<option value="VIEWER">Viewer</option>
|
||||||
|
</select>
|
||||||
|
<button
|
||||||
|
type="submit"
|
||||||
|
className="px-5 py-2 text-sm font-medium text-white bg-[#238636] border border-transparent rounded-md hover:bg-[#2ea043] transition-colors "
|
||||||
|
>
|
||||||
|
Add member
|
||||||
|
</button>
|
||||||
|
</div>
|
||||||
|
</form>
|
||||||
|
|
||||||
|
<div className="border border-gray-200 dark:border-[#30363d] rounded-xl overflow-hidden ">
|
||||||
|
<div className="divide-y divide-gray-200 dark:divide-[#30363d]">
|
||||||
|
{project.members && project.members.length > 0 ? (
|
||||||
|
project.members.map((member) => (
|
||||||
|
<div
|
||||||
|
key={member.user_id}
|
||||||
|
className="flex items-center justify-between p-4 hover:bg-gray-50 dark:hover:bg-[#161b22]/50 transition-colors"
|
||||||
|
>
|
||||||
|
<div className="flex items-center gap-4">
|
||||||
|
<img
|
||||||
|
src={
|
||||||
|
member.avatar_url ||
|
||||||
|
"https://github.com/identicons/jasonlong.png"
|
||||||
|
}
|
||||||
|
alt={member.display_name}
|
||||||
|
className="w-10 h-10 rounded-full border border-gray-200 dark:border-gray-700"
|
||||||
|
/>
|
||||||
|
<div>
|
||||||
|
<div className="font-semibold text-sm text-gray-800 dark:text-[#c9d1d9]">
|
||||||
|
{member.display_name}
|
||||||
|
</div>
|
||||||
|
<div className="text-xs text-gray-500 dark:text-[#8b949e]">
|
||||||
|
ID: {member.user_id}
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<div className="flex items-center gap-3">
|
||||||
|
<select
|
||||||
|
value={member.role}
|
||||||
|
onChange={(e) =>
|
||||||
|
handleUpdateRole(member.user_id, e.target.value)
|
||||||
|
}
|
||||||
|
className="text-sm px-3 py-1.5 rounded-md border border-gray-300 dark:border-[#30363d] bg-white dark:bg-[#21262d] outline-none hover:bg-gray-50 dark:hover:bg-[#30363d] cursor-pointer transition-colors"
|
||||||
|
>
|
||||||
|
<option value="EDITOR">Editor</option>
|
||||||
|
<option value="VIEWER">Viewer</option>
|
||||||
|
</select>
|
||||||
|
<button
|
||||||
|
onClick={() => handleRemoveMember(member.user_id)}
|
||||||
|
className="text-red-500 hover:text-red-600 p-2 rounded-md hover:bg-red-50 dark:hover:bg-red-900/20 transition-colors"
|
||||||
|
title="Remove member"
|
||||||
|
>
|
||||||
|
<svg
|
||||||
|
className="w-5 h-5"
|
||||||
|
fill="none"
|
||||||
|
viewBox="0 0 24 24"
|
||||||
|
stroke="currentColor"
|
||||||
|
>
|
||||||
|
<path
|
||||||
|
strokeLinecap="round"
|
||||||
|
strokeLinejoin="round"
|
||||||
|
strokeWidth={2}
|
||||||
|
d="M19 7l-.867 12.142A2 2 0 0116.138 21H7.862a2 2 0 01-1.995-1.858L5 7m5 4v6m4-6v6m1-10V4a1 1 0 00-1-1h-4a1 1 0 00-1 1v3M4 7h16"
|
||||||
|
/>
|
||||||
|
</svg>
|
||||||
|
</button>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
))
|
||||||
|
) : (
|
||||||
|
<div className="p-8 text-center text-gray-500 dark:text-[#8b949e] text-sm italic">
|
||||||
|
Chưa có thành viên nào.
|
||||||
|
</div>
|
||||||
|
)}
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
)}
|
||||||
|
|
||||||
|
{activeTab === "settings" && (
|
||||||
|
<div className="max-w-3xl space-y-10">
|
||||||
|
<section>
|
||||||
|
<h2 className="text-2xl font-normal mb-4 pb-2 border-b border-gray-200 dark:border-[#30363d]">
|
||||||
|
General
|
||||||
|
</h2>
|
||||||
|
<form onSubmit={handleUpdateInfo} className="space-y-5">
|
||||||
|
<div>
|
||||||
|
<label className="block text-sm font-semibold mb-1.5 text-gray-800 dark:text-[#c9d1d9]">
|
||||||
|
Project name
|
||||||
|
</label>
|
||||||
|
<input
|
||||||
|
type="text"
|
||||||
|
value={editForm.title}
|
||||||
|
onChange={(e) =>
|
||||||
|
setEditForm({ ...editForm, title: e.target.value })
|
||||||
|
}
|
||||||
|
className="w-full max-w-md px-3 py-2 text-sm rounded-md border border-gray-300 dark:border-[#30363d] bg-white dark:bg-[#0d1117] outline-none focus:ring-2 focus:ring-blue-500/30 focus:border-blue-500 transition-shadow"
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
<div>
|
||||||
|
<label className="block text-sm font-semibold mb-1.5 text-gray-800 dark:text-[#c9d1d9]">
|
||||||
|
Description
|
||||||
|
</label>
|
||||||
|
<textarea
|
||||||
|
rows={4}
|
||||||
|
value={editForm.description}
|
||||||
|
onChange={(e) =>
|
||||||
|
setEditForm({ ...editForm, description: e.target.value })
|
||||||
|
}
|
||||||
|
className="w-full px-3 py-2 text-sm rounded-md border border-gray-300 dark:border-[#30363d] bg-white dark:bg-[#0d1117] outline-none focus:ring-2 focus:ring-blue-500/30 focus:border-blue-500 transition-shadow"
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
<div>
|
||||||
|
<label className="block text-sm font-semibold mb-1.5 text-gray-800 dark:text-[#c9d1d9]">
|
||||||
|
Status
|
||||||
|
</label>
|
||||||
|
<select
|
||||||
|
value={editForm.status}
|
||||||
|
onChange={(e) =>
|
||||||
|
setEditForm({
|
||||||
|
...editForm,
|
||||||
|
status: e.target.value as any,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
className="w-48 px-3 py-2 text-sm rounded-md border border-gray-300 dark:border-[#30363d] bg-white dark:bg-[#0d1117] outline-none focus:ring-2 focus:ring-blue-500/30 focus:border-blue-500 cursor-pointer"
|
||||||
|
>
|
||||||
|
<option value="PUBLIC">Public</option>
|
||||||
|
<option value="PRIVATE">Private</option>
|
||||||
|
<option value="ARCHIVE">Archive</option>
|
||||||
|
</select>
|
||||||
|
</div>
|
||||||
|
<button
|
||||||
|
type="submit"
|
||||||
|
className="px-5 py-2 text-sm font-medium rounded-md bg-[#21262d] text-[#c9d1d9] border border-[#30363d] hover:bg-[#30363d] transition-colors "
|
||||||
|
>
|
||||||
|
Update settings
|
||||||
|
</button>
|
||||||
|
</form>
|
||||||
|
</section>
|
||||||
|
|
||||||
|
<section>
|
||||||
|
<h2 className="text-2xl font-normal text-red-500 mb-4 pb-2 border-b border-red-500/30">
|
||||||
|
Danger Zone
|
||||||
|
</h2>
|
||||||
|
<div className="border border-red-500/30 rounded-xl overflow-hidden">
|
||||||
|
<div className="p-5 flex flex-col sm:flex-row sm:items-center justify-between gap-4">
|
||||||
|
<div>
|
||||||
|
<div className="font-semibold text-sm text-gray-800 dark:text-[#c9d1d9]">
|
||||||
|
Transfer ownership
|
||||||
|
</div>
|
||||||
|
<div className="text-xs text-gray-500 dark:text-[#8b949e] mt-1">
|
||||||
|
Transfer this project to another member in the project.
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<form
|
||||||
|
onSubmit={handleTransferOwnership}
|
||||||
|
className="flex gap-2"
|
||||||
|
>
|
||||||
|
<select
|
||||||
|
value={newOwnerId}
|
||||||
|
onChange={(e) => setNewOwnerId(e.target.value)}
|
||||||
|
className="w-full sm:w-56 px-3 py-2 text-sm rounded-md border border-gray-300 dark:border-[#30363d] bg-white dark:bg-[#0d1117] outline-none focus:ring-2 focus:ring-red-500/30 focus:border-red-500 cursor-pointer"
|
||||||
|
required
|
||||||
|
>
|
||||||
|
<option value="" disabled>
|
||||||
|
-- Thành viên --
|
||||||
|
</option>
|
||||||
|
{project.members && project.members.length > 0 ? (
|
||||||
|
project.members.map((member) => (
|
||||||
|
<option key={member.user_id} value={member.user_id}>
|
||||||
|
{member.display_name}
|
||||||
|
</option>
|
||||||
|
))
|
||||||
|
) : (
|
||||||
|
<option value="" disabled>
|
||||||
|
Chưa có thành viên nào
|
||||||
|
</option>
|
||||||
|
)}
|
||||||
|
</select>
|
||||||
|
<button
|
||||||
|
type="submit"
|
||||||
|
disabled={
|
||||||
|
!newOwnerId ||
|
||||||
|
!project.members ||
|
||||||
|
project.members.length === 0
|
||||||
|
}
|
||||||
|
className="shrink-0 px-4 py-2 text-sm font-medium text-red-500 bg-transparent border border-red-500/50 rounded-md hover:bg-red-500 hover:text-white dark:hover:bg-red-900/30 transition-colors disabled:opacity-50 disabled:cursor-not-allowed disabled:hover:bg-transparent disabled:hover:text-red-500 dark:disabled:hover:bg-transparent"
|
||||||
|
>
|
||||||
|
Transfer
|
||||||
|
</button>
|
||||||
|
</form>
|
||||||
|
</div>
|
||||||
|
<div className="p-5 flex flex-col sm:flex-row sm:items-center justify-between gap-4 hover:bg-red-50/30 dark:hover:bg-red-900/10 transition-colors">
|
||||||
|
<div>
|
||||||
|
<div className="font-semibold text-sm text-gray-800 dark:text-[#c9d1d9]">
|
||||||
|
Delete this project
|
||||||
|
</div>
|
||||||
|
<div className="text-xs text-gray-500 dark:text-[#8b949e] mt-1">
|
||||||
|
Once you delete a project, there is no going back. Please
|
||||||
|
be certain.
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<button
|
||||||
|
type="button"
|
||||||
|
onClick={handleDeleteProject}
|
||||||
|
className="shrink-0 px-4 py-2 text-sm font-medium text-red-500 bg-transparent border border-red-500/50 rounded-md hover:bg-red-500 hover:text-white dark:hover:bg-red-900/30 transition-colors"
|
||||||
|
>
|
||||||
|
Delete project
|
||||||
|
</button>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</section>
|
||||||
|
</div>
|
||||||
|
)}
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
}
|
||||||
@@ -1,12 +1,6 @@
|
|||||||
"use client";
|
"use client";
|
||||||
|
|
||||||
import {
|
import Image from "next/image";
|
||||||
Table,
|
|
||||||
TableBody,
|
|
||||||
TableCell,
|
|
||||||
TableHeader,
|
|
||||||
TableRow,
|
|
||||||
} from "../ui/table";
|
|
||||||
import Badge from "../ui/badge/Badge";
|
import Badge from "../ui/badge/Badge";
|
||||||
|
|
||||||
export type ProjectSortColumn = "created_at" | "updated_at" | "title";
|
export type ProjectSortColumn = "created_at" | "updated_at" | "title";
|
||||||
@@ -19,12 +13,18 @@ export interface ProjectItem {
|
|||||||
owner_id: string;
|
owner_id: string;
|
||||||
created_at: string;
|
created_at: string;
|
||||||
updated_at: string;
|
updated_at: string;
|
||||||
user:{
|
user: {
|
||||||
id: string;
|
id: string;
|
||||||
display_name: string;
|
display_name: string;
|
||||||
email:string;
|
email: string;
|
||||||
avatar_url:string;
|
avatar_url: string;
|
||||||
}
|
};
|
||||||
|
members?: {
|
||||||
|
user_id: string;
|
||||||
|
role: string;
|
||||||
|
display_name: string;
|
||||||
|
avatar_url: string;
|
||||||
|
}[];
|
||||||
}
|
}
|
||||||
|
|
||||||
interface ProjectsTableProps {
|
interface ProjectsTableProps {
|
||||||
@@ -32,10 +32,7 @@ interface ProjectsTableProps {
|
|||||||
onSort: (column: ProjectSortColumn) => void;
|
onSort: (column: ProjectSortColumn) => void;
|
||||||
sortBy?: ProjectSortColumn;
|
sortBy?: ProjectSortColumn;
|
||||||
sortOrder?: "asc" | "desc";
|
sortOrder?: "asc" | "desc";
|
||||||
onUpdate: (item: ProjectItem) => void;
|
onViewDetails: (id: string) => void;
|
||||||
onDelete: (id: string) => void;
|
|
||||||
onTransferOwner: (item: ProjectItem) => void;
|
|
||||||
onViewDetails: (id: string) => void; // Để xem commits, members...
|
|
||||||
}
|
}
|
||||||
|
|
||||||
export default function ProjectsTable({
|
export default function ProjectsTable({
|
||||||
@@ -43,21 +40,16 @@ export default function ProjectsTable({
|
|||||||
onSort,
|
onSort,
|
||||||
sortBy,
|
sortBy,
|
||||||
sortOrder,
|
sortOrder,
|
||||||
onUpdate,
|
|
||||||
onDelete,
|
|
||||||
onTransferOwner,
|
|
||||||
onViewDetails,
|
onViewDetails,
|
||||||
}: ProjectsTableProps) {
|
}: ProjectsTableProps) {
|
||||||
const formatDate = (dateString: string | null | undefined) => {
|
const formatDate = (dateString: string | null | undefined) => {
|
||||||
if (!dateString) return "-";
|
if (!dateString) return "-";
|
||||||
const date = new Date(dateString);
|
const date = new Date(dateString);
|
||||||
return date.toLocaleDateString("vi-VN", {
|
return `Updated on ${date.toLocaleDateString("vi-VN", {
|
||||||
day: "2-digit",
|
day: "2-digit",
|
||||||
month: "2-digit",
|
month: "short",
|
||||||
year: "numeric",
|
year: "numeric",
|
||||||
hour: "2-digit",
|
})}`;
|
||||||
minute: "2-digit",
|
|
||||||
});
|
|
||||||
};
|
};
|
||||||
|
|
||||||
const getStatusBadge = (status: ProjectItem["project_status"]) => {
|
const getStatusBadge = (status: ProjectItem["project_status"]) => {
|
||||||
@@ -89,101 +81,150 @@ export default function ProjectsTable({
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
const SortIcon = ({ column }: { column: ProjectSortColumn }) => {
|
const SortButton = ({
|
||||||
|
column,
|
||||||
|
label,
|
||||||
|
}: {
|
||||||
|
column: ProjectSortColumn;
|
||||||
|
label: string;
|
||||||
|
}) => {
|
||||||
const isActive = sortBy === column;
|
const isActive = sortBy === column;
|
||||||
return (
|
return (
|
||||||
<div className="flex flex-col ml-2 opacity-50 cursor-pointer hover:opacity-100">
|
<button
|
||||||
<svg
|
onClick={() => onSort(column)}
|
||||||
className={`w-3 h-3 ${isActive && sortOrder === "asc" ? "text-blue-700 opacity-100" : "text-gray-400"}`}
|
className={`w-20 text-sm font-medium text-left hover:text-blue-500 transition-colors ${
|
||||||
fill="none" stroke="currentColor" viewBox="0 0 24 24"
|
isActive
|
||||||
>
|
? "text-blue-600 dark:text-blue-400"
|
||||||
<path strokeLinecap="round" strokeLinejoin="round" strokeWidth={3} d="M5 15l7-7 7 7" />
|
: "text-gray-500 dark:text-gray-400"
|
||||||
</svg>
|
}`}
|
||||||
<svg
|
>
|
||||||
className={`w-3 h-3 -mt-1 ${isActive && sortOrder === "desc" ? "text-blue-700 opacity-100" : "text-gray-400"}`}
|
{label} {isActive && (sortOrder === "asc" ? "↑" : "↓")}
|
||||||
fill="none" stroke="currentColor" viewBox="0 0 24 24"
|
</button>
|
||||||
>
|
|
||||||
<path strokeLinecap="round" strokeLinejoin="round" strokeWidth={3} d="M19 9l-7 7-7-7" />
|
|
||||||
</svg>
|
|
||||||
</div>
|
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className="overflow-hidden rounded-xl border border-gray-200 bg-white dark:border-white/[0.05] dark:bg-white/[0.03]">
|
<div className="overflow-hidden rounded-xl border border-gray-200 bg-white dark:border-gray-800 dark:bg-[#0d1117] min-w-[700px]">
|
||||||
<div className="max-w-full overflow-x-auto">
|
<div className="flex items-center justify-between px-5 py-3 border-b border-gray-200 dark:border-gray-800 bg-gray-50/50 dark:bg-[#161b22]">
|
||||||
<div className="min-w-[1000px]">
|
<span className="text-sm font-semibold text-gray-700 dark:text-gray-300 w-40">
|
||||||
<Table>
|
</span>
|
||||||
<TableHeader className="border-b border-gray-100 dark:border-white/[0.05]">
|
<div className="flex items-center gap-4 shrink-0">
|
||||||
<TableRow>
|
<span className="text-sm text-gray-500 dark:text-gray-400 w-20">
|
||||||
<TableCell isHeader className="px-5 py-3 font-medium text-gray-500 text-start text-theme-xs dark:text-gray-400">
|
Sắp xếp:
|
||||||
<div className="flex items-center cursor-pointer select-none" onClick={() => onSort("title")}>
|
</span>
|
||||||
Tiêu đề <SortIcon column="title" />
|
<SortButton column="title" label="Tên" />
|
||||||
</div>
|
<SortButton column="created_at" label="Ngày tạo" />
|
||||||
</TableCell>
|
<SortButton column="updated_at" label="Cập nhật" />
|
||||||
<TableCell isHeader className="px-5 py-3 font-medium text-gray-500 text-start text-theme-xs dark:text-gray-400">Trạng thái</TableCell>
|
|
||||||
<TableCell isHeader className="px-5 py-3 font-medium text-gray-500 text-start text-theme-xs dark:text-gray-400">Chủ sở hữu</TableCell>
|
|
||||||
<TableCell isHeader className="px-5 py-3 font-medium text-gray-500 text-start text-theme-xs dark:text-gray-400">
|
|
||||||
<div className="flex items-center cursor-pointer select-none" onClick={() => onSort("created_at")}>
|
|
||||||
Ngày tạo <SortIcon column="created_at" />
|
|
||||||
</div>
|
|
||||||
</TableCell>
|
|
||||||
<TableCell isHeader className="px-5 py-3 font-medium text-gray-500 text-start text-theme-xs dark:text-gray-400">
|
|
||||||
<div className="flex items-center cursor-pointer select-none" onClick={() => onSort("updated_at")}>
|
|
||||||
Cập nhật <SortIcon column="updated_at" />
|
|
||||||
</div>
|
|
||||||
</TableCell>
|
|
||||||
<TableCell isHeader className="px-5 py-3 font-medium text-center text-gray-500 text-theme-xs dark:text-gray-400 min-w-[200px]">Thao tác</TableCell>
|
|
||||||
</TableRow>
|
|
||||||
</TableHeader>
|
|
||||||
|
|
||||||
<TableBody className="divide-y divide-gray-100 dark:divide-white/[0.05]">
|
|
||||||
{data.length > 0 ? (
|
|
||||||
data.map((item) => (
|
|
||||||
<TableRow key={item.id} className="hover:bg-gray-50/50 dark:hover:bg-white/[0.01] transition-colors">
|
|
||||||
<TableCell className="px-5 py-4 text-start font-medium text-theme-sm truncate max-w-[250px]">{item.title}</TableCell>
|
|
||||||
<TableCell className="px-5 py-4 text-start">{getStatusBadge(item.project_status)}</TableCell>
|
|
||||||
<TableCell className="px-5 py-4 text-start text-theme-sm">{item.user?.display_name}</TableCell>
|
|
||||||
<TableCell className="px-5 py-4 text-gray-600 text-theme-sm dark:text-gray-400">{formatDate(item.created_at)}</TableCell>
|
|
||||||
<TableCell className="px-5 py-4 text-gray-600 text-theme-sm dark:text-gray-400">{formatDate(item.updated_at)}</TableCell>
|
|
||||||
<TableCell className="px-5 py-4 text-center">
|
|
||||||
<div className="flex items-center justify-center gap-3">
|
|
||||||
<button onClick={() => onViewDetails(item.id)} title="Chi tiết" className="text-gray-500 hover:text-gray-700 dark:hover:text-gray-300">
|
|
||||||
<svg className="w-5 h-5" fill="none" viewBox="0 0 24 24" stroke="currentColor">
|
|
||||||
<path strokeLinecap="round" strokeLinejoin="round" strokeWidth={2} d="M15 12a3 3 0 11-6 0 3 3 0 016 0z" />
|
|
||||||
<path strokeLinecap="round" strokeLinejoin="round" strokeWidth={2} d="M2.458 12C3.732 7.943 7.523 5 12 5c4.478 0 8.268 2.943 9.542 7-1.274 4.057-5.064 7-9.542 7-4.477 0-8.268-2.943-9.542-7z" />
|
|
||||||
</svg>
|
|
||||||
</button>
|
|
||||||
<button onClick={() => onUpdate(item)} title="Cập nhật" className="text-blue-500 hover:text-blue-700 dark:hover:text-blue-400">
|
|
||||||
<svg className="w-5 h-5" fill="none" viewBox="0 0 24 24" stroke="currentColor">
|
|
||||||
<path strokeLinecap="round" strokeLinejoin="round" strokeWidth={2} d="M11 5H6a2 2 0 00-2 2v11a2 2 0 002 2h11a2 2 0 002-2v-5m-1.414-9.414a2 2 0 112.828 2.828L11.828 15H9v-2.828l8.586-8.586z" />
|
|
||||||
</svg>
|
|
||||||
</button>
|
|
||||||
<button onClick={() => onTransferOwner(item)} title="Chuyển quyền sở hữu" className="text-green-500 hover:text-green-700 dark:hover:text-green-400">
|
|
||||||
<svg className="w-5 h-5" fill="none" viewBox="0 0 24 24" stroke="currentColor">
|
|
||||||
<path strokeLinecap="round" strokeLinejoin="round" strokeWidth={2} d="M8 7h12m0 0l-4-4m4 4l-4 4m0 6H4m0 0l4 4m-4-4l4-4" />
|
|
||||||
</svg>
|
|
||||||
</button>
|
|
||||||
<button onClick={() => onDelete(item.id)} title="Xóa" className="text-red-500 hover:text-red-700 dark:hover:text-red-400">
|
|
||||||
<svg className="w-5 h-5" fill="none" viewBox="0 0 24 24" stroke="currentColor">
|
|
||||||
<path strokeLinecap="round" strokeLinejoin="round" strokeWidth={2} d="M19 7l-.867 12.142A2 2 0 0116.138 21H7.862a2 2 0 01-1.995-1.858L5 7m5 4v6m4-6v6m1-10V4a1 1 0 00-1-1h-4a1 1 0 00-1 1v3M4 7h16" />
|
|
||||||
</svg>
|
|
||||||
</button>
|
|
||||||
</div>
|
|
||||||
</TableCell>
|
|
||||||
</TableRow>
|
|
||||||
))
|
|
||||||
) : (
|
|
||||||
<TableRow>
|
|
||||||
<TableCell colSpan={6} className="px-5 py-20 text-center text-gray-500 italic">
|
|
||||||
Không tìm thấy dự án nào
|
|
||||||
</TableCell>
|
|
||||||
</TableRow>
|
|
||||||
)}
|
|
||||||
</TableBody>
|
|
||||||
</Table>
|
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
<div className="flex flex-col divide-y divide-gray-200 dark:divide-gray-800">
|
||||||
|
{data.length > 0 ? (
|
||||||
|
data.map((item) => (
|
||||||
|
<div
|
||||||
|
key={item.id}
|
||||||
|
className="group flex flex-col p-5 md:flex-row md:items-center justify-between hover:bg-gray-50 dark:hover:bg-[#161b22] transition-colors"
|
||||||
|
>
|
||||||
|
<div className="flex-1 pr-4 max-w-full md:max-w-[75%]">
|
||||||
|
<div
|
||||||
|
onClick={() => onViewDetails(item.id)}
|
||||||
|
className="flex items-center gap-2 mb-2 cursor-pointer hover:underline"
|
||||||
|
>
|
||||||
|
<div className="w-6 h-6 shrink-0 flex items-center justify-center">
|
||||||
|
{item.user?.avatar_url ? (
|
||||||
|
<div className="relative w-6 h-6 rounded-full overflow-hidden border border-gray-200 dark:border-gray-800">
|
||||||
|
<Image
|
||||||
|
src={item.user.avatar_url}
|
||||||
|
alt="avatar"
|
||||||
|
fill
|
||||||
|
className="object-cover rounded-full"
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
) : (
|
||||||
|
<div className="w-6 h-6 rounded-full bg-gray-200 dark:bg-gray-700 flex items-center justify-center border border-gray-300 dark:border-gray-600">
|
||||||
|
<span className="text-[10px] font-bold text-gray-500 dark:text-gray-300 leading-none">
|
||||||
|
{item.user?.display_name?.charAt(0)?.toUpperCase() ||
|
||||||
|
"U"}
|
||||||
|
</span>
|
||||||
|
</div>
|
||||||
|
)}
|
||||||
|
</div>
|
||||||
|
<div className="flex items-center max-w-[250px]">
|
||||||
|
<span className="text-lg font-medium text-gray-700 dark:text-gray-300 truncate">
|
||||||
|
{item.user?.display_name || "Unknown"}
|
||||||
|
</span>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<span className="text-lg text-gray-400 dark:text-gray-600 shrink-0">
|
||||||
|
/
|
||||||
|
</span>
|
||||||
|
|
||||||
|
<h3 className="text-lg font-semibold text-blue-600 dark:text-[#58a6ff] truncate max-w-[300px]">
|
||||||
|
{item.title}
|
||||||
|
</h3>
|
||||||
|
|
||||||
|
<div className="shrink-0 w-20 flex justify-start">
|
||||||
|
{getStatusBadge(item.project_status)}
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div className="flex flex-wrap items-center gap-4 text-xs text-gray-500 dark:text-[#8b949e] h-5">
|
||||||
|
<span>{formatDate(item.updated_at)}</span>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div className="flex items-center mt-4 md:mt-0 w-[120px] justify-end shrink-0">
|
||||||
|
<div className="flex -space-x-2 overflow-hidden">
|
||||||
|
{item.members && item.members.length > 0 ? (
|
||||||
|
<>
|
||||||
|
{item.members.slice(0, 4).map((m, index) =>
|
||||||
|
m.avatar_url ? (
|
||||||
|
<Image
|
||||||
|
key={index}
|
||||||
|
src={m.avatar_url}
|
||||||
|
alt={m.display_name}
|
||||||
|
width={32}
|
||||||
|
height={32}
|
||||||
|
title={m.display_name}
|
||||||
|
className="inline-block w-8 h-8 rounded-full object-cover ring-2 ring-white group-hover:ring-gray-50 dark:ring-[#0d1117] dark:group-hover:ring-[#161b22] transition-colors"
|
||||||
|
/>
|
||||||
|
) : (
|
||||||
|
<div
|
||||||
|
key={index}
|
||||||
|
title={m.display_name}
|
||||||
|
className="inline-flex items-center justify-center w-8 h-8 rounded-full bg-gray-200 dark:bg-gray-700 ring-2 ring-white group-hover:ring-gray-50 dark:ring-[#0d1117] dark:group-hover:ring-[#161b22] transition-colors"
|
||||||
|
>
|
||||||
|
<span className="text-xs font-medium text-gray-500 dark:text-gray-300">
|
||||||
|
{m.display_name?.charAt(0)?.toUpperCase() || "U"}
|
||||||
|
</span>
|
||||||
|
</div>
|
||||||
|
),
|
||||||
|
)}
|
||||||
|
|
||||||
|
{item.members.length > 4 && (
|
||||||
|
<div
|
||||||
|
title="Những người khác"
|
||||||
|
className="inline-flex items-center justify-center w-8 h-8 rounded-full bg-gray-100 dark:bg-gray-800 ring-2 ring-white group-hover:ring-gray-50 dark:ring-[#0d1117] dark:group-hover:ring-[#161b22] transition-colors z-10"
|
||||||
|
>
|
||||||
|
<span className="text-xs font-medium text-gray-600 dark:text-gray-400">
|
||||||
|
+{item.members.length - 4}
|
||||||
|
</span>
|
||||||
|
</div>
|
||||||
|
)}
|
||||||
|
</>
|
||||||
|
) : (
|
||||||
|
<span className="text-sm text-gray-400 dark:text-gray-600 italic"></span>
|
||||||
|
)}
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
))
|
||||||
|
) : (
|
||||||
|
<div className="p-10 text-center text-gray-500 dark:text-gray-400 italic">
|
||||||
|
Không tìm thấy dự án nào
|
||||||
|
</div>
|
||||||
|
)}
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
@@ -5,5 +5,62 @@ export interface Project {
|
|||||||
project_status: "PRIVATE" | "PUBLIC" | "ARCHIVE";
|
project_status: "PRIVATE" | "PUBLIC" | "ARCHIVE";
|
||||||
created_at: string;
|
created_at: string;
|
||||||
updated_at: string;
|
updated_at: string;
|
||||||
// You can add other fields like 'members' if they are part of the response
|
is_deleted?: boolean;
|
||||||
|
user_id?: string;
|
||||||
|
user?: {
|
||||||
|
id: string;
|
||||||
|
email: string;
|
||||||
|
display_name: string;
|
||||||
|
avatar_url: string;
|
||||||
|
};
|
||||||
|
commits?: any[];
|
||||||
|
submission_ids?: any[];
|
||||||
|
members?: ProjectMember[];
|
||||||
|
}
|
||||||
|
export interface ProjectsResponse<T = Project> {
|
||||||
|
status: boolean;
|
||||||
|
message: string;
|
||||||
|
data: T[];
|
||||||
|
pagination: {
|
||||||
|
current_page: number;
|
||||||
|
page_size: number;
|
||||||
|
total_records: number;
|
||||||
|
total_pages: number;
|
||||||
|
};
|
||||||
|
}
|
||||||
|
export interface UpdateProjectPayload {
|
||||||
|
title: string;
|
||||||
|
description: string;
|
||||||
|
status: "PRIVATE" | "PUBLIC" | "ARCHIVE";
|
||||||
|
}
|
||||||
|
export interface ChangeOwnerPayload {
|
||||||
|
new_owner_id: string;
|
||||||
|
}
|
||||||
|
export interface ProjectMemberPayload {
|
||||||
|
user_id?: string;
|
||||||
|
role: "EDITOR" | "VIEWER" | "ADMIN";
|
||||||
|
}
|
||||||
|
export interface ProjectMember {
|
||||||
|
user_id: string;
|
||||||
|
role: string;
|
||||||
|
display_name: string;
|
||||||
|
avatar_url: string;
|
||||||
|
}
|
||||||
|
export interface GetProjectsParams {
|
||||||
|
page?: number;
|
||||||
|
limit?: number;
|
||||||
|
search?: string;
|
||||||
|
sort?: "created_at" | "updated_at" | "title";
|
||||||
|
order?: "asc" | "desc";
|
||||||
|
statuses?: string; // comma-separated
|
||||||
|
user_ids?: string; // comma-separated
|
||||||
|
created_from?: string; // ISO date string
|
||||||
|
created_to?: string; // ISO date string
|
||||||
|
}
|
||||||
|
export interface CreateCommitPayload {
|
||||||
|
edit_summary: string;
|
||||||
|
snapshot_json: number[];
|
||||||
|
}
|
||||||
|
export interface RestoreCommitPayload {
|
||||||
|
commit_id: string;
|
||||||
}
|
}
|
||||||
@@ -1,63 +1,14 @@
|
|||||||
import api from "@/config/config";
|
import api from "@/config/config";
|
||||||
import { API } from "../../api";
|
import { API } from "../../api";
|
||||||
import { Project } from "@/interface/project";
|
import { ProjectMemberPayload, ChangeOwnerPayload, CreateCommitPayload, GetProjectsParams, Project, RestoreCommitPayload, UpdateProjectPayload } from "@/interface/project";
|
||||||
import { CommonResponse, CursorPaginatedResponse, PaginatedResponse } from "@/interface/common";
|
import { CommonResponse, CursorPaginatedResponse, PaginatedResponse } from "@/interface/common";
|
||||||
|
|
||||||
// ==========================================
|
|
||||||
// TYPES & INTERFACES (Cơ bản theo logic chuẩn)
|
|
||||||
// ==========================================
|
|
||||||
|
|
||||||
export interface GetProjectsParams {
|
|
||||||
page?: number;
|
|
||||||
limit?: number;
|
|
||||||
search?: string;
|
|
||||||
sort?: "created_at" | "updated_at" | "title";
|
|
||||||
order?: "asc" | "desc";
|
|
||||||
statuses?: string; // comma-separated
|
|
||||||
user_ids?: string; // comma-separated
|
|
||||||
created_from?: string; // ISO date string
|
|
||||||
created_to?: string; // ISO date string
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
export interface UpdateProjectPayload {
|
|
||||||
title?: string;
|
|
||||||
description?: string;
|
|
||||||
status?: "PRIVATE" | "PUBLIC" | "ARCHIVE";
|
|
||||||
}
|
|
||||||
|
|
||||||
export interface AddMemberPayload {
|
|
||||||
user_id: string;
|
|
||||||
role: "EDITOR" | "VIEWER";
|
|
||||||
}
|
|
||||||
|
|
||||||
export interface UpdateMemberRolePayload {
|
|
||||||
role: "EDITOR" | "VIEWER";
|
|
||||||
}
|
|
||||||
|
|
||||||
export interface ChangeOwnerPayload {
|
|
||||||
new_owner_id: string;
|
|
||||||
}
|
|
||||||
|
|
||||||
export interface CreateCommitPayload {
|
|
||||||
edit_summary: string;
|
|
||||||
snapshot_json: number[];
|
|
||||||
}
|
|
||||||
|
|
||||||
export interface RestoreCommitPayload {
|
|
||||||
commit_id: string;
|
|
||||||
}
|
|
||||||
|
|
||||||
// ==========================================
|
|
||||||
// 1. NHÓM: QUẢN LÝ DỰ ÁN (PROJECTS)
|
|
||||||
// ==========================================
|
|
||||||
|
|
||||||
export const getProjects = async (params: GetProjectsParams): Promise<PaginatedResponse<Project>> => {
|
export const getProjects = async (params: GetProjectsParams): Promise<PaginatedResponse<Project>> => {
|
||||||
const response = await api.get(API.Project.GET_ALL, { params });
|
const response = await api.get(API.Project.GET_ALL, { params });
|
||||||
return response?.data;
|
return response?.data;
|
||||||
};
|
};
|
||||||
|
|
||||||
export const getProjectDetail = async (id: string): Promise<CommonResponse<Project>> => {
|
export const getProjectDetailByID = async (id: string): Promise<CommonResponse<Project>> => {
|
||||||
const response = await api.get(API.Project.GET_DETAIL(id));
|
const response = await api.get(API.Project.GET_DETAIL(id));
|
||||||
return response?.data;
|
return response?.data;
|
||||||
};
|
};
|
||||||
@@ -81,12 +32,12 @@ export const transferProjectOwnership = async (id: string, payload: ChangeOwnerP
|
|||||||
// 2. NHÓM: QUẢN LÝ THÀNH VIÊN (MEMBERS)
|
// 2. NHÓM: QUẢN LÝ THÀNH VIÊN (MEMBERS)
|
||||||
// ==========================================
|
// ==========================================
|
||||||
|
|
||||||
export const addProjectMember = async (id: string, payload: AddMemberPayload): Promise<CommonResponse> => {
|
export const addProjectMember = async (id: string, payload: ProjectMemberPayload): Promise<CommonResponse> => {
|
||||||
const response = await api.post(API.Project.ADD_MEMBER(id), payload);
|
const response = await api.post(API.Project.ADD_MEMBER(id), payload);
|
||||||
return response?.data;
|
return response?.data;
|
||||||
};
|
};
|
||||||
|
|
||||||
export const updateProjectMemberRole = async (id: string, userId: string, payload: UpdateMemberRolePayload): Promise<CommonResponse> => {
|
export const updateProjectMemberRole = async (id: string, userId: string, payload: ProjectMemberPayload): Promise<CommonResponse> => {
|
||||||
const response = await api.put(API.Project.UPDATE_MEMBER(id, userId), payload);
|
const response = await api.put(API.Project.UPDATE_MEMBER(id, userId), payload);
|
||||||
return response?.data;
|
return response?.data;
|
||||||
};
|
};
|
||||||
@@ -105,7 +56,7 @@ export const createProjectCommit = async (id: string, payload: CreateCommitPaylo
|
|||||||
return response?.data;
|
return response?.data;
|
||||||
};
|
};
|
||||||
|
|
||||||
export const getProjectCommits = async (id: string): Promise<CommonResponse> => { // Assuming it returns a list of commits
|
export const getProjectCommits = async (id: string): Promise<CommonResponse> => {
|
||||||
const response = await api.get(API.Project.GET_COMMITS(id));
|
const response = await api.get(API.Project.GET_COMMITS(id));
|
||||||
return response?.data;
|
return response?.data;
|
||||||
};
|
};
|
||||||
@@ -119,12 +70,3 @@ export const getCurrentProject = async (params?: { cursor_id?: string; limit?: n
|
|||||||
const response = await api.get(API.Project.GET_CURRENT_PROJECT, { params });
|
const response = await api.get(API.Project.GET_CURRENT_PROJECT, { params });
|
||||||
return response?.data;
|
return response?.data;
|
||||||
};
|
};
|
||||||
|
|
||||||
// ==========================================
|
|
||||||
// 4. NHÓM: LẤY DỰ ÁN QUA USER
|
|
||||||
// ==========================================
|
|
||||||
|
|
||||||
export const getUserProjects = async (userId: string, params?: { cursor_id?: string; limit?: number }): Promise<CursorPaginatedResponse<Project>> => {
|
|
||||||
const response = await api.get(API.Project.GET_CURRENT_PROJECT, { params });
|
|
||||||
return response?.data;
|
|
||||||
};
|
|
||||||
Reference in New Issue
Block a user