File tree Expand file tree Collapse file tree
app/(dashboard)/[organizationId]/projects Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -27,6 +27,7 @@ export default function ProjectsPage({
2727 const createModal = useModal ( ) ;
2828 const deleteModal = useModal ( ) ;
2929 const [ projectList , setProjectList ] = useState < Project [ ] > ( [ ] ) ;
30+ const [ deleteModalOpen , setDeleteModalOpen ] = useState ( false ) ;
3031 const [ projectToDelete , setProjectToDelete ] = useState < Project | null > (
3132 null ,
3233 ) ;
@@ -43,7 +44,7 @@ export default function ProjectsPage({
4344
4445 const handleDeleteClick = ( project : Project ) => {
4546 setProjectToDelete ( project ) ;
46- deleteModal . open ( ) ;
47+ setDeleteModalOpen ( true ) ;
4748 } ;
4849
4950 const handleDeleteConfirm = async ( projectId : string ) => {
@@ -143,8 +144,8 @@ export default function ProjectsPage({
143144 </ Card >
144145 { projectToDelete && (
145146 < DeleteProjectModal
146- open = { deleteModal . isOpen }
147- onOpenChange = { deleteModal . setIsOpen }
147+ open = { deleteModalOpen }
148+ onOpenChange = { setDeleteModalOpen }
148149 projectName = { projectToDelete . name }
149150 projectId = { projectToDelete . id }
150151 onDelete = { handleDeleteConfirm }
Original file line number Diff line number Diff line change @@ -48,16 +48,38 @@ export async function fetchApiServer<T>(
4848 return null ;
4949 }
5050
51- // Parse JSON response
52- try {
53- return await response . json ( ) ;
54- } catch ( e ) {
55- // If JSON parsing fails (e.g., empty response body), return null
56- console . warn (
57- `Empty or invalid JSON response from ${ endpoint } , returning null` ,
58- ) ;
51+ // Handle 204 No Content responses (e.g., DELETE operations)
52+ if ( response . status === 204 ) {
5953 return null ;
6054 }
55+
56+ // Special handling for endpoints that might return null
57+ if (
58+ endpoint . includes ( "/organizations/" ) &&
59+ endpoint . includes ( "/sums" )
60+ ) {
61+ // For organization sums endpoint that might return null
62+ try {
63+ return await response . json ( ) ;
64+ } catch ( e ) {
65+ // If JSON parsing fails (e.g., empty response), return default values
66+ console . warn (
67+ "Empty response from organization sums endpoint, using default values" ,
68+ ) ;
69+ return {
70+ name : "" ,
71+ description : "" ,
72+ emissions : 0 ,
73+ energy_consumed : 0 ,
74+ duration : 0 ,
75+ cpu_power : 0 ,
76+ gpu_power : 0 ,
77+ ram_power : 0 ,
78+ emissions_rate : 0 ,
79+ emissions_count : 0 ,
80+ } as unknown as T ;
81+ }
82+ }
6183 } catch ( error ) {
6284 // Log server-side error with more details
6385 console . error ( "API server request failed:" , {
You can’t perform that action at this time.
0 commit comments