mirror of
https://github.com/awatertrevi/infisical.git
synced 2026-10-05 04:26:33 +00:00
feat: adds secret sharing validity info
This commit is contained in:
@@ -59,6 +59,8 @@ export type TViewSharedSecretResponse = {
|
|||||||
tag: string;
|
tag: string;
|
||||||
accessType: SecretSharingAccessType;
|
accessType: SecretSharingAccessType;
|
||||||
orgName?: string;
|
orgName?: string;
|
||||||
|
expiresAt?: Date | string;
|
||||||
|
expiresAfterViews?: number | null;
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@@ -13,6 +13,8 @@ import { Button, IconButton } from "@app/components/v2";
|
|||||||
import { useTimedReset, useToggle } from "@app/hooks";
|
import { useTimedReset, useToggle } from "@app/hooks";
|
||||||
import { TViewSharedSecretResponse } from "@app/hooks/api/secretSharing";
|
import { TViewSharedSecretResponse } from "@app/hooks/api/secretSharing";
|
||||||
|
|
||||||
|
import { SecretShareInfo } from "./SecretShareInfo";
|
||||||
|
|
||||||
type Props = {
|
type Props = {
|
||||||
secret: TViewSharedSecretResponse["secret"];
|
secret: TViewSharedSecretResponse["secret"];
|
||||||
secretKey: string | null;
|
secretKey: string | null;
|
||||||
@@ -71,6 +73,7 @@ export const SecretContainer = ({ secret, secretKey: key }: Props) => {
|
|||||||
</IconButton>
|
</IconButton>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
<SecretShareInfo secret={secret} />
|
||||||
<Button
|
<Button
|
||||||
className="mt-4 w-full bg-mineshaft-700 py-3 text-bunker-200"
|
className="mt-4 w-full bg-mineshaft-700 py-3 text-bunker-200"
|
||||||
colorSchema="primary"
|
colorSchema="primary"
|
||||||
|
|||||||
@@ -0,0 +1,53 @@
|
|||||||
|
import { useMemo } from "react";
|
||||||
|
import { faClock, faEye } from "@fortawesome/free-solid-svg-icons";
|
||||||
|
import { FontAwesomeIcon } from "@fortawesome/react-fontawesome";
|
||||||
|
import { format } from "date-fns";
|
||||||
|
|
||||||
|
import { TViewSharedSecretResponse } from "@app/hooks/api/secretSharing";
|
||||||
|
|
||||||
|
type Props = {
|
||||||
|
secret: TViewSharedSecretResponse["secret"];
|
||||||
|
};
|
||||||
|
|
||||||
|
export const SecretShareInfo = ({ secret }: Props) => {
|
||||||
|
const timeRemaining = useMemo(() => {
|
||||||
|
if (!secret.expiresAt) return null;
|
||||||
|
|
||||||
|
try {
|
||||||
|
return format(new Date(secret.expiresAt), "yyyy-MM-dd 'at' HH:mm a");
|
||||||
|
} catch {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}, [secret.expiresAt]);
|
||||||
|
|
||||||
|
const viewsRemaining = useMemo(() => {
|
||||||
|
if (!secret.expiresAfterViews) return null;
|
||||||
|
|
||||||
|
return secret.expiresAfterViews - 1;
|
||||||
|
}, [secret.expiresAfterViews]);
|
||||||
|
|
||||||
|
if (!timeRemaining && viewsRemaining === null) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
return (
|
||||||
|
<div className="mt-4 flex flex-col gap-2 rounded-md border border-mineshaft-600 bg-mineshaft-700/50 p-3 text-sm text-gray-300">
|
||||||
|
{timeRemaining && (
|
||||||
|
<div className="flex items-center gap-2">
|
||||||
|
<FontAwesomeIcon icon={faClock} className="text-mineshaft-400" />
|
||||||
|
<span>Expires on {timeRemaining}</span>
|
||||||
|
</div>
|
||||||
|
)}
|
||||||
|
{viewsRemaining !== null && (
|
||||||
|
<div className="flex items-center gap-2">
|
||||||
|
<FontAwesomeIcon icon={faEye} className="text-mineshaft-400" />
|
||||||
|
<span>
|
||||||
|
{viewsRemaining === 0
|
||||||
|
? "This is the last time you can view this secret"
|
||||||
|
: `${viewsRemaining} more view${viewsRemaining === 1 ? "" : "s"} remaining after this`}
|
||||||
|
</span>
|
||||||
|
</div>
|
||||||
|
)}
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
};
|
||||||
Reference in New Issue
Block a user