Refactor network service to use config objects for clarity

This commit is contained in:
Alex Holliday committed 2024-09-22 11:38:42 +08:00
1 parent a8e069b820
commit 1c8376dc24
11 files changed
+325 -286

No files matched your search

@@ -53,27 +53,27 @@ const IncidentTable = ({ monitors, selectedMonitor, filter }) => {
try {
let res;
if (selectedMonitor === "0") {
res = await networkService.getChecksByTeam(
authToken,
user.teamId,
"desc",
null,
null,
filter,
paginationController.page,
paginationController.rowsPerPage
);
res = await networkService.getChecksByTeam({
authToken: authToken,
userId: user.teamId,
sortOrder: "desc",
limit: null,
dateRange: null,
filter: filter,
page: paginationController.page,
rowsPerPage: paginationController.rowsPerPage,
});
} else {
res = await networkService.getChecksByMonitor(
authToken,
selectedMonitor,
"desc",
null,
null,
filter,
paginationController.page,
paginationController.rowsPerPage
);
res = await networkService.getChecksByMonitor({
authToken: authToken,
monitorId: selectedMonitor,
sortOrder: "desc",
limit: null,
dateRange: null,
sitler: filter,
page: paginationController.page,
rowsPerPage: paginationController.rowsPerPage,
});
}
setChecks(res.data.data.checks);
setChecksCount(res.data.data.checksCount);
@@ -40,16 +40,16 @@ const PaginationTable = ({ monitorId, dateRange }) => {
useEffect(() => {
const fetchPage = async () => {
try {
const res = await networkService.getChecksByMonitor(
authToken,
monitorId,
"desc",
null,
dateRange,
null,
paginationController.page,
paginationController.rowsPerPage
);
const res = await networkService.getChecksByMonitor({
authToken: authToken,
moniotrId: monitorId,
sortOrder: "desc",
limit: null,
dateRange: dateRange,
filter: null,
page: paginationController.page,
rowsPerPage: paginationController.rowsPerPage,
});
setChecks(res.data.data.checks);
setChecksCount(res.data.data.checksCount);
} catch (error) {
+13 -13
View File
@@ -63,15 +63,15 @@ const DetailsPage = ({ isAdmin }) => {
const fetchMonitor = useCallback(async () => {
try {
const res = await networkService.getStatsByMonitorId(
authToken,
monitorId,
null,
null,
dateRange,
50,
true
);
const res = await networkService.getStatsByMonitorId({
authToken: authToken,
monitorId: monitorId,
sortOrder: null,
limit: null,
dateRange: dateRange,
numToDisplay: 50,
normalize: true,
});
setMonitor(res?.data?.data ?? {});
} catch (error) {
logger.error(error);
@@ -89,10 +89,10 @@ const DetailsPage = ({ isAdmin }) => {
return;
}
try {
const res = await networkService.getCertificateExpiry(
authToken,
monitorId
);
const res = await networkService.getCertificateExpiry({
authToken: authToken,
monitorId: monitorId,
});
if (res?.data?.data?.certificateDate) {
let [month, day, year] = res.data.data.certificateDate.split("/");
+9 -9
View File
@@ -44,15 +44,15 @@ const PageSpeedDetails = () => {
useEffect(() => {
const fetchMonitor = async () => {
try {
const res = await networkService.getStatsByMonitorId(
authToken,
monitorId,
"desc",
50,
"day",
null,
null
);
const res = await networkService.getStatsByMonitorId({
authToken: authToken,
monitorId: monitorId,
sortOrder: "desc",
limit: 50,
dateRange: "day",
numToDisplay: null,
normalize: null,
});
setMonitor(res?.data?.data ?? {});
setAudits(res?.data?.data?.checks?.[0]?.audits ?? []);
} catch (error) {
+4 -1
View File
@@ -69,7 +69,10 @@ const Settings = ({ isAdmin }) => {
const handleSave = async () => {
try {
setChecksIsLoading(true);
await networkService.updateChecksTTL(authToken, form.ttl);
await networkService.updateChecksTTL({
authToken: authToken,
ttl: form.ttl,
});
const updatedUser = { ...user, checkTTL: form.ttl };
const action = await dispatch(
update({ authToken, localData: updatedUser })