diff --git a/package-lock.json b/package-lock.json index 2555ce0..97d4016 100644 --- a/package-lock.json +++ b/package-lock.json @@ -32,6 +32,7 @@ "react-dropzone": "^14.3.8", "react-redux": "^9.2.0", "sonner": "^2.0.7", + "sweetalert2": "^11.26.24", "swiper": "^11.2.10", "tailwind-merge": "^2.6.0", "yet-another-react-lightbox": "^3.30.1" @@ -8908,6 +8909,16 @@ "url": "https://opencollective.com/svgo" } }, + "node_modules/sweetalert2": { + "version": "11.26.24", + "resolved": "https://registry.npmjs.org/sweetalert2/-/sweetalert2-11.26.24.tgz", + "integrity": "sha512-SLgukW4wicewpW5VOukSXY5Z6DL/z7HCOK2ODSjmQPiSphCN8gJAmh9npoceXOtBRNoDN0xIz+zHYthtfiHmjg==", + "license": "MIT", + "funding": { + "type": "individual", + "url": "https://github.com/sponsors/limonte" + } + }, "node_modules/swiper": { "version": "11.2.10", "resolved": "https://registry.npmjs.org/swiper/-/swiper-11.2.10.tgz", diff --git a/package.json b/package.json index e274410..340b3b3 100644 --- a/package.json +++ b/package.json @@ -33,6 +33,7 @@ "react-dropzone": "^14.3.8", "react-redux": "^9.2.0", "sonner": "^2.0.7", + "sweetalert2": "^11.26.24", "swiper": "^11.2.10", "tailwind-merge": "^2.6.0", "yet-another-react-lightbox": "^3.30.1" diff --git a/src/app/(admin)/(others-pages)/(tables)/user-table/page.tsx b/src/app/(admin)/(others-pages)/(tables)/user-table/page.tsx index fee8a9d..aa7ff89 100644 --- a/src/app/(admin)/(others-pages)/(tables)/user-table/page.tsx +++ b/src/app/(admin)/(others-pages)/(tables)/user-table/page.tsx @@ -1,10 +1,10 @@ "use client"; import ComponentCard from "@/components/common/ComponentCard"; +import Swal from "sweetalert2"; import PageBreadcrumb from "@/components/common/PageBreadCrumb"; import BasicTableOne from "@/components/tables/BasicTableOne"; import ChangeRoleModal from "@/components/tables/ChangeRoleModal"; import UserDetailModal from "@/components/tables/UserDetailModal"; -import { Modal } from "@/components/ui/modal"; import { responseUserTable, getUserDto, fullDataUser } from "@/interface/admin"; import { apiDeleteUser, @@ -13,7 +13,7 @@ import { apiRestoreUser, } from "@/service/adminService"; import { useEffect, useState, useCallback } from "react"; -import { toast } from "sonner"; +import Pagination from "@/components/tables/Pagination"; export type SortColumn = "created_at" | "updated_at" | "display_name" | "email"; @@ -48,7 +48,6 @@ export default function UserTable() { const fetchRoles = async () => { try { const res = await apiGetAllRole(); - console.log("Danh sách role:", res); if (res?.status) { setRoles(res.data); } @@ -58,7 +57,7 @@ export default function UserTable() { }; fetchRoles(); }, []); - console.log("Roles đã fetch:", roles); + useEffect(() => { const handler = setTimeout(() => { setDebouncedParams({ @@ -124,36 +123,57 @@ export default function UserTable() { }; const handleDelete = async (user: fullDataUser) => { - if ( - window.confirm( - `Khóa người dùng ${user.profile?.display_name || user.email}?`, - ) - ) { + const result = await Swal.fire({ + title: "Xác nhận khóa?", + text: `Bạn có chắc muốn khóa người dùng ${user.profile?.display_name || user.email}?`, + icon: "warning", + showCancelButton: true, + showCloseButton: true, + confirmButtonColor: "#d33", + cancelButtonColor: "#3085d6", + confirmButtonText: "Đồng ý, khóa!", + cancelButtonText: "Hủy", + reverseButtons: true, + }); + + if (result.isConfirmed) { try { await apiDeleteUser(user.id); - toast.success("Đã khóa người dùng thành công!"); + Swal.fire( + "Đã khóa!", + "Người dùng đã bị tạm dừng hoạt động.", + "success", + ); fetchUsers(); } catch (err) { - toast.error("Đã xảy ra lỗi khi xóa!"); + Swal.fire("Lỗi!", "Không thể thực hiện thao tác này.", "error"); } } }; const handleRestore = async (user: fullDataUser) => { - if ( - window.confirm( - `Khôi phục người dùng ${user.profile?.display_name || user.email}?`, - ) - ) { + const result = await Swal.fire({ + title: "Khôi phục tài khoản?", + text: `Khôi phục quyền truy cập cho ${user.profile?.display_name || user.email}?`, + icon: "question", + showCancelButton: true, + showCloseButton: true, + confirmButtonColor: "#28a745", + confirmButtonText: "Xác nhận", + cancelButtonText: "Hủy", + }); + + if (result.isConfirmed) { try { await apiRestoreUser(user.id); - toast.success("Khôi phục người dùng thành công!"); + Swal.fire("Thành công", "Tài khoản đã được khôi phục.", "success"); fetchUsers(); } catch (err) { - toast.error("Đã xảy ra lỗi khi khôi phục!"); + Swal.fire("Thất bại", "Vui lòng thử lại sau.", "error"); } } }; + return (