From 71658ad39d7e3638de659e8230fad4e05f60fdd8 Mon Sep 17 00:00:00 2001 From: Elias Schneider Date: Fri, 30 Dec 2022 19:23:17 +0100 Subject: [PATCH] feat: show version and show button if new release is available on admin page --- backend/package-lock.json | 4 +- backend/package.json | 2 +- frontend/next.config.js | 8 +- frontend/package-lock.json | 8 +- frontend/package.json | 4 +- frontend/src/pages/_app.tsx | 3 +- frontend/src/pages/admin/index.tsx | 110 ++++++++++++++++-------- frontend/src/services/config.service.ts | 11 +++ 8 files changed, 103 insertions(+), 47 deletions(-) diff --git a/backend/package-lock.json b/backend/package-lock.json index d734a21cc..b260dfa73 100644 --- a/backend/package-lock.json +++ b/backend/package-lock.json @@ -1,12 +1,12 @@ { "name": "pingvin-share-backend", - "version": "0.0.1", + "version": "0.5.0", "lockfileVersion": 2, "requires": true, "packages": { "": { "name": "pingvin-share-backend", - "version": "0.0.1", + "version": "0.5.0", "dependencies": { "@nestjs/common": "^9.2.1", "@nestjs/config": "^2.2.0", diff --git a/backend/package.json b/backend/package.json index 9f6e8e06a..e48cee30e 100644 --- a/backend/package.json +++ b/backend/package.json @@ -1,6 +1,6 @@ { "name": "pingvin-share-backend", - "version": "0.0.1", + "version": "0.5.0", "scripts": { "build": "nest build", "dev": "nest start --watch", diff --git a/frontend/next.config.js b/frontend/next.config.js index 045a767d9..cd037170f 100644 --- a/frontend/next.config.js +++ b/frontend/next.config.js @@ -1,8 +1,14 @@ /** @type {import('next').NextConfig} */ +const { version } = require('./package.json'); + const withPWA = require("next-pwa")({ dest: "public", disable: process.env.NODE_ENV == "development", }); -module.exports = withPWA({ output: "standalone" }); +module.exports = withPWA({ + output: "standalone", env: { + VERSION: version, + }, +}); diff --git a/frontend/package-lock.json b/frontend/package-lock.json index f2164b0d9..137ab0d86 100644 --- a/frontend/package-lock.json +++ b/frontend/package-lock.json @@ -1,12 +1,12 @@ { - "name": "pingvin-share", - "version": "0.0.1", + "name": "pingvin-share-frontend", + "version": "0.5.0", "lockfileVersion": 2, "requires": true, "packages": { "": { - "name": "pingvin-share", - "version": "0.0.1", + "name": "pingvin-share-frontend", + "version": "0.5.0", "dependencies": { "@emotion/react": "^11.10.5", "@emotion/server": "^11.10.0", diff --git a/frontend/package.json b/frontend/package.json index d127b3253..3bde4c5f3 100644 --- a/frontend/package.json +++ b/frontend/package.json @@ -1,6 +1,6 @@ { - "name": "pingvin-share", - "version": "0.0.1", + "name": "pingvin-share-frontend", + "version": "0.5.0", "scripts": { "dev": "next dev", "build": "next build", diff --git a/frontend/src/pages/_app.tsx b/frontend/src/pages/_app.tsx index 93bbbe9db..af9743292 100644 --- a/frontend/src/pages/_app.tsx +++ b/frontend/src/pages/_app.tsx @@ -28,7 +28,6 @@ function App({ Component, pageProps }: AppProps) { const systemTheme = useColorScheme(); const router = useRouter(); const preferences = usePreferences(); - const [colorScheme, setColorScheme] = useState("light"); const [isLoading, setIsLoading] = useState(true); const [user, setUser] = useState(null); @@ -89,7 +88,7 @@ function App({ Component, pageProps }: AppProps) { - {" "} + )} diff --git a/frontend/src/pages/admin/index.tsx b/frontend/src/pages/admin/index.tsx index bcdc5ce0f..44c10a308 100644 --- a/frontend/src/pages/admin/index.tsx +++ b/frontend/src/pages/admin/index.tsx @@ -1,19 +1,17 @@ -import { Col, createStyles, Grid, Paper, Text } from "@mantine/core"; +import { + Center, + Col, + createStyles, + Grid, + Paper, + Stack, + Text, + Title, +} from "@mantine/core"; import Link from "next/link"; -import { TbSettings, TbUsers } from "react-icons/tb"; - -const managementOptions = [ - { - title: "User management", - icon: TbUsers, - route: "/admin/users", - }, - { - title: "Configuration", - icon: TbSettings, - route: "/admin/config", - }, -]; +import { useEffect, useState } from "react"; +import { TbRefresh, TbSettings, TbUsers } from "react-icons/tb"; +import configService from "../../services/config.service"; const useStyles = createStyles((theme) => ({ item: { @@ -33,27 +31,69 @@ const useStyles = createStyles((theme) => ({ const Admin = () => { const { classes, theme } = useStyles(); + const [managementOptions, setManagementOptions] = useState([ + { + title: "User management", + icon: TbUsers, + route: "/admin/users", + }, + { + title: "Configuration", + icon: TbSettings, + route: "/admin/config", + }, + ]); + + useEffect(() => { + configService.isNewReleaseAvailable().then((isNewReleaseAvailable) => { + if (isNewReleaseAvailable) { + setManagementOptions([ + ...managementOptions, + { + title: "Update", + icon: TbRefresh, + route: + "https://github.com/stonith404/pingvin-share/releases/tag/v0.5.0", + }, + ]); + } + }); + }, []); + return ( - - - {managementOptions.map((item) => { - return ( - - - - {item.title} - - - ); - })} - - + <> + + Administration + + + + + {managementOptions.map((item) => { + return ( + + + + {item.title} + + + ); + })} + + + +
+ + Version {process.env.VERSION} + +
+
+ ); }; diff --git a/frontend/src/services/config.service.ts b/frontend/src/services/config.service.ts index 028fc30ae..e2ed9eff7 100644 --- a/frontend/src/services/config.service.ts +++ b/frontend/src/services/config.service.ts @@ -1,3 +1,4 @@ +import axios from "axios"; import Config, { AdminConfig, UpdateConfig } from "../types/config.type"; import api from "./api.service"; @@ -36,6 +37,15 @@ const sendTestEmail = async (email: string) => { await api.post("/configs/admin/testEmail", { email }); }; +const isNewReleaseAvailable = async () => { + const response = ( + await axios.get( + "https://api.github.com/repos/stonith404/pingvin-share/releases/latest" + ) + ).data; + return response.tag_name.replace("v", "") != process.env.VERSION; +}; + export default { list, listForAdmin, @@ -43,4 +53,5 @@ export default { get, finishSetup, sendTestEmail, + isNewReleaseAvailable, };