mirror of
https://github.com/awatertrevi/infisical.git
synced 2026-10-07 14:27:30 +00:00
Update UpgradeProjectAlert.tsx
This commit is contained in:
@@ -2,6 +2,7 @@ import { useCallback, useState } from "react";
|
|||||||
import { useRouter } from "next/router";
|
import { useRouter } from "next/router";
|
||||||
import { faWarning } from "@fortawesome/free-solid-svg-icons";
|
import { faWarning } from "@fortawesome/free-solid-svg-icons";
|
||||||
import { FontAwesomeIcon } from "@fortawesome/react-fontawesome";
|
import { FontAwesomeIcon } from "@fortawesome/react-fontawesome";
|
||||||
|
import { twMerge } from "tailwind-merge";
|
||||||
|
|
||||||
import { useNotificationContext } from "@app/components/context/Notifications/NotificationProvider";
|
import { useNotificationContext } from "@app/components/context/Notifications/NotificationProvider";
|
||||||
import { useProjectPermission } from "@app/context";
|
import { useProjectPermission } from "@app/context";
|
||||||
@@ -10,12 +11,14 @@ import { Workspace } from "@app/hooks/api/types";
|
|||||||
import { ProjectVersion } from "@app/hooks/api/workspace/types";
|
import { ProjectVersion } from "@app/hooks/api/workspace/types";
|
||||||
|
|
||||||
import { Button } from "../Button";
|
import { Button } from "../Button";
|
||||||
|
import { Tooltip } from "../Tooltip";
|
||||||
|
|
||||||
export type UpgradeProjectAlertProps = {
|
export type UpgradeProjectAlertProps = {
|
||||||
project: Workspace;
|
project: Workspace;
|
||||||
};
|
};
|
||||||
|
|
||||||
export const UpgradeProjectAlert = ({ project }: UpgradeProjectAlertProps): JSX.Element | null => {
|
export const UpgradeProjectAlert = ({ project }: UpgradeProjectAlertProps): JSX.Element | null => {
|
||||||
|
console.log("yes");
|
||||||
const { createNotification } = useNotificationContext();
|
const { createNotification } = useNotificationContext();
|
||||||
const router = useRouter();
|
const router = useRouter();
|
||||||
const { membership } = useProjectPermission();
|
const { membership } = useProjectPermission();
|
||||||
@@ -23,6 +26,8 @@ export const UpgradeProjectAlert = ({ project }: UpgradeProjectAlertProps): JSX.
|
|||||||
const [currentStatus, setCurrentStatus] = useState<string | null>(null);
|
const [currentStatus, setCurrentStatus] = useState<string | null>(null);
|
||||||
const [isUpgrading, setIsUpgrading] = useState(false);
|
const [isUpgrading, setIsUpgrading] = useState(false);
|
||||||
|
|
||||||
|
console.log("yes 2");
|
||||||
|
|
||||||
const {
|
const {
|
||||||
data: projectStatus,
|
data: projectStatus,
|
||||||
isLoading: statusIsLoading,
|
isLoading: statusIsLoading,
|
||||||
@@ -50,6 +55,8 @@ export const UpgradeProjectAlert = ({ project }: UpgradeProjectAlertProps): JSX.
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
console.log("yes 3");
|
||||||
|
|
||||||
const onUpgradeProject = useCallback(async () => {
|
const onUpgradeProject = useCallback(async () => {
|
||||||
if (upgradeProject.isLoading) {
|
if (upgradeProject.isLoading) {
|
||||||
return;
|
return;
|
||||||
@@ -75,6 +82,8 @@ export const UpgradeProjectAlert = ({ project }: UpgradeProjectAlertProps): JSX.
|
|||||||
setTimeout(() => setIsUpgrading(false), 5_000);
|
setTimeout(() => setIsUpgrading(false), 5_000);
|
||||||
}, []);
|
}, []);
|
||||||
|
|
||||||
|
console.log("yes 4");
|
||||||
|
|
||||||
const isLoading =
|
const isLoading =
|
||||||
isUpgrading ||
|
isUpgrading ||
|
||||||
((upgradeProject.isLoading ||
|
((upgradeProject.isLoading ||
|
||||||
@@ -82,21 +91,48 @@ export const UpgradeProjectAlert = ({ project }: UpgradeProjectAlertProps): JSX.
|
|||||||
(currentStatus === null && statusIsLoading)) &&
|
(currentStatus === null && statusIsLoading)) &&
|
||||||
projectStatus?.status !== "FAILED");
|
projectStatus?.status !== "FAILED");
|
||||||
|
|
||||||
if (project.version !== ProjectVersion.V1) return null;
|
console.log("yes 5");
|
||||||
if (membership.role !== "admin") return null;
|
|
||||||
|
|
||||||
|
if (project.version !== ProjectVersion.V1) return null;
|
||||||
|
|
||||||
|
console.log("yes 6");
|
||||||
return (
|
return (
|
||||||
<div className="mt-4 flex w-full flex-row items-center rounded-md border border-primary-600/70 bg-primary/[.07] p-4 text-base text-white">
|
<div
|
||||||
|
className={twMerge(
|
||||||
|
"mt-4 flex w-full flex-row items-center rounded-md border border-primary-600/70 bg-primary/[.07] p-4 text-base text-white",
|
||||||
|
membership.role !== "admin" && "opacity-80"
|
||||||
|
)}
|
||||||
|
>
|
||||||
<FontAwesomeIcon icon={faWarning} className="pr-6 text-6xl text-white/80" />
|
<FontAwesomeIcon icon={faWarning} className="pr-6 text-6xl text-white/80" />
|
||||||
<div className="flex w-full flex-col text-sm">
|
<div className="flex w-full flex-col text-sm">
|
||||||
<span className="mb-2 text-lg font-semibold">Upgrade your project</span>
|
<span className="mb-2 text-lg font-semibold">Upgrade your project</span>
|
||||||
Upgrade your project version to continue receiving the latest improvements and patches.
|
{membership.role === "admin" ? (
|
||||||
|
<p>
|
||||||
|
Upgrade your project version to continue receiving the latest improvements and patches.
|
||||||
|
</p>
|
||||||
|
) : (
|
||||||
|
<p>
|
||||||
|
<span className="font-bold">Please ask a project admin to upgrade the project.</span>
|
||||||
|
<br />
|
||||||
|
Upgrading the project version is required to continue receiving the latest improvements
|
||||||
|
and patches.
|
||||||
|
</p>
|
||||||
|
)}
|
||||||
{currentStatus && <p className="mt-2 opacity-80">Status: {currentStatus}</p>}
|
{currentStatus && <p className="mt-2 opacity-80">Status: {currentStatus}</p>}
|
||||||
</div>
|
</div>
|
||||||
<div className="my-2">
|
<div className="my-2">
|
||||||
<Button isLoading={isLoading} isDisabled={isLoading} onClick={onUpgradeProject}>
|
<Tooltip
|
||||||
Upgrade
|
className={twMerge(membership.role === "admin" && "hidden")}
|
||||||
</Button>
|
content="You need to be an admin to upgrade the project."
|
||||||
|
>
|
||||||
|
<Button
|
||||||
|
isLoading={isLoading}
|
||||||
|
isDisabled={isLoading || membership.role !== "admin"}
|
||||||
|
onClick={onUpgradeProject}
|
||||||
|
>
|
||||||
|
Upgrade
|
||||||
|
</Button>
|
||||||
|
</Tooltip>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
|
|||||||
Reference in New Issue
Block a user