diff --git a/src/App.jsx b/src/App.jsx index 706a9cf..edecd05 100644 --- a/src/App.jsx +++ b/src/App.jsx @@ -14,7 +14,7 @@ function App() { const [employee, setEmployee] = useState(null); const [searchTerm, setSearchTerm] = useState(''); const [page, setPage] = useState(1); - const [limit, setLimit] = useState(2); + const [limit, setLimit] = useState(5); const [totalPage, setTotalPage] = useState(1); const [allEmployeeData, setAllEmployeeData] = useState([]); @@ -86,8 +86,7 @@ function App() { } // เมื่อกดปุ่มเปลี่ยนหน้า - const handlePageChange = (value)=>{ - console.log(value); + const handlePageChange = (value, index, paginationArray)=>{ if(value === "«"){ setPage(1); } @@ -105,7 +104,9 @@ function App() { setPage(totalPage); } else if(value === "..."){ - if(page < totalPage){ + // หาว่าหน้าปัจจุบันอยู่ตรง index ไหนใน paginationArray เปรียบเทียบกับ index ของ "..." ที่กด + const currentIndex = paginationArray.findIndex(p => p === page); + if(index > currentIndex){ setPage(page + 1); } else{ diff --git a/src/api/employee.js b/src/api/employee.js index 13b148d..61c9f55 100644 --- a/src/api/employee.js +++ b/src/api/employee.js @@ -1,4 +1,4 @@ -const employees = [ +const employees = [ { id: 1, name: "Cy Ganderton", @@ -22,8 +22,312 @@ const employees = [ job: "Tax Accountant", department: "Desktop Support Department", active: false + }, + { + id: 4, + name: "Grace Lee", + mail: "grace.lee@example.com", + job: "Software Engineer", + department: "Data Analysis Department", + active: false + }, + { + id: 5, + name: "Frank Miller", + mail: "frank.miller@example.com", + job: "Project Manager", + department: "Data Analysis Department", + active: true + }, + { + id: 6, + name: "Alice Johnson", + mail: "alice.johnson@company.com", + job: "HR Specialist", + department: "HR Department", + active: false + }, + { + id: 7, + name: "Charlie Davis", + mail: "charlie.davis@business.com", + job: "Software Engineer", + department: "Data Analysis Department", + active: true + }, + { + id: 8, + name: "Emily Wilson", + mail: "emily.wilson@company.com", + job: "Marketing Coordinator", + department: "Marketing Department", + active: false + }, + { + id: 9, + name: "Henry Clark", + mail: "henry.clark@business.com", + job: "HR Specialist", + department: "HR Department", + active: true + }, + { + id: 10, + name: "Ivy Lewis", + mail: "ivy.lewis@example.com", + job: "Software Engineer", + department: "Engineering Department", + active: false + }, + { + id: 11, + name: "John Doe", + mail: "john.doe@company.com", + job: "Marketing Coordinator", + department: "Marketing Department", + active: true + }, + { + id: 12, + name: "Jane Smith", + mail: "jane.smith@business.com", + job: "Data Analyst", + department: "Data Analysis Department", + active: false + }, + { + id: 13, + name: "Alice Johnson", + mail: "alice.johnson@example.com", + job: "Project Manager", + department: "Project Management Department", + active: true + }, + { + id: 14, + name: "Bob Brown", + mail: "bob.brown@company.com", + job: "HR Specialist", + department: "HR Department", + active: false + }, + { + id: 15, + name: "Charlie Davis", + mail: "charlie.davis@business.com", + job: "Software Engineer", + department: "Data Analysis Department", + active: true + }, + { + id: 16, + name: "Emily Wilson", + mail: "emily.wilson@company.com", + job: "Marketing Coordinator", + department: "Marketing Department", + active: false + }, + { + id: 17, + name: "Frank Miller", + mail: "frank.miller@business.com", + job: "Project Manager", + department: "Project Management Department", + active: true + }, + { + id: 18, + name: "Grace Lee", + mail: "grace.lee@example.com", + job: "Data Analyst", + department: "Data Analysis Department", + active: false + }, + { + id: 19, + name: "Henry Clark", + mail: "henry.clark@company.com", + job: "Software Engineer", + department: "Engineering Department", + active: true + }, + { + id: 20, + name: "Ivy Lewis", + mail: "ivy.lewis@business.com", + job: "HR Specialist", + department: "HR Department", + active: false + }, + { + id: 21, + name: "John Doe", + mail: "john.doe@example.com", + job: "Marketing Coordinator", + department: "Marketing Department", + active: true + }, + { + id: 22, + name: "Jane Smith", + mail: "jane.smith@company.com", + job: "Data Analyst", + department: "Data Analysis Department", + active: false + }, + { + id: 23, + name: "Alice Johnson", + mail: "alice.johnson@business.com", + job: "Project Manager", + department: "Project Management Department", + active: true + }, + { + id: 24, + name: "Bob Brown", + mail: "bob.brown@example.com", + job: "HR Specialist", + department: "HR Department", + active: false + }, + { + id: 25, + name: "Charlie Davis", + mail: "charlie.davis@company.com", + job: "Software Engineer", + department: "Data Analysis Department", + active: true + }, + { + id: 26, + name: "Emily Wilson", + mail: "emily.wilson@business.com", + job: "Marketing Coordinator", + department: "Marketing Department", + active: false + }, + { + id: 27, + name: "Frank Miller", + mail: "frank.miller@company.com", + job: "Project Manager", + department: "Project Management Department", + active: true + }, + { + id: 28, + name: "Grace Lee", + mail: "grace.lee@business.com", + job: "Data Analyst", + department: "Data Analysis Department", + active: false + }, + { + id: 29, + name: "Henry Clark", + mail: "henry.clark@example.com", + job: "Software Engineer", + department: "Engineering Department", + active: true + }, + { + id: 30, + name: "Ivy Lewis", + mail: "ivy.lewis@company.com", + job: "HR Specialist", + department: "HR Department", + active: false + }, + { + id: 31, + name: "John Doe", + mail: "john.doe@business.com", + job: "Marketing Coordinator", + department: "Marketing Department", + active: true + }, + { + id: 32, + name: "Jane Smith", + mail: "jane.smith@example.com", + job: "Data Analyst", + department: "Data Analysis Department", + active: false + }, + { + id: 33, + name: "Alice Johnson", + mail: "alice.johnson@company.com", + job: "Project Manager", + department: "Project Management Department", + active: true + }, + { + id: 34, + name: "Bob Brown", + mail: "bob.brown@business.com", + job: "HR Specialist", + department: "HR Department", + active: false + }, + { + id: 35, + name: "Charlie Davis", + mail: "charlie.davis@example.com", + job: "Software Engineer", + department: "Data Analysis Department", + active: true + }, + { + id: 36, + name: "Emily Wilson", + mail: "emily.wilson@company.com", + job: "Marketing Coordinator", + department: "Marketing Department", + active: false + }, + { + id: 37, + name: "Frank Miller", + mail: "frank.miller@business.com", + job: "Project Manager", + department: "Project Management Department", + active: true + }, + { + id: 38, + name: "Grace Lee", + mail: "grace.lee@company.com", + job: "Data Analyst", + department: "Data Analysis Department", + active: false + }, + { + id: 39, + name: "Henry Clark", + mail: "henry.clark@business.com", + job: "Software Engineer", + department: "Engineering Department", + active: true + }, + { + id: 40, + name: "Ivy Lewis", + mail: "ivy.lewis@example.com", + job: "HR Specialist", + department: "HR Department", + active: false + }, + { + id: 41, + name: "John Doe", + mail: "john.doe@company.com", + job: "Marketing Coordinator", + department: "Marketing Department", + active: true } -] +]; export const getEmployees = ()=>{ return employees; diff --git a/src/components/Navbar.jsx b/src/components/Navbar.jsx index 2677e07..0972ff9 100644 --- a/src/components/Navbar.jsx +++ b/src/components/Navbar.jsx @@ -1,24 +1,49 @@ +import {useEffect, useState} from "react"; + export default function Navbar ({onOpen, setSearchTerm}){ + // ใช้ state สำหรับเก็บ theme และให้ React จัดการ render ใหม่ + const [theme, setTheme] = useState("light"); + + useEffect(() => { + document.documentElement.setAttribute("data-theme", theme); + }, [theme]); const handleSearch = (e) =>{ setSearchTerm(e.target.value); } + const handleSwitchTheme = () => { + setTheme(prev=>(prev === "light" ? "dark" : "light")); + } + return(<> -
+
- CRUD APP + CRUD APP
-
+
-
+
+ {/* Mobile search (visible only on small screens) */} +
+ +
Add + {theme === "dark" ? "🌞" : "🌙"} +
) diff --git a/src/components/Pagination.jsx b/src/components/Pagination.jsx index efbb3c3..78fba11 100644 --- a/src/components/Pagination.jsx +++ b/src/components/Pagination.jsx @@ -9,13 +9,14 @@ export default function Pagination({totalPage, page, limit, sibling, setPage}){
- {paginationArray.map(pageNumber=> { + {paginationArray.map((pageNumber, index)=> { + const key = `${pageNumber}-${index}`; if(pageNumber === page){ return ( ) @@ -23,9 +24,9 @@ export default function Pagination({totalPage, page, limit, sibling, setPage}){ else{ return( ) diff --git a/src/components/Table.jsx b/src/components/Table.jsx index 1003fb8..4046ef9 100644 --- a/src/components/Table.jsx +++ b/src/components/Table.jsx @@ -38,8 +38,10 @@ export default function Table({handleOpen, tableData, onDelete}){ Job Department Status + Actions + {/* row */} {employees.map((employee)=>( @@ -55,24 +57,27 @@ export default function Table({handleOpen, tableData, onDelete}){ - - - - +
+ {/* ปุ่ม Update พร้อมไอคอน */} + + {/* ปุ่ม Delete แบบไอคอน */} + +
))} -