Skip to content

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

feat: add brand

Marc Seitz21ce465c8252
diff --git a/components/settings/navbar.tsx b/components/settings/navbar.tsx
index 7b95232c..2069d04f 100644
--- a/components/settings/navbar.tsx
+++ b/components/settings/navbar.tsx
@@ -5,6 +5,7 @@ const tabs = [
{ name: "General", href: "/settings/general" },
{ name: "People", href: "/settings/people" },
{ name: "Domains", href: "/settings/domains" },
+ { name: "Branding", href: "/settings/branding" },
{ name: "Billing", href: "/settings/billing" },
];
diff --git a/components/ui/popover.tsx b/components/ui/popover.tsx
new file mode 100644
index 00000000..bbba7e0e
--- /dev/null
+++ b/components/ui/popover.tsx
@@ -0,0 +1,29 @@
+import * as React from "react"
+import * as PopoverPrimitive from "@radix-ui/react-popover"
+
+import { cn } from "@/lib/utils"
+
+const Popover = PopoverPrimitive.Root
+
+const PopoverTrigger = PopoverPrimitive.Trigger
+
+const PopoverContent = React.forwardRef<
+ React.ElementRef<typeof PopoverPrimitive.Content>,
+ React.ComponentPropsWithoutRef<typeof PopoverPrimitive.Content>
+>(({ className, align = "center", sideOffset = 4, ...props }, ref) => (
+ <PopoverPrimitive.Portal>
+ <PopoverPrimitive.Content
+ ref={ref}
+ align={align}
+ sideOffset={sideOffset}
+ className={cn(
+ "z-50 w-72 rounded-md border bg-popover p-4 text-popover-foreground shadow-md outline-none 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",
+ className
+ )}
+ {...props}
+ />
+ </PopoverPrimitive.Portal>
+))
+PopoverContent.displayName = PopoverPrimitive.Content.displayName
+
+export { Popover, PopoverTrigger, PopoverContent }
diff --git a/components/ui/scroll-area.tsx b/components/ui/scroll-area.tsx
new file mode 100644
index 00000000..cf253cf1
--- /dev/null
+++ b/components/ui/scroll-area.tsx
@@ -0,0 +1,46 @@
+import * as React from "react"
+import * as ScrollAreaPrimitive from "@radix-ui/react-scroll-area"
+
+import { cn } from "@/lib/utils"
+
+const ScrollArea = React.forwardRef<
+ React.ElementRef<typeof ScrollAreaPrimitive.Root>,
+ React.ComponentPropsWithoutRef<typeof ScrollAreaPrimitive.Root>
+>(({ className, children, ...props }, ref) => (
+ <ScrollAreaPrimitive.Root
+ ref={ref}
+ className={cn("relative overflow-hidden", className)}
+ {...props}
+ >
+ <ScrollAreaPrimitive.Viewport className="h-full w-full rounded-[inherit]">
+ {children}
+ </ScrollAreaPrimitive.Viewport>
+ <ScrollBar />
+ <ScrollAreaPrimitive.Corner />
+ </ScrollAreaPrimitive.Root>
+))
+ScrollArea.displayName = ScrollAreaPrimitive.Root.displayName
+
+const ScrollBar = React.forwardRef<
+ React.ElementRef<typeof ScrollAreaPrimitive.ScrollAreaScrollbar>,
+ React.ComponentPropsWithoutRef<typeof ScrollAreaPrimitive.ScrollAreaScrollbar>
+>(({ className, orientation = "vertical", ...props }, ref) => (
+ <ScrollAreaPrimitive.ScrollAreaScrollbar
+ ref={ref}
+ orientation={orientation}
+ className={cn(
+ "flex touch-none select-none transition-colors",
+ orientation === "vertical" &&
+ "h-full w-2.5 border-l border-l-transparent p-[1px]",
+ orientation === "horizontal" &&
+ "h-2.5 flex-col border-t border-t-transparent p-[1px]",
+ className
+ )}
+ {...props}
+ >
+ <ScrollAreaPrimitive.ScrollAreaThumb className="relative flex-1 rounded-full bg-border" />
+ </ScrollAreaPrimitive.ScrollAreaScrollbar>
+))
+ScrollBar.displayName = ScrollAreaPrimitive.ScrollAreaScrollbar.displayName
+
+export { ScrollArea, ScrollBar }
diff --git a/components/view/PagesViewer.tsx b/components/view/PagesViewer.tsx
index 6894e1a3..01ff69ac 100644
--- a/components/view/PagesViewer.tsx
+++ b/components/view/PagesViewer.tsx
@@ -5,6 +5,7 @@ import LoadingSpinner from "../ui/loading-spinner";
import BlankImg from "@/public/_static/blank.gif";
import Nav from "./nav";
import Toolbar from "./toolbar";
+import { Brand } from "@prisma/client";
const DEFAULT_PRELOADED_IMAGES_NUM = 10;
@@ -16,6 +17,7 @@ export default function PagesViewer({
assistantEnabled,
feedbackEnabled,
versionNumber,
+ brand,
}: {
pages: { file: string; pageNumber: string }[];
linkId: string;
@@ -24,6 +26,7 @@ export default function PagesViewer({
assistantEnabled: boolean;
feedbackEnabled: boolean;
versionNumber: number;
+ brand?: Brand;
}) {
const numPages = pages.length;
const [pageNumber, setPageNumber] = useState<number>(1); // start on first page
@@ -145,6 +148,7 @@ export default function PagesViewer({
pageNumber={pageNumber}
numPages={numPages}
assistantEnabled={assistantEnabled}
+ brand={brand}
/>
<div
style={{ height: "calc(100vh - 64px)" }}
diff --git a/components/view/document-view.tsx b/components/view/document-view.tsx
index 64687f3c..09130403 100644
--- a/components/view/document-view.tsx
+++ b/components/view/document-view.tsx
@@ -11,6 +11,7 @@ import PagesViewer from "@/components/view/PagesViewer";
import PDFViewer from "@/components/view/PDFViewer";
import { NotionPage } from "../NotionPage";
import { ExtendedRecordMap } from "notion-types";
+import { Brand } from "@prisma/client";
export type DEFAULT_DOCUMENT_VIEW_TYPE = {
viewId: string;
@@ -24,6 +25,7 @@ export default function DocumentView({
userId,
isProtected,
notionData,
+ brand,
}: {
link: LinkWithDocument;
userEmail: string | null | undefined;
@@ -33,6 +35,7 @@ export default function DocumentView({
rootNotionPageId: string | null;
recordMap: ExtendedRecordMap | null;
};
+ brand?: Brand;
}) {
const { document, emailProtected, password: linkPassword } = link;
@@ -145,6 +148,7 @@ export default function DocumentView({
assistantEnabled={document.assistantEnabled}
feedbackEnabled={link.enableFeedback!}
versionNumber={document.versions[0].versionNumber}
+ brand={brand}
/>
) : (
<PDFViewer
diff --git a/components/view/nav.tsx b/components/view/nav.tsx
index 4af894d7..13f6d152 100644
--- a/components/view/nav.tsx
+++ b/components/view/nav.tsx
@@ -3,6 +3,7 @@ import { useRouter } from "next/router";
import { Button } from "../ui/button";
import PapermarkSparkle from "../shared/icons/papermark-sparkle";
import { Download } from "lucide-react";
+import { Brand } from "@prisma/client";
export default function Nav({
pageNumber,
@@ -10,12 +11,14 @@ export default function Nav({
allowDownload,
assistantEnabled,
file,
+ brand,
}: {
pageNumber: number;
numPages: number;
allowDownload?: boolean;
assistantEnabled?: boolean;
file?: { name: string; url: string };
+ brand?: Brand;
}) {
const router = useRouter();
const { linkId } = router.query as { linkId: string };
@@ -42,15 +45,26 @@ export default function Nav({
}
}
+ console.log("brand ", brand);
+
return (
- <nav className="bg-black">
+ <nav
+ className="bg-black"
+ style={{
+ backgroundColor: brand && brand.brandColor ? brand.brandColor : "black",
+ }}
+ >
<div className="mx-auto px-2 sm:px-6 lg:px-8">
<div className="relative flex h-16 items-center justify-between">
<div className="flex flex-1 items-stretch justify-start">
<div className="flex flex-shrink-0 items-center">
- <p className="text-2xl font-bold tracking-tighter text-white">
- Papermark
- </p>
+ {brand && brand.logo ? (
+ <img className="block h-8 w-auto" src={brand.logo} alt="Logo" />
+ ) : (
+ <p className="text-2xl font-bold tracking-tighter text-white">
+ Papermark
+ </p>
+ )}
</div>
</div>
<div className="absolute inset-y-0 right-0 flex items-center pr-2 sm:static sm:inset-auto sm:ml-6 sm:pr-0 space-x-2">
diff --git a/lib/swr/use-brand.ts b/lib/swr/use-brand.ts
new file mode 100644
index 00000000..7e305218
--- /dev/null
+++ b/lib/swr/use-brand.ts
@@ -0,0 +1,24 @@
+import { useRouter } from "next/router";
+import useSWR from "swr";
+import { fetcher } from "@/lib/utils";
+import { useMemo } from "react";
+import { useTeam } from "@/context/team-context";
+import { Brand } from "@prisma/client";
+
+export function useBrand() {
+ const teamInfo = useTeam();
+
+ const { data: brand, error } = useSWR<Brand>(
+ `/api/teams/${teamInfo?.currentTeam?.id}/branding`,
+ fetcher,
+ {
+ dedupingInterval: 30000,
+ },
+ );
+
+ return {
+ brand,
+ error,
+ loading: !brand && !error,
+ };
+}
diff --git a/package-lock.json b/package-lock.json
index 6655a26e..bb811f4f 100644
--- a/package-lock.json
+++ b/package-lock.json
@@ -22,7 +22,9 @@
"@radix-ui/react-dialog": "^1.0.5",
"@radix-ui/react-dropdown-menu": "^2.0.6",
"@radix-ui/react-label": "^2.0.2",
+ "@radix-ui/react-popover": "^1.0.7",
"@radix-ui/react-progress": "^1.0.3",
+ "@radix-ui/react-scroll-area": "^1.0.5",
"@radix-ui/react-select": "^2.0.0",
"@radix-ui/react-separator": "^1.0.3",
"@radix-ui/react-slot": "^1.0.2",
@@ -72,6 +74,7 @@
"openai": "^4.20.0",
"postcss": "^8.4.32",
"react": "^18.2.0",
+ "react-colorful": "^5.6.1",
"react-dom": "^18.2.0",
"react-draggable": "^4.4.6",
"react-dropzone": "^14.2.3",
@@ -1729,6 +1732,43 @@
}
}
},
+ "node_modules/@radix-ui/react-popover": {
+ "version": "1.0.7",
+ "resolved": "https://registry.npmjs.org/@radix-ui/react-popover/-/react-popover-1.0.7.tgz",
+ "integrity": "sha512-shtvVnlsxT6faMnK/a7n0wptwBD23xc1Z5mdrtKLwVEfsEMXodS0r5s0/g5P0hX//EKYZS2sxUjqfzlg52ZSnQ==",
+ "dependencies": {
+ "@babel/runtime": "^7.13.10",
+ "@radix-ui/primitive": "1.0.1",
+ "@radix-ui/react-compose-refs": "1.0.1",
+ "@radix-ui/react-context": "1.0.1",
+ "@radix-ui/react-dismissable-layer": "1.0.5",
+ "@radix-ui/react-focus-guards": "1.0.1",
+ "@radix-ui/react-focus-scope": "1.0.4",
+ "@radix-ui/react-id": "1.0.1",
+ "@radix-ui/react-popper": "1.1.3",
+ "@radix-ui/react-portal": "1.0.4",
+ "@radix-ui/react-presence": "1.0.1",
+ "@radix-ui/react-primitive": "1.0.3",
+ "@radix-ui/react-slot": "1.0.2",
+ "@radix-ui/react-use-controllable-state": "1.0.1",
+ "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-popper": {
"version": "1.1.3",
"resolved": "https://registry.npmjs.org/@radix-ui/react-popper/-/react-popper-1.1.3.tgz",
@@ -1898,6 +1938,37 @@
}
}
},
+ "node_modules/@radix-ui/react-scroll-area": {
+ "version": "1.0.5",
+ "resolved": "https://registry.npmjs.org/@radix-ui/react-scroll-area/-/react-scroll-area-1.0.5.tgz",
+ "integrity": "sha512-b6PAgH4GQf9QEn8zbT2XUHpW5z8BzqEc7Kl11TwDrvuTrxlkcjTD5qa/bxgKr+nmuXKu4L/W5UZ4mlP/VG/5Gw==",
+ "dependencies": {
+ "@babel/runtime": "^7.13.10",
+ "@radix-ui/number": "1.0.1",
+ "@radix-ui/primitive": "1.0.1",
+ "@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-presence": "1.0.1",
+ "@radix-ui/react-primitive": "1.0.3",
+ "@radix-ui/react-use-callback-ref": "1.0.1",
+ "@radix-ui/react-use-layout-effect": "1.0.1"
+ },
+ "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-select": {
"version": "2.0.0",
"resolved": "https://registry.npmjs.org/@radix-ui/react-select/-/react-select-2.0.0.tgz",
@@ -9600,6 +9671,15 @@
"node": ">=0.10.0"
}
},
+ "node_modules/react-colorful": {
+ "version": "5.6.1",
+ "resolved": "https://registry.npmjs.org/react-colorful/-/react-colorful-5.6.1.tgz",
+ "integrity": "sha512-1exovf0uGTGyq5mXQT0zgQ80uvj2PCwvF8zY1RN9/vbJVSjSo3fsB/4L3ObbF7u70NduSiK4xu4Y6q1MHoUGEw==",
+ "peerDependencies": {
+ "react": ">=16.8.0",
+ "react-dom": ">=16.8.0"
+ }
+ },
"node_modules/react-day-picker": {
"version": "8.8.0",
"resolved": "https://registry.npmjs.org/react-day-picker/-/react-day-picker-8.8.0.tgz",
diff --git a/package.json b/package.json
index a4faa196..dfc28384 100644
--- a/package.json
+++ b/package.json
@@ -29,7 +29,9 @@
"@radix-ui/react-dialog": "^1.0.5",
"@radix-ui/react-dropdown-menu": "^2.0.6",
"@radix-ui/react-label": "^2.0.2",
+ "@radix-ui/react-popover": "^1.0.7",
"@radix-ui/react-progress": "^1.0.3",
+ "@radix-ui/react-scroll-area": "^1.0.5",
"@radix-ui/react-select": "^2.0.0",
"@radix-ui/react-separator": "^1.0.3",
"@radix-ui/react-slot": "^1.0.2",
@@ -79,6 +81,7 @@
"openai": "^4.20.0",
"postcss": "^8.4.32",
"react": "^18.2.0",
+ "react-colorful": "^5.6.1",
"react-dom": "^18.2.0",
"react-draggable": "^4.4.6",
"react-dropzone": "^14.2.3",
diff --git a/pages/api/file/logo-upload.ts b/pages/api/file/logo-upload.ts
new file mode 100644
index 00000000..a7fc7582
--- /dev/null
+++ b/pages/api/file/logo-upload.ts
@@ -0,0 +1,57 @@
+import { handleUpload, type HandleUploadBody } from "@vercel/blob/client";
+import type { NextApiResponse, NextApiRequest } from "next";
+import { getServerSession } from "next-auth/next";
+import { authOptions } from "../auth/[...nextauth]";
+import { CustomUser } from "@/lib/types";
+
+export default async function handler(
+ req: NextApiRequest,
+ res: NextApiResponse,
+) {
+ const body = req.body as HandleUploadBody;
+
+ try {
+ const jsonResponse = await handleUpload({
+ body,
+ request: req,
+ onBeforeGenerateToken: async (pathname: string) => {
+ // Generate a client token for the browser to upload the file
+
+ const session = await getServerSession(req, res, authOptions);
+ if (!session) {
+ res.status(401).end("Unauthorized");
+ throw new Error("Unauthorized");
+ }
+
+ return {
+ allowedContentTypes: ["image/png", "image/jpeg"],
+ maximumSizeInBytes: 5 * 1024 * 1024, // 5 MB
+ metadata: JSON.stringify({
+ // optional, sent to your server on upload completion
+ userId: (session.user as CustomUser).id,
+ }),
+ };
+ },
+ onUploadCompleted: async ({ blob, tokenPayload }) => {
+ // Get notified of browser upload completion
+ // ⚠️ This will not work on `localhost` websites,
+ // Use ngrok or similar to get the full upload flow
+
+ console.log("blob upload completed", blob, tokenPayload);
+
+ try {
+ // Run any logic after the file upload completed
+ // const { userId } = JSON.parse(tokenPayload);
+ // await db.update({ avatar: blob.url, userId });
+ } catch (error) {
+ // throw new Error("Could not update user");
+ }
+ },
+ });
+
+ return res.status(200).json(jsonResponse);
+ } catch (error) {
+ // The webhook will retry 5 times waiting for a 200
+ return res.status(400).json({ error: (error as Error).message });
+ }
+}
diff --git a/pages/api/links/[id]/index.ts b/pages/api/links/[id]/index.ts
index 5362128b..5f0d626d 100644
--- a/pages/api/links/[id]/index.ts
+++ b/pages/api/links/[id]/index.ts
@@ -31,6 +31,7 @@ export default async function handle(
select: {
id: true,
assistantEnabled: true,
+ teamId: true,
versions: {
where: { isPrimary: true },
select: {
@@ -53,7 +54,21 @@ export default async function handle(
return res.status(404).json({ error: "Link not found" });
}
- return res.status(200).json(link);
+ let brand = await prisma.brand.findFirst({
+ where: {
+ teamId: link.document.teamId!,
+ },
+ select: {
+ logo: true,
+ brandColor: true,
+ },
+ });
+
+ if (!brand) {
+ brand = null;
+ }
+
+ return res.status(200).json({ link, brand });
} catch (error) {
return res.status(500).json({
message: "Internal Server Error",
diff --git a/pages/api/teams/[teamId]/branding.ts b/pages/api/teams/[teamId]/branding.ts
new file mode 100644
index 00000000..57500e2e
--- /dev/null
+++ b/pages/api/teams/[teamId]/branding.ts
@@ -0,0 +1,113 @@
+import { NextApiRequest, NextApiResponse } from "next";
+import { getServerSession } from "next-auth";
+import prisma from "@/lib/prisma";
+import { CustomUser } from "@/lib/types";
+import { authOptions } from "../../auth/[...nextauth]";
+import { errorhandler } from "@/lib/errorHandler";
+import { PutBlobResult, put } from "@vercel/blob";
+import { Brand } from "@prisma/client";
+
+export default async function handle(
+ req: NextApiRequest,
+ res: NextApiResponse,
+) {
+ const session = await getServerSession(req, res, authOptions);
+ if (!session) {
+ return res.status(401).end("Unauthorized");
+ }
+
+ const { teamId } = req.query as { teamId: string };
+
+ try {
+ const team = await prisma.team.findUnique({
+ where: {
+ id: teamId,
+ },
+ select: {
+ id: true,
+ users: { select: { userId: true } },
+ },
+ });
+
+ // check that the user is member of the team, otherwise return 403
+ const teamUsers = team?.users;
+ const isUserPartOfTeam = teamUsers?.some(
+ (user) => user.userId === (session.user as CustomUser).id,
+ );
+ if (!isUserPartOfTeam) {
+ return res.status(403).end("Unauthorized to access this team");
+ }
+ } catch (error) {
+ errorhandler(error, res);
+ }
+
+ if (req.method === "GET") {
+ // GET /api/teams/:teamId/branding
+ const brand = await prisma.brand.findUnique({
+ where: {
+ teamId: teamId,
+ },
+ });
+
+ if (!brand) {
+ res.status(404).end("Brand not found");
+ }
+
+ return res.status(200).json(brand);
+ } else if (req.method === "POST") {
+ // POST /api/teams/:teamId/branding
+ const { logo, brandColor, accentColor, isNewLogo } = req.body as {
+ logo?: string;
+ brandColor?: string;
+ accentColor?: string;
+ isNewLogo: boolean;
+ };
+
+ let blob: PutBlobResult | null = null;
+
+ if (isNewLogo && logo) {
+ const logoString = Buffer.from(logo, "base64").toString("utf-8");
+
+ // upload logo to blob storage
+ blob = await put("Logo", logoString, { access: "public" });
+ console.log(blob);
+ }
+
+ // update team with new branding
+ const brand = await prisma.brand.create({
+ data: {
+ logo: blob ? blob.url : null,
+ brandColor,
+ accentColor,
+ teamId: teamId,
+ },
+ });
+
+ return res.status(200).json(brand);
+ } else if (req.method === "PUT") {
+ // POST /api/teams/:teamId/branding
+ const { logo, brandColor, accentColor, isNewLogo } = req.body as {
+ logo?: string;
+ brandColor?: string;
+ accentColor?: string;
+ isNewLogo: boolean;
+ };
+
+ const brand = await prisma.brand.update({
+ where: {
+ teamId: teamId,
+ },
+ data: {
+ logo,
+ brandColor,
+ accentColor,
+ },
+ });
+
+ return res.status(200).json(brand);
+ } else {
+ // We only allow GET and DELETE requests
+ res.setHeader("Allow", ["GET", "DELETE"]);
+ return res.status(405).end(`Method ${req.method} Not Allowed`);
+ }
+}
diff --git a/pages/settings/branding.tsx b/pages/settings/branding.tsx
new file mode 100644
index 00000000..6d4fb780
--- /dev/null
+++ b/pages/settings/branding.tsx
@@ -0,0 +1,274 @@
+import { AddDomainModal } from "@/components/domains/add-domain-modal";
+import DomainCard from "@/components/domains/domain-card";
+import AppLayout from "@/components/layouts/app";
+import Navbar from "@/components/settings/navbar";
+import { Button } from "@/components/ui/button";
+import {
+ Card,
+ CardContent,
+ CardDescription,
+ CardFooter,
+ CardHeader,
+ CardTitle,
+} from "@/components/ui/card";
+import {
+ Popover,
+ PopoverContent,
+ PopoverTrigger,
+} from "@/components/ui/popover";
+import { Input } from "@/components/ui/input";
+import { Label } from "@/components/ui/label";
+import { useTeam } from "@/context/team-context";
+import { useCallback, useEffect, useState } from "react";
+import { mutate } from "swr";
+import { HexColorInput, HexColorPicker } from "react-colorful";
+import LoadingSpinner from "@/components/ui/loading-spinner";
+import { PlusIcon } from "lucide-react";
+import { useBrand } from "@/lib/swr/use-brand";
+import { upload } from "@vercel/blob/client";
+import { set } from "date-fns";
+import { toast } from "sonner";
+
+export default function Branding() {
+ const { brand } = useBrand();
+ const teamInfo = useTeam();
+
+ const [brandColor, setBrandColor] = useState<string>("#000000");
+ const [logo, setLogo] = useState<string | null>(null);
+ const [logoFile, setLogoFile] = useState<File | null>(null); // [TODO
+
+ const [isLoading, setIsLoading] = useState<boolean>(false);
+ const [fileError, setFileError] = useState<string | null>(null);
+ const [dragActive, setDragActive] = useState(false);
+
+ const onChangeLogo = useCallback(
+ (e: any) => {
+ setFileError(null);
+ const file = e.target.files[0];
+ if (file) {
+ if (file.size / 1024 / 1024 > 5) {
+ setFileError("File size too big (max 5MB)");
+ } else if (file.type !== "image/png" && file.type !== "image/jpeg") {
+ setFileError("File type not supported (.png or .jpg only)");
+ } else {
+ const reader = new FileReader();
+ reader.onload = (e) => {
+ setLogo(e.target?.result as string);
+ };
+ reader.readAsDataURL(file);
+ setLogoFile(file);
+ }
+ }
+ },
+ [setLogo],
+ );
+
+ useEffect(() => {
+ if (brand) {
+ setBrandColor(brand.brandColor || "#000000");
+ setLogo(brand.logo || null);
+ }
+ }, [brand]);
+
+ const uploadImage = async (file: File) => {
+ const newBlob = await upload(file.name, file, {
+ access: "public",
+ handleUploadUrl: "/api/file/logo-upload",
+ });
+
+ return newBlob.url;
+ };
+
+ const saveBranding = async (e: any) => {
+ e.preventDefault();
+
+ setIsLoading(true);
+
+ let newLogo: string | null = logo;
+ if (logoFile) {
+ newLogo = await uploadImage(logoFile);
+ }
+
+ const data = {
+ brandColor: brandColor,
+ logo: newLogo,
+ isNewLogo: newLogo !== brand?.logo,
+ };
+
+ const res = await fetch(
+ `/api/teams/${teamInfo?.currentTeam?.id}/branding`,
+ {
+ method: brand ? "PUT" : "POST",
+ body: JSON.stringify(data),
+ headers: {
+ "Content-Type": "application/json",
+ },
+ },
+ );
+ if (res.ok) {
+ mutate("/api/teams");
+ setIsLoading(false);
+ toast.success("Branding updated successfully");
+ }
+ };
+
+ return (
+ <AppLayout>
+ <Navbar current="Branding" />
+ <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">
+ <h3 className="text-2xl text-foreground font-semibold tracking-tight">
+ Branding
+ </h3>
+ <p className="text-sm text-muted-foreground">
+ Customize how your brand appears globally across Papermark
+ documents your visitors see.
+ </p>
+ </div>
+ </div>
+ <div>
+ <Card className="dark:bg-secondary">
+ <CardContent className="pt-6">
+ <div className="grid gap-6">
+ <div className="flex flex-col gap-2">
+ <div className="flex items-center justify-between">
+ <Label htmlFor="logo">
+ Logo{" "}
+ <span className="italic text-muted-foreground text-sm">
+ (max 2 MB)
+ </span>
+ </Label>
+ {fileError ? (
+ <p className="text-sm text-red-500">{fileError}</p>
+ ) : null}
+ </div>
+ <label
+ htmlFor="image"
+ className="group relative mt-1 flex h-[4rem] w-[12rem] cursor-pointer flex-col items-center justify-center rounded-md border border-gray-300 bg-white shadow-sm transition-all hover:bg-gray-50"
+ >
+ {false && (
+ <div className="absolute z-[5] flex h-full w-full items-center justify-center rounded-md bg-white">
+ <LoadingSpinner />
+ </div>
+ )}
+ <div
+ className="absolute z-[5] h-full w-full rounded-md"
+ onDragOver={(e) => {
+ e.preventDefault();
+ e.stopPropagation();
+ setDragActive(true);
+ }}
+ onDragEnter={(e) => {
+ e.preventDefault();
+ e.stopPropagation();
+ setDragActive(true);
+ }}
+ onDragLeave={(e) => {
+ e.preventDefault();
+ e.stopPropagation();
+ setDragActive(false);
+ }}
+ onDrop={(e) => {
+ e.preventDefault();
+ e.stopPropagation();
+ setDragActive(false);
+ setFileError(null);
+ const file =
+ e.dataTransfer.files && e.dataTransfer.files[0];
+ if (file) {
+ if (file.size / 1024 / 1024 > 2) {
+ setFileError("File size too big (max 2MB)");
+ } else if (
+ file.type !== "image/png" &&
+ file.type !== "image/jpeg"
+ ) {
+ setFileError(
+ "File type not supported (.png or .jpg only)",
+ );
+ } else {
+ const reader = new FileReader();
+ reader.onload = (e) => {
+ setLogo(e.target?.result as string);
+ setLogoFile(file);
+ };
+ reader.readAsDataURL(file);
+ }
+ }
+ }}
+ />
+ <div
+ className={`${
+ dragActive
+ ? "cursor-copy border-2 border-black bg-gray-50 opacity-100"
+ : ""
+ } absolute z-[3] flex h-full w-full flex-col items-center justify-center rounded-md bg-white transition-all ${
+ logo
+ ? "opacity-0 group-hover:opacity-100"
+ : "group-hover:bg-gray-50"
+ }`}
+ >
+ <PlusIcon
+ className={`${
+ dragActive ? "scale-110" : "scale-100"
+ } h-7 w-7 text-gray-500 transition-all duration-75 group-hover:scale-110 group-active:scale-95`}
+ />
+ <span className="sr-only">OG image upload</span>
+ </div>
+ {logo && (
+ <img
+ src={logo}
+ alt="Preview"
+ className="h-full w-full rounded-md object-contain"
+ />
+ )}
+ </label>
+ <div className="mt-1 flex rounded-md shadow-sm">
+ <input
+ id="image"
+ name="image"
+ type="file"
+ accept="image/*"
+ className="sr-only"
+ onChange={onChangeLogo}
+ />
+ </div>
+ </div>
+ <div className="flex flex-col gap-2">
+ <Label htmlFor="primary-color">Brand Color</Label>
+ <div className="flex space-x-1">
+ <Popover>
+ <PopoverTrigger>
+ <div
+ className="w-9 h-9 rounded-md cursor-pointer ring-1 ring-muted-foreground shadow-sm hover:ring-1 hover:ring-gray-300"
+ style={{ backgroundColor: brandColor }}
+ />
+ </PopoverTrigger>
+ <PopoverContent>
+ <HexColorPicker
+ color={brandColor}
+ onChange={setBrandColor}
+ />
+ </PopoverContent>
+ </Popover>
+ <HexColorInput
+ className="flex h-9 w-full rounded-md border-0 bg-background px-3 py-2 text-sm ring-1 ring-muted-foreground shadow-sm placeholder:text-muted-foreground focus:ring-1 focus:ring-gray-300 focus:border-0"
+ color={brandColor}
+ onChange={setBrandColor}
+ prefixed
+ />
+ </div>
+ </div>
+ </div>
+ </CardContent>
+ <CardFooter className="border-t p-6">
+ <Button onClick={saveBranding} loading={isLoading}>
+ Save changes
+ </Button>
+ </CardFooter>
+ </Card>
+ </div>
+ </div>
+ </AppLayout>
+ );
+}
diff --git a/pages/view/[linkId]/index.tsx b/pages/view/[linkId]/index.tsx
index 6b57f90f..b2f3b1cd 100644
--- a/pages/view/[linkId]/index.tsx
+++ b/pages/view/[linkId]/index.tsx
@@ -9,6 +9,7 @@ import { CustomUser, LinkWithDocument } from "@/lib/types";
import { parsePageId } from "notion-utils";
import { GetStaticPropsContext } from "next";
import { useRouter } from "next/router";
+import { Brand } from "@prisma/client";
export const getStaticProps = async (context: GetStaticPropsContext) => {
const { linkId } = context.params as { linkId: string };
@@ -18,7 +19,10 @@ export const getStaticProps = async (context: GetStaticPropsContext) => {
if (!res.ok) {
return { notFound: true };
}
- const link = (await res.json()) as LinkWithDocument;
+ const { link, brand } = (await res.json()) as {
+ link: LinkWithDocument;
+ brand: Brand | null;
+ };
if (!link || !link.document) {
return {
@@ -58,6 +62,7 @@ export const getStaticProps = async (context: GetStaticPropsContext) => {
rootNotionPageId: null, // do not pass rootNotionPageId to the client
recordMap,
},
+ brand, // pass brand to the client
},
};
};
@@ -72,12 +77,14 @@ export async function getStaticPaths() {
export default function ViewPage({
link,
notionData,
+ brand,
}: {
link: LinkWithDocument;
notionData: {
rootNotionPageId: string | null;
recordMap: ExtendedRecordMap | null;
};
+ brand?: Brand;
}) {
const router = useRouter();
const { data: session, status } = useSession();
@@ -120,6 +127,7 @@ export default function ViewPage({
userId={userId}
isProtected={true}
notionData={notionData}
+ brand={brand}
/>
);
}
@@ -131,6 +139,7 @@ export default function ViewPage({
userId={userId}
isProtected={false}
notionData={notionData}
+ brand={brand}
/>
);
}
diff --git a/prisma/schema.prisma b/prisma/schema.prisma
index 3963e30d..5a082c7a 100644
--- a/prisma/schema.prisma
+++ b/prisma/schema.prisma
@@ -65,6 +65,7 @@ model Team {
domains Domain[]
invitations Invitation[]
sentEmails SentEmail[]
+ brand Brand?
plan String @default("free")
stripeId String? @unique // Stripe subscription / customer ID
subscriptionId String? @unique // Stripe subscription ID
@@ -74,6 +75,18 @@ model Team {
updatedAt DateTime @updatedAt
}
+model Brand {
+ id String @id @default(cuid())
+ logo String? // This should be a reference to where the file is stored (S3, Google Cloud Storage, etc.)
+ brandColor String? // This should be a reference to the brand color
+ accentColor String? // This should be a reference to the accent color
+ teamId String @unique
+ team Team @relation(fields: [teamId], references: [id], onDelete: Cascade)
+
+ createdAt DateTime @default(now())
+ updatedAt DateTime @updatedAt
+}
+
enum Role {
ADMIN
MEMBER