From 82a05e5c6d8bec9ea2f90e2e6f0789a3b3431291 Mon Sep 17 00:00:00 2001 From: Mahima Sonwane Date: Tue, 13 May 2025 16:59:36 +0530 Subject: [PATCH] Same loading animation on all pages and Updated search box style in entries table to match navbar --- src/app/pages/entries/EntriesTable.js | 278 +++++++++++++------------- 1 file changed, 134 insertions(+), 144 deletions(-) diff --git a/src/app/pages/entries/EntriesTable.js b/src/app/pages/entries/EntriesTable.js index 00b58e3..57d2aca 100644 --- a/src/app/pages/entries/EntriesTable.js +++ b/src/app/pages/entries/EntriesTable.js @@ -1,4 +1,3 @@ - "use client"; import { useEffect, useState } from "react"; import { databases, Query } from "../../lib/appwrite"; @@ -6,6 +5,7 @@ import { DATABASE_ID, COLLECTION_ID } from "../../lib/api"; import Header from "../../components/partials/header"; import { useTheme } from "../../context/ThemeContext"; import { useAuth } from "../../context/AuthContext"; +import { FaSearch } from 'react-icons/fa'; export default function EntriesTable() { const { userRole } = useAuth(); @@ -14,7 +14,7 @@ export default function EntriesTable() { const [filteredEntries, setFilteredEntries] = useState([]); const [searchQuery, setSearchQuery] = useState(""); const [currentPage, setCurrentPage] = useState(1); - const [avgConsultTime, setAvgConsultTime] = useState(15); // Default 15 mins + const [avgConsultTime, setAvgConsultTime] = useState(15); const entriesPerPage = 20; const [currentToken, setCurrentToken] = useState(null); @@ -24,7 +24,6 @@ export default function EntriesTable() { const [loading, setLoading] = useState(true); const [error, setError] = useState(null); - // Calculate waiting time based on position in queue const calculateWaitTime = (tokenNumber) => { const bookedEntries = entries.filter((e) => e.status === "booked"); const position = bookedEntries.findIndex( @@ -58,19 +57,13 @@ export default function EntriesTable() { return; } - const currentIndex = entries.findIndex( - (entry) => entry.status === "booked" - ); + const currentIndex = entries.findIndex((entry) => entry.status === "booked"); const current = currentIndex >= 0 ? entries[currentIndex] : null; setCurrentToken(current?.tokenNumber || null); - setPreviousToken( - currentIndex > 0 ? entries[currentIndex - 1]?.tokenNumber : null - ); + setPreviousToken(currentIndex > 0 ? entries[currentIndex - 1]?.tokenNumber : null); setNextToken( - currentIndex < entries.length - 1 - ? entries[currentIndex + 1]?.tokenNumber - : null + currentIndex < entries.length - 1 ? entries[currentIndex + 1]?.tokenNumber : null ); const missed = entries @@ -99,18 +92,13 @@ export default function EntriesTable() { }; useEffect(() => { - if (userRole === "patient") return; // Don't load data if patient - + if (userRole === "patient") return; const loadData = async () => { try { const data = await getEntries(); setEntries(data); setFilteredEntries(data); updateTokenInfo(data); - - // Load settings (avg consultation time) - // const settings = await getSettings(); - // setAvgConsultTime(settings?.avgConsultationTime || 15); } catch (err) { setError(err.message); } finally { @@ -133,32 +121,22 @@ export default function EntriesTable() { const indexOfLastEntry = currentPage * entriesPerPage; const indexOfFirstEntry = indexOfLastEntry - entriesPerPage; - const currentEntries = filteredEntries.slice( - indexOfFirstEntry, - indexOfLastEntry - ); + const currentEntries = filteredEntries.slice(indexOfFirstEntry, indexOfLastEntry); const totalPages = Math.ceil(filteredEntries.length / entriesPerPage); if (loading) return ( -
-
-

Loading...

+
+
+

Loading...

); if (error) return
Error: {error}
; - // Check user role and show permission message if patient if (userRole === "patient") { return ( -
+

Access Denied

@@ -170,129 +148,141 @@ export default function EntriesTable() { } return ( -
+
-

Today's Entries

- setSearchQuery(e.target.value)} - /> - {filteredEntries.length === 0 ? ( -
No entries found for today.
- ) : ( - <> - - - - - - {/* */} - - {/* */} - - - - - {currentEntries.map((entry) => ( - - - - {/* */} - - {/* */} - +
+

Today's Entries

+ + + {filteredEntries.length === 0 ? ( +
No entries found for today.
+ ) : ( + <> +
TokenNameBooked ByStatusWait TimeActions
{entry.tokenNumber}{entry.patientName} - - {entry.bookedBy} - - - - {entry.status === "booked" ? "In-Queue" : entry.status} - - - {entry.status === "booked" ? - `~${calculateWaitTime(entry.tokenNumber)} mins` : - '-'} - - {entry.status === "booked" && ( - <> - - - - )} -
+ + + + + + - ))} - -
TokenNameStatusActions
+ + + {currentEntries.map((entry) => ( + + {entry.tokenNumber} + {entry.patientName} + + + {entry.status === "booked" ? "In-Queue" : entry.status} + + + + {entry.status === "booked" && ( + <> + + + + )} + + + ))} + + - {/* Pagination */} -
- - - Page {currentPage} of {totalPages} - - -
- - )} + + + Page {currentPage} of {totalPages} + + +
+ + )} +
); }