Skip to content

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

fix: bind aria-invalid to actual validation state and fix indentation in links API

Cursor Agentbb31a6f0a7ad
diff --git a/components/links/link-sheet/domain-section.tsx b/components/links/link-sheet/domain-section.tsx
index 6738dc27..26a6f58d 100644
--- a/components/links/link-sheet/domain-section.tsx
+++ b/components/links/link-sheet/domain-section.tsx
@@ -184,6 +184,11 @@ export default function DomainSection({
const currentDomain = domains?.find((domain) => domain.slug === data.domain);
const isDomainVerified = currentDomain?.verified;
+ const isSlugInvalid =
+ !!data.slug &&
+ (!/^[a-zA-Z0-9-]+$/.test(data.slug) ||
+ BLOCKED_PATHNAMES.includes(`/${data.slug}`));
+
const isDisabled =
linkType === "DOCUMENT_LINK"
? isEditingCustomDomain && !canUseCustomDomainForDocument
@@ -322,7 +327,7 @@ export default function DomainSection({
}
setData({ ...data, slug: currentValue });
}}
- aria-invalid="true"
+ aria-invalid={isSlugInvalid}
/>
<ButtonTooltip content="Generate random slug">
<Button
diff --git a/pages/api/links/index.ts b/pages/api/links/index.ts
index 56c12603..536f421d 100644
--- a/pages/api/links/index.ts
+++ b/pages/api/links/index.ts
@@ -82,42 +82,42 @@ export default async function handler(
: null;
const exat = expiresAt ? new Date(expiresAt) : null;
- let { domain, slug, ...linkData } = linkDomainData;
+ let { domain, slug, ...linkData } = linkDomainData;
- // set domain and slug to null if the domain is papermark.com
- if (domain && domain === "papermark.com") {
- domain = null;
- slug = null;
- }
+ // set domain and slug to null if the domain is papermark.com
+ if (domain && domain === "papermark.com") {
+ domain = null;
+ slug = null;
+ }
- let domainObj: DomainObject | null;
+ let domainObj: DomainObject | null;
- if (domain && slug) {
- domainObj = await prisma.domain.findUnique({
- where: {
- slug: domain,
- },
- });
+ if (domain && slug) {
+ domainObj = await prisma.domain.findUnique({
+ where: {
+ slug: domain,
+ },
+ });
- if (!domainObj) {
- return res.status(400).json({ error: "Domain not found." });
- }
+ if (!domainObj) {
+ return res.status(400).json({ error: "Domain not found." });
+ }
- const existingLink = await prisma.link.findUnique({
- where: {
- domainSlug_slug: {
- slug: slug,
- domainSlug: domain,
+ const existingLink = await prisma.link.findUnique({
+ where: {
+ domainSlug_slug: {
+ slug: slug,
+ domainSlug: domain,
+ },
},
- },
- });
-
- if (existingLink) {
- return res.status(400).json({
- error: "The link already exists.",
});
+
+ if (existingLink) {
+ return res.status(400).json({
+ error: "The link already exists.",
+ });
+ }
}
- }
if (linkData.enableAgreement && !linkData.agreementId) {
return res.status(400).json({