Skip to content

Papermark is the open-source DocSend alternative and secure data rooms with built-in analytics and custom domains.

feat: add dynamic link expiration presets

Ashish Viradiya03cb43287c55
diff --git a/components/links/link-sheet/expiration-section.tsx b/components/links/link-sheet/expiration-section.tsx
index 37c7ac0c..3c026a05 100644
--- a/components/links/link-sheet/expiration-section.tsx
+++ b/components/links/link-sheet/expiration-section.tsx
@@ -2,36 +2,178 @@ import { useEffect, useState } from "react";
import { motion } from "motion/react";
-import { Input } from "@/components/ui/input";
-
import { FADE_IN_ANIMATION_SETTINGS } from "@/lib/constants";
-import { getDateTimeLocal } from "@/lib/utils";
+import { formatDate, getDateTimeLocal } from "@/lib/utils";
+
+import { Input } from "@/components/ui/input";
+import {
+ Select,
+ SelectContent,
+ SelectItem,
+ SelectTrigger,
+ SelectValue,
+} from "@/components/ui/select";
import { DEFAULT_LINK_TYPE } from ".";
import LinkItem from "./link-item";
+const PRESET_OPTIONS = [
+ { label: "in 1 hour", value: 3600 },
+ { label: "in 6 hours", value: 21600 },
+ { label: "in 12 hours", value: 43200 },
+ { label: "in 1 day", value: 86400 },
+ { label: "in 3 days", value: 259200 },
+ { label: "in 7 days", value: 604800 },
+ { label: "in 14 days", value: 1209600 },
+ { label: "in 1 month", value: 2592000 },
+ { label: "in 3 months", value: 7776000 },
+ { label: "in 6 months", value: 15552000 },
+ { label: "in 1 year", value: 31536000 },
+ { label: "Custom", value: "custom" },
+];
+
export default function ExpirationSection({
data,
setData,
}: {
- data: DEFAULT_LINK_TYPE;
- setData: React.Dispatch<React.SetStateAction<DEFAULT_LINK_TYPE>>;
+ data: DEFAULT_LINK_TYPE & { expiresIn?: number | null };
+ setData: React.Dispatch<
+ React.SetStateAction<DEFAULT_LINK_TYPE & { expiresIn?: number | null }>
+ >;
}) {
const { expiresAt } = data;
+ console.log("expiresAt", expiresAt);
const [enabled, setEnabled] = useState<boolean>(false);
+ const [selectedPreset, setSelectedPreset] = useState<string>("");
+ const [error, setError] = useState<string | null>(null);
+ // Initialize state based on existing expiration
useEffect(() => {
setEnabled(!!expiresAt);
+
+ if (expiresAt) {
+ const now = new Date();
+ const expirationDate =
+ typeof expiresAt === "string" ? new Date(expiresAt) : expiresAt;
+ const diffInSeconds = Math.floor(
+ (expirationDate.getTime() - now.getTime()) / 1000,
+ );
+
+ const matchingPreset = PRESET_OPTIONS.find(
+ (option) =>
+ option.value !== "custom" &&
+ Math.abs(parseInt(option.value.toString()) - diffInSeconds) < 60,
+ );
+
+ if (matchingPreset) {
+ setSelectedPreset(matchingPreset.value.toString());
+ } else {
+ setSelectedPreset("custom");
+ }
+ }
}, [expiresAt]);
const handleEnableExpiration = () => {
if (enabled) {
- // if expiration is currently set and we're toggling it off
setData({ ...data, expiresAt: null });
+ setSelectedPreset("");
+ setError(null);
+ } else {
+ const defaultExpiresAt = new Date();
+ defaultExpiresAt.setDate(defaultExpiresAt.getDate() + 7);
+ setData({ ...data, expiresAt: defaultExpiresAt, expiresIn: null });
+ setSelectedPreset("604800");
+ setError(null);
}
setEnabled(!enabled);
};
+ const handlePresetChange = (value: string) => {
+ setSelectedPreset(value);
+ setError(null);
+ if (value === "custom") {
+ return;
+ }
+
+ const seconds = parseInt(value);
+ if (!isNaN(seconds)) {
+ const newExpiresAt = new Date();
+ newExpiresAt.setSeconds(newExpiresAt.getSeconds() + seconds);
+ setData({ ...data, expiresAt: newExpiresAt });
+ }
+ };
+
+ const handleCustomDateChange = (e: React.ChangeEvent<HTMLInputElement>) => {
+ const selectedDate = new Date(e.target.value);
+ const now = new Date();
+
+ // Check if the selected date is in the past
+ if (selectedDate <= now) {
+ setError("Expiration time must be in the future");
+ return;
+ }
+
+ setData({ ...data, expiresAt: selectedDate });
+ setSelectedPreset("custom");
+ setError(null);
+ };
+
+ const formatExpirationTime = (date: Date | string) => {
+ const now = new Date();
+ const dateObj = typeof date === "string" ? new Date(date) : date;
+ const diffInSeconds = Math.floor(
+ (dateObj.getTime() - now.getTime()) / 1000,
+ );
+
+ if (diffInSeconds < 60) {
+ return "Less than a minute";
+ } else if (diffInSeconds < 3600) {
+ const minutes = Math.floor(diffInSeconds / 60);
+ return `${minutes} minute${minutes > 1 ? "s" : ""}`;
+ } else if (diffInSeconds < 86400) {
+ const hours = Math.floor(diffInSeconds / 3600);
+ return `${hours} hour${hours > 1 ? "s" : ""}`;
+ } else {
+ const days = Math.floor(diffInSeconds / 86400);
+ const remainingHours = Math.floor((diffInSeconds % 86400) / 3600);
+
+ if (remainingHours === 0) {
+ return `${days} day${days > 1 ? "s" : ""}`;
+ } else {
+ return `${days} day${days > 1 ? "s" : ""} and ${remainingHours} hour${remainingHours > 1 ? "s" : ""}`;
+ }
+ }
+ };
+
+ const formatNaturalExpiration = (date: Date | string) => {
+ const now = new Date();
+ const dateObj = typeof date === "string" ? new Date(date) : date;
+
+ const formattedDate = dateObj.toLocaleDateString(undefined, {
+ weekday: "long",
+ month: "long",
+ day: "numeric",
+ });
+
+ const formattedTime = dateObj.toLocaleTimeString(undefined, {
+ hour: "numeric",
+ minute: "2-digit",
+ hour12: true,
+ });
+
+ if (dateObj.toDateString() === now.toDateString()) {
+ return `today at ${formattedTime}`;
+ }
+
+ const tomorrow = new Date(now);
+ tomorrow.setDate(tomorrow.getDate() + 1);
+ if (dateObj.toDateString() === tomorrow.toDateString()) {
+ return `tomorrow at ${formattedTime}`;
+ }
+
+ return `on ${formattedDate} at ${formattedTime}`;
+ };
+
return (
<div className="pb-5">
<LinkItem
@@ -43,21 +185,50 @@ export default function ExpirationSection({
/>
{enabled && (
- <motion.div className="mt-3" {...FADE_IN_ANIMATION_SETTINGS}>
- <Input
- type="datetime-local"
- id="expiresAt"
- name="expiresAt"
- min={getDateTimeLocal()}
- value={expiresAt ? getDateTimeLocal(expiresAt) : ""}
- step="60" // need to add step to prevent weird date bug (https://stackoverflow.com/q/19284193/10639526)
- onChange={(e) => {
- setData({ ...data, expiresAt: new Date(e.target.value) });
- }}
- className="focus:ring-inset"
- />
+ <motion.div className="mt-3 space-y-3" {...FADE_IN_ANIMATION_SETTINGS}>
+ <div className="flex flex-col space-y-2">
+ <Select value={selectedPreset} onValueChange={handlePresetChange}>
+ <SelectTrigger>
+ <SelectValue placeholder="Select expiration time" />
+ </SelectTrigger>
+ <SelectContent>
+ {PRESET_OPTIONS.map((option) => (
+ <SelectItem
+ key={option.value}
+ value={option.value.toString()}
+ >
+ {option.label}
+ </SelectItem>
+ ))}
+ </SelectContent>
+ </Select>
+
+ {expiresAt && (
+ <div className="space-y-1 text-xs text-muted-foreground">
+ <div>
+ Link will expire {formatNaturalExpiration(expiresAt)} ( in{" "}
+ {formatExpirationTime(expiresAt)})
+ </div>
+ </div>
+ )}
+
+ {error && <div className="text-xs text-red-500">{error}</div>}
+ </div>
+
+ {(selectedPreset === "custom" || !selectedPreset) && (
+ <Input
+ type="datetime-local"
+ id="expiresAt"
+ name="expiresAt"
+ min={getDateTimeLocal()}
+ value={expiresAt ? getDateTimeLocal(expiresAt) : ""}
+ step="60" // need to add step to prevent weird date bug (https://stackoverflow.com/q/19284193/10639526)
+ onChange={handleCustomDateChange}
+ className="focus:ring-inset"
+ />
+ )}
</motion.div>
)}
</div>
);
-}
+}
\ No newline at end of file
diff --git a/components/links/link-sheet/expirationIn-section.tsx b/components/links/link-sheet/expirationIn-section.tsx
new file mode 100644
index 00000000..20260d01
--- /dev/null
+++ b/components/links/link-sheet/expirationIn-section.tsx
@@ -0,0 +1,160 @@
+import { useEffect, useState } from "react";
+
+
+
+import { PRESET_DATA } from "@/pages/settings/presets/[id]";
+import { motion } from "motion/react";
+
+import { FADE_IN_ANIMATION_SETTINGS } from "@/lib/constants";
+
+import {
+ Select,
+ SelectContent,
+ SelectItem,
+ SelectTrigger,
+ SelectValue,
+} from "@/components/ui/select";
+
+import { DEFAULT_LINK_TYPE } from ".";
+import LinkItem from "./link-item";
+
+const PRESET_OPTIONS = [
+ { label: "in 1 hour", value: 3600 },
+ { label: "in 6 hours", value: 21600 },
+ { label: "in 12 hours", value: 43200 },
+ { label: "in 1 day", value: 86400 },
+ { label: "in 3 days", value: 259200 },
+ { label: "in 7 days", value: 604800 },
+ { label: "in 14 days", value: 1209600 },
+ { label: "in 1 month", value: 2592000 },
+ { label: "in 3 months", value: 7776000 },
+ { label: "in 6 months", value: 15552000 },
+ { label: "in 1 year", value: 31536000 },
+];
+
+export const formatExpirationTime = (seconds: number) => {
+ if (seconds < 60) {
+ return "Less than a minute";
+ } else if (seconds < 3600) {
+ const minutes = Math.floor(seconds / 60);
+ return `${minutes} minute${minutes > 1 ? "s" : ""}`;
+ } else if (seconds < 86400) {
+ const hours = Math.floor(seconds / 3600);
+ return `${hours} hour${hours > 1 ? "s" : ""}`;
+ } else if (seconds < 2592000) {
+ // Less than a month
+ const days = Math.floor(seconds / 86400);
+ return `${days} day${days > 1 ? "s" : ""}`;
+ } else if (seconds < 31536000) {
+ // Less than a year
+ const months = Math.floor(seconds / 2592000);
+ return `${months} month${months > 1 ? "s" : ""}`;
+ } else {
+ const years = Math.floor(seconds / 31536000);
+ return `${years} year${years > 1 ? "s" : ""}`;
+ }
+};
+
+export default function ExpirationInSection({
+ data,
+ setData,
+}: {
+ data: DEFAULT_LINK_TYPE & { expiresIn?: number | null };
+ setData: React.Dispatch<
+ React.SetStateAction<DEFAULT_LINK_TYPE & { expiresIn?: number | null }>
+ >;
+}) {
+ console.log("data data", data);
+ const [enabled, setEnabled] = useState<boolean>(false);
+ const [selectedPreset, setSelectedPreset] = useState<string>("");
+ const [error, setError] = useState<string | null>(null);
+
+ useEffect(() => {
+ setEnabled(!!data.expiresIn);
+
+ if (data.expiresIn) {
+ const matchingPreset = PRESET_OPTIONS.find(
+ (option) => option.value === data.expiresIn,
+ );
+
+ if (matchingPreset) {
+ setSelectedPreset(matchingPreset.value.toString());
+ } else {
+ setSelectedPreset("");
+ }
+ }
+ }, [data.expiresIn]);
+
+ const handleEnableExpiration = () => {
+ if (enabled) {
+ setSelectedPreset("");
+ setError(null);
+ } else {
+ setData({
+ ...data,
+ expiresIn: 604800,
+ expiresAt: null,
+ });
+ setSelectedPreset("604800");
+ setError(null);
+ }
+ setEnabled(!enabled);
+ };
+
+ const handlePresetChange = (value: string) => {
+ setSelectedPreset(value);
+ setError(null);
+
+ const seconds = parseInt(value);
+ if (!isNaN(seconds)) {
+ setData({
+ ...data,
+ expiresIn: seconds,
+ });
+ }
+ };
+
+ return (
+ <div className="pb-5">
+ <LinkItem
+ title="Link Expires After"
+ enabled={enabled}
+ link="https://www.papermark.com/help/article/expiration-date"
+ action={handleEnableExpiration}
+ tooltipContent="Set how long the link will remain active."
+ />
+
+ {enabled && (
+ <motion.div className="mt-3 space-y-3" {...FADE_IN_ANIMATION_SETTINGS}>
+ <div className="flex flex-col space-y-2">
+ <Select value={selectedPreset} onValueChange={handlePresetChange}>
+ <SelectTrigger>
+ <SelectValue placeholder="Select expiration time" />
+ </SelectTrigger>
+ <SelectContent>
+ {PRESET_OPTIONS.map((option) => (
+ <SelectItem
+ key={option.value}
+ value={option.value.toString()}
+ >
+ {option.label}
+ </SelectItem>
+ ))}
+ </SelectContent>
+ </Select>
+
+ {data.expiresIn && (
+ <div className="space-y-1 text-xs text-muted-foreground">
+ <div>
+ Links will expire in {formatExpirationTime(data.expiresIn)}
+ </div>
+ </div>
+ )}
+
+ {error && <div className="text-xs text-red-500">{error}</div>}
+ </div>
+ </motion.div>
+ )}
+ </div>
+ );
+}
diff --git a/components/links/link-sheet/index.tsx b/components/links/link-sheet/index.tsx
index 587a4978..ebee6fe2 100644
--- a/components/links/link-sheet/index.tsx
+++ b/components/links/link-sheet/index.tsx
@@ -222,27 +222,38 @@ export default function LinkSheet({
const preset = presets?.find((p) => p.id === presetId);
if (!preset) return;
- setData((prev) => ({
- ...prev,
- name: prev.name, // Keep existing name
- domain: prev.domain, // Keep existing domain
- slug: prev.slug, // Keep existing slug
-
- // Apply preset values
- emailProtected: preset.emailProtected ?? prev.emailProtected,
- emailAuthenticated: preset.emailAuthenticated ?? prev.emailAuthenticated,
- allowList: preset.allowList || prev.allowList,
- denyList: preset.denyList || prev.denyList,
- password: preset.password || prev.password,
- enableCustomMetatag:
- preset.enableCustomMetaTag ?? prev.enableCustomMetatag,
- metaTitle: preset.metaTitle || prev.metaTitle,
- metaDescription: preset.metaDescription || prev.metaDescription,
- metaImage: preset.metaImage || prev.metaImage,
- metaFavicon: preset.metaFavicon || prev.metaFavicon,
- allowDownload: preset.allowDownload || prev.allowDownload,
- expiresAt: preset.expiresAt || prev.expiresAt,
- }));
+ setData((prev) => {
+ // Calculate expiresAt if expiresIn is provided
+ let expiresAt = prev.expiresAt;
+ if (preset.expiresIn) {
+ const newExpiresAt = new Date();
+ newExpiresAt.setSeconds(newExpiresAt.getSeconds() + preset.expiresIn);
+ expiresAt = newExpiresAt;
+ } else {
+ expiresAt = preset.expiresAt || prev.expiresAt;
+ }
+
+ return {
+ ...prev,
+ name: prev.name, // Keep existing name
+ domain: prev.domain, // Keep existing domain
+ slug: prev.slug, // Keep existing slug
+ emailProtected: preset.emailProtected ?? prev.emailProtected,
+ emailAuthenticated:
+ preset.emailAuthenticated ?? prev.emailAuthenticated,
+ allowList: preset.allowList || prev.allowList,
+ denyList: preset.denyList || prev.denyList,
+ password: preset.password || prev.password,
+ enableCustomMetatag:
+ preset.enableCustomMetaTag ?? prev.enableCustomMetatag,
+ metaTitle: preset.metaTitle || prev.metaTitle,
+ metaDescription: preset.metaDescription || prev.metaDescription,
+ metaImage: preset.metaImage || prev.metaImage,
+ metaFavicon: preset.metaFavicon || prev.metaFavicon,
+ allowDownload: preset.allowDownload || prev.allowDownload,
+ expiresAt,
+ };
+ });
setCurrentPreset(preset);
};
diff --git a/components/ui/badge.tsx b/components/ui/badge.tsx
index 0ea1c88f..5f2bf4ea 100644
--- a/components/ui/badge.tsx
+++ b/components/ui/badge.tsx
@@ -16,6 +16,17 @@ const badgeVariants = cva(
destructive:
"border-transparent bg-destructive text-destructive-foreground hover:bg-destructive/80",
outline: "text-foreground",
+ time: "border-transparent bg-amber-50 text-amber-700 hover:bg-amber-100 dark:bg-amber-900/30 dark:text-amber-400 dark:hover:bg-amber-900/50",
+ email:
+ "border-transparent bg-blue-50 text-blue-700 hover:bg-blue-100 dark:bg-blue-900/30 dark:text-blue-400 dark:hover:bg-blue-900/50",
+ password:
+ "border-transparent bg-purple-50 text-purple-700 hover:bg-purple-100 dark:bg-purple-900/30 dark:text-purple-400 dark:hover:bg-purple-900/50",
+ preview:
+ "border-transparent bg-green-50 text-green-700 hover:bg-green-100 dark:bg-green-900/30 dark:text-green-400 dark:hover:bg-green-900/50",
+ download:
+ "border-transparent bg-orange-50 text-orange-700 hover:bg-orange-100 dark:bg-orange-900/30 dark:text-orange-400 dark:hover:bg-orange-900/50",
+ watermark:
+ "border-transparent bg-indigo-50 text-indigo-700 hover:bg-indigo-100 dark:bg-indigo-900/30 dark:text-indigo-400 dark:hover:bg-indigo-900/50",
},
},
defaultVariants: {
diff --git a/lib/zod/schemas/presets.ts b/lib/zod/schemas/presets.ts
index 71ebcb53..4501183c 100644
--- a/lib/zod/schemas/presets.ts
+++ b/lib/zod/schemas/presets.ts
@@ -52,6 +52,7 @@ export const presetDataSchema = z.object({
enablePassword: z.boolean(),
password: z.string().nullable(),
expiresAt: z.string().nullable(),
+ expiresIn: z.number().nullable(),
});
export type PresetDataSchema = z.infer<typeof presetDataSchema>;
diff --git a/pages/settings/presets/[id].tsx b/pages/settings/presets/[id].tsx
index 501c4c87..ccfda998 100644
--- a/pages/settings/presets/[id].tsx
+++ b/pages/settings/presets/[id].tsx
@@ -23,6 +23,7 @@ import DenyListSection from "@/components/links/link-sheet/deny-list-section";
import EmailAuthenticationSection from "@/components/links/link-sheet/email-authentication-section";
import EmailProtectionSection from "@/components/links/link-sheet/email-protection-section";
import ExpirationSection from "@/components/links/link-sheet/expiration-section";
+import ExpirationInSection from "@/components/links/link-sheet/expirationIn-section";
import { LinkUpgradeOptions } from "@/components/links/link-sheet/link-options";
import OGSection from "@/components/links/link-sheet/og-section";
import PasswordSection from "@/components/links/link-sheet/password-section";
@@ -40,11 +41,12 @@ import { Input } from "@/components/ui/input";
import { Label } from "@/components/ui/label";
import { Separator } from "@/components/ui/separator";
-type PRESET_DATA = Partial<DEFAULT_LINK_TYPE> & {
+export type PRESET_DATA = Partial<DEFAULT_LINK_TYPE> & {
name: string;
enableAllowList?: boolean;
enableDenyList?: boolean;
expiresAt?: Date | null;
+ expiresIn?: number | null;
pId?: string | null;
};
@@ -66,7 +68,6 @@ export default function EditPreset() {
const [isLoading, setIsLoading] = useState(false);
const [isDeleting, setIsDeleting] = useState(false);
const [data, setData] = useState<PRESET_DATA | null>(null);
- const [showDeleteDialog, setShowDeleteDialog] = useState(false);
const [showDeleteAlert, setShowDeleteAlert] = useState(false);
const {
@@ -109,6 +110,7 @@ export default function EditPreset() {
id: null,
name: preset.name,
expiresAt: preset.expiresAt,
+ expiresIn: preset.expiresIn,
password: preset.password,
emailProtected: preset.emailProtected ?? true,
emailAuthenticated: preset.emailAuthenticated ?? false,
@@ -133,6 +135,12 @@ export default function EditPreset() {
setIsLoading(true);
+ if (data.expiresAt && data.expiresAt < new Date()) {
+ toast.error("Expiration time must be in the future");
+ setIsLoading(false);
+ return;
+ }
+
try {
const response = await fetch(`/api/teams/${teamId}/presets/${id}`, {
method: "PUT",
@@ -158,6 +166,7 @@ export default function EditPreset() {
watermarkConfig: data.watermarkConfig,
allowDownload: data.allowDownload,
expiresAt: data.expiresAt,
+ expiresIn: data.expiresIn,
pId: data.pId,
}),
});
@@ -194,7 +203,6 @@ export default function EditPreset() {
console.error(error);
} finally {
setIsDeleting(false);
- setShowDeleteDialog(false);
}
};
@@ -362,6 +370,10 @@ export default function EditPreset() {
data={data as any}
setData={setData as any}
/>
+ <ExpirationInSection
+ data={data as any}
+ setData={setData as any}
+ />
</div>
<div className="rounded-lg border p-6">
@@ -412,7 +424,7 @@ export default function EditPreset() {
</div>
</div>
- <div className="sticky top-0 md:max-h-[95vh] md:overflow-auto">
+ <div className="sticky top-0 md:overflow-auto">
<div className="rounded-lg border">
{/* <div className="sticky top-0 flex h-14 items-center justify-center border-b bg-white px-5 dark:bg-gray-900">
<h2 className="text-lg font-medium">Preview</h2>
diff --git a/pages/settings/presets/index.tsx b/pages/settings/presets/index.tsx
index 0984143d..873008b3 100644
--- a/pages/settings/presets/index.tsx
+++ b/pages/settings/presets/index.tsx
@@ -15,7 +15,9 @@ import { fetcher } from "@/lib/utils";
import { UpgradePlanModal } from "@/components/billing/upgrade-plan-modal";
import AppLayout from "@/components/layouts/app";
+import { formatExpirationTime } from "@/components/links/link-sheet/expirationIn-section";
import { SettingsHeader } from "@/components/settings/settings-header";
+import { Badge } from "@/components/ui/badge";
import { Button } from "@/components/ui/button";
import { BadgeTooltip } from "@/components/ui/tooltip";
@@ -102,27 +104,56 @@ export default function Presets() {
)}
</div>
) : (
- <div className="grid grid-cols-1 gap-3">
+ <div className="grid grid-cols-1 gap-4 sm:grid-cols-2 lg:grid-cols-3">
{presets.map((preset) => (
<Link
key={preset.id}
href={`/settings/presets/${preset.id}`}
- className="rounded-xl border border-gray-200 bg-white p-4 transition-[filter] hover:bg-gray-50 dark:border-gray-400 dark:bg-secondary dark:hover:bg-gray-800 sm:p-5"
+ className="group relative flex flex-col rounded-xl border border-border bg-card p-5 transition-all hover:border-primary/50 hover:shadow-md dark:border-border dark:bg-card dark:hover:border-primary/50"
>
- <div className="flex items-center justify-between">
- <div>
- <div className="flex items-center gap-2">
- <span className="font-semibold">{preset.name}</span>
+ <div className="flex flex-col space-y-4">
+ <div className="flex items-start justify-between">
+ <div className="space-y-1">
+ <h3 className="font-semibold text-foreground group-hover:text-primary">
+ {preset.name}
+ </h3>
+ <p className="text-sm text-muted-foreground">
+ Created{" "}
+ {format(new Date(preset.createdAt), "MMM d, yyyy")}
+ </p>
</div>
- <div className="mt-1 flex items-center gap-4 text-sm text-muted-foreground">
- <div className="flex items-center gap-1">
- <span>
- Created:{" "}
- {format(new Date(preset.createdAt), "MMM d, yyyy")}
- </span>
- </div>
+ <div className="rounded-full bg-primary/10 p-2">
+ <PlusIcon className="h-4 w-4 text-primary" />
</div>
</div>
+
+ <div className="flex flex-wrap gap-2">
+ {preset.emailProtected && (
+ <Badge variant="email">Email Protected</Badge>
+ )}
+ {preset.password && (
+ <Badge variant="password">Password Protected</Badge>
+ )}
+ {preset.enableCustomMetaTag && (
+ <Badge variant="preview">Custom Preview</Badge>
+ )}
+ {preset.allowDownload && (
+ <Badge variant="download">Download Allowed</Badge>
+ )}
+ {preset.enableWatermark && (
+ <Badge variant="watermark">Watermark</Badge>
+ )}
+ {preset.expiresAt && (
+ <Badge variant="time">
+ Expires {format(new Date(preset.expiresAt), "MMM d")}
+ </Badge>
+ )}
+ {preset.expiresIn && (
+ <Badge variant="time">
+ Expires in {formatExpirationTime(preset.expiresIn)}
+ </Badge>
+ )}
+ </div>
</div>
</Link>
))}
diff --git a/pages/settings/presets/new.tsx b/pages/settings/presets/new.tsx
index a1297f03..edfcca1a 100644
--- a/pages/settings/presets/new.tsx
+++ b/pages/settings/presets/new.tsx
@@ -23,6 +23,7 @@ import DenyListSection from "@/components/links/link-sheet/deny-list-section";
import EmailAuthenticationSection from "@/components/links/link-sheet/email-authentication-section";
import EmailProtectionSection from "@/components/links/link-sheet/email-protection-section";
import ExpirationSection from "@/components/links/link-sheet/expiration-section";
+import ExpirationInSection from "@/components/links/link-sheet/expirationIn-section";
import { LinkUpgradeOptions } from "@/components/links/link-sheet/link-options";
import OGSection from "@/components/links/link-sheet/og-section";
import PasswordSection from "@/components/links/link-sheet/password-section";
@@ -40,7 +41,9 @@ export default function NewPreset() {
const teamId = teamInfo?.currentTeam?.id;
const [isLoading, setIsLoading] = useState(false);
- const [data, setData] = useState<DEFAULT_LINK_TYPE>({
+ const [data, setData] = useState<
+ DEFAULT_LINK_TYPE & { expiresIn?: number | null }
+ >({
...DEFAULT_LINK_PROPS(LinkType.DOCUMENT_LINK),
name: "",
});
@@ -82,6 +85,11 @@ export default function NewPreset() {
return;
}
+ if (data.expiresAt && data.expiresAt < new Date()) {
+ toast.error("Expiration time must be in the future");
+ return;
+ }
+
setIsLoading(true);
try {
@@ -109,6 +117,7 @@ export default function NewPreset() {
watermarkConfig: data.watermarkConfig,
allowDownload: data.allowDownload,
expiresAt: data.expiresAt,
+ expiresIn: data.expiresIn,
}),
});
@@ -203,6 +212,7 @@ export default function NewPreset() {
/>
<AllowDownloadSection data={data} setData={setData} />
<ExpirationSection data={data} setData={setData} />
+ <ExpirationInSection data={data} setData={setData} />
</div>
<div className="rounded-lg border p-6">
@@ -253,7 +263,7 @@ export default function NewPreset() {
</div>
</div>
- <div className="sticky top-0 md:max-h-[95vh] md:overflow-auto">
+ <div className="sticky top-0 md:overflow-auto">
<div className="rounded-lg border">
{/* <div className="sticky top-0 flex h-14 items-center justify-center border-b bg-white px-5 dark:bg-gray-900">
<h2 className="text-lg font-medium">Preview</h2>