+);
+
export const UpdateWebServer = () => {
- const [updating, setUpdating] = useState(false);
+ const [modalState, setModalState] = useState("idle");
const [open, setOpen] = useState(false);
+ const [healthResult, setHealthResult] = useState(null);
const { mutateAsync: updateServer } = api.settings.updateServer.useMutation();
+ const { refetch: checkHealth } =
+ api.settings.checkInfrastructureHealth.useQuery(undefined, {
+ enabled: false,
+ });
+
+ const handleVerify = async () => {
+ setModalState("checking");
+ setHealthResult(null);
+
+ try {
+ const result = await checkHealth();
+ if (result.data) {
+ setHealthResult(result.data);
+ }
+ } catch {
+ // checkHealth failed entirely
+ }
+ setModalState("results");
+ };
+
+ const allHealthy =
+ healthResult &&
+ healthResult.postgres.status === "healthy" &&
+ healthResult.redis.status === "healthy" &&
+ healthResult.traefik.status === "healthy";
const checkIsUpdateFinished = async () => {
try {
@@ -33,28 +99,24 @@ export const UpdateWebServer = () => {
);
setTimeout(() => {
- // Allow seeing the toast before reloading
window.location.reload();
}, 2000);
} catch {
- // Delay each request
await new Promise((resolve) => setTimeout(resolve, 2000));
- // Keep running until it returns 200
void checkIsUpdateFinished();
}
};
const handleConfirm = async () => {
try {
- setUpdating(true);
+ setModalState("updating");
await updateServer();
- // Give some time for docker service restart before starting to check status
await new Promise((resolve) => setTimeout(resolve, 8000));
await checkIsUpdateFinished();
} catch (error) {
- setUpdating(false);
+ setModalState("results");
console.error("Error updating server:", error);
toast.error(
"An error occurred while updating the server, please try again.",
@@ -62,6 +124,14 @@ export const UpdateWebServer = () => {
}
};
+ const handleClose = () => {
+ if (modalState !== "updating") {
+ setOpen(false);
+ setModalState("idle");
+ setHealthResult(null);
+ }
+ };
+
return (
@@ -81,36 +151,111 @@ export const UpdateWebServer = () => {
- {updating
- ? "Server update in progress"
- : "Are you absolutely sure?"}
+ {modalState === "idle" && "Are you absolutely sure?"}
+ {modalState === "checking" && "Verifying Services..."}
+ {modalState === "results" &&
+ (allHealthy ? "Ready to Update" : "Service Issues Detected")}
+ {modalState === "updating" && "Server update in progress"}
-
- {updating ? (
-
-
- The server is being updated, please wait...
-
- ) : (
- <>
- This action cannot be undone. This will update the web server to
- the new version. You will not be able to use the panel during
- the update process. The page will be reloaded once the update is
- finished.
- >
- )}
+
+
+ {modalState === "idle" && (
+
+ This will update the web server to the new version. You will
+ not be able to use the panel during the update process. The
+ page will be reloaded once the update is finished.
+
+
+ We recommend verifying that all services are running before
+ updating.
+
+ )}
+
+ {modalState === "checking" && (
+
+
+ Checking PostgreSQL, Redis and Traefik...
+
+ )}
+
+ {modalState === "results" && healthResult && (
+
+
+
+
+
+
+
+ {!allHealthy && (
+
+
+
+ Some services are not healthy. You can still proceed
+ with the update.
+
+
+ )}
+
+ {allHealthy && (
+
+ All services are running. You can proceed with the update.
+
+ )}
+