@@ -30,7 +30,7 @@ const CreateAwardNotice = () => {
3030 vendorId : '' ,
3131 } )
3232
33- const [ vendors , setVendors ] = useState ( [ ] )
33+ const [ vendors , setVendors ] = useState ( [ ] ) // Ensure vendors is an empty array by default
3434 const [ toasts , setToasts ] = useState ( [ ] )
3535 const [ loading , setLoading ] = useState ( false )
3636
@@ -44,7 +44,8 @@ const CreateAwardNotice = () => {
4444 const res = await axios . get ( VENDOR_API_URL , {
4545 headers : { Authorization : `Bearer ${ accessToken } ` } ,
4646 } )
47- setVendors ( res . data )
47+ // Ensure vendors is an array and update state
48+ setVendors ( Array . isArray ( res . data ) ? res . data : [ ] )
4849 } catch ( err ) {
4950 console . error ( 'Failed to fetch vendors' , err )
5051 showToast ( 'Error loading vendors' , 'danger' )
@@ -143,11 +144,15 @@ const CreateAwardNotice = () => {
143144 < CFormLabel > Vendor</ CFormLabel >
144145 < CFormSelect name = "vendorId" value = { awardData . vendorId } onChange = { handleChange } required >
145146 < option value = "" > Select Vendor</ option >
146- { vendors . map ( ( vendor ) => (
147- < option key = { vendor . _id } value = { vendor . _id } >
148- { vendor . businessName } ({ vendor . fullName } )
149- </ option >
150- ) ) }
147+ { Array . isArray ( vendors ) && vendors . length > 0 ? (
148+ vendors . map ( ( vendor ) => (
149+ < option key = { vendor . _id } value = { vendor . _id } >
150+ { vendor . businessName } ({ vendor . fullName } )
151+ </ option >
152+ ) )
153+ ) : (
154+ < option disabled > No vendors available</ option >
155+ ) }
151156 </ CFormSelect >
152157 </ CCol >
153158 </ CRow >
0 commit comments