mirror of
https://github.com/awatertrevi/infisical.git
synced 2026-09-22 13:39:35 +00:00
Make alert only visible to admins and add reloading on completion
This commit is contained in:
@@ -1,6 +1,8 @@
|
|||||||
import { useCallback, useEffect, useState } from "react";
|
import { useCallback, useEffect, useState } from "react";
|
||||||
|
import { useRouter } from "next/router";
|
||||||
|
|
||||||
import { useNotificationContext } from "@app/components/context/Notifications/NotificationProvider";
|
import { useNotificationContext } from "@app/components/context/Notifications/NotificationProvider";
|
||||||
|
import { useProjectPermission } from "@app/context";
|
||||||
import { useGetUpgradeProjectStatus, useUpgradeProject } from "@app/hooks/api";
|
import { useGetUpgradeProjectStatus, useUpgradeProject } from "@app/hooks/api";
|
||||||
import { Workspace } from "@app/hooks/api/types";
|
import { Workspace } from "@app/hooks/api/types";
|
||||||
|
|
||||||
@@ -13,6 +15,8 @@ export type UpgradeProjectAlertProps = {
|
|||||||
|
|
||||||
export const UpgradeProjectAlert = ({ project }: UpgradeProjectAlertProps): JSX.Element | null => {
|
export const UpgradeProjectAlert = ({ project }: UpgradeProjectAlertProps): JSX.Element | null => {
|
||||||
const { createNotification } = useNotificationContext();
|
const { createNotification } = useNotificationContext();
|
||||||
|
const router = useRouter();
|
||||||
|
const { membership } = useProjectPermission();
|
||||||
const upgradeProject = useUpgradeProject();
|
const upgradeProject = useUpgradeProject();
|
||||||
const [currentStatus, setCurrentStatus] = useState<string | null>(null);
|
const [currentStatus, setCurrentStatus] = useState<string | null>(null);
|
||||||
const {
|
const {
|
||||||
@@ -41,26 +45,36 @@ export const UpgradeProjectAlert = ({ project }: UpgradeProjectAlertProps): JSX.
|
|||||||
}, []);
|
}, []);
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (project.version === "v1") {
|
let interval: NodeJS.Timeout | null = null;
|
||||||
getLatestProjectStatus();
|
|
||||||
}
|
|
||||||
|
|
||||||
if (projectStatus && projectStatus?.status !== null) {
|
if (membership.role === "admin") {
|
||||||
if (projectStatus.status === "IN_PROGRESS") {
|
|
||||||
setCurrentStatus("Your upgrade is being processed.");
|
|
||||||
} else if (projectStatus.status === "FAILED") {
|
|
||||||
setCurrentStatus("Upgrade failed, please try again.");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
const interval = setInterval(() => {
|
|
||||||
if (project.version === "v1") {
|
if (project.version === "v1") {
|
||||||
getLatestProjectStatus();
|
getLatestProjectStatus();
|
||||||
}
|
}
|
||||||
}, 5_000);
|
|
||||||
|
if (projectStatus && projectStatus?.status !== null) {
|
||||||
|
if (projectStatus.status === "IN_PROGRESS") {
|
||||||
|
setCurrentStatus("Your upgrade is being processed.");
|
||||||
|
} else if (projectStatus.status === "FAILED") {
|
||||||
|
setCurrentStatus("Upgrade failed, please try again.");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (currentStatus !== null && projectStatus?.status === null) {
|
||||||
|
router.reload();
|
||||||
|
}
|
||||||
|
|
||||||
|
interval = setInterval(() => {
|
||||||
|
if (project.version === "v1") {
|
||||||
|
getLatestProjectStatus();
|
||||||
|
}
|
||||||
|
}, 5_000);
|
||||||
|
}
|
||||||
|
|
||||||
return () => {
|
return () => {
|
||||||
clearInterval(interval);
|
if (interval) {
|
||||||
|
clearInterval(interval);
|
||||||
|
}
|
||||||
};
|
};
|
||||||
}, [projectStatus]);
|
}, [projectStatus]);
|
||||||
|
|
||||||
@@ -71,6 +85,7 @@ export const UpgradeProjectAlert = ({ project }: UpgradeProjectAlertProps): JSX.
|
|||||||
projectStatus?.status !== "FAILED";
|
projectStatus?.status !== "FAILED";
|
||||||
|
|
||||||
if (project.version !== "v1") return null;
|
if (project.version !== "v1") return null;
|
||||||
|
if (membership.role !== "admin") return null;
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className="my-8">
|
<div className="my-8">
|
||||||
|
|||||||
Reference in New Issue
Block a user