avatar update and manage user table
This commit is contained in:
3
api.ts
3
api.ts
@@ -17,5 +17,8 @@ export const API = {
|
|||||||
VERIFYOTP: `${API_URL_ROOT}/auth/token/verify`,
|
VERIFYOTP: `${API_URL_ROOT}/auth/token/verify`,
|
||||||
REFRESH: `${API_URL_ROOT}/auth/refresh`,
|
REFRESH: `${API_URL_ROOT}/auth/refresh`,
|
||||||
GOOGLE_LOGIN: `${API_URL_ROOT}/auth/google/login`
|
GOOGLE_LOGIN: `${API_URL_ROOT}/auth/google/login`
|
||||||
|
},
|
||||||
|
Admin:{
|
||||||
|
GET_LIST_USERS: `${API_URL_ROOT}/users`,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -10,6 +10,12 @@ const nextConfig: NextConfig = {
|
|||||||
port: '',
|
port: '',
|
||||||
pathname: '/**',
|
pathname: '/**',
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
protocol: 'https',
|
||||||
|
hostname: 'cdn.kain.id.vn',
|
||||||
|
port: '',
|
||||||
|
pathname: '/**',
|
||||||
|
},
|
||||||
],
|
],
|
||||||
},
|
},
|
||||||
|
|
||||||
|
|||||||
@@ -15,11 +15,11 @@ export default function BasicTables() {
|
|||||||
return (
|
return (
|
||||||
<div>
|
<div>
|
||||||
<PageBreadcrumb pageTitle="Basic Table" />
|
<PageBreadcrumb pageTitle="Basic Table" />
|
||||||
<div className="space-y-6">
|
{/* <div className="space-y-6">
|
||||||
<ComponentCard title="Basic Table 1">
|
<ComponentCard title="Basic Table 1">
|
||||||
<BasicTableOne />
|
<BasicTableOne />
|
||||||
</ComponentCard>
|
</ComponentCard>
|
||||||
</div>
|
</div> */}
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|||||||
111
src/app/(admin)/(others-pages)/(tables)/user-table/page.tsx
Normal file
111
src/app/(admin)/(others-pages)/(tables)/user-table/page.tsx
Normal file
@@ -0,0 +1,111 @@
|
|||||||
|
"use client";
|
||||||
|
import ComponentCard from "@/components/common/ComponentCard";
|
||||||
|
import PageBreadcrumb from "@/components/common/PageBreadCrumb";
|
||||||
|
import BasicTableOne from "@/components/tables/BasicTableOne";
|
||||||
|
import { fullDataUser, getUserDto } from "@/interface/admin";
|
||||||
|
import { apiGetListUser } from "@/service/adminService";
|
||||||
|
import { useEffect, useState } from "react";
|
||||||
|
|
||||||
|
// Trích xuất type sort cho dễ tái sử dụng
|
||||||
|
export type SortColumn = "created_at" | "updated_at" | "display_name" | "email";
|
||||||
|
|
||||||
|
export default function UserTable() {
|
||||||
|
const [users, setUsers] = useState<fullDataUser[]>([]);
|
||||||
|
const [loading, setLoading] = useState<boolean>(true);
|
||||||
|
|
||||||
|
const [searchTerm, setSearchTerm] = useState<string>("");
|
||||||
|
const [debouncedSearch, setDebouncedSearch] = useState<string>("");
|
||||||
|
|
||||||
|
const [sortBy, setSortBy] = useState<SortColumn | undefined>(undefined);
|
||||||
|
const [sortOrder, setSortOrder] = useState<"asc" | "desc">("asc");
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
const handler = setTimeout(() => {
|
||||||
|
setDebouncedSearch(searchTerm);
|
||||||
|
}, 500);
|
||||||
|
|
||||||
|
return () => clearTimeout(handler);
|
||||||
|
}, [searchTerm]);
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
const fetchUser = async () => {
|
||||||
|
setLoading(true);
|
||||||
|
try {
|
||||||
|
const payload: getUserDto = { limit: 10 };
|
||||||
|
if (debouncedSearch) payload.search = debouncedSearch;
|
||||||
|
if (sortBy) {
|
||||||
|
payload.sort = sortBy;
|
||||||
|
payload.order = sortOrder;
|
||||||
|
}
|
||||||
|
|
||||||
|
const response = await apiGetListUser(payload);
|
||||||
|
// console.log("Request Payload:", payload);
|
||||||
|
// console.log("API Response:", response);
|
||||||
|
if (response && response.data) {
|
||||||
|
setUsers(response.data);
|
||||||
|
} else {
|
||||||
|
setUsers([]);
|
||||||
|
}
|
||||||
|
} catch (err) {
|
||||||
|
console.error("Lỗi:", err);
|
||||||
|
setUsers([]);
|
||||||
|
} finally {
|
||||||
|
setLoading(false);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
fetchUser();
|
||||||
|
}, [debouncedSearch, sortBy, sortOrder]);
|
||||||
|
|
||||||
|
const handleSort = (column: SortColumn) => {
|
||||||
|
if (sortBy === column) {
|
||||||
|
setSortOrder(sortOrder === "asc" ? "desc" : "asc");
|
||||||
|
} else {
|
||||||
|
setSortBy(column);
|
||||||
|
setSortOrder("desc");
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
return (
|
||||||
|
<div>
|
||||||
|
<PageBreadcrumb pageTitle="Users Table" />
|
||||||
|
<div className="space-y-6">
|
||||||
|
<ComponentCard title="Danh sách người dùng">
|
||||||
|
{/* Ô nhập tìm kiếm */}
|
||||||
|
<div className="mb-4">
|
||||||
|
<input
|
||||||
|
type="text"
|
||||||
|
placeholder="Tìm kiếm người dùng..."
|
||||||
|
value={searchTerm}
|
||||||
|
onChange={(e) => setSearchTerm(e.target.value)}
|
||||||
|
className="w-full sm:w-1/3 px-4 py-2 text-sm border border-gray-300 rounded-lg focus:outline-none focus:ring-2 focus:ring-brand-500 focus:border-transparent dark:bg-gray-800 dark:border-gray-700 dark:text-white"
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div className="relative min-h-[400px]">
|
||||||
|
{loading && (
|
||||||
|
<div className="absolute inset-0 z-10 flex items-center justify-center bg-white/50 dark:bg-gray-900/50 backdrop-blur-[1px] transition-opacity">
|
||||||
|
<div className="flex flex-col items-center">
|
||||||
|
{/* Spinner xoay tròn */}
|
||||||
|
<div className="w-10 h-10 border-4 border-gray-200 border-t-brand-500 rounded-full animate-spin"></div>
|
||||||
|
<p className="mt-2 text-sm font-medium text-gray-500">
|
||||||
|
Đang tải...
|
||||||
|
</p>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
)}
|
||||||
|
|
||||||
|
{/* Bảng vẫn hiển thị ở dưới (mờ đi) hoặc ẩn tùy bạn,
|
||||||
|
nhưng truyền data vào để tránh giật lag layout */}
|
||||||
|
<BasicTableOne
|
||||||
|
data={users}
|
||||||
|
onSort={handleSort}
|
||||||
|
sortBy={sortBy}
|
||||||
|
sortOrder={sortOrder}
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
</ComponentCard>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
}
|
||||||
@@ -70,6 +70,7 @@ export default function SignInForm() {
|
|||||||
if (res.status === true) {
|
if (res.status === true) {
|
||||||
toast.success("Đăng nhập thành công!");
|
toast.success("Đăng nhập thành công!");
|
||||||
const data = await apiGetCurrentUser();
|
const data = await apiGetCurrentUser();
|
||||||
|
|
||||||
console.log("Current User Data:", data);
|
console.log("Current User Data:", data);
|
||||||
if (data?.data) {
|
if (data?.data) {
|
||||||
dispatch(setUserData(data.data));
|
dispatch(setUserData(data.data));
|
||||||
|
|||||||
@@ -1,13 +1,17 @@
|
|||||||
"use client";
|
"use client";
|
||||||
import Image from "next/image";
|
import Image from "next/image";
|
||||||
import Link from "next/link";
|
import Link from "next/link";
|
||||||
import React, { useState } from "react";
|
import React, { useEffect, useState } from "react";
|
||||||
import { Dropdown } from "../ui/dropdown/Dropdown";
|
import { Dropdown } from "../ui/dropdown/Dropdown";
|
||||||
import { DropdownItem } from "../ui/dropdown/DropdownItem";
|
import { DropdownItem } from "../ui/dropdown/DropdownItem";
|
||||||
|
import { fullDataUser } from "@/interface/admin";
|
||||||
|
import { UserMetaCardProps } from "@/interface/user";
|
||||||
|
import { apiGetCurrentUser } from "@/service/auth";
|
||||||
|
|
||||||
export default function UserDropdown() {
|
export default function UserDropdown() {
|
||||||
const [isOpen, setIsOpen] = useState(false);
|
const [isOpen, setIsOpen] = useState(false);
|
||||||
|
const [user, setUser] = useState<UserMetaCardProps | null>(null);
|
||||||
|
const [loading, setLoading] = useState<boolean>(true);
|
||||||
function toggleDropdown(e: React.MouseEvent<HTMLButtonElement, MouseEvent>) {
|
function toggleDropdown(e: React.MouseEvent<HTMLButtonElement, MouseEvent>) {
|
||||||
e.stopPropagation();
|
e.stopPropagation();
|
||||||
setIsOpen((prev) => !prev);
|
setIsOpen((prev) => !prev);
|
||||||
@@ -16,6 +20,23 @@ function toggleDropdown(e: React.MouseEvent<HTMLButtonElement, MouseEvent>) {
|
|||||||
function closeDropdown() {
|
function closeDropdown() {
|
||||||
setIsOpen(false);
|
setIsOpen(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
const fetchUser = async () => {
|
||||||
|
try {
|
||||||
|
const userData = await apiGetCurrentUser();
|
||||||
|
console.log("User data in dropdown:", userData);
|
||||||
|
setUser(userData);
|
||||||
|
} catch (err) {
|
||||||
|
console.error("Lỗi:", err);
|
||||||
|
} finally {
|
||||||
|
setLoading(false);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
fetchUser();
|
||||||
|
}, []);
|
||||||
|
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className="relative">
|
<div className="relative">
|
||||||
<button
|
<button
|
||||||
@@ -26,12 +47,14 @@ function toggleDropdown(e: React.MouseEvent<HTMLButtonElement, MouseEvent>) {
|
|||||||
<Image
|
<Image
|
||||||
width={44}
|
width={44}
|
||||||
height={44}
|
height={44}
|
||||||
src="/images/user/owner.jpg"
|
src={user?.data?.profile?.avatar_url || "/images/no-images.jpg"}
|
||||||
alt="User"
|
alt="User"
|
||||||
/>
|
/>
|
||||||
</span>
|
</span>
|
||||||
|
|
||||||
<span className="block mr-1 font-medium text-theme-sm">Musharof</span>
|
<span className="block mr-1 font-medium text-theme-sm">
|
||||||
|
{user?.data?.profile?.display_name || "User"}
|
||||||
|
</span>
|
||||||
|
|
||||||
<svg
|
<svg
|
||||||
className={`stroke-gray-500 dark:stroke-gray-400 transition-transform duration-200 ${
|
className={`stroke-gray-500 dark:stroke-gray-400 transition-transform duration-200 ${
|
||||||
@@ -60,10 +83,10 @@ function toggleDropdown(e: React.MouseEvent<HTMLButtonElement, MouseEvent>) {
|
|||||||
>
|
>
|
||||||
<div>
|
<div>
|
||||||
<span className="block font-medium text-gray-700 text-theme-sm dark:text-gray-400">
|
<span className="block font-medium text-gray-700 text-theme-sm dark:text-gray-400">
|
||||||
Musharof Chowdhury
|
{user?.data?.profile?.display_name || "User"}
|
||||||
</span>
|
</span>
|
||||||
<span className="mt-0.5 block text-theme-xs text-gray-500 dark:text-gray-400">
|
<span className="mt-0.5 block text-theme-xs text-gray-500 dark:text-gray-400">
|
||||||
randomuser@pimjo.com
|
{user?.data?.email || "email"}
|
||||||
</span>
|
</span>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
@@ -93,7 +116,7 @@ function toggleDropdown(e: React.MouseEvent<HTMLButtonElement, MouseEvent>) {
|
|||||||
Edit profile
|
Edit profile
|
||||||
</DropdownItem>
|
</DropdownItem>
|
||||||
</li>
|
</li>
|
||||||
<li>
|
{/* <li>
|
||||||
<DropdownItem
|
<DropdownItem
|
||||||
onItemClick={closeDropdown}
|
onItemClick={closeDropdown}
|
||||||
tag="a"
|
tag="a"
|
||||||
@@ -117,7 +140,7 @@ function toggleDropdown(e: React.MouseEvent<HTMLButtonElement, MouseEvent>) {
|
|||||||
</svg>
|
</svg>
|
||||||
Account settings
|
Account settings
|
||||||
</DropdownItem>
|
</DropdownItem>
|
||||||
</li>
|
</li> */}
|
||||||
<li>
|
<li>
|
||||||
<DropdownItem
|
<DropdownItem
|
||||||
onItemClick={closeDropdown}
|
onItemClick={closeDropdown}
|
||||||
|
|||||||
@@ -1,3 +1,4 @@
|
|||||||
|
"use client";
|
||||||
import React from "react";
|
import React from "react";
|
||||||
import {
|
import {
|
||||||
Table,
|
Table,
|
||||||
@@ -6,112 +7,54 @@ import {
|
|||||||
TableHeader,
|
TableHeader,
|
||||||
TableRow,
|
TableRow,
|
||||||
} from "../ui/table";
|
} from "../ui/table";
|
||||||
|
|
||||||
import Badge from "../ui/badge/Badge";
|
import Badge from "../ui/badge/Badge";
|
||||||
import Image from "next/image";
|
import Image from "next/image";
|
||||||
|
import { fullDataUser } from "@/interface/admin";
|
||||||
|
|
||||||
interface Order {
|
// Kiểu dữ liệu sort
|
||||||
id: number;
|
type SortColumn = "created_at" | "updated_at" | "display_name" | "email";
|
||||||
user: {
|
|
||||||
image: string;
|
// Định nghĩa kiểu dữ liệu cho props truyền từ cha xuống
|
||||||
name: string;
|
interface BasicTableOneProps {
|
||||||
role: string;
|
data: fullDataUser[];
|
||||||
};
|
onSort: (column: SortColumn) => void;
|
||||||
projectName: string;
|
sortBy?: SortColumn;
|
||||||
team: {
|
sortOrder?: "asc" | "desc";
|
||||||
images: string[];
|
|
||||||
};
|
|
||||||
status: string;
|
|
||||||
budget: string;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Define the table data using the interface
|
export default function BasicTableOne({ data, onSort, sortBy, sortOrder }: BasicTableOneProps) {
|
||||||
const tableData: Order[] = [
|
// Hàm phụ trợ để format lại ngày tháng năm
|
||||||
{
|
const formatDate = (dateString: string) => {
|
||||||
id: 1,
|
if (!dateString) return "";
|
||||||
user: {
|
const date = new Date(dateString);
|
||||||
image: "/images/user/user-17.jpg",
|
return date.toLocaleDateString("en-GB", {
|
||||||
name: "Lindsey Curtis",
|
day: "2-digit",
|
||||||
role: "Web Designer",
|
month: "short",
|
||||||
},
|
year: "numeric",
|
||||||
projectName: "Agency Website",
|
});
|
||||||
team: {
|
};
|
||||||
images: [
|
|
||||||
"/images/user/user-22.jpg",
|
// Component phụ trợ để vẽ icon mũi tên Sort
|
||||||
"/images/user/user-23.jpg",
|
const SortIcon = ({ column }: { column: SortColumn }) => {
|
||||||
"/images/user/user-24.jpg",
|
const isActive = sortBy === column;
|
||||||
],
|
return (
|
||||||
},
|
<div className="flex flex-col ml-2 opacity-50 cursor-pointer hover:opacity-100">
|
||||||
budget: "3.9K",
|
<svg
|
||||||
status: "Active",
|
className={`w-3 h-3 ${isActive && sortOrder === "asc" ? "text-blue-600 dark:text-blue-400 opacity-100" : "text-gray-400"}`}
|
||||||
},
|
fill="none" stroke="currentColor" viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg"
|
||||||
{
|
>
|
||||||
id: 2,
|
<path strokeLinecap="round" strokeLinejoin="round" strokeWidth={3} d="M5 15l7-7 7 7" />
|
||||||
user: {
|
</svg>
|
||||||
image: "/images/user/user-18.jpg",
|
<svg
|
||||||
name: "Kaiya George",
|
className={`w-3 h-3 -mt-1 ${isActive && sortOrder === "desc" ? "text-blue-600 dark:text-blue-400 opacity-100" : "text-gray-400"}`}
|
||||||
role: "Project Manager",
|
fill="none" stroke="currentColor" viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg"
|
||||||
},
|
>
|
||||||
projectName: "Technology",
|
<path strokeLinecap="round" strokeLinejoin="round" strokeWidth={3} d="M19 9l-7 7-7-7" />
|
||||||
team: {
|
</svg>
|
||||||
images: ["/images/user/user-25.jpg", "/images/user/user-26.jpg"],
|
</div>
|
||||||
},
|
);
|
||||||
budget: "24.9K",
|
};
|
||||||
status: "Pending",
|
|
||||||
},
|
|
||||||
{
|
|
||||||
id: 3,
|
|
||||||
user: {
|
|
||||||
image: "/images/user/user-17.jpg",
|
|
||||||
name: "Zain Geidt",
|
|
||||||
role: "Content Writing",
|
|
||||||
},
|
|
||||||
projectName: "Blog Writing",
|
|
||||||
team: {
|
|
||||||
images: ["/images/user/user-27.jpg"],
|
|
||||||
},
|
|
||||||
budget: "12.7K",
|
|
||||||
status: "Active",
|
|
||||||
},
|
|
||||||
{
|
|
||||||
id: 4,
|
|
||||||
user: {
|
|
||||||
image: "/images/user/user-20.jpg",
|
|
||||||
name: "Abram Schleifer",
|
|
||||||
role: "Digital Marketer",
|
|
||||||
},
|
|
||||||
projectName: "Social Media",
|
|
||||||
team: {
|
|
||||||
images: [
|
|
||||||
"/images/user/user-28.jpg",
|
|
||||||
"/images/user/user-29.jpg",
|
|
||||||
"/images/user/user-30.jpg",
|
|
||||||
],
|
|
||||||
},
|
|
||||||
budget: "2.8K",
|
|
||||||
status: "Cancel",
|
|
||||||
},
|
|
||||||
{
|
|
||||||
id: 5,
|
|
||||||
user: {
|
|
||||||
image: "/images/user/user-21.jpg",
|
|
||||||
name: "Carla George",
|
|
||||||
role: "Front-end Developer",
|
|
||||||
},
|
|
||||||
projectName: "Website",
|
|
||||||
team: {
|
|
||||||
images: [
|
|
||||||
"/images/user/user-31.jpg",
|
|
||||||
"/images/user/user-32.jpg",
|
|
||||||
"/images/user/user-33.jpg",
|
|
||||||
],
|
|
||||||
},
|
|
||||||
budget: "4.5K",
|
|
||||||
status: "Active",
|
|
||||||
},
|
|
||||||
];
|
|
||||||
|
|
||||||
export default function BasicTableOne() {
|
|
||||||
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-white/[0.05] dark:bg-white/[0.03]">
|
||||||
<div className="max-w-full overflow-x-auto">
|
<div className="max-w-full overflow-x-auto">
|
||||||
@@ -120,101 +63,116 @@ export default function BasicTableOne() {
|
|||||||
{/* Table Header */}
|
{/* Table Header */}
|
||||||
<TableHeader className="border-b border-gray-100 dark:border-white/[0.05]">
|
<TableHeader className="border-b border-gray-100 dark:border-white/[0.05]">
|
||||||
<TableRow>
|
<TableRow>
|
||||||
<TableCell
|
<TableCell isHeader className="px-5 py-3 font-medium text-gray-500 text-start text-theme-xs dark:text-gray-400">
|
||||||
isHeader
|
<div className="flex items-center cursor-pointer" onClick={() => onSort("display_name")}>
|
||||||
className="px-5 py-3 font-medium text-gray-500 text-start text-theme-xs dark:text-gray-400"
|
Người dùng
|
||||||
>
|
<SortIcon column="display_name" />
|
||||||
User
|
</div>
|
||||||
</TableCell>
|
</TableCell>
|
||||||
<TableCell
|
|
||||||
isHeader
|
<TableCell isHeader className="px-5 py-3 font-medium text-gray-500 text-start text-theme-xs dark:text-gray-400">
|
||||||
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" onClick={() => onSort("email")}>
|
||||||
>
|
Email
|
||||||
Project Name
|
<SortIcon column="email" />
|
||||||
|
</div>
|
||||||
</TableCell>
|
</TableCell>
|
||||||
<TableCell
|
|
||||||
isHeader
|
<TableCell isHeader className="px-5 py-3 font-medium text-gray-500 text-start text-theme-xs dark:text-gray-400">
|
||||||
className="px-5 py-3 font-medium text-gray-500 text-start text-theme-xs dark:text-gray-400"
|
Vai trò (Role)
|
||||||
>
|
|
||||||
Team
|
|
||||||
</TableCell>
|
</TableCell>
|
||||||
<TableCell
|
|
||||||
isHeader
|
<TableCell isHeader className="px-5 py-3 font-medium text-gray-500 text-start text-theme-xs dark:text-gray-400">
|
||||||
className="px-5 py-3 font-medium text-gray-500 text-start text-theme-xs dark:text-gray-400"
|
Trạng thái
|
||||||
>
|
|
||||||
Status
|
|
||||||
</TableCell>
|
</TableCell>
|
||||||
<TableCell
|
|
||||||
isHeader
|
<TableCell isHeader className="px-5 py-3 font-medium text-gray-500 text-start text-theme-xs dark:text-gray-400">
|
||||||
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" onClick={() => onSort("created_at")}>
|
||||||
>
|
Ngày tham gia
|
||||||
Budget
|
<SortIcon column="created_at" />
|
||||||
|
</div>
|
||||||
|
</TableCell>
|
||||||
|
|
||||||
|
{/* Thêm cột Ngày 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">
|
||||||
|
<div className="flex items-center cursor-pointer" onClick={() => onSort("updated_at")}>
|
||||||
|
Cập nhật lần cuối
|
||||||
|
<SortIcon column="updated_at" />
|
||||||
|
</div>
|
||||||
</TableCell>
|
</TableCell>
|
||||||
</TableRow>
|
</TableRow>
|
||||||
</TableHeader>
|
</TableHeader>
|
||||||
|
|
||||||
{/* Table Body */}
|
{/* Table Body */}
|
||||||
<TableBody className="divide-y divide-gray-100 dark:divide-white/[0.05]">
|
<TableBody className="divide-y divide-gray-100 dark:divide-white/[0.05]">
|
||||||
{tableData.map((order) => (
|
{data.map((user) => (
|
||||||
<TableRow key={order.id}>
|
<TableRow key={user.id}>
|
||||||
|
|
||||||
|
{/* Cột User */}
|
||||||
<TableCell className="px-5 py-4 sm:px-6 text-start">
|
<TableCell className="px-5 py-4 sm:px-6 text-start">
|
||||||
<div className="flex items-center gap-3">
|
<div className="flex items-center gap-3">
|
||||||
<div className="w-10 h-10 overflow-hidden rounded-full">
|
<div className="w-10 h-10 overflow-hidden rounded-full flex-shrink-0 bg-gray-100 dark:bg-gray-800 flex items-center justify-center">
|
||||||
|
{user.profile?.avatar_url ? (
|
||||||
<Image
|
<Image
|
||||||
width={40}
|
width={40}
|
||||||
height={40}
|
height={40}
|
||||||
src={order.user.image}
|
src={user.profile.avatar_url}
|
||||||
alt={order.user.name}
|
alt={user.profile.display_name || "Avatar"}
|
||||||
|
className="object-cover w-full h-full"
|
||||||
/>
|
/>
|
||||||
|
) : (
|
||||||
|
<span className="font-semibold text-gray-500 uppercase">
|
||||||
|
{user.profile?.display_name?.charAt(0) || "U"}
|
||||||
|
</span>
|
||||||
|
)}
|
||||||
</div>
|
</div>
|
||||||
<div>
|
<div>
|
||||||
<span className="block font-medium text-gray-800 text-theme-sm dark:text-white/90">
|
<span className="block font-medium text-gray-800 text-theme-sm dark:text-white/90">
|
||||||
{order.user.name}
|
{user.profile?.display_name || "Chưa cập nhật tên"}
|
||||||
</span>
|
</span>
|
||||||
|
{user.profile?.phone && (
|
||||||
<span className="block text-gray-500 text-theme-xs dark:text-gray-400">
|
<span className="block text-gray-500 text-theme-xs dark:text-gray-400">
|
||||||
{order.user.role}
|
{user.profile.phone}
|
||||||
</span>
|
</span>
|
||||||
|
)}
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</TableCell>
|
</TableCell>
|
||||||
|
|
||||||
|
{/* Cột Email */}
|
||||||
<TableCell className="px-4 py-3 text-gray-500 text-start text-theme-sm dark:text-gray-400">
|
<TableCell className="px-4 py-3 text-gray-500 text-start text-theme-sm dark:text-gray-400">
|
||||||
{order.projectName}
|
{user.email}
|
||||||
</TableCell>
|
</TableCell>
|
||||||
|
|
||||||
|
{/* Cột Roles */}
|
||||||
<TableCell className="px-4 py-3 text-gray-500 text-start text-theme-sm dark:text-gray-400">
|
<TableCell className="px-4 py-3 text-gray-500 text-start text-theme-sm dark:text-gray-400">
|
||||||
<div className="flex -space-x-2">
|
{user.roles && user.roles.length > 0 ? (
|
||||||
{order.team.images.map((teamImage, index) => (
|
user.roles.map((role: any) => (
|
||||||
<div
|
<span key={role.id} className="block">
|
||||||
key={index}
|
{role.name}
|
||||||
className="w-6 h-6 overflow-hidden border-2 border-white rounded-full dark:border-gray-900"
|
</span>
|
||||||
>
|
))
|
||||||
<Image
|
) : (
|
||||||
width={24}
|
<span>Chưa cấp quyền</span>
|
||||||
height={24}
|
)}
|
||||||
src={teamImage}
|
|
||||||
alt={`Team member ${index + 1}`}
|
|
||||||
className="w-full"
|
|
||||||
/>
|
|
||||||
</div>
|
|
||||||
))}
|
|
||||||
</div>
|
|
||||||
</TableCell>
|
</TableCell>
|
||||||
|
|
||||||
|
{/* Cột Trạng thái */}
|
||||||
<TableCell className="px-4 py-3 text-gray-500 text-start text-theme-sm dark:text-gray-400">
|
<TableCell className="px-4 py-3 text-gray-500 text-start text-theme-sm dark:text-gray-400">
|
||||||
<Badge
|
<Badge size="sm" color={user.is_deleted ? "error" : "success"}>
|
||||||
size="sm"
|
{user.is_deleted ? "Bị khóa" : "Hoạt động"}
|
||||||
color={
|
|
||||||
order.status === "Active"
|
|
||||||
? "success"
|
|
||||||
: order.status === "Pending"
|
|
||||||
? "warning"
|
|
||||||
: "error"
|
|
||||||
}
|
|
||||||
>
|
|
||||||
{order.status}
|
|
||||||
</Badge>
|
</Badge>
|
||||||
</TableCell>
|
</TableCell>
|
||||||
|
|
||||||
|
{/* Cột Ngày tham gia */}
|
||||||
<TableCell className="px-4 py-3 text-gray-500 text-theme-sm dark:text-gray-400">
|
<TableCell className="px-4 py-3 text-gray-500 text-theme-sm dark:text-gray-400">
|
||||||
{order.budget}
|
{formatDate(user.created_at)}
|
||||||
</TableCell>
|
</TableCell>
|
||||||
|
|
||||||
|
{/* Cột Ngày cập nhật */}
|
||||||
|
<TableCell className="px-4 py-3 text-gray-500 text-theme-sm dark:text-gray-400">
|
||||||
|
{formatDate(user.updated_at)}
|
||||||
|
</TableCell>
|
||||||
|
|
||||||
</TableRow>
|
</TableRow>
|
||||||
))}
|
))}
|
||||||
</TableBody>
|
</TableBody>
|
||||||
|
|||||||
26
src/interface/admin.ts
Normal file
26
src/interface/admin.ts
Normal file
@@ -0,0 +1,26 @@
|
|||||||
|
import { Profile, UserRole } from "@/interface/user";
|
||||||
|
|
||||||
|
export interface getUserDto {
|
||||||
|
cursor?: string;
|
||||||
|
limit: number;
|
||||||
|
is_deleted?: boolean;
|
||||||
|
order?: "asc" | "desc";
|
||||||
|
role_ids?: string[];
|
||||||
|
search?: string;
|
||||||
|
sort?: "created_at" | "updated_at" | "display_name" | "email";
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface fullDataUser {
|
||||||
|
auth_provider: string;
|
||||||
|
id: string;
|
||||||
|
email: string;
|
||||||
|
google_id: string;
|
||||||
|
display_name: string;
|
||||||
|
created_at: string;
|
||||||
|
updated_at: string;
|
||||||
|
is_deleted: boolean;
|
||||||
|
password_hash: string;
|
||||||
|
roles: UserRole[];
|
||||||
|
profile: Profile;
|
||||||
|
token_version: number;
|
||||||
|
}
|
||||||
@@ -51,7 +51,10 @@ const navItems: NavItem[] = [
|
|||||||
{
|
{
|
||||||
name: "Tables",
|
name: "Tables",
|
||||||
icon: <TableIcon />,
|
icon: <TableIcon />,
|
||||||
subItems: [{ name: "Basic Tables", path: "/basic-tables", pro: false }],
|
subItems: [
|
||||||
|
{ name: "Basic Tables", path: "/basic-tables", pro: false },
|
||||||
|
{ name: "User Tables", path: "/user-table", pro: false },
|
||||||
|
],
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "Pages",
|
name: "Pages",
|
||||||
@@ -100,7 +103,7 @@ const AppSidebar: React.FC = () => {
|
|||||||
|
|
||||||
const renderMenuItems = (
|
const renderMenuItems = (
|
||||||
navItems: NavItem[],
|
navItems: NavItem[],
|
||||||
menuType: "main" | "others"
|
menuType: "main" | "others",
|
||||||
) => (
|
) => (
|
||||||
<ul className="flex flex-col gap-4">
|
<ul className="flex flex-col gap-4">
|
||||||
{navItems.map((nav, index) => (
|
{navItems.map((nav, index) => (
|
||||||
@@ -229,7 +232,7 @@ const AppSidebar: React.FC = () => {
|
|||||||
index: number;
|
index: number;
|
||||||
} | null>(null);
|
} | null>(null);
|
||||||
const [subMenuHeight, setSubMenuHeight] = useState<Record<string, number>>(
|
const [subMenuHeight, setSubMenuHeight] = useState<Record<string, number>>(
|
||||||
{}
|
{},
|
||||||
);
|
);
|
||||||
const subMenuRefs = useRef<Record<string, HTMLDivElement | null>>({});
|
const subMenuRefs = useRef<Record<string, HTMLDivElement | null>>({});
|
||||||
|
|
||||||
|
|||||||
10
src/service/adminService.ts
Normal file
10
src/service/adminService.ts
Normal file
@@ -0,0 +1,10 @@
|
|||||||
|
import api from "@/config/config";
|
||||||
|
import { API } from "../../api";
|
||||||
|
import { getUserDto } from "@/interface/admin";
|
||||||
|
|
||||||
|
export const apiGetListUser = async (payload: getUserDto) => {
|
||||||
|
const response = await api.get(API.Admin.GET_LIST_USERS, {
|
||||||
|
params: payload,
|
||||||
|
});
|
||||||
|
return response?.data;
|
||||||
|
};
|
||||||
Reference in New Issue
Block a user