feat: get review data total

This commit is contained in:
Mahen 2026-02-11 07:56:16 +07:00
parent 443ad59077
commit 126772beca
3 changed files with 5 additions and 12 deletions

View File

@ -18,10 +18,12 @@ import {
import { signOut } from "next-auth/react"; import { signOut } from "next-auth/react";
import Link from "next/link"; import Link from "next/link";
import { useHeader } from "@/src/hooks/useHeader"; import { useHeader } from "@/src/hooks/useHeader";
import { useDashboards } from "@/src/hooks/useDashboard";
export function Header() { export function Header() {
const { open, setOpen, session, mounted, productCount, loadingProductCount } = const { open, setOpen, session, mounted, productCount } =
useHeader(); useHeader();
const { totalReviews } = useDashboards();
if (!mounted) return null; if (!mounted) return null;
return ( return (
@ -50,7 +52,7 @@ export function Header() {
</div> </div>
<div className="flex items-center gap-2 text-muted-foreground"> <div className="flex items-center gap-2 text-muted-foreground">
<Database className="h-4 w-4" /> <Database className="h-4 w-4" />
<span>12,450 Ulasan</span> <span>{totalReviews} Ulasan</span>
</div> </div>
</div> </div>
<div onClick={() => setOpen(true)}> <div onClick={() => setOpen(true)}>

View File

@ -7,7 +7,6 @@ export const useHeader = () => {
const session = useSession(); const session = useSession();
const [mounted, setMounted] = useState(false); const [mounted, setMounted] = useState(false);
const [productCount, setProductCount] = useState<number | null>(null); const [productCount, setProductCount] = useState<number | null>(null);
const [loadingProductCount, setLoadingProductCount] = useState(false);
const handleRefresh = () => { const handleRefresh = () => {
setIsRefreshing(true); setIsRefreshing(true);
@ -18,8 +17,6 @@ export const useHeader = () => {
setMounted(true); setMounted(true);
const getProductCount = async () => { const getProductCount = async () => {
try { try {
setLoadingProductCount(true);
const res = await fetch("/api/product"); const res = await fetch("/api/product");
if (!res.ok) throw new Error("Failed to fetch product count"); if (!res.ok) throw new Error("Failed to fetch product count");
@ -27,18 +24,12 @@ export const useHeader = () => {
setProductCount(data.count); setProductCount(data.count);
} catch (error) { } catch (error) {
console.error("Failed get product count:", error); console.error("Failed get product count:", error);
} finally {
setLoadingProductCount(false);
} }
}; };
getProductCount(); getProductCount();
}, []); }, []);
useEffect(()=>{
})
return { return {
open, open,
setOpen, setOpen,
@ -47,6 +38,5 @@ export const useHeader = () => {
handleRefresh, handleRefresh,
mounted, mounted,
productCount, productCount,
loadingProductCount,
}; };
}; };

View File

@ -28,6 +28,7 @@ export interface BrandFilterProps {
} }
export type Review = { export type Review = {
brand: string;
id: number; id: number;
createdAt: string; createdAt: string;
sentiment: Sentiment; sentiment: Sentiment;