Skip to content

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

feat: update link sheet section to reflect link editing

Marc Seitzaeb370725d3b
diff --git a/components/links/link-sheet/email-protection-section.tsx b/components/links/link-sheet/email-protection-section.tsx
index 5add1fb5..59d6c9bd 100644
--- a/components/links/link-sheet/email-protection-section.tsx
+++ b/components/links/link-sheet/email-protection-section.tsx
@@ -1,4 +1,4 @@
-import { Dispatch, SetStateAction, useState } from "react";
+import { Dispatch, SetStateAction, useState, useEffect } from "react";
import { Switch } from "@/components/ui/switch";
import { cn } from "@/lib/utils";
import { DEFAULT_LINK_TYPE } from ".";
@@ -6,12 +6,19 @@ import { DEFAULT_LINK_TYPE } from ".";
export default function EmailProtectionSection({data, setData}: {data: DEFAULT_LINK_TYPE, setData: Dispatch<SetStateAction<DEFAULT_LINK_TYPE>>}) {
- const [enabled, setEnabled] = useState(true);
+ const { emailProtected } = data;
+ const [enabled, setEnabled] = useState<boolean>(true);
+
+ useEffect(() => {
+ setEnabled(emailProtected);
+ }, [emailProtected]);
+
+ const handleEnableProtection = () => {
+ const updatedEmailProtection = !enabled;
+ setData({ ...data, emailProtected: updatedEmailProtection });
+ setEnabled(updatedEmailProtection);
+ };
- function handleCheckedChange() {
- setData({ ...data, emailProtected: enabled });
- setEnabled(!enabled);
- }
return (
<div className="pb-5">
<div className="flex items-center justify-between">
@@ -27,7 +34,7 @@ export default function EmailProtectionSection({data, setData}: {data: DEFAULT_L
</div>
<Switch
checked={enabled}
- onCheckedChange={() => handleCheckedChange()}
+ onCheckedChange={handleEnableProtection}
/>
</div>
</div>
diff --git a/components/links/link-sheet/expiration-section.tsx b/components/links/link-sheet/expiration-section.tsx
index 1c4ffb23..a2a7149c 100644
--- a/components/links/link-sheet/expiration-section.tsx
+++ b/components/links/link-sheet/expiration-section.tsx
@@ -1,4 +1,4 @@
-import { Dispatch, SetStateAction, useState } from "react";
+import { Dispatch, SetStateAction, useState, useEffect } from "react";
import { Switch } from "@/components/ui/switch";
import { motion } from "framer-motion";
import { FADE_IN_ANIMATION_SETTINGS } from "@/lib/contants";
@@ -9,7 +9,19 @@ import { DEFAULT_LINK_TYPE } from ".";
export default function ExpirationSection({data, setData}: {data: DEFAULT_LINK_TYPE, setData: Dispatch<SetStateAction<DEFAULT_LINK_TYPE>>}) {
const { expiresAt } = data;
- const [enabled, setEnabled] = useState(!!expiresAt);
+ const [enabled, setEnabled] = useState<boolean>(false);
+
+ useEffect(() => {
+ setEnabled(!!expiresAt);
+ }, [expiresAt]);
+
+ const handleEnableExpiration = () => {
+ if (enabled) {
+ // if expiration is currently set and we're toggling it off
+ setData({ ...data, expiresAt: null });
+ }
+ setEnabled(!enabled);
+ };
return (
<div className="pb-5">
@@ -26,7 +38,7 @@ export default function ExpirationSection({data, setData}: {data: DEFAULT_LINK_T
</div>
<Switch
checked={enabled}
- onCheckedChange={() => setEnabled(!enabled)}
+ onCheckedChange={handleEnableExpiration}
/>
</div>
{enabled && (
diff --git a/components/links/link-sheet/password-section.tsx b/components/links/link-sheet/password-section.tsx
index 1da4d8d7..33cf7811 100644
--- a/components/links/link-sheet/password-section.tsx
+++ b/components/links/link-sheet/password-section.tsx
@@ -1,4 +1,4 @@
-import { Dispatch, SetStateAction, useState } from "react";
+import { Dispatch, SetStateAction, useEffect, useState } from "react";
import { Switch } from "@/components/ui/switch";
import { motion } from "framer-motion";
import { FADE_IN_ANIMATION_SETTINGS } from "@/lib/contants";
@@ -10,8 +10,20 @@ import { DEFAULT_LINK_TYPE } from ".";
export default function PasswordSection({data, setData}: {data: DEFAULT_LINK_TYPE, setData: Dispatch<SetStateAction<DEFAULT_LINK_TYPE>>}) {
const { password } = data;
- const [enabled, setEnabled] = useState(!!password);
- const [showPassword, setShowPassword] = useState(false);
+ const [enabled, setEnabled] = useState<boolean>(false);
+ const [showPassword, setShowPassword] = useState<boolean>(false);
+
+ useEffect(() => {
+ setEnabled(!!password);
+ }, [password]);
+
+ const handleEnablePassword = () => {
+ if (enabled) {
+ // if password protection is currently enabled and we're toggling it off
+ setData({ ...data, password: null });
+ }
+ setEnabled(!enabled);
+ };
return (
<div className="pb-5">
@@ -23,7 +35,7 @@ export default function PasswordSection({data, setData}: {data: DEFAULT_LINK_TYP
</div>
<Switch
checked={enabled}
- onCheckedChange={() => setEnabled(!enabled)}
+ onCheckedChange={handleEnablePassword}
/>
</div>
{enabled && (