Merge pull request #970 from navishmonga/feature/github-repo-version

Added the latest repo version in about section of Settings page
This commit is contained in:
Alexander Holliday authored and GitHub committed 2024-10-16 14:55:05 +08:00
commit 4f9a53c377
2 files changed
+38 -4

No files matched your search

+24 -4
View File
@@ -17,7 +17,7 @@ import PropTypes from "prop-types";
import LoadingButton from "@mui/lab/LoadingButton"; import LoadingButton from "@mui/lab/LoadingButton";
import { setTimezone, setMode } from "../../Features/UI/uiSlice"; import { setTimezone, setMode } from "../../Features/UI/uiSlice";
import timezones from "../../Utils/timezones.json"; import timezones from "../../Utils/timezones.json";
import { useState } from "react"; import { useState,useEffect } from "react";
import { ConfigBox } from "./styled"; import { ConfigBox } from "./styled";
import { networkService } from "../../main"; import { networkService } from "../../main";
import { settingsValidation } from "../../Validation/validation"; import { settingsValidation } from "../../Validation/validation";
@@ -37,10 +37,30 @@ const Settings = ({ isAdmin }) => {
const [form, setForm] = useState({ const [form, setForm] = useState({
ttl: checkTTL ? (checkTTL / SECONDS_PER_DAY).toString() : 0, ttl: checkTTL ? (checkTTL / SECONDS_PER_DAY).toString() : 0,
}); });
const [version,setVersion]=useState("unknown");
const [errors, setErrors] = useState({}); const [errors, setErrors] = useState({});
const dispatch = useDispatch(); const dispatch = useDispatch();
const navigate = useNavigate(); const navigate = useNavigate();
//Fetching latest release version from github
useEffect(() => {
const fetchLatestVersion = async () => {
let version="unknown";
try {
const response = await networkService.fetchGithubLatestRelease();
if (!response.status===200) {
throw new Error("Failed to fetch latest version");
}
version=response.data.tag_name;
} catch (error) {
createToast({ body: error.message || "Error fetching latest version" }); // Set error message
} finally{
setVersion(version);
}
};
fetchLatestVersion();
},[]);
const handleChange = (event) => { const handleChange = (event) => {
const { value, id } = event.target; const { value, id } = event.target;
const { error } = settingsValidation.validate( const { error } = settingsValidation.validate(
@@ -299,7 +319,7 @@ const Settings = ({ isAdmin }) => {
<Typography component="h1">About</Typography> <Typography component="h1">About</Typography>
</Box> </Box>
<Box> <Box>
<Typography component="h2">BlueWave Uptime v1.0.0</Typography> <Typography component="h2">BlueWave Uptime {version}</Typography>
<Typography <Typography
sx={{ mt: theme.spacing(2), mb: theme.spacing(6), opacity: 0.6 }} sx={{ mt: theme.spacing(2), mb: theme.spacing(6), opacity: 0.6 }}
> >
@@ -307,8 +327,8 @@ const Settings = ({ isAdmin }) => {
</Typography> </Typography>
<Link <Link
level="secondary" level="secondary"
url="https://github.com/bluewave-labs" url="https://github.com/bluewave-labs/bluewave-uptime"
label="https://github.com/bluewave-labs" label="https://github.com/bluewave-labs/bluewave-uptime"
/> />
</Box> </Box>
</ConfigBox> </ConfigBox>
+14
View File
@@ -832,6 +832,20 @@ class NetworkService {
} }
); );
} }
/**
* ************************************
* Fetcher github latest release version
* ************************************
*
* @async
* @returns {Promise<AxiosResponse>} The response from the axios GET request.
*
*/
async fetchGithubLatestRelease() {
return this.axiosInstance.get('https://api.github.com/repos/bluewave-labs/bluewave-uptime/releases/latest');
}
} }
export default NetworkService; export default NetworkService;