Skip to content

Commit

Permalink
Merge pull request #30 from superaura/status-page
Browse files Browse the repository at this point in the history
Adiciona primeira versão da página `/status`
  • Loading branch information
superaura authored Jan 14, 2025
2 parents 434371a + 80510e1 commit 83bbb9d
Show file tree
Hide file tree
Showing 3 changed files with 127 additions and 2 deletions.
25 changes: 24 additions & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,8 @@
"node-pg-migrate": "7.6.1",
"pg": "8.12.0",
"react": "18.3.1",
"react-dom": "18.3.1"
"react-dom": "18.3.1",
"swr": "2.2.5"
},
"devDependencies": {
"@commitlint/cli": "19.4.0",
Expand Down
101 changes: 101 additions & 0 deletions pages/status/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
import useSWR from "swr";

async function fetchAPI(key) {
const response = await fetch(key);
const responseBody = await response.json();
console.log(responseBody);
return responseBody;
}

export default function StatusPage() {
return (
<>
<h1
style={{
color: "#323437",
textAlign: "center",
}}
>
Status – Clone TabNews
</h1>
<UpdateAt />
</>
);
}

function UpdateAt() {
const { isLoading, data } = useSWR("/api/v1/status", fetchAPI, {
refreshInterval: 2000,
});

let updatedAtText,
databaseVersionText,
databaseMaxConnectionsText,
databaseOpenedConnectionsText = "Carregando...";

if (!isLoading && data) {
updatedAtText = new Date(data.update_at).toLocaleString("pt-BR");
databaseVersionText = data.dependencies.database.version;
databaseMaxConnectionsText = data.dependencies.database.max_connections;
databaseOpenedConnectionsText =
data.dependencies.database.opened_connections;
}

return (
<div>
<hr />
<p
style={{
color: "#323437",
fontFamily: "monospace",
textAlign: "center",
}}
>
Última atualização: {updatedAtText}
</p>
<hr />
<div
id="UPDATED-STATUS"
style={{
display: "flex",
flexWrap: "wrap",
justifyContent: "space-evenly",
padding: "15px",
}}
>
<div
id="DB-STATUS"
style={{
display: "flex",
flexDirection: "column",
fontFamily: "monospace",
padding: "20px",
background: "#323437",
color: "#d1d0c5",
border: "solid thick #d1d0c5",
borderRadius: "15px",
}}
>
<h2 style={{ color: "#e2b714" }}>Banco de Dados:</h2>
<p>
<strong>Versão: </strong>
<span style={{ color: "#f28b54" }}>{databaseVersionText}</span>
</p>
<p>
<strong>Limite de conexões: </strong>
<span style={{ color: "#a1f7b5" }}>
{databaseMaxConnectionsText}
</span>
</p>
<p>
<strong>Conexões abertas: </strong>
<span style={{ color: "#a1f7b5" }}>
{databaseOpenedConnectionsText}
</span>
</p>
</div>
</div>
</div>
);
}
//

0 comments on commit 83bbb9d

Please sign in to comment.