diff --git a/app/dashboard/page.tsx b/app/dashboard/page.tsx index 08a49e2..780292f 100644 --- a/app/dashboard/page.tsx +++ b/app/dashboard/page.tsx @@ -1,6 +1,6 @@ import Dashboard from "@/components/kokonutui/dashboard"; import Content from "@/components/kokonutui/content"; -import { fetchWithAuthorization } from "@/lib/server-utils" +import { fetchServer } from "@/lib/server-utils" // ✅ Corrected Vendor Type interface Vendor { @@ -24,8 +24,8 @@ interface OrderStats { export default async function DashboardPage() { const [userResponse, orderStats] = await Promise.all([ - fetchWithAuthorization("/auth/me"), - fetchWithAuthorization("/orders/stats"), + fetchServer("/auth/me"), + fetchServer("/orders/stats"), ]); const vendor = userResponse.vendor; diff --git a/components/broadcast-dialog.tsx b/components/broadcast-dialog.tsx index 4cbb7b2..e314e50 100644 --- a/components/broadcast-dialog.tsx +++ b/components/broadcast-dialog.tsx @@ -6,19 +6,17 @@ import { Textarea } from "@/components/ui/textarea"; import { Dialog, DialogContent, DialogHeader, DialogTitle, DialogFooter } from "@/components/ui/dialog"; import { Send } from "lucide-react"; import { toast } from "sonner"; -import { apiRequest } from "@/lib/storeHelper"; // ✅ API helper +import { apiRequest } from "@/lib/storeHelper"; -// ✅ Define props type interface BroadcastDialogProps { open: boolean; setOpen: (open: boolean) => void; } export default function BroadcastDialog({ open, setOpen }: BroadcastDialogProps) { - const [broadcastMessage, setBroadcastMessage] = useState(""); - const [sendingBroadcast, setSendingBroadcast] = useState(false); + const [broadcastMessage, setBroadcastMessage] = useState(""); + const [isSending, setIsSending] = useState(false); - // ✅ Send Broadcast Message const sendBroadcast = async () => { if (!broadcastMessage.trim()) { toast.warning("Broadcast message cannot be empty."); @@ -26,14 +24,10 @@ export default function BroadcastDialog({ open, setOpen }: BroadcastDialogProps) } try { - setSendingBroadcast(true); - - // ✅ API Call + setIsSending(true); const response = await apiRequest("/storefront/broadcast", "POST", { message: broadcastMessage }); - if (response.error) { - throw new Error(response.error); - } + if (response.error) throw new Error(response.error); toast.success(`Broadcast sent to ${response.totalUsers} users!`); setBroadcastMessage(""); @@ -41,7 +35,7 @@ export default function BroadcastDialog({ open, setOpen }: BroadcastDialogProps) } catch (error) { toast.error("Failed to send broadcast message."); } finally { - setSendingBroadcast(false); + setIsSending(false); } }; @@ -52,17 +46,23 @@ export default function BroadcastDialog({ open, setOpen }: BroadcastDialogProps) Global Broadcast Message +