Compare commits
No commits in common. "b14383f8fda2a97d1db6b4b10bffe16771acbd27" and "8a00507431971e0f9082a58b41167faeee1eaaf7" have entirely different histories.
b14383f8fd
...
8a00507431
2
.prod/update.sh
Normal file → Executable file
2
.prod/update.sh
Normal file → Executable file
@ -1,4 +1,4 @@
|
||||
cd ~/Documents/Web/Tech_Tracker_Web || exit
|
||||
cd ~/Documents/Web/Tech_Tracker_Web
|
||||
git pull
|
||||
pnpm update
|
||||
sudo docker restart techtracker
|
||||
|
@ -8,7 +8,6 @@ export const GET = async (request: Request) => {
|
||||
const url = new URL(request.url);
|
||||
const apiKey = url.searchParams.get('apikey');
|
||||
const page = Number(url.searchParams.get('page')) || 1;
|
||||
const perPage = Number(url.searchParams.get('per_page')) || 50;
|
||||
if (apiKey !== process.env.API_KEY) {
|
||||
const session = await auth();
|
||||
if (!session)
|
||||
@ -17,6 +16,7 @@ export const GET = async (request: Request) => {
|
||||
{ status: 401 }
|
||||
);
|
||||
}
|
||||
const perPage = 50;
|
||||
const historyData = await getHistory(page, perPage);
|
||||
return NextResponse.json(historyData, { status: 200 });
|
||||
} catch (error) {
|
||||
|
@ -1,4 +1,3 @@
|
||||
import React, { useState, useEffect } from "react";
|
||||
import Image from "next/image";
|
||||
import {
|
||||
Drawer,
|
||||
@ -20,56 +19,14 @@ import {
|
||||
import {
|
||||
Pagination,
|
||||
PaginationContent,
|
||||
PaginationEllipsis,
|
||||
PaginationItem,
|
||||
PaginationLink,
|
||||
PaginationNext,
|
||||
PaginationPrevious,
|
||||
} from "~/components/ui/shadcn/pagination";
|
||||
|
||||
// Type definitions for Paginated History API
|
||||
type HistoryEntry = {
|
||||
name: string;
|
||||
status: string;
|
||||
updatedAt: Date;
|
||||
}
|
||||
type PaginatedHistory = {
|
||||
data: HistoryEntry[];
|
||||
meta: {
|
||||
current_page: number;
|
||||
per_page: number;
|
||||
total_pages: number;
|
||||
total_count: number;
|
||||
}
|
||||
}
|
||||
|
||||
export default function History_Drawer() {
|
||||
const [history, setHistory] = useState<HistoryEntry[]>([]);
|
||||
const [page, setPage] = useState<number>(1);
|
||||
const [totalPages, setTotalPages] = useState<number>(1);
|
||||
const perPage = 5;
|
||||
|
||||
useEffect(() => {
|
||||
const fetchHistory = async (currentPage: number) => {
|
||||
try {
|
||||
const response = await fetch(`/api/get_paginated_history?page=${currentPage}&per_page=${perPage}`);
|
||||
if (!response.ok)
|
||||
throw new Error('Failed to fetch history');
|
||||
const data: PaginatedHistory = await response.json() as PaginatedHistory;
|
||||
setHistory(data.data);
|
||||
setTotalPages(data.meta.total_pages);
|
||||
} catch (error) {
|
||||
console.error('Error fetching history:', error);
|
||||
}
|
||||
};
|
||||
fetchHistory(page)
|
||||
.catch((error) => {
|
||||
console.error('Error fetching history:', error);
|
||||
});
|
||||
}, [page]);
|
||||
|
||||
const handlePageChange = (newPage: number) => {
|
||||
setPage(newPage);
|
||||
};
|
||||
|
||||
return (
|
||||
<Drawer>
|
||||
<DrawerTrigger>
|
||||
@ -92,50 +49,38 @@ export default function History_Drawer() {
|
||||
</div>
|
||||
</DrawerTitle>
|
||||
</DrawerHeader>
|
||||
<Table className="w-5/6 lg:w-1/2 m-auto ">
|
||||
<Table className="w-5/6 lg:w-1/2 m-auto"
|
||||
>
|
||||
<TableHeader>
|
||||
<TableRow>
|
||||
<TableHead>Name</TableHead>
|
||||
<TableHead className="">Name</TableHead>
|
||||
<TableHead>Status</TableHead>
|
||||
<TableHead>Updated At</TableHead>
|
||||
</TableRow>
|
||||
</TableHeader>
|
||||
<TableBody>
|
||||
{history.map((entry, index) => (
|
||||
<TableRow key={index}>
|
||||
<TableCell className="font-medium">{entry.name}</TableCell>
|
||||
<TableCell>{entry.status}</TableCell>
|
||||
<TableCell>{new Date(entry.updatedAt).toLocaleString()}</TableCell>
|
||||
</TableRow>
|
||||
))}
|
||||
<TableRow>
|
||||
<TableCell className="font-medium">INV001</TableCell>
|
||||
<TableCell>Paid</TableCell>
|
||||
<TableCell>Credit Card</TableCell>
|
||||
</TableRow>
|
||||
</TableBody>
|
||||
</Table>
|
||||
<DrawerFooter>
|
||||
<Pagination>
|
||||
<PaginationContent>
|
||||
{page > 1 && (
|
||||
<PaginationItem>
|
||||
<PaginationPrevious
|
||||
href="#"
|
||||
onClick={(e) => {
|
||||
e.preventDefault();
|
||||
handlePageChange(page - 1);
|
||||
}}
|
||||
/>
|
||||
</PaginationItem>
|
||||
)}
|
||||
<h3 className="text-center font-semibold">Page {page}</h3>
|
||||
{page < totalPages && (
|
||||
<PaginationItem>
|
||||
<PaginationNext
|
||||
href="#"
|
||||
onClick={(e) => {
|
||||
e.preventDefault();
|
||||
handlePageChange(page + 1);
|
||||
}}
|
||||
/>
|
||||
</PaginationItem>
|
||||
)}
|
||||
<PaginationItem>
|
||||
<PaginationPrevious href="#" />
|
||||
</PaginationItem>
|
||||
<PaginationItem>
|
||||
<PaginationLink href="#">1</PaginationLink>
|
||||
</PaginationItem>
|
||||
<PaginationItem>
|
||||
<PaginationEllipsis />
|
||||
</PaginationItem>
|
||||
<PaginationItem>
|
||||
<PaginationNext href="#" />
|
||||
</PaginationItem>
|
||||
</PaginationContent>
|
||||
</Pagination>
|
||||
<DrawerClose>
|
||||
@ -143,19 +88,5 @@ export default function History_Drawer() {
|
||||
</DrawerFooter>
|
||||
</DrawerContent>
|
||||
</Drawer>
|
||||
);
|
||||
}
|
||||
// If you want to show all page numbers:
|
||||
//{Array.from({ length: totalPages }).map((_, idx) => (
|
||||
//<PaginationItem key={idx}>
|
||||
//<PaginationLink
|
||||
//href="#"
|
||||
//onClick={(e) => {
|
||||
//e.preventDefault();
|
||||
//handlePageChange(idx + 1);
|
||||
//}}
|
||||
//>{idx + 1}
|
||||
//</PaginationLink>
|
||||
//</PaginationItem>
|
||||
//))}
|
||||
|
||||
);
|
||||
};
|
||||
|
@ -53,12 +53,12 @@ export const updateEmployeeStatusByName =
|
||||
};
|
||||
|
||||
// Type definitions for Paginated History API
|
||||
type HistoryEntry = {
|
||||
interface HistoryEntry {
|
||||
name: string;
|
||||
status: string;
|
||||
updatedAt: Date;
|
||||
}
|
||||
type PaginatedHistory = {
|
||||
interface PaginatedHistory {
|
||||
data: HistoryEntry[];
|
||||
meta: {
|
||||
current_page: number;
|
||||
|
Loading…
Reference in New Issue
Block a user