Refactor API calls to use apiRequest instead of clientFetch

Replaces all usages of clientFetch with the new apiRequest utility across dashboard pages, modal components, and the profit analytics service. This standardizes API interaction and improves consistency in request handling.
This commit is contained in:
g
2025-12-12 20:05:26 +00:00
parent fd5440c4da
commit 07dcaf55c0
7 changed files with 26 additions and 37 deletions

View File

@@ -5,7 +5,7 @@ import { Button } from "@/components/ui/button";
import { Dialog, DialogContent, DialogHeader, DialogTitle, DialogFooter } from "@/components/ui/dialog";
import { Send, Bold, Italic, Code, Link as LinkIcon, Image as ImageIcon, X, Eye, EyeOff, Package } from "lucide-react";
import { toast } from "sonner";
import { apiRequest } from "@/lib/api";
import { clientFetch } from "@/lib/api";
import { Textarea } from "@/components/ui/textarea";
import ReactMarkdown from 'react-markdown';
import ProductSelector from "./product-selector";
@@ -137,6 +137,9 @@ export default function BroadcastDialog({ open, setOpen }: BroadcastDialogProps)
message: broadcastMessage,
productIds: selectedProducts
}),
headers: {
'Content-Type': 'application/json'
}
});
}

View File

@@ -20,7 +20,7 @@ import type { ProductModalProps, ProductData } from "@/lib/types";
import { toast } from "sonner";
import type React from "react";
import { Plus } from "lucide-react";
import { clientFetch } from "@/lib/api";
import { apiRequest } from "@/lib/api";
import { Switch } from "@/components/ui/switch";
type CategorySelectProps = {

View File

@@ -6,7 +6,7 @@ import { Input } from "@/components/ui/input";
import { Checkbox } from "@/components/ui/checkbox";
import { ScrollArea } from "@/components/ui/scroll-area";
import { Search, Package } from "lucide-react";
import { clientFetch } from "@/lib/api";
import { apiRequest } from "@/lib/api";
interface Product {
_id: string;
@@ -30,7 +30,7 @@ export default function ProductSelector({ selectedProducts, onSelectionChange }:
useEffect(() => {
const fetchProducts = async () => {
try {
const fetchedProducts = await clientFetch('/products/for-selection');
const fetchedProducts = await apiRequest('/products/for-selection', 'GET');
setProducts(fetchedProducts);
} catch (error) {
console.error('Error fetching products:', error);

View File

@@ -7,7 +7,7 @@ import { Card, CardContent, CardHeader, CardTitle } from "@/components/ui/card";
import { Badge } from "@/components/ui/badge";
import { TrendingUp, TrendingDown, Calculator, DollarSign } from "lucide-react";
import { toast } from "sonner";
import { clientFetch } from "@/lib/api";
import { apiRequest } from "@/lib/api";
interface ProfitAnalysisModalProps {
open: boolean;
@@ -57,7 +57,7 @@ export const ProfitAnalysisModal: React.FC<ProfitAnalysisModalProps> = ({
const fetchProfitAnalysis = async () => {
try {
setLoading(true);
const response = await clientFetch(`/products/${productId}/profit-analysis`);
const response = await apiRequest(`/products/${productId}/profit-analysis`);
setProfitData(response);
} catch (error) {
console.error("Error fetching profit analysis:", error);