Skip to content

Commit 0038c79

Browse files
committed
lint
1 parent 029dfdf commit 0038c79

22 files changed

+310
-156
lines changed

.env

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,3 @@
1-
PORT=3002
1+
VITE_PORT=3000
2+
VITE_ENV_API_URL=127.0.0.1
3+
EXPOSED_PORT=3002

.prettierrc.json

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
{
2+
"tabWidth": 2,
3+
"printWidth": 80,
4+
"singleQuote": true,
5+
"jsxSingleQuote": true,
6+
"bracketSpacing": true,
7+
"arrowParens": "avoid",
8+
"trailingComma": "all"
9+
}

Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,5 +21,5 @@ dev:
2121
docker run --rm -it \
2222
-v $(CURRENT_DIR):/app \
2323
-w /app \
24-
-p $(PORT):$(PORT) \
24+
-p $(EXPOSED_PORT):$(EXPOSED_PORT) \
2525
$(DOCKER_IMAGE) /bin/bash

models/ccn-coverage-models

package.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@
1313
"@mui/x-date-pickers": "^7.27.3",
1414
"add": "^2.0.6",
1515
"arquero": "^8.0.1",
16-
"axios": "^1.6.7",
1716
"cors": "^2.8.5",
1817
"d3": "^7.8.5",
1918
"dayjs": "^1.11.13",

src/admin/AdminPortal.tsx

Lines changed: 18 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,7 @@ import ChevronLeftIcon from '@mui/icons-material/ChevronLeft';
1616
import { mainListItems, secondaryListItems } from '../ListItems';
1717
import Footer from '../Footer';
1818
import AdminBody from './AdminBody';
19-
import axios from 'axios';
20-
import { API_URL } from '../utils/config';
19+
import { apiClient } from '@/utils/fetch';
2120

2221
const drawerWidth: number = 240;
2322

@@ -75,6 +74,22 @@ const Drawer = styled(MuiDrawer, {
7574

7675
const mdTheme = createTheme();
7776

77+
const logout = () => {
78+
apiClient
79+
.GET('/api/logout')
80+
.then(res => {
81+
const { data, error } = res;
82+
if (!data || error) {
83+
console.log(`Unable to logout: ${error}`);
84+
return;
85+
}
86+
window.open('/', '_self');
87+
})
88+
.catch(err => {
89+
console.log(`Error occurred while logging out: ${err}`);
90+
});
91+
};
92+
7893
export default function AdminPortal(props: AdminPortalProps) {
7994
const [open, setOpen] = React.useState(false);
8095
const toggleDrawer = () => {
@@ -117,19 +132,7 @@ export default function AdminPortal(props: AdminPortalProps) {
117132
>
118133
Admin Portal
119134
</Typography>
120-
<Button
121-
color='inherit'
122-
onClick={() => {
123-
axios
124-
.get(API_URL + '/api/logout')
125-
.then(function (response) {
126-
window.open('/', '_self');
127-
})
128-
.catch(function (error) {
129-
console.log(error);
130-
});
131-
}}
132-
>
135+
<Button color='inherit' onClick={logout}>
133136
Logout
134137
</Button>
135138
</Toolbar>

src/admin/EditData.tsx

Lines changed: 41 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,8 @@ import DialogContentText from '@mui/material/DialogContentText';
1818
import DialogTitle from '@mui/material/DialogTitle';
1919

2020
import { styled } from '@mui/material/styles';
21-
import axios from 'axios';
22-
23-
import { API_URL } from '../utils/config';
2421
import '../utils/fonts.css';
22+
import { apiClient } from '@/utils/fetch';
2523

2624
const Input = styled('input')({
2725
display: 'none',
@@ -33,7 +31,7 @@ export default function EditData() {
3331
const [csv, setCsv] = useState('');
3432
const [group, setGroup] = useState('');
3533
const [newGroup, setNewGroup] = useState('');
36-
const [groups, setGroups] = useState([]);
34+
const [groups, setGroups] = useState<string[]>([]);
3735
const [loading, setLoading] = useState(true);
3836
const [open, setOpen] = React.useState(false);
3937
const handleFileChange = (e: React.ChangeEvent<HTMLInputElement>) => {
@@ -56,12 +54,20 @@ export default function EditData() {
5654
};
5755

5856
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+
},
6363
})
6464
.then(res => {
65+
const { data, error } = res;
66+
if (error || !data) {
67+
console.log(`Unable to upload data: ${error}`);
68+
return;
69+
}
70+
6571
setLoading(true);
6672
alert('Successfully replaced');
6773
})
@@ -73,11 +79,19 @@ export default function EditData() {
7379
};
7480

7581
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+
},
7987
})
8088
.then(res => {
89+
const { data, error } = res;
90+
if (error || !data) {
91+
console.log(`Unable to delete group: ${error}`);
92+
return;
93+
}
94+
8195
setLoading(true);
8296
alert('Successfully deleted');
8397
})
@@ -97,9 +111,15 @@ export default function EditData() {
97111
};
98112

99113
const handleDeleteAllClick = () => {
100-
axios
101-
.post(API_URL + '/secure/delete_manual')
114+
apiClient
115+
.POST('/secure/delete_manual')
102116
.then(res => {
117+
const { data, error } = res;
118+
if (error || !data) {
119+
console.log(`Unable to delete manually: ${error}`);
120+
return;
121+
}
122+
103123
setLoading(true);
104124
alert('Successfully deleted');
105125
handleClose();
@@ -112,10 +132,15 @@ export default function EditData() {
112132
};
113133

114134
useEffect(() => {
115-
axios
116-
.post(API_URL + '/secure/get_groups')
135+
apiClient
136+
.POST('/secure/get_groups')
117137
.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);
119144
setLoading(false);
120145
})
121146
.catch(err => {

src/admin/EditSite.tsx

Lines changed: 25 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,9 @@ import TextField from '@mui/material/TextField';
1010
import Typography from '@mui/material/Typography';
1111
import EditLocationAltIcon from '@mui/icons-material/EditLocationAlt';
1212
import Loading from '../Loading';
13-
import axios from 'axios';
14-
import { API_URL } from '../utils/config';
1513
import '../utils/fonts.css';
14+
import { apiClient } from '@/utils/fetch';
15+
1616
var newSites = '';
1717
export default function EditSite() {
1818
const [loadingSites, setLoadingSites] = useState(true);
@@ -62,31 +62,45 @@ export default function EditSite() {
6262
setOpenJsonError(true);
6363
return;
6464
}
65-
axios
66-
.post(API_URL + '/secure/edit_sites', {
67-
sites: sitesJson,
65+
66+
apiClient
67+
.POST('/secure/edit_sites', {
68+
body: {
69+
sites: sitesJson,
70+
},
6871
})
6972
.then(res => {
73+
const { data, error } = res;
74+
if (error || !data) {
75+
console.log(`Unable to edit site: ${error}`);
76+
return;
77+
}
78+
7079
setOpenApiError(false);
7180
setOpenJsonError(false);
7281
setOpenSuccess(true);
7382
reloadSites();
7483
})
7584
.catch(err => {
85+
console.error(`Error occurred while editting site: ${err}`);
7686
setOpenApiError(false);
7787
setOpenSuccess(false);
7888
setOpenApiError(true);
79-
console.log(err);
8089
});
8190
};
8291
const reloadSites = () => {
83-
axios
84-
.get(API_URL + '/api/sites')
92+
apiClient
93+
.GET('/api/sites')
8594
.then(res => {
86-
const sites = res.data;
95+
const { data, error } = res;
96+
if (error || !data) {
97+
console.log(`Unable to query sites: ${error}`);
98+
return;
99+
}
100+
87101
setLoadingSites(false);
88-
setSites(JSON.stringify(sites, null, 2));
89-
newSites = JSON.stringify(sites, null, 2);
102+
setSites(JSON.stringify(data, null, 2));
103+
newSites = JSON.stringify(data, null, 2);
90104
})
91105
.catch(err => {
92106
setLoadingSites(false);

src/admin/Login.tsx

Lines changed: 28 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,8 @@ import Alert from '@mui/material/Alert';
1010
import Typography from '@mui/material/Typography';
1111
import Container from '@mui/material/Container';
1212
import Footer from '../Footer';
13-
import axios from 'axios';
1413
import { createTheme, ThemeProvider } from '@mui/material/styles';
15-
import { API_URL } from '../utils/config';
14+
import { apiClient } from '@/utils/fetch';
1615
const theme = createTheme();
1716

1817
export default function Login() {
@@ -31,20 +30,41 @@ export default function Login() {
3130
event.preventDefault();
3231
const data = new FormData(event.currentTarget);
3332
// eslint-disable-next-line no-console
34-
axios
35-
.post(API_URL + '/secure/login', {
36-
username: data.get('username'),
37-
password: data.get('password'),
33+
34+
if (!data.has('username')) {
35+
return;
36+
}
37+
38+
if (!data.has('password')) {
39+
return;
40+
}
41+
42+
const username = data.get('username')?.toString() as string;
43+
const password = data.get('password')?.toString() as string;
44+
45+
apiClient
46+
.POST('/secure/login', {
47+
body: {
48+
username: username,
49+
password: password,
50+
},
3851
})
3952
.then(res => {
40-
if (res.data === 'success') {
53+
const { data, error } = res;
54+
if (!data || error) {
55+
console.log(`Unable to login: ${error}`);
56+
setOpen(true);
57+
return;
58+
}
59+
60+
if (data === 'success') {
4161
window.open('/admin/users', '_self');
4262
} else {
4363
setOpen(true);
4464
}
4565
})
4666
.catch(err => {
47-
console.log(err);
67+
console.error(`Error occurred while logging in: ${err}`);
4868
setOpen(true);
4969
});
5070
};

src/admin/NewUserDialog.tsx

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,7 @@ import DialogContentText from '@mui/material/DialogContentText';
88
import DialogTitle from '@mui/material/DialogTitle';
99
import Stack from '@mui/material/Stack';
1010
import AddIcon from '@mui/icons-material/Add';
11-
import axios from 'axios';
12-
import { API_URL } from '../utils/config';
11+
import { apiClient } from '@/utils/fetch';
1312

1413
interface NewUserDialogProp {
1514
setCalled: React.Dispatch<React.SetStateAction<boolean>>;
@@ -29,18 +28,27 @@ export default function NewUserDialog(props: NewUserDialogProp) {
2928
};
3029

3130
const handleSubmit = () => {
32-
axios
33-
.post(API_URL + '/secure/new-user', {
34-
firstName: firstName,
35-
lastName: lastName,
36-
email: email,
31+
apiClient
32+
.POST('/secure/new-user', {
33+
body: {
34+
firstName: firstName,
35+
lastName: lastName,
36+
email: email,
37+
},
3738
})
3839
.then(res => {
40+
const { error } = res;
41+
if (error) {
42+
console.log(`Unable to create user: ${error}`);
43+
setOpen(true);
44+
return;
45+
}
46+
3947
props.setCalled(false);
4048
setOpen(false);
4149
})
4250
.catch(err => {
43-
console.log(err);
51+
console.log(`Unable to create user: ${err}`);
4452
setOpen(true);
4553
});
4654
};

0 commit comments

Comments
 (0)