22import { CustomButton , DashboardSidebar , SectionTitle } from "@/components" ;
33import Image from "next/image" ;
44import { useRouter } from "next/navigation" ;
5- import React , { useEffect , useState } from "react" ;
5+ import React , { useEffect , useState , use } from "react" ;
66import toast from "react-hot-toast" ;
77import {
88 convertCategoryNameToURLFriendly as convertSlugToURLFriendly ,
@@ -12,12 +12,15 @@ import { nanoid } from "nanoid";
1212import apiClient from "@/lib/api" ;
1313
1414interface DashboardProductDetailsProps {
15- params : { id : number } ;
15+ params : Promise < { id : string } > ;
1616}
1717
1818const DashboardProductDetails = ( {
19- params : { id } ,
19+ params,
2020} : DashboardProductDetailsProps ) => {
21+ const resolvedParams = use ( params ) ;
22+ const id = resolvedParams . id ;
23+
2124 const [ product , setProduct ] = useState < Product > ( ) ;
2225 const [ categories , setCategories ] = useState < Category [ ] > ( ) ;
2326 const [ otherImages , setOtherImages ] = useState < OtherImages [ ] > ( [ ] ) ;
@@ -149,7 +152,7 @@ const DashboardProductDetails = ({
149152 < input
150153 type = "text"
151154 className = "input input-bordered w-full max-w-xs"
152- value = { product ?. title }
155+ value = { product ?. title || "" }
153156 onChange = { ( e ) =>
154157 setProduct ( { ...product ! , title : e . target . value } )
155158 }
@@ -167,7 +170,7 @@ const DashboardProductDetails = ({
167170 < input
168171 type = "text"
169172 className = "input input-bordered w-full max-w-xs"
170- value = { product ?. price }
173+ value = { product ?. price || "" }
171174 onChange = { ( e ) =>
172175 setProduct ( { ...product ! , price : Number ( e . target . value ) } )
173176 }
@@ -184,7 +187,7 @@ const DashboardProductDetails = ({
184187 < input
185188 type = "text"
186189 className = "input input-bordered w-full max-w-xs"
187- value = { product ?. manufacturer }
190+ value = { product ?. manufacturer || "" }
188191 onChange = { ( e ) =>
189192 setProduct ( { ...product ! , manufacturer : e . target . value } )
190193 }
@@ -202,7 +205,7 @@ const DashboardProductDetails = ({
202205 < input
203206 type = "text"
204207 className = "input input-bordered w-full max-w-xs"
205- value = { product ?. slug && convertSlugToURLFriendly ( product ?. slug ) }
208+ value = { product ?. slug ? convertSlugToURLFriendly ( product ?. slug ) : "" }
206209 onChange = { ( e ) =>
207210 setProduct ( {
208211 ...product ! ,
@@ -222,7 +225,7 @@ const DashboardProductDetails = ({
222225 </ div >
223226 < select
224227 className = "select select-bordered"
225- value = { product ?. inStock }
228+ value = { product ?. inStock ?? 1 }
226229 onChange = { ( e ) => {
227230 setProduct ( { ...product ! , inStock : Number ( e . target . value ) } ) ;
228231 } }
@@ -241,7 +244,7 @@ const DashboardProductDetails = ({
241244 </ div >
242245 < select
243246 className = "select select-bordered"
244- value = { product ?. categoryId }
247+ value = { product ?. categoryId || "" }
245248 onChange = { ( e ) =>
246249 setProduct ( {
247250 ...product ! ,
@@ -308,7 +311,7 @@ const DashboardProductDetails = ({
308311 </ div >
309312 < textarea
310313 className = "textarea textarea-bordered h-24"
311- value = { product ?. description }
314+ value = { product ?. description || "" }
312315 onChange = { ( e ) =>
313316 setProduct ( { ...product ! , description : e . target . value } )
314317 }
0 commit comments