From ff70fc78f555b14fb1bd323d8e8c7325fd90378a Mon Sep 17 00:00:00 2001 From: bokhonglo Date: Wed, 29 Apr 2026 15:03:49 +0700 Subject: [PATCH] update: management project Co-authored-by: Copilot --- .../(others-pages)/projects/[id]/page.tsx | 58 +++++++++++++++---- src/components/tables/ProjectsTable.tsx | 6 +- src/components/user-profile/UserMetaCard.tsx | 3 + 3 files changed, 52 insertions(+), 15 deletions(-) diff --git a/src/app/(admin)/(others-pages)/projects/[id]/page.tsx b/src/app/(admin)/(others-pages)/projects/[id]/page.tsx index 2f8d347..1201b99 100644 --- a/src/app/(admin)/(others-pages)/projects/[id]/page.tsx +++ b/src/app/(admin)/(others-pages)/projects/[id]/page.tsx @@ -15,6 +15,7 @@ import { } from "@/service/projectService"; import { Project } from "@/interface/project"; import Swal from "sweetalert2"; +import PageBreadcrumb from "@/components/common/PageBreadCrumb"; type TabType = "overview" | "members" | "settings"; @@ -84,7 +85,7 @@ export default function ProjectDetailsPage() { html: `Bạn có chắc chắn muốn chuyển dự án này cho ${memberName}?
Hành động này không thể hoàn tác và bạn sẽ không còn là chủ sở hữu nữa.`, icon: "error", showCancelButton: true, - confirmButtonColor: "#238636", + confirmButtonColor: "#238636", cancelButtonColor: "#30363d", confirmButtonText: "Tôi hiểu, chuyển quyền sở hữu", cancelButtonText: "Hủy bỏ", @@ -127,22 +128,54 @@ export default function ProjectDetailsPage() { 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 res = await updateProjectMemberRole(id, userId, { + role: newRole as any, + }); + + if (res?.status) { + toast.success("Cập nhật quyền thành công"); + fetchProject(); + } else { + toast.error(res?.message || "Cập nhật quyền thất bại"); + } + } catch (error: any) { + const errorMessage = + error.response?.data?.message || "Cập nhật quyền thất bại"; + toast.error(errorMessage); } }; const handleRemoveMember = async (userId: string) => { - if (!confirm("Xác nhận xóa thành viên này?")) return; + // 1. Hiển thị hộp thoại xác nhận bằng SweetAlert2 + const result = await Swal.fire({ + title: "Xác nhận xóa?", + text: "Bạn có chắc chắn muốn xóa thành viên này khỏi dự án?", + icon: "warning", + showCancelButton: true, + confirmButtonColor: "#3085d6", + cancelButtonColor: "#d33", + confirmButtonText: "Đồng ý", + cancelButtonText: "Hủy", + }); + + if (!result.isConfirmed) return; + try { - await removeProjectMember(id, userId); - toast.success("Đã xóa thành viên"); + const res = await removeProjectMember(id, userId); + + if (res?.status) { + toast.success("Đã xóa thành viên"); + } else { + toast.error(res?.message || "Xóa thành viên thất bại"); + } + } catch (error: any) { + const errorMessage = + error.response?.data?.message || "Xóa thành viên thất bại"; + toast.error(errorMessage); + + console.error("Remove Member Error:", error); + } finally { fetchProject(); - } catch (error) { - toast.error("Xóa thành viên thất bại"); } }; @@ -192,7 +225,8 @@ export default function ProjectDetailsPage() { ); return ( -
+
+
diff --git a/src/components/tables/ProjectsTable.tsx b/src/components/tables/ProjectsTable.tsx index 4f5e149..e1005f9 100644 --- a/src/components/tables/ProjectsTable.tsx +++ b/src/components/tables/ProjectsTable.tsx @@ -150,16 +150,16 @@ export default function ProjectsTable({ )}
- + {item.user?.display_name || "Unknown"}
- + / -

+

{item.title}

diff --git a/src/components/user-profile/UserMetaCard.tsx b/src/components/user-profile/UserMetaCard.tsx index 0d0b20a..5fabf50 100644 --- a/src/components/user-profile/UserMetaCard.tsx +++ b/src/components/user-profile/UserMetaCard.tsx @@ -159,6 +159,9 @@ export default function UserMetaCard({ data }: { data: UserMetaCardProps }) { )}
+ + ID: {data.data?.id} +