99 formatCategoryName ,
1010} from "../../../../../utils/categoryFormating" ;
1111import { nanoid } from "nanoid" ;
12+ import apiClient from "@/lib/api" ;
1213
1314interface DashboardProductDetailsProps {
1415 params : { id : number } ;
@@ -27,7 +28,7 @@ const DashboardProductDetails = ({
2728 const requestOptions = {
2829 method : "DELETE" ,
2930 } ;
30- fetch ( `http://localhost:3001 /api/products/${ id } `, requestOptions )
31+ apiClient . delete ( ` /api/products/${ id } `, requestOptions )
3132 . then ( ( response ) => {
3233 if ( response . status !== 204 ) {
3334 if ( response . status === 400 ) {
@@ -65,7 +66,7 @@ const DashboardProductDetails = ({
6566 headers : { "Content-Type" : "application/json" } ,
6667 body : JSON . stringify ( product ) ,
6768 } ;
68- fetch ( `http://localhost:3001 /api/products/${ id } `, requestOptions )
69+ apiClient . put ( ` /api/products/${ id } `, requestOptions )
6970 . then ( ( response ) => {
7071 if ( response . status === 200 ) {
7172 return response . json ( ) ;
@@ -85,7 +86,7 @@ const DashboardProductDetails = ({
8586 formData . append ( "uploadedFile" , file ) ;
8687
8788 try {
88- const response = await fetch ( "http://localhost:3001 /api/main-image", {
89+ const response = await apiClient . post ( " /api/main-image", {
8990 method : "POST" ,
9091 body : formData ,
9192 } ) ;
@@ -103,15 +104,15 @@ const DashboardProductDetails = ({
103104
104105 // fetching main product data including other product images
105106 const fetchProductData = async ( ) => {
106- fetch ( `http://localhost:3001 /api/products/${ id } `)
107+ apiClient . get ( ` /api/products/${ id } `)
107108 . then ( ( res ) => {
108109 return res . json ( ) ;
109110 } )
110111 . then ( ( data ) => {
111112 setProduct ( data ) ;
112113 } ) ;
113114
114- const imagesData = await fetch ( `http://localhost:3001 /api/images/${ id } `, {
115+ const imagesData = await apiClient . get ( ` /api/images/${ id } `, {
115116 cache : "no-store" ,
116117 } ) ;
117118 const images = await imagesData . json ( ) ;
@@ -120,7 +121,7 @@ const DashboardProductDetails = ({
120121
121122 // fetching all product categories. It will be used for displaying categories in select category input
122123 const fetchCategories = async ( ) => {
123- fetch ( `http://localhost:3001 /api/categories`)
124+ apiClient . get ( ` /api/categories`)
124125 . then ( ( res ) => {
125126 return res . json ( ) ;
126127 } )
0 commit comments