) {
function TableHead({ className, ...props }: React.ComponentProps<"th">) {
return (
| [role=checkbox]]:translate-y-[2px]",
+ "h-12 px-4 text-left align-middle font-medium text-muted-foreground [&:has([role=checkbox])]:pr-0",
className,
)}
{...props}
@@ -81,9 +63,8 @@ function TableHead({ className, ...props }: React.ComponentProps<"th">) {
function TableCell({ className, ...props }: React.ComponentProps<"td">) {
return (
| [role=checkbox]]:translate-y-[2px]",
+ "p-4 align-middle [&:has([role=checkbox])]:pr-0", // Dihapus: whitespace-nowrap agar text panjang bisa wrap
className,
)}
{...props}
@@ -97,8 +78,7 @@ function TableCaption({
}: React.ComponentProps<"caption">) {
return (
);
diff --git a/src/hooks/useReviewTable.ts b/src/hooks/useReviewTable.ts
new file mode 100644
index 0000000..4a82b91
--- /dev/null
+++ b/src/hooks/useReviewTable.ts
@@ -0,0 +1,29 @@
+import { useEffect, useState } from "react";
+import { ApiResponse, ReviewItem } from "../types";
+
+export const useReviewTable = () => {
+ const [data, setData] = useState([]);
+ const [isLoading, setIsLoading] = useState(true);
+
+ useEffect(() => {
+ const getReviewData = async () => {
+ try {
+ const req = await fetch("/api/review");
+ const res: ApiResponse = await req.json();
+
+ if (res.data && Array.isArray(res.data)) {
+ setData(res.data);
+ } else {
+ setData([]);
+ }
+ } catch (error) {
+ console.error("Gagal fetch data:", error);
+ } finally {
+ setIsLoading(false);
+ }
+ };
+ getReviewData();
+ }, []);
+
+ return { data, isLoading };
+};
diff --git a/src/types/index.ts b/src/types/index.ts
index 2b4b3d3..283f73e 100644
--- a/src/types/index.ts
+++ b/src/types/index.ts
@@ -122,3 +122,21 @@ export interface UseStatCardProps {
value: number;
delay?: number;
}
+
+export interface ReviewItem {
+ id: number;
+ content: string;
+ sentiment: string;
+ confidenceScore: number;
+ createdAt: string;
+ keywords: string[];
+ product: {
+ name: string;
+ brand?: string;
+ } | null;
+}
+
+export interface ApiResponse {
+ message: string;
+ data: ReviewItem[];
+}
|