1
- import { Fragment , useState } from 'react' ;
1
+ import { Fragment , useState , useEffect } from 'react' ;
2
2
import { Dialog , Transition } from '@headlessui/react' ;
3
3
import { XMarkIcon } from '@heroicons/react/24/outline' ;
4
4
import { TextInput , NumberInput , Button } from '@tremor/react' ;
@@ -17,6 +17,11 @@ export default function AddStockModal({ open, setOpen, onStockAdded }) {
17
17
target_price : ''
18
18
} ) ;
19
19
20
+ // Log API URL on component mount
21
+ useEffect ( ( ) => {
22
+ console . log ( 'API Base URL:' , API_BASE_URL ) ;
23
+ } , [ ] ) ;
24
+
20
25
const handleChange = ( e ) => {
21
26
const { name, value } = e . target ;
22
27
setFormData ( prev => ( {
@@ -37,13 +42,18 @@ export default function AddStockModal({ open, setOpen, onStockAdded }) {
37
42
throw new Error ( 'Please fill in all required fields' ) ;
38
43
}
39
44
40
- const response = await axios . post ( ` ${ API_BASE_URL } /stocks` , {
45
+ const requestData = {
41
46
name : formData . name ,
42
47
ticker : formData . ticker . toUpperCase ( ) ,
43
48
shares : parseFloat ( formData . shares ) ,
44
49
buy_price : parseFloat ( formData . buy_price ) ,
45
50
target_price : parseFloat ( formData . target_price || formData . buy_price )
46
- } ) ;
51
+ } ;
52
+
53
+ console . log ( 'Making API request to:' , `${ API_BASE_URL } /stocks` ) ;
54
+ console . log ( 'Request data:' , requestData ) ;
55
+
56
+ const response = await axios . post ( `${ API_BASE_URL } /stocks` , requestData ) ;
47
57
48
58
console . log ( 'Stock added successfully:' , response . data ) ;
49
59
@@ -62,7 +72,12 @@ export default function AddStockModal({ open, setOpen, onStockAdded }) {
62
72
onStockAdded ( response . data ) ;
63
73
}
64
74
} catch ( error ) {
65
- console . error ( 'Error adding stock:' , error ) ;
75
+ console . error ( 'Error details:' , {
76
+ message : error . message ,
77
+ response : error . response ?. data ,
78
+ status : error . response ?. status ,
79
+ apiUrl : API_BASE_URL
80
+ } ) ;
66
81
setError ( error . response ?. data ?. error || error . message || 'Failed to add stock' ) ;
67
82
} finally {
68
83
setLoading ( false ) ;
0 commit comments