Skip to content

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

refactor: reorder custom fields section

Marc Seitz5708448bd505
diff --git a/components/links/link-sheet/custom-fields-panel/index.tsx b/components/links/link-sheet/custom-fields-panel/index.tsx
index 80f06fac..b3bb03b1 100644
--- a/components/links/link-sheet/custom-fields-panel/index.tsx
+++ b/components/links/link-sheet/custom-fields-panel/index.tsx
@@ -1,7 +1,10 @@
+import { useCallback, useMemo } from "react";
+
import { CustomField, CustomFieldType } from "@prisma/client";
import { Plus } from "lucide-react";
import { toast } from "sonner";
-import { useCallback, useMemo } from "react";
+
+import { usePlan } from "@/lib/swr/use-billing";
import { Button } from "@/components/ui/button";
import { ScrollArea } from "@/components/ui/scroll-area";
@@ -14,18 +17,13 @@ import {
SheetTitle,
} from "@/components/ui/sheet";
-import { usePlan } from "@/lib/swr/use-billing";
-
import CustomFieldComponent from "./custom-field";
export type CustomFieldData = Omit<
CustomField,
"id" | "createdAt" | "updatedAt" | "linkId"
> & {
- type: Omit<
- CustomFieldType,
- "CHECKBOX" | "SELECT" | "MULTI_SELECT"
- >;
+ type: Omit<CustomFieldType, "CHECKBOX" | "SELECT" | "MULTI_SELECT">;
};
export default function CustomFieldsPanel({
@@ -67,48 +65,57 @@ export default function CustomFieldsPanel({
onChange([...fields, newField]);
}, [fields, fieldLimit, isDatarooms, onChange]);
- const updateField = useCallback((index: number, updatedField: CustomFieldData) => {
- const newFields = [...fields];
- newFields[index] = updatedField;
- onChange(newFields);
- }, [fields, onChange]);
-
- const removeField = useCallback((index: number) => {
- const newFields = fields.filter((_, i) => i !== index);
- // Update orderIndex for remaining fields
- newFields.forEach((field, i) => {
- field.orderIndex = i;
- });
- onChange(newFields);
- }, [fields, onChange]);
-
- const moveField = useCallback((index: number, direction: "up" | "down") => {
- if (
- (direction === "up" && index === 0) ||
- (direction === "down" && index === fields.length - 1)
- )
- return;
-
- const newFields = [...fields];
- const newIndex = direction === "up" ? index - 1 : index + 1;
- [newFields[index], newFields[newIndex]] = [
- newFields[newIndex],
- newFields[index],
- ];
+ const updateField = useCallback(
+ (index: number, updatedField: CustomFieldData) => {
+ const newFields = [...fields];
+ newFields[index] = updatedField;
+ onChange(newFields);
+ },
+ [fields, onChange],
+ );
- // Update orderIndex for all fields
- newFields.forEach((field, i) => {
- field.orderIndex = i;
- });
+ const removeField = useCallback(
+ (index: number) => {
+ const newFields = fields.filter((_, i) => i !== index);
+ // Update orderIndex for remaining fields
+ newFields.forEach((field, i) => {
+ field.orderIndex = i;
+ });
+ onChange(newFields);
+ },
+ [fields, onChange],
+ );
- onChange(newFields);
- }, [fields, onChange]);
+ const moveField = useCallback(
+ (index: number, direction: "up" | "down") => {
+ if (
+ (direction === "up" && index === 0) ||
+ (direction === "down" && index === fields.length - 1)
+ )
+ return;
+
+ const newFields = [...fields];
+ const newIndex = direction === "up" ? index - 1 : index + 1;
+ [newFields[index], newFields[newIndex]] = [
+ newFields[newIndex],
+ newFields[index],
+ ];
+
+ // Update orderIndex for all fields
+ newFields.forEach((field, i) => {
+ field.orderIndex = i;
+ });
+
+ onChange(newFields);
+ },
+ [fields, onChange],
+ );
return (
<Sheet open={isConfigOpen} onOpenChange={setIsConfigOpen}>
<SheetContent className="flex h-full flex-col">
<SheetHeader>
- <SheetTitle>Configure Custom Fields</SheetTitle>
+ <SheetTitle>Configure Custom Form Fields</SheetTitle>
<SheetDescription>
Configure the custom fields that will be shown to viewers.
{fieldLimit > 0 && (
diff --git a/components/links/link-sheet/custom-fields-section.tsx b/components/links/link-sheet/custom-fields-section.tsx
index f3cc87c7..80d3e12c 100644
--- a/components/links/link-sheet/custom-fields-section.tsx
+++ b/components/links/link-sheet/custom-fields-section.tsx
@@ -89,7 +89,7 @@ export default function CustomFieldsSection({
return (
<div className="pb-5">
<LinkItem
- title="Custom Fields"
+ title="Custom Form Fields"
tooltipContent="Add custom fields to collect additional information from viewers"
link="https://www.papermark.com/help/article/custom-fields"
enabled={enabled}
diff --git a/components/links/link-sheet/link-options.tsx b/components/links/link-sheet/link-options.tsx
index 08db241d..37f65390 100644
--- a/components/links/link-sheet/link-options.tsx
+++ b/components/links/link-sheet/link-options.tsx
@@ -208,14 +208,12 @@ export const LinkOptions = ({
}
handleUpgradeStateChange={handleUpgradeStateChange}
/>
- {linkType === LinkType.DOCUMENT_LINK ? (
- <CustomFieldsSection
- {...{ data, setData }}
- isAllowed={isTrial || isBusiness || isDatarooms || isDataroomsPlus}
- handleUpgradeStateChange={handleUpgradeStateChange}
- presets={currentPreset}
- />
- ) : null}
+ <CustomFieldsSection
+ {...{ data, setData }}
+ isAllowed={isTrial || isBusiness || isDatarooms || isDataroomsPlus}
+ handleUpgradeStateChange={handleUpgradeStateChange}
+ presets={currentPreset}
+ />
</div>
</CollapsibleSection>
@@ -279,18 +277,12 @@ export const LinkOptions = ({
{...{ data, setData }}
isAllowed={
isDataroomsPlus ||
- ((isBusiness || isDatarooms) && limits?.conversationsInDataroom)
+ ((isBusiness || isDatarooms) &&
+ limits?.conversationsInDataroom)
}
handleUpgradeStateChange={handleUpgradeStateChange}
/>
) : null}
-
- <CustomFieldsSection
- {...{ data, setData }}
- isAllowed={isTrial || isBusiness || isDatarooms || isDataroomsPlus}
- handleUpgradeStateChange={handleUpgradeStateChange}
- presets={currentPreset}
- />
</div>
</CollapsibleSection>
) : null}