From cbb4dc79581b392e8f4cbf1ef86f52109376cc63 Mon Sep 17 00:00:00 2001 From: unknown Date: Tue, 15 Oct 2024 21:35:17 +0530 Subject: [PATCH] Added the latest repo version in about section of Settings page --- Client/src/Pages/Settings/index.jsx | 27 ++++++++++++++++++++++++--- 1 file changed, 24 insertions(+), 3 deletions(-) diff --git a/Client/src/Pages/Settings/index.jsx b/Client/src/Pages/Settings/index.jsx index db3fe232b..e957d020f 100644 --- a/Client/src/Pages/Settings/index.jsx +++ b/Client/src/Pages/Settings/index.jsx @@ -17,7 +17,7 @@ import PropTypes from "prop-types"; import LoadingButton from "@mui/lab/LoadingButton"; import { setTimezone, setMode } from "../../Features/UI/uiSlice"; import timezones from "../../Utils/timezones.json"; -import { useState } from "react"; +import { useState,useEffect } from "react"; import { ConfigBox } from "./styled"; import { networkService } from "../../main"; import { settingsValidation } from "../../Validation/validation"; @@ -37,10 +37,30 @@ const Settings = ({ isAdmin }) => { const [form, setForm] = useState({ ttl: checkTTL ? (checkTTL / SECONDS_PER_DAY).toString() : 0, }); + const [version,setVersion]=useState(""); const [errors, setErrors] = useState({}); const dispatch = useDispatch(); const navigate = useNavigate(); + //Fetching latest release version from github + useEffect(() => { + const fetchLatestVersion = async () => { + try { + const response = await fetch( + "https://api.github.com/repos/bluewave-labs/bluewave-uptime/releases/latest" + ); + if (!response.ok) { + throw new Error("Failed to fetch latest version"); + } + const data = await response.json(); + setVersion(data.tag_name); // Set the latest version number + } catch (error) { + createToast({ body: error.message || "Error fetching latest version" }); // Set error message + } + }; + fetchLatestVersion(); + }); + const handleChange = (event) => { const { value, id } = event.target; const { error } = settingsValidation.validate( @@ -300,6 +320,7 @@ const Settings = ({ isAdmin }) => { BlueWave Uptime v1.0.0 + Latest Version: {version} @@ -307,8 +328,8 @@ const Settings = ({ isAdmin }) => {