Skip to content

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

Improvement

Ashish Viradiya82aade5b7ed7
diff --git a/components/links/link-sheet/expiration-section.tsx b/components/links/link-sheet/expiration-section.tsx
index 3c026a05..de3592d8 100644
--- a/components/links/link-sheet/expiration-section.tsx
+++ b/components/links/link-sheet/expiration-section.tsx
@@ -1,9 +1,11 @@
import { useEffect, useState } from "react";
+
+
import { motion } from "motion/react";
import { FADE_IN_ANIMATION_SETTINGS } from "@/lib/constants";
-import { formatDate, getDateTimeLocal } from "@/lib/utils";
+import { WITH_CUSTOM_PRESET_OPTION, getDateTimeLocal } from "@/lib/utils";
import { Input } from "@/components/ui/input";
import {
@@ -17,21 +19,6 @@ import {
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,
@@ -59,8 +46,8 @@ export default function ExpirationSection({
(expirationDate.getTime() - now.getTime()) / 1000,
);
- const matchingPreset = PRESET_OPTIONS.find(
- (option) =>
+ const matchingPreset = WITH_CUSTOM_PRESET_OPTION.find(
+ (option: { value: number | string }) =>
option.value !== "custom" &&
Math.abs(parseInt(option.value.toString()) - diffInSeconds) < 60,
);
@@ -192,7 +179,7 @@ export default function ExpirationSection({
<SelectValue placeholder="Select expiration time" />
</SelectTrigger>
<SelectContent>
- {PRESET_OPTIONS.map((option) => (
+ {WITH_CUSTOM_PRESET_OPTION.map((option) => (
<SelectItem
key={option.value}
value={option.value.toString()}
diff --git a/components/links/link-sheet/expirationIn-section.tsx b/components/links/link-sheet/expirationIn-section.tsx
index 20260d01..0b3d3fe6 100644
--- a/components/links/link-sheet/expirationIn-section.tsx
+++ b/components/links/link-sheet/expirationIn-section.tsx
@@ -6,6 +6,7 @@ import { PRESET_DATA } from "@/pages/settings/presets/[id]";
import { motion } from "motion/react";
import { FADE_IN_ANIMATION_SETTINGS } from "@/lib/constants";
+import { PRESET_OPTIONS } from "@/lib/utils";
import {
Select,
@@ -18,20 +19,6 @@ import {
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";
@@ -74,7 +61,7 @@ export default function ExpirationInSection({
if (data.expiresIn) {
const matchingPreset = PRESET_OPTIONS.find(
- (option) => option.value === data.expiresIn,
+ (option: { value: number }) => option.value === data.expiresIn,
);
if (matchingPreset) {
@@ -132,14 +119,16 @@ export default function ExpirationInSection({
<SelectValue placeholder="Select expiration time" />
</SelectTrigger>
<SelectContent>
- {PRESET_OPTIONS.map((option) => (
- <SelectItem
- key={option.value}
- value={option.value.toString()}
- >
- {option.label}
- </SelectItem>
- ))}
+ {PRESET_OPTIONS.map(
+ (option: { value: number; label: string }) => (
+ <SelectItem
+ key={option.value}
+ value={option.value.toString()}
+ >
+ {option.label}
+ </SelectItem>
+ ),
+ )}
</SelectContent>
</Select>
diff --git a/lib/utils.ts b/lib/utils.ts
index af8803ca..6a40b2be 100644
--- a/lib/utils.ts
+++ b/lib/utils.ts
@@ -583,3 +583,26 @@ export const handleInvitationStatus = (
shallow: true,
});
};
+
+/**
+ * Preset options for the expiration time of a link.
+ * @type {Array<{ label: string, value: number }>}
+ */
+
+export const PRESET_OPTIONS: { label: string; value: number }[] = [
+ { 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 WITH_CUSTOM_PRESET_OPTION: { label: string; value: number | string }[] = [
+ ...PRESET_OPTIONS,
+ { label: "Custom", value: "custom" },
+];