-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add initial version of
/status
page
- Loading branch information
Showing
1 changed file
with
64 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
import useSWR from "swr"; | ||
|
||
async function fetchAPI(key) { | ||
const response = await fetch(key); | ||
const responseBody = await response.json(); | ||
|
||
return responseBody; | ||
} | ||
|
||
export default function StatusPage() { | ||
return ( | ||
<> | ||
<h1>Status</h1> | ||
<UpdatedAt /> | ||
<DatabaseStatus /> | ||
</> | ||
); | ||
} | ||
|
||
function UpdatedAt() { | ||
const { isLoading, data } = useSWR("/api/v1/status", fetchAPI, { | ||
//Recarregar de 2 em 2 segundos | ||
refreshInterval: 2000, | ||
//Guarda a resposta no cache por padrão de 2 segundos não executando nova chamada nesse tempo | ||
dedupingInterval: 2000, | ||
}); | ||
|
||
let updatedAtText = "Carregando..."; | ||
|
||
if (!isLoading && data) { | ||
updatedAtText = new Date(data.updated_at).toLocaleString("pt-BR"); | ||
} | ||
|
||
return <div>Última atualização: {updatedAtText}</div>; | ||
} | ||
|
||
function DatabaseStatus() { | ||
const { isLoading, data } = useSWR("/api/v1/status", fetchAPI, { | ||
refreshInterval: 2000, | ||
}); | ||
|
||
let databaseStatusInformation = "Carregando..."; | ||
|
||
if (!isLoading && data) { | ||
databaseStatusInformation = ( | ||
<> | ||
<div>Versão: {data.dependencies.database.version}</div> | ||
<div> | ||
Conexões abertas: {data.dependencies.database.opened_connections} | ||
</div> | ||
<div> | ||
Conexões máximas: {data.dependencies.database.max_connections} | ||
</div> | ||
</> | ||
); | ||
|
||
return ( | ||
<> | ||
<h2>Database</h2> | ||
<div>{databaseStatusInformation}</div> | ||
</> | ||
); | ||
} | ||
} |