Skip to content
Merged
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
7 changes: 7 additions & 0 deletions frontend/Dockerfile.prod
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,13 @@ COPY nginx-prod/nginx.conf.template.no-ssl /etc/nginx/nginx.conf.template.no-ssl
COPY nginx-prod/docker-entrypoint.sh /docker-entrypoint.sh

# Add version information
ARG APP_VERSION_TAG
ARG APP_COMMIT
ARG APP_BRANCH
ENV VITE_APP_VERSION_TAG=$APP_VERSION_TAG
ENV VITE_APP_COMMIT=$APP_COMMIT
ENV VITE_APP_BRANCH=$APP_BRANCH
ENV VITE_APP_BUILD_FILE="prod"
RUN echo "{\"tag\": \"$VITE_APP_VERSION_TAG\", \"commit\": \"$VITE_APP_COMMIT\", \"branch\": \"$VITE_APP_BRANCH\", \"build_file\": \"$VITE_APP_BUILD_FILE\"}" > /usr/share/nginx/html/version.json

# Give permissions to the entry script
Expand Down
32 changes: 30 additions & 2 deletions frontend/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions frontend/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@
"react-router-dom": "^6.26.0",
"react-select": "^5.8.0",
"react-toastify": "^10.0.5",
"react-update-popup": "^2.1.1",
"react18-json-view": "^0.2.9",
"redux": "^4.2.1",
"redux-form": "^8.3.10",
Expand Down
4 changes: 4 additions & 0 deletions frontend/src/App.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,20 @@ import { BrowserRouter } from "react-router-dom";
import routes, { renderRoutes } from "routes";
import Alert from "components/Alert/Alert";
import { useTokenManager } from "hooks/useTokenManager";
import { useVersionPopup } from "hooks/useVersionPopup";

const App = () => {
useTokenManager();

const { VersionPopup } = useVersionPopup();

return (
<>
<Alert component="all" />
<BrowserRouter basename={import.meta.env.VITE_APP_BASE_NAME}>
{renderRoutes(routes)}
</BrowserRouter>
<VersionPopup />
</>
);
};
Expand Down
57 changes: 57 additions & 0 deletions frontend/src/hooks/useVersionPopup.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
import React, { useState } from "react";
import { UpdateNotification } from "react-update-popup";
// import "react-update-popup/dist/index.css";

export const useVersionPopup = () => {
const [latestVersion, setLatestVersion] = useState(null);
const key_version = "last-frontend-version";

// Function that checks if there is a new version
const checkHasUpdate = async () => {
try {
const res = await fetch("/version.json", { cache: "no-store" });
const data = await res.json();

const storedVersion = localStorage.getItem(key_version);

if (!storedVersion) {
// First time load, store the version
localStorage.setItem(key_version, data.tag);
setLatestVersion(data.tag);
return false; // no popup on first load
}

if (storedVersion !== data.tag) {
setLatestVersion(data.tag);
return true; // new version: popup shows
}

return false; // same version
} catch (err) {
console.error("Error checking version:", err);
return false; // fallback
}
};

const onReload = () => {
if (latestVersion) {
localStorage.setItem(key_version, latestVersion);
}
window.location.reload(true);
};

const VersionPopup = () => (
<UpdateNotification
title="New Version Available"
description="There is a new version of the frontend. Refresh the page to update."
buttonText="Refresh"
refreshInterval={30_000} // every 30 seconds
checkHasUpdate={checkHasUpdate}
onReload={onReload}
/>
);

return { VersionPopup };
};

export default useVersionPopup;