mirror of
https://github.com/house-of-vanity/OutFleet.git
synced 2025-10-24 01:09:08 +00:00
feat: fetch dashboard data
This commit is contained in:
3
client/.env
Normal file
3
client/.env
Normal file
@@ -0,0 +1,3 @@
|
|||||||
|
VITE_API_BASE=/api
|
||||||
|
VITE_API_HOST=http://localhost
|
||||||
|
VITE_API_PORT=8081
|
||||||
9
client/src/api/api.ts
Normal file
9
client/src/api/api.ts
Normal file
@@ -0,0 +1,9 @@
|
|||||||
|
import axios from 'axios';
|
||||||
|
|
||||||
|
const VITE_API_BASE = import.meta.env.VITE_API_BASE;
|
||||||
|
const VITE_API_HOST = import.meta.env.VITE_API_HOST;
|
||||||
|
const VITE_API_PORT = import.meta.env.VITE_API_PORT;
|
||||||
|
|
||||||
|
export const api = axios.create({
|
||||||
|
baseURL: `${VITE_API_HOST}:${VITE_API_PORT}${VITE_API_BASE}`,
|
||||||
|
});
|
||||||
5
client/src/api/certificates.ts
Normal file
5
client/src/api/certificates.ts
Normal file
@@ -0,0 +1,5 @@
|
|||||||
|
import { api } from './api';
|
||||||
|
|
||||||
|
export interface Certificate {}
|
||||||
|
|
||||||
|
export const getCertificates = api.get<never, Certificate[]>('/certificates');
|
||||||
4
client/src/api/index.ts
Normal file
4
client/src/api/index.ts
Normal file
@@ -0,0 +1,4 @@
|
|||||||
|
export * from './certificates';
|
||||||
|
export * from './servers';
|
||||||
|
export * from './templates';
|
||||||
|
export * from './users';
|
||||||
5
client/src/api/servers.ts
Normal file
5
client/src/api/servers.ts
Normal file
@@ -0,0 +1,5 @@
|
|||||||
|
import { api } from './api';
|
||||||
|
|
||||||
|
export interface Server {}
|
||||||
|
|
||||||
|
export const getServers = api.get<never, Server[]>('/servers');
|
||||||
5
client/src/api/templates.ts
Normal file
5
client/src/api/templates.ts
Normal file
@@ -0,0 +1,5 @@
|
|||||||
|
import { api } from './api';
|
||||||
|
|
||||||
|
export interface Template {}
|
||||||
|
|
||||||
|
export const getTemplates = api.get<never, Template[]>('/templates');
|
||||||
5
client/src/api/users.ts
Normal file
5
client/src/api/users.ts
Normal file
@@ -0,0 +1,5 @@
|
|||||||
|
import { api } from './api';
|
||||||
|
|
||||||
|
export interface User {}
|
||||||
|
|
||||||
|
export const getUsers = api.get<never, User[]>('/users');
|
||||||
@@ -1,21 +1,81 @@
|
|||||||
import type { RouteObject } from 'react-router';
|
import type { RouteObject } from 'react-router';
|
||||||
|
import {
|
||||||
|
getServers,
|
||||||
|
getTemplates,
|
||||||
|
getCertificates,
|
||||||
|
getUsers,
|
||||||
|
type Server,
|
||||||
|
type Template,
|
||||||
|
type Certificate,
|
||||||
|
type User,
|
||||||
|
} from '../../api';
|
||||||
|
import { useEffect, useState } from 'react';
|
||||||
|
|
||||||
|
export const loadDashboard = async () => {
|
||||||
|
try {
|
||||||
|
const [servers, templates, certificates, users] = await Promise.all([
|
||||||
|
getServers.then((data) => data),
|
||||||
|
getTemplates.then((data) => data),
|
||||||
|
getCertificates.then((data) => data),
|
||||||
|
getUsers.then((data) => data),
|
||||||
|
]);
|
||||||
|
|
||||||
|
return [servers, templates, certificates, users];
|
||||||
|
} catch (error) {
|
||||||
|
console.log(error);
|
||||||
|
alert('loading error');
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
export const Dashboard = () => {
|
export const Dashboard = () => {
|
||||||
|
const [servers, setServers] = useState<Server[] | undefined>(undefined);
|
||||||
|
const [templates, setTemplates] = useState<Template[] | undefined>(undefined);
|
||||||
|
const [certificates, setCertificates] = useState<Certificate[] | undefined>(
|
||||||
|
undefined,
|
||||||
|
);
|
||||||
|
const [users, setUsers] = useState<User[] | undefined>(undefined);
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
loadDashboard()
|
||||||
|
.then((res) => {
|
||||||
|
if (res) {
|
||||||
|
const [servers, templates, certificates, users] = res;
|
||||||
|
setServers(servers);
|
||||||
|
setTemplates(templates);
|
||||||
|
setCertificates(certificates);
|
||||||
|
setUsers(users);
|
||||||
|
}
|
||||||
|
})
|
||||||
|
.catch((e) => {
|
||||||
|
console.log(e);
|
||||||
|
});
|
||||||
|
}, []);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div id="dashboard" className="tab-content active">
|
<div id="dashboard" className="tab-content active">
|
||||||
<div className="section">
|
<div className="section">
|
||||||
<h2>Statistics</h2>
|
<h2>Statistics</h2>
|
||||||
<p>
|
<p>
|
||||||
Servers: <span id="serverCount">Loading...</span>
|
Servers:{' '}
|
||||||
|
<span id="serverCount">
|
||||||
|
{servers ? servers.length || 0 : 'Loading...'}
|
||||||
|
</span>
|
||||||
</p>
|
</p>
|
||||||
<p>
|
<p>
|
||||||
Templates: <span id="templateCount">Loading...</span>
|
Templates:{' '}
|
||||||
|
<span id="templateCount">
|
||||||
|
{templates ? templates.length || 0 : 'Loading...'}
|
||||||
|
</span>
|
||||||
</p>
|
</p>
|
||||||
<p>
|
<p>
|
||||||
Certificates: <span id="certCount">Loading...</span>
|
Certificates:{' '}
|
||||||
|
<span id="certCount">
|
||||||
|
{certificates ? certificates.length || 0 : 'Loading...'}
|
||||||
|
</span>
|
||||||
</p>
|
</p>
|
||||||
<p>
|
<p>
|
||||||
Users: <span id="userCount">Loading...</span>
|
Users:{' '}
|
||||||
|
<span id="userCount">{users ? users.length || 0 : 'Loading...'}</span>
|
||||||
</p>
|
</p>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
Reference in New Issue
Block a user