Fakultas Ilmu Komputer UI

Commit 34e2a050 authored by Sean Zeliq Urian's avatar Sean Zeliq Urian
Browse files

[GREEN] route ActivityLog scene and put it on navbar

parent d6b893da
Pipeline #79885 passed with stages
in 4 minutes and 9 seconds
...@@ -6,7 +6,7 @@ import { Home, AccountManagement, Login, CaseRecapitulation, PositiveCaseInput } ...@@ -6,7 +6,7 @@ import { Home, AccountManagement, Login, CaseRecapitulation, PositiveCaseInput }
import { LocalStorage } from 'services'; import { LocalStorage } from 'services';
import { DEFAULT_SECRET_KEY } from 'constant'; import { DEFAULT_SECRET_KEY } from 'constant';
import Layout from './components/Layout'; import Layout from './components/Layout';
import ActivityLog from 'scenes/ActivityLog/components/ActivityLog'; import ActivityLog from 'scenes/ActivityLog';
export default function Routes() { export default function Routes() {
const { user, setUser, setToken, token, services, alert } = useContext( const { user, setUser, setToken, token, services, alert } = useContext(
......
import { createEndpoint, createDateFilterParam } from 'helper';
import axios from 'axios'; import axios from 'axios';
import { DateProps } from 'contexts/AppContext/types';
import { FilterType, StatisticType, AgeKeyProps, ExportPayload, SexKeyProps, DistrictKeyProps, SubDistrictKeyProps } from 'contexts/AppContext/types'; import { createEndpoint, createDateFilterParam } from 'helper';
import {
FilterType,
StatisticType,
AgeKeyProps,
ExportPayload,
SexKeyProps,
DistrictKeyProps,
SubDistrictKeyProps,
} from 'contexts/AppContext/types';
const API_MAIN_URL = process.env.REACT_APP_API_MAIN_URL; const API_MAIN_URL = process.env.REACT_APP_API_MAIN_URL;
...@@ -145,7 +153,7 @@ export default function useMainService(token: string) { ...@@ -145,7 +153,7 @@ export default function useMainService(token: string) {
async function listInvestigationCases( async function listInvestigationCases(
query: string = '', query: string = '',
page: number = 1, page: number = 1,
includePositive: boolean = false, includePositive: boolean = false
) { ) {
const endpoint = END_POINTS.INVESTIGATION_CASES([ const endpoint = END_POINTS.INVESTIGATION_CASES([
includePositive includePositive
...@@ -160,14 +168,18 @@ export default function useMainService(token: string) { ...@@ -160,14 +168,18 @@ export default function useMainService(token: string) {
page: number = 1, page: number = 1,
includePositive: boolean = false includePositive: boolean = false
) { ) {
const endpoint = END_POINTS.INVESTIGATION_CASES( const endpoint = END_POINTS.INVESTIGATION_CASES([
[ includePositive? `?include_positive=true&search=${query}&page=${page}` : `?search=${query}&page=${page}`] includePositive
); ? `?include_positive=true&search=${query}&page=${page}`
: `?search=${query}&page=${page}`,
]);
return fetchWithAuthentication(endpoint.slice(0, -1), Method.GET); return fetchWithAuthentication(endpoint.slice(0, -1), Method.GET);
} }
async function filterInvestigationCases( async function filterInvestigationCases(
filterType: string, query: string, includePositive: boolean = false filterType: string,
query: string,
includePositive: boolean = false
) { ) {
let urlQuery = ''; let urlQuery = '';
switch (filterType) { switch (filterType) {
...@@ -194,9 +206,9 @@ export default function useMainService(token: string) { ...@@ -194,9 +206,9 @@ export default function useMainService(token: string) {
break; break;
} }
const endpoint = END_POINTS.INVESTIGATION_CASES( const endpoint = END_POINTS.INVESTIGATION_CASES([
[includePositive ? `?include_positive=true&${urlQuery}` :`?${urlQuery}`] includePositive ? `?include_positive=true&${urlQuery}` : `?${urlQuery}`,
); ]);
return fetchWithAuthentication(endpoint.slice(0, -1), Method.GET); return fetchWithAuthentication(endpoint.slice(0, -1), Method.GET);
} }
...@@ -206,21 +218,24 @@ export default function useMainService(token: string) { ...@@ -206,21 +218,24 @@ export default function useMainService(token: string) {
} }
async function createCaseSubject(body: object) { async function createCaseSubject(body: object) {
const endpoint = END_POINTS.CASE_SUBJECTS([null]) const endpoint = END_POINTS.CASE_SUBJECTS([null]);
return fetchWithAuthentication(endpoint, Method.POST, body); return fetchWithAuthentication(endpoint, Method.POST, body);
} }
async function createInvestigationCase(body: object) { async function createInvestigationCase(body: object) {
const endpoint = END_POINTS.INVESTIGATION_CASES([null]) const endpoint = END_POINTS.INVESTIGATION_CASES([null]);
return fetchWithAuthentication(endpoint, Method.POST, body); return fetchWithAuthentication(endpoint, Method.POST, body);
} }
async function createMonitoringCase(body: object) { async function createMonitoringCase(body: object) {
const endpoint = END_POINTS.MONITORING_CASES([null]) const endpoint = END_POINTS.MONITORING_CASES([null]);
return fetchWithAuthentication(endpoint, Method.POST, body); return fetchWithAuthentication(endpoint, Method.POST, body);
} }
async function listNotCheckedMonitoringCase(query: string = '', page: number = 1) { async function listNotCheckedMonitoringCase(
query: string = '',
page: number = 1
) {
const endpoint = END_POINTS.MONITORING_CASES([ const endpoint = END_POINTS.MONITORING_CASES([
`?page=${page}&search=${query}&is_checked=false`, `?page=${page}&search=${query}&is_checked=false`,
]); ]);
...@@ -229,7 +244,7 @@ export default function useMainService(token: string) { ...@@ -229,7 +244,7 @@ export default function useMainService(token: string) {
async function searchNotCheckedMonitoringCase(query: string = '') { async function searchNotCheckedMonitoringCase(query: string = '') {
const endpoint = END_POINTS.MONITORING_CASES([ const endpoint = END_POINTS.MONITORING_CASES([
`?search=${query}&is_checked=false` `?search=${query}&is_checked=false`,
]); ]);
return fetchWithAuthentication(endpoint.slice(0, -1), Method.GET); return fetchWithAuthentication(endpoint.slice(0, -1), Method.GET);
} }
...@@ -244,9 +259,7 @@ export default function useMainService(token: string) { ...@@ -244,9 +259,7 @@ export default function useMainService(token: string) {
return fetchWithAuthentication(endpoint, Method.PUT, body); return fetchWithAuthentication(endpoint, Method.PUT, body);
} }
async function fetchStatistics( async function fetchStatistics(filter: ExportPayload) {
filter : ExportPayload
) {
let urlQuery = '?'; let urlQuery = '?';
switch (filter?.filterType) { switch (filter?.filterType) {
case StatisticType.Sex: case StatisticType.Sex:
...@@ -263,10 +276,11 @@ export default function useMainService(token: string) { ...@@ -263,10 +276,11 @@ export default function useMainService(token: string) {
break; break;
case StatisticType.Age: case StatisticType.Age:
const ageKey = filter?.filters as AgeKeyProps; const ageKey = filter?.filters as AgeKeyProps;
urlQuery= `?min_age=${ageKey.minAge}&max_age=${ageKey.maxAge}`; urlQuery = `?min_age=${ageKey.minAge}&max_age=${ageKey.maxAge}`;
} }
urlQuery+= "&" + createDateFilterParam(filter?.start_date, filter?.end_date) urlQuery +=
'&' + createDateFilterParam(filter?.start_date, filter?.end_date);
const endpoint = END_POINTS.EXPORTABLES([`${urlQuery}`]); const endpoint = END_POINTS.EXPORTABLES([`${urlQuery}`]);
return fetchWithAuthentication(endpoint.slice(0, -1), Method.GET); return fetchWithAuthentication(endpoint.slice(0, -1), Method.GET);
...@@ -278,13 +292,13 @@ export default function useMainService(token: string) { ...@@ -278,13 +292,13 @@ export default function useMainService(token: string) {
} }
async function exportXLS() { async function exportXLS() {
const endpoint = END_POINTS.EXPORTABLES(['investigation-cases-csv?download_as_xls=1']); const endpoint = END_POINTS.EXPORTABLES([
'investigation-cases-csv?download_as_xls=1',
]);
return downloadWithAuthentication(endpoint.slice(0, -1), Method.GET); return downloadWithAuthentication(endpoint.slice(0, -1), Method.GET);
} }
async function filterExportCSV( async function filterExportCSV(filter: ExportPayload) {
filter: ExportPayload
) {
let urlQuery = '?'; let urlQuery = '?';
switch (filter.filterType) { switch (filter.filterType) {
case StatisticType.Sex: case StatisticType.Sex:
...@@ -301,18 +315,19 @@ export default function useMainService(token: string) { ...@@ -301,18 +315,19 @@ export default function useMainService(token: string) {
break; break;
case StatisticType.Age: case StatisticType.Age:
const ageKey = filter.filters as AgeKeyProps; const ageKey = filter.filters as AgeKeyProps;
urlQuery= `?min_age=${ageKey.minAge}&max_age=${ageKey.maxAge}`; urlQuery = `?min_age=${ageKey.minAge}&max_age=${ageKey.maxAge}`;
} }
urlQuery+= "&" + createDateFilterParam(filter?.start_date, filter?.end_date) urlQuery +=
'&' + createDateFilterParam(filter?.start_date, filter?.end_date);
const endpoint = END_POINTS.EXPORTABLES([`investigation-cases-csv${urlQuery}`]); const endpoint = END_POINTS.EXPORTABLES([
`investigation-cases-csv${urlQuery}`,
]);
return downloadWithAuthentication(endpoint.slice(0, -1), Method.GET); return downloadWithAuthentication(endpoint.slice(0, -1), Method.GET);
} }
async function filterExportXLS( async function filterExportXLS(filter: ExportPayload) {
filter: ExportPayload
) {
let urlQuery = '?'; let urlQuery = '?';
switch (filter.filterType) { switch (filter.filterType) {
case StatisticType.Sex: case StatisticType.Sex:
...@@ -329,34 +344,40 @@ export default function useMainService(token: string) { ...@@ -329,34 +344,40 @@ export default function useMainService(token: string) {
break; break;
case StatisticType.Age: case StatisticType.Age:
const ageKey = filter.filters as AgeKeyProps; const ageKey = filter.filters as AgeKeyProps;
urlQuery= `?min_age=${ageKey.minAge}&max_age=${ageKey.maxAge}`; urlQuery = `?min_age=${ageKey.minAge}&max_age=${ageKey.maxAge}`;
} }
urlQuery+= "&" + createDateFilterParam(filter?.start_date, filter?.end_date) urlQuery +=
'&' + createDateFilterParam(filter?.start_date, filter?.end_date);
const endpoint = END_POINTS.EXPORTABLES([`investigation-cases-csv${urlQuery}&download_as_xls=1`]); const endpoint = END_POINTS.EXPORTABLES([
`investigation-cases-csv${urlQuery}&download_as_xls=1`,
]);
return downloadWithAuthentication(endpoint.slice(0, -1), Method.GET); return downloadWithAuthentication(endpoint.slice(0, -1), Method.GET);
} }
async function getLog(page: number) { async function getLog(
if (page === 1) { page: number,
const endpoint = END_POINTS.LOGS([ roleFilterQuery: String,
null, start_date: String,
]) end_date: String,
return fetchWithAuthentication(endpoint, Method.GET); ignoreDateFilterQuery: boolean
) {
let param = "?page=" + page + "&";
if (roleFilterQuery !== "Semua Peran") {
param += "is_admin=" + (roleFilterQuery.toLowerCase() === "admin") + "&";
} }
const endpointWithPaging = END_POINTS.LOGS([ if (!ignoreDateFilterQuery) {
`?page=${page}`, param += "start_date=" + start_date + "&";
]) param += "end_date=" + end_date;
return fetchWithAuthentication(
endpointWithPaging.slice(0, -1),
Method.GET,
);
} }
async function fetchStatisticsByDate( const endpointWithPaging = END_POINTS.LOGS([param]);
start_date: string, end_date: string console.log(endpointWithPaging)
) { return fetchWithAuthentication(endpointWithPaging.slice(0, -1), Method.GET);
}
async function fetchStatisticsByDate(start_date: string, end_date: string) {
let urlQuery = `?start_date=${start_date}&end_date=${end_date}`; let urlQuery = `?start_date=${start_date}&end_date=${end_date}`;
const endpoint = END_POINTS.EXPORTABLES([`${urlQuery}`]); const endpoint = END_POINTS.EXPORTABLES([`${urlQuery}`]);
return fetchWithAuthentication(endpoint.slice(0, -1), Method.GET); return fetchWithAuthentication(endpoint.slice(0, -1), Method.GET);
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment