Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add version tracking and notification for updates in Settings page #1633

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 23 additions & 18 deletions Client/src/Pages/Settings/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ import { settingsValidation } from "../../Validation/validation";
import Dialog from "../../Components/Dialog";
import { useIsAdmin } from "../../Hooks/useIsAdmin";
import ConfigBox from "../../Components/ConfigBox";
import { version } from "../../../version";

const SECONDS_PER_DAY = 86400;

const Settings = () => {
Expand All @@ -38,30 +40,33 @@ const Settings = () => {
const [form, setForm] = useState({
ttl: checkTTL ? (checkTTL / SECONDS_PER_DAY).toString() : 0,
});
const [version, setVersion] = useState("unknown");
const [errors, setErrors] = useState({});
const deleteStatsMonitorsInitState = { deleteMonitors: false, deleteStats: false };
const [isOpen, setIsOpen] = useState(deleteStatsMonitorsInitState);
const dispatch = useDispatch();

//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();
}, []);
useEffect(() => {
const fetchLatestVersion = async () => {
let fetchedVersion = "unknown";
try {
const response = await networkService.fetchGithubLatestRelease();
if (!response.status === 200) {
throw new Error("Failed to fetch latest version");
}
fetchedVersion = response.data.tag_name;
if (fetchedVersion && version !== fetchedVersion) {
createToast({
body: `A new update is available! Current version: ${version}, New version: ${fetchedVersion}`,
type: "info",
});
}
} catch (error) {
createToast({ body: error.message || "Error fetching latest version" });
}
};
fetchLatestVersion();
}, []);

const handleChange = (event) => {
const { value, id } = event.target;
Expand Down
1 change: 1 addition & 0 deletions Client/version.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export const version = "v2.0.1";
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This requires us to update this variable every time a new release is made