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

View File

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

View File

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