Skip to content

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

update

Ashish Viradiya25bbba3408c5
diff --git a/components/links/link-sheet/expiration-section.tsx b/components/links/link-sheet/expiration-section.tsx
index de3592d8..0b3c3c41 100644
--- a/components/links/link-sheet/expiration-section.tsx
+++ b/components/links/link-sheet/expiration-section.tsx
@@ -1,6 +1,4 @@
-import { useEffect, useState } from "react";
-
-
+import { useCallback, useEffect, useState } from "react";
import { motion } from "motion/react";
@@ -29,7 +27,6 @@ export default function ExpirationSection({
>;
}) {
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);
@@ -105,7 +102,7 @@ export default function ExpirationSection({
setError(null);
};
- const formatExpirationTime = (date: Date | string) => {
+ const formatExpirationTime = useCallback((date: Date | string) => {
const now = new Date();
const dateObj = typeof date === "string" ? new Date(date) : date;
const diffInSeconds = Math.floor(
@@ -130,9 +127,9 @@ export default function ExpirationSection({
return `${days} day${days > 1 ? "s" : ""} and ${remainingHours} hour${remainingHours > 1 ? "s" : ""}`;
}
}
- };
+ }, []);
- const formatNaturalExpiration = (date: Date | string) => {
+ const formatNaturalExpiration = useCallback((date: Date | string) => {
const now = new Date();
const dateObj = typeof date === "string" ? new Date(date) : date;
@@ -159,7 +156,7 @@ export default function ExpirationSection({
}
return `on ${formattedDate} at ${formattedTime}`;
- };
+ }, []);
return (
<div className="pb-5">
diff --git a/components/links/link-sheet/expirationIn-section.tsx b/components/links/link-sheet/expirationIn-section.tsx
index 0b3d3fe6..160f1009 100644
--- a/components/links/link-sheet/expirationIn-section.tsx
+++ b/components/links/link-sheet/expirationIn-section.tsx
@@ -6,7 +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 { PRESET_OPTIONS, formatExpirationTime } from "@/lib/utils";
import {
Select,
@@ -19,29 +19,6 @@ import {
import { DEFAULT_LINK_TYPE } from ".";
import LinkItem from "./link-item";
-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,
@@ -51,7 +28,6 @@ export default function ExpirationInSection({
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);
diff --git a/lib/utils.ts b/lib/utils.ts
index 6a40b2be..44967c3e 100644
--- a/lib/utils.ts
+++ b/lib/utils.ts
@@ -606,3 +606,26 @@ export const WITH_CUSTOM_PRESET_OPTION: { label: string; value: number | string
...PRESET_OPTIONS,
{ label: "Custom", value: "custom" },
];
+
+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" : ""}`;
+ }
+};
\ No newline at end of file