Replace apiRequest with clientFetch across app
Refactored all API calls to use the new clientFetch utility instead of apiRequest in dashboard pages, modal components, and profit analytics service. This improves consistency and aligns with updated API handling patterns.
This commit is contained in:
@@ -131,9 +131,12 @@ export default function BroadcastDialog({ open, setOpen }: BroadcastDialogProps)
|
||||
|
||||
response = await res.json();
|
||||
} else {
|
||||
response = await apiRequest("/storefront/broadcast", "POST", {
|
||||
message: broadcastMessage,
|
||||
productIds: selectedProducts
|
||||
response = await clientFetch("/storefront/broadcast", {
|
||||
method: "POST",
|
||||
body: JSON.stringify({
|
||||
message: broadcastMessage,
|
||||
productIds: selectedProducts
|
||||
}),
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
@@ -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 { apiRequest } from "@/lib/api";
|
||||
import { clientFetch } from "@/lib/api";
|
||||
import { Switch } from "@/components/ui/switch";
|
||||
|
||||
type CategorySelectProps = {
|
||||
|
||||
@@ -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 { apiRequest } from "@/lib/api";
|
||||
import { clientFetch } 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 apiRequest('/products/for-selection', 'GET');
|
||||
const fetchedProducts = await clientFetch('/products/for-selection');
|
||||
setProducts(fetchedProducts);
|
||||
} catch (error) {
|
||||
console.error('Error fetching products:', error);
|
||||
|
||||
@@ -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 { apiRequest } from "@/lib/api";
|
||||
import { clientFetch } 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 apiRequest(`/products/${productId}/profit-analysis`);
|
||||
const response = await clientFetch(`/products/${productId}/profit-analysis`);
|
||||
setProfitData(response);
|
||||
} catch (error) {
|
||||
console.error("Error fetching profit analysis:", error);
|
||||
|
||||
Reference in New Issue
Block a user