feat: adds secret sharing validity info

This commit is contained in:
Piyush Gupta
2025-11-13 22:09:34 +05:30
parent d5947ba34c
commit 9e97cf68a5
3 changed files with 58 additions and 0 deletions

View File

@@ -59,6 +59,8 @@ export type TViewSharedSecretResponse = {
tag: string;
accessType: SecretSharingAccessType;
orgName?: string;
expiresAt?: Date | string;
expiresAfterViews?: number | null;
};
};

View File

@@ -13,6 +13,8 @@ import { Button, IconButton } from "@app/components/v2";
import { useTimedReset, useToggle } from "@app/hooks";
import { TViewSharedSecretResponse } from "@app/hooks/api/secretSharing";
import { SecretShareInfo } from "./SecretShareInfo";
type Props = {
secret: TViewSharedSecretResponse["secret"];
secretKey: string | null;
@@ -71,6 +73,7 @@ export const SecretContainer = ({ secret, secretKey: key }: Props) => {
</IconButton>
</div>
</div>
<SecretShareInfo secret={secret} />
<Button
className="mt-4 w-full bg-mineshaft-700 py-3 text-bunker-200"
colorSchema="primary"

View File

@@ -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>
);
};