diff --git a/src/app/(admin)/(others-pages)/(tables)/applications-tables/page.tsx b/src/app/(admin)/(others-pages)/(tables)/applications-tables/page.tsx index 7f42cf3..c42d92f 100644 --- a/src/app/(admin)/(others-pages)/(tables)/applications-tables/page.tsx +++ b/src/app/(admin)/(others-pages)/(tables)/applications-tables/page.tsx @@ -186,7 +186,8 @@ export default function HistorianApplicationPage() { }; const pagination = tableData?.pagination; - + + // console.log("Pagination info:", pagination); return (
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 1b198d7..2840909 100644 --- a/src/app/(admin)/(others-pages)/(tables)/user-table/page.tsx +++ b/src/app/(admin)/(others-pages)/(tables)/user-table/page.tsx @@ -18,7 +18,6 @@ import { LIMIT_ITEM_TABLE } from "../../../../../../constant"; export type SortColumn = "created_at" | "updated_at" | "display_name" | "email"; -// Hàm helper format ngày giờ giống với Historian const formatDateTimeToISO = ( dateStr: string, timeStr: string, @@ -42,7 +41,6 @@ export default function UserTable() { const [authProvider, setAuthProvider] = useState(""); const [isDeleted, setIsDeleted] = useState(undefined); - // --- THÊM STATE CHO NGÀY GIỜ --- const [fromDate, setFromDate] = useState(""); const [fromTime, setFromTime] = useState(""); const [toDate, setToDate] = useState(""); @@ -53,7 +51,6 @@ export default function UserTable() { const [roleUser, setRoleUser] = useState(null); const [isRoleModalOpen, setIsRoleModalOpen] = useState(false); - // Cập nhật params để chứa thêm ngày giờ const [debouncedParams, setDebouncedParams] = useState({ search: "", limit: 5, @@ -69,7 +66,6 @@ export default function UserTable() { const [sortBy, setSortBy] = useState(undefined); const [sortOrder, setSortOrder] = useState<"asc" | "desc">("asc"); - // Hàm Reset bộ lọc const handleReset = () => { setSearchTerm(""); setAuthProvider(""); @@ -136,7 +132,6 @@ export default function UserTable() { const fetchUsers = useCallback(async () => { setLoading(true); try { - // Dùng any để tránh lỗi TS nếu interface getUserDto chưa update const payload: any = { page: page, limit: debouncedParams.limit, @@ -190,6 +185,8 @@ export default function UserTable() { }; const pagination = tableData?.pagination; + + console.log(pagination); const handleOpenDetail = (user: fullDataUser) => { setSelectedUser(user); diff --git a/src/components/tables/ApplicationDetailModal.tsx b/src/components/tables/ApplicationDetailModal.tsx index f5439c1..99fdd26 100644 --- a/src/components/tables/ApplicationDetailModal.tsx +++ b/src/components/tables/ApplicationDetailModal.tsx @@ -1,22 +1,18 @@ "use client"; -import React, { useEffect, useState } from "react"; +import React, { useEffect, useRef, useState } from "react"; import Image from "next/image"; import Swal from "sweetalert2"; import { ApplicationDto } from "@/interface/historian"; -import { - apiGetUserById, - apiUpdateApplicationStatus, -} from "@/service/adminService"; -import { getMediaById } from "@/service/mediaService"; +import { apiUpdateApplicationStatus } from "@/service/adminService"; import Link from "next/link"; import { URL_MEDIA } from "../../../api"; interface Props { isOpen: boolean; onClose: () => void; - application: ApplicationDto | null; - onRefresh: () => void; // Gọi lại hàm fetch danh sách sau khi duyệt xong + application: any; + onRefresh: () => void; } export default function ApplicationDetailModal({ @@ -25,80 +21,37 @@ export default function ApplicationDetailModal({ application, onRefresh, }: Props) { - - const [userData, setUserData] = useState(null); - const [mediaList, setMediaList] = useState([]); const [reviewNote, setReviewNote] = useState(""); - const [loadingContent, setLoadingContent] = useState(false); const [isSubmitting, setIsSubmitting] = useState(false); - + const textareaRef = useRef(null); useEffect(() => { if (isOpen && application) { setReviewNote(application.review_note || ""); - fetchDetails(); } else { - setUserData(null); - setMediaList([]); setReviewNote(""); } }, [isOpen, application]); - const fetchDetails = async () => { - if (!application) return; - setLoadingContent(true); - try { - const userRes = await apiGetUserById(application.user_id); - - // console.log("User data:", userRes); - - if (userRes?.data) setUserData(userRes.data); - - if (application.media && application.media.length > 0) { - const mediaPromises = application.media.map((m: any) => - getMediaById(m.id), - ); - const mediaResponses = await Promise.all(mediaPromises); - - setMediaList(mediaResponses.map((res) => res?.data || res)); - } - } catch (error) { - console.error("Lỗi khi tải chi tiết:", error); - } finally { - setLoadingContent(false); - } - }; - const handleUpdateStatus = async (status: "APPROVED" | "REJECTED") => { if (!application) return; - if (status === "REJECTED" && !reviewNote.trim()) { - Swal.fire( - "Cảnh báo", - "Vui lòng nhập lý do từ chối vào ô Ghi chú!", - "warning", - ); + if (!reviewNote.trim()) { + textareaRef.current?.focus(); return; } try { setIsSubmitting(true); - const payload = { - status: status, + await apiUpdateApplicationStatus(application.id, { + status, review_note: reviewNote, - }; - // console.log("Payload gửi lên API:", payload, "Application ID:", application.id); - await apiUpdateApplicationStatus(application.id, payload); + }); - Swal.fire( - "Thành công!", - `Hồ sơ đã được ${status === "APPROVED" ? "Phê duyệt" : "Từ chối"}.`, - "success", - ); + Swal.fire("Thành công!", "Trạng thái hồ sơ đã được cập nhật.", "success"); onRefresh(); onClose(); } catch (error) { - console.error("Lỗi cập nhật trạng thái:", error); - Swal.fire("Lỗi", "Không thể cập nhật trạng thái lúc này.", "error"); + Swal.fire("Lỗi", "Không thể cập nhật trạng thái.", "error"); } finally { setIsSubmitting(false); } @@ -106,40 +59,18 @@ export default function ApplicationDetailModal({ if (!isOpen || !application) return null; - const handleOpenFile = (media: any) => { - if (!media.url) { - Swal.fire("Lỗi", "Không tìm thấy đường dẫn file", "error"); - return; - } - - const isImage = media.url.match(/\.(jpeg|jpg|gif|png)$/i); - const isPdf = media.url.match(/\.(pdf)$/i); - - if (isImage || isPdf) { - window.open(media.url, "_blank"); - } else { - const link = document.createElement("a"); - link.href = media.url; - link.download = media.original_name || "download"; - document.body.appendChild(link); - link.click(); - document.body.removeChild(link); - } - }; - - // console.log("ApplicationDetailModal:", application); + const userData = application.user || {}; + const mediaList = application.media || []; return ( -
-
+
+
{/* HEADER */}
-

- Chi tiết yêu cầu nâng cấp -

+

Chi tiết yêu cầu nâng cấp

*/} - -
- ); - })} -
- ) : ( -

- Không có tệp đính kèm nào. -

- )} -
- - {/* KHỐI 4: GHI CHÚ ADMIN */} -
-

- Ghi chú duyệt hồ sơ -

-