Papermark is the open-source DocSend alternative and secure data rooms with built-in analytics and custom domains.
feat: make domains editable and light mode
Marc Seitz3e4b98f1b596
diff --git a/components/domains/domain-card.tsx b/components/domains/domain-card.tsxindex ab7d3995..e17e72df 100644--- a/components/domains/domain-card.tsx+++ b/components/domains/domain-card.tsx@@ -39,7 +39,7 @@ export default function DomainCard({return (<>- <div className="flex flex-col space-y-3 rounded-lg border border-gray-700 bg-gray-800 px-5 py-8 sm:px-10">+ <div className="flex flex-col space-y-3 rounded-lg ring-1 ring-gray-200 dark:ring-gray-700 bg-white dark:bg-secondary hover:ring-gray-400 hover:dark:ring-gray-500 px-5 py-8 sm:px-10"><div className="flex flex-col justify-between space-y-4 sm:flex-row sm:space-x-4"><div className="flex items-center space-x-2"><a@@ -57,7 +57,7 @@ export default function DomainCard({<div className="flex space-x-3"><Buttonvariant="secondary"- className="bg-gray-700 hover:bg-gray-700/80"+ className="bg-gray-300 hover:bg-gray-300/80 dark:bg-gray-700 hover:dark:bg-gray-700/80"loading={loading}onClick={() => {mutate(`/api/domains/${domain}/verify`);@@ -78,7 +78,7 @@ export default function DomainCard({<div className="flex items-center space-x-2">{status ? (status === "Valid Configuration" ? (- <CheckCircle2 className="h-6 w-6 text-blue-500" />+ <CheckCircle2 className="h-6 w-6 text-emerald-500" />) : status === "Pending Verification" ? (<AlertCircle className="h-6 w-6 text-yellow-500" />) : (@@ -87,7 +87,7 @@ export default function DomainCard({) : (<LoadingSpinner className="mr-1 h-5 w-5" />)}- <p className="text-sm text-gray-400">+ <p className="text-sm text-muted-foreground">{status ? status : "Checking Domain Status"}</p></div>diff --git a/components/domains/domain-configuration.tsx b/components/domains/domain-configuration.tsxindex 0aef6824..c5795357 100644--- a/components/domains/domain-configuration.tsx+++ b/components/domains/domain-configuration.tsx@@ -37,7 +37,7 @@ export default function DomainConfiguration({ domain }: { domain: string }) {null;return (- <div className="border-t border-stone-200 pb-5 pt-7 dark:border-stone-700">+ <div className="border-t border-gray-200 pb-5 pt-7 dark:border-gray-700">{txtVerification ? (<><p className="text-sm dark:text-white">@@ -45,7 +45,7 @@ export default function DomainConfiguration({ domain }: { domain: string }) {<InlineSnippet>{domainJson.apexName}</InlineSnippet> to proveownership of <InlineSnippet>{domainJson.name}</InlineSnippet>:</p>- <div className="my-5 flex items-start justify-start space-x-10 rounded-md bg-stone-50 p-2 dark:bg-stone-800 dark:text-white">+ <div className="my-5 flex items-start justify-start space-x-10 rounded-md bg-gray-50 p-2 dark:bg-gray-800 dark:text-white"><div><p className="text-sm font-bold">Type</p><p className="mt-2 font-mono text-sm">{txtVerification.type}</p>@@ -66,7 +66,7 @@ export default function DomainConfiguration({ domain }: { domain: string }) {</p></div></div>- <p className="text-sm dark:text-stone-400">+ <p className="text-sm dark:text-muted-foreground">Warning: if you are using this domain for another site, setting thisTXT record will transfer domain ownership away from that site andbreak it. Please exercise caution when setting this record.@@ -112,7 +112,7 @@ export default function DomainConfiguration({ domain }: { domain: string }) {), set the following {recordType} record on your DNS provider tocontinue:</p>- <div className="flex items-center justify-start space-x-10 rounded-md bg-stone-50 p-2 dark:bg-stone-800 dark:text-white">+ <div className="flex items-center justify-start space-x-10 rounded-md bg-gray-50 p-2 dark:bg-gray-800 dark:text-white"><div><p className="text-sm font-bold">Type</p><p className="mt-2 font-mono text-sm">{recordType}</p>diff --git a/components/links/link-sheet/index.tsx b/components/links/link-sheet/index.tsxindex df66f10e..951f525e 100644--- a/components/links/link-sheet/index.tsx+++ b/components/links/link-sheet/index.tsx@@ -18,10 +18,15 @@ import { useDomains } from "@/lib/swr/use-domains";import { mutate } from "swr";import { Button } from "@/components/ui/button";import { toast } from "sonner";+import { Label } from "@/components/ui/label";+import { cn } from "@/lib/utils";+import { set } from "date-fns";export const DEFAULT_LINK_PROPS = {id: null,name: null,+ domain: null,+ slug: null,expiresAt: null,password: null,emailProtected: true,@@ -30,6 +35,8 @@ export const DEFAULT_LINK_PROPS = {export type DEFAULT_LINK_TYPE = {id: string | null;name: string | null;+ domain: string | null;+ slug: string | null;expiresAt: Date | null;password: string | null;emailProtected: boolean;@@ -38,6 +45,7 @@ export type DEFAULT_LINK_TYPE = {export default function LinkSheet({ isOpen, setIsOpen, currentLink }: { isOpen: boolean, setIsOpen: Dispatch<SetStateAction<boolean>>, currentLink?: DEFAULT_LINK_TYPE }) {const { links } = useDocumentLinks();+ const { domains } = useDomains();const [data, setData] = useState<DEFAULT_LINK_TYPE>(DEFAULT_LINK_PROPS);const [isLoading, setIsLoading] = useState<boolean>(false);@@ -74,12 +82,17 @@ export default function LinkSheet({ isOpen, setIsOpen, currentLink }: { isOpen:});if (!response.ok) {- throw new Error(`HTTP error! status: ${response.status}`);+ // handle error with toast message+ const { error } = await response.json();+ toast.error(error)+ setIsLoading(false);+ return;}const returnedLink = await response.json();if (currentLink) {+ setIsOpen(false);// Update the link in the list of linksmutate(`/api/documents/${encodeURIComponent(documentId)}/links`,@@ -88,6 +101,7 @@ export default function LinkSheet({ isOpen, setIsOpen, currentLink }: { isOpen:);toast.success("Link updated successfully");} else {+ setIsOpen(false);// Add the new link to the list of linksmutate(`/api/documents/${encodeURIComponent(documentId)}/links`,@@ -103,6 +117,7 @@ export default function LinkSheet({ isOpen, setIsOpen, currentLink }: { isOpen:setIsLoading(false);}+ console.log("current Data", data)return (@@ -120,13 +135,8 @@ export default function LinkSheet({ isOpen, setIsOpen, currentLink }: { isOpen:<div className="flex flex-1 flex-col justify-between"><div className="divide-y divide-gray-200"><div className="space-y-6 pb-5 pt-6">- <div>- <label- htmlFor="project-name"- className="block text-sm font-medium leading-6 text-foreground"- >- Link Name- </label>+ <div className="space-y-2">+ <Label htmlFor="link-name">Link Name</Label><div className="mt-2"><inputtype="text"@@ -142,6 +152,62 @@ export default function LinkSheet({ isOpen, setIsOpen, currentLink }: { isOpen:</div></div>+ {domains ? (+ <div className="space-y-2">+ <Label htmlFor="link-domain">Domain</Label>+ <div className="flex">+ <select+ value={data.domain || "papermark.io"}+ onChange={(e) => {+ setData({ ...data, domain: e.target.value });+ }}+ className={cn(+ "w-48 rounded-l-md border border-r-0 border-gray-300 bg-gray-50 px-5 text-sm text-gray-500 focus:border-gray-300 focus:outline-none focus:ring-0",+ data.domain && data.domain !== "papermark.io"+ ? ""+ : "rounded-r-md border-r-1"+ )}+ >+ <option key="papermark.io" value="papermark.io">+ papermark.io+ </option>+ {domains?.map(({ slug }) => (+ <option key={slug} value={slug}>+ {slug}+ </option>+ ))}+ </select>+ {data.domain && data.domain !== "papermark.io" ? (+ <input+ type="text"+ name="key"+ required+ value={data.slug || ""}+ pattern="[\p{L}\p{N}\p{Pd}\/]+"+ onInvalid={(e) => {+ e.currentTarget.setCustomValidity(+ "Only letters, numbers, '-', and '/' are allowed."+ );+ }}+ autoComplete="off"+ className={cn(+ "hidden w-full rounded-r-md border-0 py-1.5 text-foreground bg-background shadow-sm ring-1 ring-inset ring-input placeholder:text-muted-foreground focus:ring-2 focus:ring-inset focus:ring-gray-400 sm:text-sm sm:leading-6",+ data.domain && data.domain !== "papermark.io"+ ? "flex"+ : ""+ )}+ placeholder="deck"+ onChange={(e) => {+ e.currentTarget.setCustomValidity("");+ setData({ ...data, slug: e.target.value });+ }}+ aria-invalid="true"+ />+ ) : null}+ </div>+ </div>+ ) : null}+<div className="flex items-center relative"><Separator className="bg-muted-foreground absolute" /><div className="relative mx-auto">@@ -163,11 +229,9 @@ export default function LinkSheet({ isOpen, setIsOpen, currentLink }: { isOpen:<SheetFooter><div className="flex items-center">- <SheetClose asChild>- <Button type="submit">+ <Button type="submit" disabled={isLoading}>{currentLink ? "Update Link" : "Save Link"}</Button>- </SheetClose></div></SheetFooter></form>diff --git a/components/links/links-table.tsx b/components/links/links-table.tsxindex 66f78396..1fa4e527 100644--- a/components/links/links-table.tsx+++ b/components/links/links-table.tsx@@ -43,14 +43,16 @@ export default function LinksTable() {const [isLinkSheetVisible, setIsLinkSheetVisible] = useState<boolean>(false);const [selectedLink, setSelectedLink] = useState<DEFAULT_LINK_TYPE>(DEFAULT_LINK_PROPS);- const handleCopyToClipboard = (id: string) => {- copyToClipboard(`${process.env.NEXT_PUBLIC_BASE_URL}/view/${id}`, "Link copied to clipboard.");+ const handleCopyToClipboard = (linkString: string) => {+ copyToClipboard(`${linkString}`, "Link copied to clipboard.");};const handleEditLink = (link: LinkWithViews) => {setSelectedLink({id: link.id,name: link.name,+ domain: link.domainSlug,+ slug: link.slug,expiresAt: link.expiresAt,password: link.password,emailProtected: link.emailProtected,@@ -124,11 +126,25 @@ export default function LinksTable() {</TableCell><TableCell className="max-w-[150px] sm:min-w-[450px]"><div className="group/cell flex items-center gap-x-4 rounded-md text-secondary-foreground bg-secondary px-3 py-1 group-hover/row:ring-1 group-hover/row:ring-gray-400 hover:bg-emerald-700 hover:dark:bg-emerald-200 group-hover/row:dark:ring-gray-100 transition-all">- <div className="whitespace-nowrap hidden sm:flex text-sm group-hover/cell:hidden">{`https://papermark.io/view/${link.id}`}</div>+ <div className="whitespace-nowrap hidden sm:flex text-sm group-hover/cell:hidden">+ {link.domainId+ ? `https://${link.domainSlug}/${link.slug}`+ : `https://${process.env.NEXT_PUBLIC_ROOT_DOMAIN}/view/${link.id}`}+ </div><div className="flex sm:hidden whitespace-nowrap text-sm group-hover/cell:hidden truncate">{`${link.id}`}</div><buttonclassName="whitespace-nowrap text-sm text-center group-hover/cell:text-primary-foreground hidden group-hover/cell:block w-full"- onClick={() => handleCopyToClipboard(link.id)}+ onClick={+ link.domainId+ ? () =>+ handleCopyToClipboard(+ `https://${link.domainSlug}/${link.slug}`+ )+ : () =>+ handleCopyToClipboard(+ `https://${process.env.NEXT_PUBLIC_ROOT_DOMAIN}/view/${link.id}`+ )+ }title="Copy to clipboard">Copy{" "}@@ -276,7 +292,11 @@ export default function LinksTable() {</TableCell><TableCell className="max-w-[150px] sm:min-w-[450px]"><div className="flex items-center gap-x-4 rounded-md text-secondary-foreground bg-secondary group-hover/row:ring-1 group-hover/row:ring-gray-400 group-hover/row:dark:ring-gray-100 px-3 py-1">- <div className="whitespace-nowrap hidden sm:flex text-sm">{`https://papermark.io/view/${link.id}`}</div>+ <div className="whitespace-nowrap hidden sm:flex text-sm">+ {link.domainId+ ? `https://${link.domainSlug}/${link.slug}`+ : `https://${process.env.NEXT_PUBLIC_ROOT_DOMAIN}/view/${link.id}`}+ </div><div className="flex sm:hidden whitespace-nowrap text-sm truncate">{`${link.id}`}</div></div></TableCell>diff --git a/components/ui/select.tsx b/components/ui/select.tsxnew file mode 100644index 00000000..952e1f9e--- /dev/null+++ b/components/ui/select.tsx@@ -0,0 +1,121 @@+import * as React from "react"+import * as SelectPrimitive from "@radix-ui/react-select"+++import { cn } from "@/lib/utils"+import Check from "../shared/icons/check"+import ChevronDown from "../shared/icons/chevron-down"++const Select = SelectPrimitive.Root++const SelectGroup = SelectPrimitive.Group++const SelectValue = SelectPrimitive.Value++const SelectTrigger = React.forwardRef<+ React.ElementRef<typeof SelectPrimitive.Trigger>,+ React.ComponentPropsWithoutRef<typeof SelectPrimitive.Trigger>+>(({ className, children, ...props }, ref) => (+ <SelectPrimitive.Trigger+ ref={ref}+ className={cn(+ "flex h-10 w-full items-center justify-between rounded-md border border-input bg-background px-3 py-2 text-sm ring-offset-background placeholder:text-muted-foreground focus:outline-none focus:ring-2 focus:ring-ring focus:ring-offset-2 disabled:cursor-not-allowed disabled:opacity-50",+ className+ )}+ {...props}+ >+ {children}+ <SelectPrimitive.Icon asChild>+ <ChevronDown className="h-4 w-4 opacity-50" />+ </SelectPrimitive.Icon>+ </SelectPrimitive.Trigger>+))+SelectTrigger.displayName = SelectPrimitive.Trigger.displayName++const SelectContent = React.forwardRef<+ React.ElementRef<typeof SelectPrimitive.Content>,+ React.ComponentPropsWithoutRef<typeof SelectPrimitive.Content>+>(({ className, children, position = "popper", ...props }, ref) => (+ <SelectPrimitive.Portal>+ <SelectPrimitive.Content+ ref={ref}+ className={cn(+ "relative z-50 min-w-[8rem] overflow-hidden rounded-md border bg-popover text-popover-foreground shadow-md data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0 data-[state=closed]:zoom-out-95 data-[state=open]:zoom-in-95 data-[side=bottom]:slide-in-from-top-2 data-[side=left]:slide-in-from-right-2 data-[side=right]:slide-in-from-left-2 data-[side=top]:slide-in-from-bottom-2",+ position === "popper" &&+ "data-[side=bottom]:translate-y-1 data-[side=left]:-translate-x-1 data-[side=right]:translate-x-1 data-[side=top]:-translate-y-1",+ className+ )}+ position={position}+ {...props}+ >+ <SelectPrimitive.Viewport+ className={cn(+ "p-1",+ position === "popper" &&+ "h-[var(--radix-select-trigger-height)] w-full min-w-[var(--radix-select-trigger-width)]"+ )}+ >+ {children}+ </SelectPrimitive.Viewport>+ </SelectPrimitive.Content>+ </SelectPrimitive.Portal>+))+SelectContent.displayName = SelectPrimitive.Content.displayName++const SelectLabel = React.forwardRef<+ React.ElementRef<typeof SelectPrimitive.Label>,+ React.ComponentPropsWithoutRef<typeof SelectPrimitive.Label>+>(({ className, ...props }, ref) => (+ <SelectPrimitive.Label+ ref={ref}+ className={cn("py-1.5 pl-8 pr-2 text-sm font-semibold", className)}+ {...props}+ />+))+SelectLabel.displayName = SelectPrimitive.Label.displayName++const SelectItem = React.forwardRef<+ React.ElementRef<typeof SelectPrimitive.Item>,+ React.ComponentPropsWithoutRef<typeof SelectPrimitive.Item>+>(({ className, children, ...props }, ref) => (+ <SelectPrimitive.Item+ ref={ref}+ className={cn(+ "relative flex w-full cursor-default select-none items-center rounded-sm py-1.5 pl-8 pr-2 text-sm outline-none focus:bg-accent focus:text-accent-foreground data-[disabled]:pointer-events-none data-[disabled]:opacity-50",+ className+ )}+ {...props}+ >+ <span className="absolute left-2 flex h-3.5 w-3.5 items-center justify-center">+ <SelectPrimitive.ItemIndicator>+ <Check className="h-4 w-4" />+ </SelectPrimitive.ItemIndicator>+ </span>++ <SelectPrimitive.ItemText>{children}</SelectPrimitive.ItemText>+ </SelectPrimitive.Item>+))+SelectItem.displayName = SelectPrimitive.Item.displayName++const SelectSeparator = React.forwardRef<+ React.ElementRef<typeof SelectPrimitive.Separator>,+ React.ComponentPropsWithoutRef<typeof SelectPrimitive.Separator>+>(({ className, ...props }, ref) => (+ <SelectPrimitive.Separator+ ref={ref}+ className={cn("-mx-1 my-1 h-px bg-muted", className)}+ {...props}+ />+))+SelectSeparator.displayName = SelectPrimitive.Separator.displayName++export {+ Select,+ SelectGroup,+ SelectValue,+ SelectTrigger,+ SelectContent,+ SelectLabel,+ SelectItem,+ SelectSeparator,+}diff --git a/package-lock.json b/package-lock.jsonindex 5b099e44..5fbe441f 100644--- a/package-lock.json+++ b/package-lock.json@@ -20,6 +20,7 @@"@radix-ui/react-dialog": "^1.0.4","@radix-ui/react-dropdown-menu": "^2.0.5","@radix-ui/react-label": "^2.0.2",+ "@radix-ui/react-select": "^1.2.2","@radix-ui/react-separator": "^1.0.3","@radix-ui/react-slot": "^1.0.2","@radix-ui/react-switch": "^1.0.3",@@ -1391,6 +1392,14 @@"resolved": "https://registry.npmjs.org/@prisma/engines-version/-/engines-version-4.16.1-1.4bc8b6e1b66cb932731fb1bdbbc550d1e010de81.tgz","integrity": "sha512-q617EUWfRIDTriWADZ4YiWRZXCa/WuhNgLTVd+HqWLffjMSPzyM5uOWoauX91wvQClSKZU4pzI4JJLQ9Kl62Qg=="},+ "node_modules/@radix-ui/number": {+ "version": "1.0.1",+ "resolved": "https://registry.npmjs.org/@radix-ui/number/-/number-1.0.1.tgz",+ "integrity": "sha512-T5gIdVO2mmPW3NNhjNgEP3cqMXjXL9UbO0BzWcXfvdBs+BohbQxvd/K5hSVKmn9/lbTdsQVKbUcP5WLCwvUbBg==",+ "dependencies": {+ "@babel/runtime": "^7.13.10"+ }+ },"node_modules/@radix-ui/primitive": {"version": "1.0.1","resolved": "https://registry.npmjs.org/@radix-ui/primitive/-/primitive-1.0.1.tgz",@@ -1945,6 +1954,49 @@}}},+ "node_modules/@radix-ui/react-select": {+ "version": "1.2.2",+ "resolved": "https://registry.npmjs.org/@radix-ui/react-select/-/react-select-1.2.2.tgz",+ "integrity": "sha512-zI7McXr8fNaSrUY9mZe4x/HC0jTLY9fWNhO1oLWYMQGDXuV4UCivIGTxwioSzO0ZCYX9iSLyWmAh/1TOmX3Cnw==",+ "dependencies": {+ "@babel/runtime": "^7.13.10",+ "@radix-ui/number": "1.0.1",+ "@radix-ui/primitive": "1.0.1",+ "@radix-ui/react-collection": "1.0.3",+ "@radix-ui/react-compose-refs": "1.0.1",+ "@radix-ui/react-context": "1.0.1",+ "@radix-ui/react-direction": "1.0.1",+ "@radix-ui/react-dismissable-layer": "1.0.4",+ "@radix-ui/react-focus-guards": "1.0.1",+ "@radix-ui/react-focus-scope": "1.0.3",+ "@radix-ui/react-id": "1.0.1",+ "@radix-ui/react-popper": "1.1.2",+ "@radix-ui/react-portal": "1.0.3",+ "@radix-ui/react-primitive": "1.0.3",+ "@radix-ui/react-slot": "1.0.2",+ "@radix-ui/react-use-callback-ref": "1.0.1",+ "@radix-ui/react-use-controllable-state": "1.0.1",+ "@radix-ui/react-use-layout-effect": "1.0.1",+ "@radix-ui/react-use-previous": "1.0.1",+ "@radix-ui/react-visually-hidden": "1.0.3",+ "aria-hidden": "^1.1.1",+ "react-remove-scroll": "2.5.5"+ },+ "peerDependencies": {+ "@types/react": "*",+ "@types/react-dom": "*",+ "react": "^16.8 || ^17.0 || ^18.0",+ "react-dom": "^16.8 || ^17.0 || ^18.0"+ },+ "peerDependenciesMeta": {+ "@types/react": {+ "optional": true+ },+ "@types/react-dom": {+ "optional": true+ }+ }+ },"node_modules/@radix-ui/react-separator": {"version": "1.0.3","resolved": "https://registry.npmjs.org/@radix-ui/react-separator/-/react-separator-1.0.3.tgz",@@ -2138,6 +2190,29 @@}}},+ "node_modules/@radix-ui/react-visually-hidden": {+ "version": "1.0.3",+ "resolved": "https://registry.npmjs.org/@radix-ui/react-visually-hidden/-/react-visually-hidden-1.0.3.tgz",+ "integrity": "sha512-D4w41yN5YRKtu464TLnByKzMDG/JlMPHtfZgQAu9v6mNakUqGUI9vUrfQKz8NK41VMm/xbZbh76NUTVtIYqOMA==",+ "dependencies": {+ "@babel/runtime": "^7.13.10",+ "@radix-ui/react-primitive": "1.0.3"+ },+ "peerDependencies": {+ "@types/react": "*",+ "@types/react-dom": "*",+ "react": "^16.8 || ^17.0 || ^18.0",+ "react-dom": "^16.8 || ^17.0 || ^18.0"+ },+ "peerDependenciesMeta": {+ "@types/react": {+ "optional": true+ },+ "@types/react-dom": {+ "optional": true+ }+ }+ },"node_modules/@radix-ui/rect": {"version": "1.0.1","resolved": "https://registry.npmjs.org/@radix-ui/rect/-/rect-1.0.1.tgz",@@ -10974,6 +11049,14 @@"resolved": "https://registry.npmjs.org/@prisma/engines-version/-/engines-version-4.16.1-1.4bc8b6e1b66cb932731fb1bdbbc550d1e010de81.tgz","integrity": "sha512-q617EUWfRIDTriWADZ4YiWRZXCa/WuhNgLTVd+HqWLffjMSPzyM5uOWoauX91wvQClSKZU4pzI4JJLQ9Kl62Qg=="},+ "@radix-ui/number": {+ "version": "1.0.1",+ "resolved": "https://registry.npmjs.org/@radix-ui/number/-/number-1.0.1.tgz",+ "integrity": "sha512-T5gIdVO2mmPW3NNhjNgEP3cqMXjXL9UbO0BzWcXfvdBs+BohbQxvd/K5hSVKmn9/lbTdsQVKbUcP5WLCwvUbBg==",+ "requires": {+ "@babel/runtime": "^7.13.10"+ }+ },"@radix-ui/primitive": {"version": "1.0.1","resolved": "https://registry.npmjs.org/@radix-ui/primitive/-/primitive-1.0.1.tgz",@@ -11257,6 +11340,35 @@"@radix-ui/react-use-controllable-state": "1.0.1"}},+ "@radix-ui/react-select": {+ "version": "1.2.2",+ "resolved": "https://registry.npmjs.org/@radix-ui/react-select/-/react-select-1.2.2.tgz",+ "integrity": "sha512-zI7McXr8fNaSrUY9mZe4x/HC0jTLY9fWNhO1oLWYMQGDXuV4UCivIGTxwioSzO0ZCYX9iSLyWmAh/1TOmX3Cnw==",+ "requires": {+ "@babel/runtime": "^7.13.10",+ "@radix-ui/number": "1.0.1",+ "@radix-ui/primitive": "1.0.1",+ "@radix-ui/react-collection": "1.0.3",+ "@radix-ui/react-compose-refs": "1.0.1",+ "@radix-ui/react-context": "1.0.1",+ "@radix-ui/react-direction": "1.0.1",+ "@radix-ui/react-dismissable-layer": "1.0.4",+ "@radix-ui/react-focus-guards": "1.0.1",+ "@radix-ui/react-focus-scope": "1.0.3",+ "@radix-ui/react-id": "1.0.1",+ "@radix-ui/react-popper": "1.1.2",+ "@radix-ui/react-portal": "1.0.3",+ "@radix-ui/react-primitive": "1.0.3",+ "@radix-ui/react-slot": "1.0.2",+ "@radix-ui/react-use-callback-ref": "1.0.1",+ "@radix-ui/react-use-controllable-state": "1.0.1",+ "@radix-ui/react-use-layout-effect": "1.0.1",+ "@radix-ui/react-use-previous": "1.0.1",+ "@radix-ui/react-visually-hidden": "1.0.3",+ "aria-hidden": "^1.1.1",+ "react-remove-scroll": "2.5.5"+ }+ },"@radix-ui/react-separator": {"version": "1.0.3","resolved": "https://registry.npmjs.org/@radix-ui/react-separator/-/react-separator-1.0.3.tgz",@@ -11350,6 +11462,15 @@"@radix-ui/react-use-layout-effect": "1.0.1"}},+ "@radix-ui/react-visually-hidden": {+ "version": "1.0.3",+ "resolved": "https://registry.npmjs.org/@radix-ui/react-visually-hidden/-/react-visually-hidden-1.0.3.tgz",+ "integrity": "sha512-D4w41yN5YRKtu464TLnByKzMDG/JlMPHtfZgQAu9v6mNakUqGUI9vUrfQKz8NK41VMm/xbZbh76NUTVtIYqOMA==",+ "requires": {+ "@babel/runtime": "^7.13.10",+ "@radix-ui/react-primitive": "1.0.3"+ }+ },"@radix-ui/rect": {"version": "1.0.1","resolved": "https://registry.npmjs.org/@radix-ui/rect/-/rect-1.0.1.tgz",diff --git a/package.json b/package.jsonindex 5e7d0703..3b6d6e61 100644--- a/package.json+++ b/package.json@@ -25,6 +25,7 @@"@radix-ui/react-dialog": "^1.0.4","@radix-ui/react-dropdown-menu": "^2.0.5","@radix-ui/react-label": "^2.0.2",+ "@radix-ui/react-select": "^1.2.2","@radix-ui/react-separator": "^1.0.3","@radix-ui/react-slot": "^1.0.2","@radix-ui/react-switch": "^1.0.3",diff --git a/pages/api/links/[id]/index.ts b/pages/api/links/[id]/index.tsindex 99230ec7..f6a7c332 100644--- a/pages/api/links/[id]/index.ts+++ b/pages/api/links/[id]/index.ts@@ -48,12 +48,61 @@ export default async function handle(}const { id } = req.query as { id: string };- const { documentId, password, expiresAt, ...linkData } = req.body;+ const { documentId, password, expiresAt, ...linkDomainData } = req.body;const hashedPassword =password && password.length > 0 ? await hashPassword(password) : null;const exat = expiresAt ? new Date(expiresAt) : null;+ let { domain, slug, ...linkData } = linkDomainData;++ // set domain and slug to null if the domain is papermark.io+ if (domain && domain === "papermark.io") {+ domain = null;+ slug = null;+ }++ let domainObj;++ if (domain && slug) {+ domainObj = await prisma.domain.findUnique({+ where: {+ slug: domain+ }+ })++ if (!domainObj) {+ return res.status(400).json({ error: "Domain not found." });+ }++ const currentLink = await prisma.link.findUnique({+ where: { id: id },+ select: {+ id: true,+ domainSlug: true,+ slug: true,+ },+ });++ // if the slug or domainSlug has changed, check if the new slug is unique+ if (currentLink?.slug !== slug || currentLink?.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.",+ });+ }+ }+ }+// Update the link in the databaseconst updatedLink = await prisma.link.update({where: { id: id },@@ -63,19 +112,22 @@ export default async function handle(name: linkData.name || null,emailProtected: linkData.emailProtected,expiresAt: exat,+ domainId: domainObj?.id || null,+ domainSlug: domain || null,+ slug: slug || null,},include: {views: {orderBy: {viewedAt: "desc",- }+ },},_count: {select: { views: true },},},});-+if (!updatedLink) {return res.status(404).json({ error: "Link not found" });}diff --git a/pages/api/links/index.ts b/pages/api/links/index.tsindex 2c8eb9e0..d32aa2c1 100644--- a/pages/api/links/index.ts+++ b/pages/api/links/index.ts@@ -14,11 +14,52 @@ export default async function handler(return res.status(401).end("Unauthorized");}- const { documentId, password, expiresAt, ...linkData } = req.body;+ const { documentId, password, expiresAt, ...linkDomainData } = req.body;const hashedPassword = password && password.length > 0 ? await hashPassword(password) : nullconst exat = expiresAt ? new Date(expiresAt) : null+ let { domain, slug, ...linkData } = linkDomainData;++ // set domain and slug to null if the domain is papermark.io+ if (domain && domain === "papermark.io") {+ domain = null;+ slug = null;+ }++ let domainObj;++ if (domain && slug) {+ domainObj = await prisma.domain.findUnique({+ where: {+ slug: domain+ }+ })++ if (!domainObj) {+ return res.status(400).json({ error: "Domain not found." });+ }++ console.log(domainObj);++ 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.",+ });+ }+ }+// Fetch the link and its related document from the databaseconst link = await prisma.link.create({data: {@@ -26,7 +67,10 @@ export default async function handler(password: hashedPassword,name: linkData.name || null,emailProtected: linkData.emailProtected,- expiresAt: exat+ expiresAt: exat,+ domainId: domainObj?.id || null,+ domainSlug: domain || null,+ slug: slug || null,},});diff --git a/pages/settings/domains.tsx b/pages/settings/domains.tsxindex 534cc800..55b776d7 100644--- a/pages/settings/domains.tsx+++ b/pages/settings/domains.tsx@@ -1,6 +1,7 @@import { AddDomainModal } from "@/components/domains/add-domain-modal";import DomainCard from "@/components/domains/domain-card";import AppLayout from "@/components/layouts/app";+import { Button } from "@/components/ui/button";import { useDomains } from "@/lib/swr/use-domains";import { mutate } from "swr";@@ -25,19 +26,14 @@ export default function Domains() {<div className="p-4 sm:p-4 sm:m-4"><div className="flex items-center justify-between mb-4 md:mb-8 lg:mb-12"><div className="space-y-1">- <h2 className="text-2xl text-white font-semibold tracking-tight">+ <h2 className="text-2xl text-foreground font-semibold tracking-tight">Domains</h2>- <p className="text-sm text-gray-400">Manage your custom domains</p>+ <p className="text-sm text-muted-foreground">Manage your custom domains</p></div><ul className="flex items-center justify-between gap-4"><AddDomainModal onAddition={handleDomainAddition}>- <button- type="button"- className="inline-flex items-center px-4 py-2 border border-transparent shadow-sm text-sm font-medium rounded-md text-gray-950 bg-gray-300 hover:bg-gray-200 focus:outline-none focus:ring-2 focus:ring-offset-2 focus:ring-gray-500"- >- Add Domain- </button>+ <Button>Add Domain</Button></AddDomainModal></ul></div>diff --git a/pages/settings/index.tsx b/pages/settings/index.tsxnew file mode 100644index 00000000..ebeb4a23--- /dev/null+++ b/pages/settings/index.tsx@@ -0,0 +1,34 @@+import AppLayout from "@/components/layouts/app";++const secondaryNavigation = [+ { name: "Account", href: "#", current: true },+ { name: "Domains", href: "/settings/domains", current: false },+ { name: "Billing", href: "#", current: false },+];++export default function Settings() {+ return (+ <AppLayout>+ <div>+ <header className="border-b border-white/5">+ {/* Secondary navigation */}+ <nav className="flex overflow-x-auto py-4">+ <ul+ role="list"+ className="flex min-w-full flex-none gap-x-6 px-4 text-sm font-semibold leading-6 text-muted-foreground sm:px-6 lg:px-8"+ >+ {secondaryNavigation.map((item) => (+ <li key={item.name}>+ <a href={item.href} className={item.current ? 'text-emerald-500' : ''}>+ {item.name}+ </a>+ </li>+ ))}+ </ul>+ </nav>+ </header>++ </div>+ </AppLayout>+ )+}\ No newline at end of file