11"use client" ;
22import { DashboardSidebar } from "@/components" ;
33import { useRouter } from "next/navigation" ;
4- import React , { useEffect , useState } from "react" ;
4+ import React , { useEffect , useState , use } from "react" ;
55import toast from "react-hot-toast" ;
66import { formatCategoryName } from "../../../../../utils/categoryFormating" ;
77import { convertCategoryNameToURLFriendly } from "../../../../../utils/categoryFormating" ;
8+ import apiClient from "@/lib/api" ;
89
910interface DashboardSingleCategoryProps {
10- params : { id : number } ;
11+ params : Promise < { id : string } > ;
1112}
1213
1314const DashboardSingleCategory = ( {
14- params : { id } ,
15+ params,
1516} : DashboardSingleCategoryProps ) => {
17+ const resolvedParams = use ( params ) ;
18+ const id = resolvedParams . id ;
19+
1620 const [ categoryInput , setCategoryInput ] = useState < { name : string } > ( {
1721 name : "" ,
1822 } ) ;
@@ -23,7 +27,7 @@ const DashboardSingleCategory = ({
2327 method : "DELETE" ,
2428 } ;
2529 // sending API request for deleting a category
26- fetch ( `http://localhost:3001 /api/categories/${ id } `, requestOptions )
30+ apiClient . delete ( ` /api/categories/${ id } `, requestOptions )
2731 . then ( ( response ) => {
2832 if ( response . status === 204 ) {
2933 toast . success ( "Category deleted successfully" ) ;
@@ -47,7 +51,7 @@ const DashboardSingleCategory = ({
4751 } ) ,
4852 } ;
4953 // sending API request for updating a category
50- fetch ( `http://localhost:3001 /api/categories/${ id } `, requestOptions )
54+ apiClient . put ( ` /api/categories/${ id } `, requestOptions )
5155 . then ( ( response ) => {
5256 if ( response . status === 200 ) {
5357 return response . json ( ) ;
@@ -67,7 +71,7 @@ const DashboardSingleCategory = ({
6771
6872 useEffect ( ( ) => {
6973 // sending API request for getting single categroy
70- fetch ( `http://localhost:3001 /api/categories/${ id } `)
74+ apiClient . get ( ` /api/categories/${ id } `)
7175 . then ( ( res ) => {
7276 return res . json ( ) ;
7377 } )
0 commit comments