@@ -18,10 +18,8 @@ import DialogContentText from '@mui/material/DialogContentText';
18
18
import DialogTitle from '@mui/material/DialogTitle' ;
19
19
20
20
import { styled } from '@mui/material/styles' ;
21
- import axios from 'axios' ;
22
-
23
- import { API_URL } from '../utils/config' ;
24
21
import '../utils/fonts.css' ;
22
+ import { apiClient } from '@/utils/fetch' ;
25
23
26
24
const Input = styled ( 'input' ) ( {
27
25
display : 'none' ,
@@ -33,7 +31,7 @@ export default function EditData() {
33
31
const [ csv , setCsv ] = useState ( '' ) ;
34
32
const [ group , setGroup ] = useState ( '' ) ;
35
33
const [ newGroup , setNewGroup ] = useState ( '' ) ;
36
- const [ groups , setGroups ] = useState ( [ ] ) ;
34
+ const [ groups , setGroups ] = useState < string [ ] > ( [ ] ) ;
37
35
const [ loading , setLoading ] = useState ( true ) ;
38
36
const [ open , setOpen ] = React . useState ( false ) ;
39
37
const handleFileChange = ( e : React . ChangeEvent < HTMLInputElement > ) => {
@@ -56,12 +54,20 @@ export default function EditData() {
56
54
} ;
57
55
58
56
const handleClick = ( ) => {
59
- axios
60
- . post ( API_URL + '/secure/upload_data' , {
61
- csv : csv ,
62
- group : group === '' ? newGroup : group ,
57
+ apiClient
58
+ . POST ( '/secure/upload_data' , {
59
+ body : {
60
+ csv : csv ,
61
+ group : group === '' ? newGroup : group ,
62
+ } ,
63
63
} )
64
64
. then ( res => {
65
+ const { data, error } = res ;
66
+ if ( error || ! data ) {
67
+ console . log ( `Unable to upload data: ${ error } ` ) ;
68
+ return ;
69
+ }
70
+
65
71
setLoading ( true ) ;
66
72
alert ( 'Successfully replaced' ) ;
67
73
} )
@@ -73,11 +79,19 @@ export default function EditData() {
73
79
} ;
74
80
75
81
const handleDeleteClick = ( ) => {
76
- axios
77
- . post ( API_URL + '/secure/delete_group' , {
78
- group : group ,
82
+ apiClient
83
+ . POST ( '/secure/delete_group' , {
84
+ body : {
85
+ group : group ,
86
+ } ,
79
87
} )
80
88
. then ( res => {
89
+ const { data, error } = res ;
90
+ if ( error || ! data ) {
91
+ console . log ( `Unable to delete group: ${ error } ` ) ;
92
+ return ;
93
+ }
94
+
81
95
setLoading ( true ) ;
82
96
alert ( 'Successfully deleted' ) ;
83
97
} )
@@ -97,9 +111,15 @@ export default function EditData() {
97
111
} ;
98
112
99
113
const handleDeleteAllClick = ( ) => {
100
- axios
101
- . post ( API_URL + '/secure/delete_manual' )
114
+ apiClient
115
+ . POST ( '/secure/delete_manual' )
102
116
. then ( res => {
117
+ const { data, error } = res ;
118
+ if ( error || ! data ) {
119
+ console . log ( `Unable to delete manually: ${ error } ` ) ;
120
+ return ;
121
+ }
122
+
103
123
setLoading ( true ) ;
104
124
alert ( 'Successfully deleted' ) ;
105
125
handleClose ( ) ;
@@ -112,10 +132,15 @@ export default function EditData() {
112
132
} ;
113
133
114
134
useEffect ( ( ) => {
115
- axios
116
- . post ( API_URL + '/secure/get_groups' )
135
+ apiClient
136
+ . POST ( '/secure/get_groups' )
117
137
. then ( res => {
118
- setGroups ( res . data ) ;
138
+ const { data, error } = res ;
139
+ if ( ! data || error ) {
140
+ console . log ( `Unable to get group: ${ error } ` ) ;
141
+ return ;
142
+ }
143
+ setGroups ( data ) ;
119
144
setLoading ( false ) ;
120
145
} )
121
146
. catch ( err => {
0 commit comments