diff --git a/.gitattributes b/.gitattributes index ad0055d..d74b3f7 100644 --- a/.gitattributes +++ b/.gitattributes @@ -1,4 +1,3 @@ -# Define o comportamento padrão para todos os arquivos de texto * text=auto *.js text eol=lf diff --git a/package-lock.json b/package-lock.json index e23a0e2..07834e6 100644 --- a/package-lock.json +++ b/package-lock.json @@ -16,7 +16,8 @@ "node-pg-migrate": "6.2.2", "pg": "8.11.3", "react": "18.2.0", - "react-dom": "18.2.0" + "react-dom": "18.2.0", + "swr": "2.2.5" }, "devDependencies": { "@commitlint/cli": "19.3.0", @@ -9123,6 +9124,18 @@ "url": "https://github.com/sponsors/ljharb" } }, + "node_modules/swr": { + "version": "2.2.5", + "resolved": "https://registry.npmjs.org/swr/-/swr-2.2.5.tgz", + "integrity": "sha512-QtxqyclFeAsxEUeZIYmsaQ0UjimSq1RZ9Un7I68/0ClKK/U3LoyQunwkQfJZr2fc22DfIXLNDc2wFyTEikCUpg==", + "dependencies": { + "client-only": "^0.0.1", + "use-sync-external-store": "^1.2.0" + }, + "peerDependencies": { + "react": "^16.11.0 || ^17.0.0 || ^18.0.0" + } + }, "node_modules/test-exclude": { "version": "6.0.0", "resolved": "https://registry.npmjs.org/test-exclude/-/test-exclude-6.0.0.tgz", @@ -9540,6 +9553,14 @@ "punycode": "^2.1.0" } }, + "node_modules/use-sync-external-store": { + "version": "1.5.0", + "resolved": "https://registry.npmjs.org/use-sync-external-store/-/use-sync-external-store-1.5.0.tgz", + "integrity": "sha512-Rb46I4cGGVBmjamjphe8L/UnvJD+uPPtTkNvX5mZgqdbavhI4EbgIWJiIHXJ8bc/i9EQGPRh4DwEURJ552Do0A==", + "peerDependencies": { + "react": "^16.8.0 || ^17.0.0 || ^18.0.0 || ^19.0.0" + } + }, "node_modules/util-deprecate": { "version": "1.0.2", "resolved": "https://registry.npmjs.org/util-deprecate/-/util-deprecate-1.0.2.tgz", diff --git a/package.json b/package.json index bdff9b0..fc3cb17 100644 --- a/package.json +++ b/package.json @@ -30,7 +30,8 @@ "node-pg-migrate": "6.2.2", "pg": "8.11.3", "react": "18.2.0", - "react-dom": "18.2.0" + "react-dom": "18.2.0", + "swr": "2.2.5" }, "devDependencies": { "@commitlint/cli": "19.3.0", diff --git a/pages/status/index.js b/pages/status/index.js new file mode 100644 index 0000000..d19e965 --- /dev/null +++ b/pages/status/index.js @@ -0,0 +1,60 @@ +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 ( + <> +

Status

+ + + + ); +} + +function UpdatedAt() { + const { isLoading, data } = useSWR("/api/v1/status", fetchAPI, { + refreshInterval: 2000, + }); + + let updatedAtText = "Carregando..."; + + if (!isLoading && data) { + updatedAtText = new Date(data.updated_at).toLocaleString("pt-BR"); + } + + return
Última atualização: {updatedAtText}
; +} + +function DatabaseStatus() { + const { isLoading, data } = useSWR("/api/v1/status", fetchAPI, { + refreshInterval: 2000, + }); + + let databaseStatusInformation = "Carregando..."; + + if (!isLoading && data) { + databaseStatusInformation = ( + <> +
Versão: {data.dependencies.database.version}
+
+ Conexões abertas: {data.dependencies.database.opened_connections} +
+
+ Conexões máximas: {data.dependencies.database.max_connections} +
+ + ); + } + + return ( + <> +

Database

+
{databaseStatusInformation}
+ + ); +}