From aaf876f0981f77ad39b0476eb12bccf1479125f9 Mon Sep 17 00:00:00 2001 From: Atul Gunjal Date: Wed, 23 Apr 2025 13:35:50 +0530 Subject: [PATCH] changes in Sidebar --- src/app/components/Sidebar.jsx | 41 +++++- src/app/components/TokenTable.jsx | 195 +++++++++++++++++++++++++++++ src/app/pages/StaffBooking/page.js | 4 +- src/app/pages/done/page.js | 11 ++ src/app/pages/missed/page.js | 10 ++ 5 files changed, 257 insertions(+), 4 deletions(-) create mode 100644 src/app/components/TokenTable.jsx create mode 100644 src/app/pages/done/page.js create mode 100644 src/app/pages/missed/page.js diff --git a/src/app/components/Sidebar.jsx b/src/app/components/Sidebar.jsx index 4e94bd5..e0e58a0 100644 --- a/src/app/components/Sidebar.jsx +++ b/src/app/components/Sidebar.jsx @@ -123,6 +123,43 @@ const Sidebar = ({ sidebarOpen, setSidebarOpen, isCollapsed }) => { {!isCollapsed && "Add Multiple Tokens"} + + + {/* Done tokens Link */} + + + {!isCollapsed && "Done List"} + + + + + {/* Missed tokens Link */} + + + {!isCollapsed && "Missed List"} + {/* -----------------------Entries-------------------------------------------- */} {/* User Profile Link */} @@ -144,7 +181,7 @@ const Sidebar = ({ sidebarOpen, setSidebarOpen, isCollapsed }) => { {!isCollapsed && "Entries"} */} - {/* ------------staffBooking---------------- */} + {/* ------------staffBooking---------------- { {!isCollapsed && "StaffBooking"} - + */} {/* ------------------------Setting--------------------------------- */} { + try { + const today = new Date().toISOString().split('T')[0]; + const response = await databases.listDocuments( + DATABASE_ID, + COLLECTION_ID, + [ + Query.equal('date', today), + Query.orderAsc('tokenNumber') + ], + 100 + ); + return response.documents; + } catch (error) { + console.error("Fetch error:", error); + throw error; + } + }; + + const updateStatus = async (entryId, newStatus) => { + try { + setLoading(true); + await databases.updateDocument( + DATABASE_ID, + COLLECTION_ID, + entryId, + { status: newStatus } + ); + const data = await getEntries(); + setEntries(data); + applyFilters(data, searchQuery); + } catch (error) { + console.error("Update error:", error); + setError(error.message); + } finally { + setLoading(false); + } + }; + + const applyFilters = (data, search) => { + let filtered = data.filter((entry) => { + const matchesSearch = + entry.patientName.toLowerCase().includes(search.toLowerCase()) || + entry.tokenNumber.toString().includes(search); + + const matchesFilter = + statusFilter === "all" || + entry.status === statusFilter || + (statusFilter === "booked" && entry.status === "booked"); + + return matchesSearch && matchesFilter; + }); + setFilteredEntries(filtered); + }; + + useEffect(() => { + const loadData = async () => { + try { + const data = await getEntries(); + setEntries(data); + applyFilters(data, searchQuery); + } catch (err) { + setError(err.message); + } finally { + setLoading(false); + } + }; + loadData(); + }, []); + + useEffect(() => { + applyFilters(entries, searchQuery); + setCurrentPage(1); + }, [searchQuery, statusFilter, entries]); + + const indexOfLastEntry = currentPage * entriesPerPage; + const indexOfFirstEntry = indexOfLastEntry - entriesPerPage; + const currentEntries = filteredEntries.slice(indexOfFirstEntry, indexOfLastEntry); + const totalPages = Math.ceil(filteredEntries.length / entriesPerPage); + + if (loading) return ( +
+
+

Loading...

+
+ ); + + if (error) return
Error: {error}
; + + return ( + <> + setSearchQuery(e.target.value)} + /> + + {filteredEntries.length === 0 ? ( +
No entries found.
+ ) : ( + <> + + + + + + + + + + + {currentEntries.map((entry) => ( + + + + + + + ))} + +
TokenNameStatusActions
{entry.tokenNumber}{entry.patientName} + + {entry.status === "booked" ? "In-Queue" : entry.status} + + + {entry.status === "booked" && ( + <> + + + + )} +
+ +
+ + + Page {currentPage} of {totalPages} + + +
+ + )} + + ); +} \ No newline at end of file diff --git a/src/app/pages/StaffBooking/page.js b/src/app/pages/StaffBooking/page.js index d6b08ce..7653b86 100644 --- a/src/app/pages/StaffBooking/page.js +++ b/src/app/pages/StaffBooking/page.js @@ -66,7 +66,7 @@ export default function StaffBooking() {
{/* Statistics Overview */} -
+ {/*

Today's Overview

@@ -84,7 +84,7 @@ export default function StaffBooking() {

{stats.done}

- + */} {/* Booking Options */}
diff --git a/src/app/pages/done/page.js b/src/app/pages/done/page.js new file mode 100644 index 0000000..1c1c2a7 --- /dev/null +++ b/src/app/pages/done/page.js @@ -0,0 +1,11 @@ +import TokenTable from "../../components/TokenTable"; + +export default function DoneTokensPage() { + return ( +
+

Done Tokens

+ +
+ + ); +} \ No newline at end of file diff --git a/src/app/pages/missed/page.js b/src/app/pages/missed/page.js new file mode 100644 index 0000000..9cd4386 --- /dev/null +++ b/src/app/pages/missed/page.js @@ -0,0 +1,10 @@ +import TokenTable from "../../components/TokenTable"; + +export default function MissedTokensPage() { + return ( +
+

Missed Tokens

+ +
+ ); +} \ No newline at end of file