From 9a7b6a517724942e7b154337f5b033486a2da89b Mon Sep 17 00:00:00 2001 From: swlho Date: Mon, 9 Dec 2024 13:14:10 +0800 Subject: [PATCH 1/2] fix: add fetch data and update render table --- .../frontend/app/admin/dashboard/page.tsx | 31 ++++++++++++------- 1 file changed, 20 insertions(+), 11 deletions(-) diff --git a/packages/frontend/app/admin/dashboard/page.tsx b/packages/frontend/app/admin/dashboard/page.tsx index 8e74c39..eaa96c2 100644 --- a/packages/frontend/app/admin/dashboard/page.tsx +++ b/packages/frontend/app/admin/dashboard/page.tsx @@ -2,7 +2,7 @@ import { useEffect, useState } from 'react' import { useRouter } from 'next/navigation' -import { appointmentRequests } from '@/src/asset/mockData/appointmentRequests' +// import { appointmentRequests } from '@/src/asset/mockData/appointmentRequests' import { filterRequestsByPeriod } from '@/src/utils/filterRequestsByPeriod' import ExportCSV from '@/src/features/exportFiles/components/ExportCSV' import ExportPDF from '@/src/features/exportFiles/components/ExportPDF' @@ -10,18 +10,23 @@ import ExportPDF from '@/src/features/exportFiles/components/ExportPDF' export default function Dashboard() { const router = useRouter() const [period, setPeriod] = useState<'all' | 'daily' | 'weekly'>('all') - const [filteredRequests, setFilteredRequests] = useState(appointmentRequests) - + const [filteredRequests, setFilteredRequests] = useState(null) + useEffect(() => { const isLoggedIn = localStorage.getItem('isLoggedIn') if (!isLoggedIn) { router.push('/admin/login') } }, [router]) - + useEffect(() => { - const filtered = filterRequestsByPeriod(appointmentRequests, period) - setFilteredRequests(filtered) + const fetchData = async () => { + const response = await fetch('http://localhost:8000/api/v1/resident/request', {method: "GET"}) + const appointmentRequests = await response.json() + const filtered = filterRequestsByPeriod(appointmentRequests.data, period) + setFilteredRequests(filtered) + } + fetchData() }, [period]) const handleLogout = () => { @@ -59,18 +64,22 @@ export default function Dashboard() { Email Phone Address - Requested At + Requested Date + Requested Timeslot + Status - {filteredRequests.length > 0 ? ( - filteredRequests.map((request) => ( + {filteredRequests?.length > 0 ? ( + filteredRequests?.map((request) => ( {request.name} {request.email} - {request.phone} + {request.phoneNumber} {request.address} - {new Date(request.requestedAt).toLocaleString()} + {new Date(request.preferred_date).toLocaleString('en-US', {dateStyle: "full"})} + {request.preferred_timeslot} + {request.request_status} )) ) : ( From bc6bcdbeef1782b3b899e2ffc4a7348b399539f7 Mon Sep 17 00:00:00 2001 From: swlho Date: Mon, 9 Dec 2024 13:14:29 +0800 Subject: [PATCH 2/2] fix: add txt to gitignore --- packages/frontend/.gitignore | 1 + 1 file changed, 1 insertion(+) diff --git a/packages/frontend/.gitignore b/packages/frontend/.gitignore index d32cc78..1c7c262 100644 --- a/packages/frontend/.gitignore +++ b/packages/frontend/.gitignore @@ -23,6 +23,7 @@ # misc .DS_Store *.pem +*.txt # debug npm-debug.log*