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 Seitz8f4993bcb98f
diff --git a/components/view/nav.tsx b/components/view/nav.tsx
index 13f6d152..80c5a747 100644
--- a/components/view/nav.tsx
+++ b/components/view/nav.tsx
@@ -4,6 +4,7 @@ import { Button } from "../ui/button";
import PapermarkSparkle from "../shared/icons/papermark-sparkle";
import { Download } from "lucide-react";
import { Brand } from "@prisma/client";
+import Image from "next/image";
export default function Nav({
pageNumber,
@@ -45,8 +46,6 @@ export default function Nav({
}
}
- console.log("brand ", brand);
-
return (
<nav
className="bg-black"
@@ -57,9 +56,16 @@ export default function Nav({
<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">
+ <div className="flex flex-shrink-0 items-center relative h-8 w-36">
{brand && brand.logo ? (
- <img className="block h-8 w-auto" src={brand.logo} alt="Logo" />
+ <Image
+ className="object-contain"
+ src={brand.logo}
+ alt="Logo"
+ fill
+ quality={100}
+ priority
+ />
) : (
<p className="text-2xl font-bold tracking-tighter text-white">
Papermark
diff --git a/pages/api/revalidate.ts b/pages/api/revalidate.ts
index 751a51e9..79390052 100644
--- a/pages/api/revalidate.ts
+++ b/pages/api/revalidate.ts
@@ -1,5 +1,6 @@
import { NextApiRequest, NextApiResponse } from "next";
import prisma from "@/lib/prisma";
+import { P } from "@upstash/redis/zmscore-b6b93f14";
export default async function handler(
req: NextApiRequest,
@@ -14,9 +15,10 @@ export default async function handler(
return res.status(401).json({ message: "Invalid token" });
}
- const { linkId, documentId } = req.query as {
+ const { linkId, documentId, teamId } = req.query as {
linkId: string;
documentId: string;
+ teamId: string;
};
try {
@@ -39,6 +41,33 @@ export default async function handler(
}
}
+ if (teamId) {
+ // revalidate all links for this team
+ const documentLinks = await prisma.document.findMany({
+ where: {
+ teamId: teamId,
+ },
+ select: {
+ links: {
+ where: { isArchived: false },
+ select: {
+ id: true,
+ },
+ },
+ },
+ });
+
+ // Flatten the array of arrays into a single array
+ const flattenedLinkIds = documentLinks.flatMap(
+ (document) => document.links,
+ );
+
+ // Now linkIds is an array of only link IDs
+ for (const link of flattenedLinkIds) {
+ await res.revalidate(`/view/${link.id}`);
+ }
+ }
+
return res.json({ revalidated: true });
} catch (err) {
// If there was an error, Next.js will continue
diff --git a/pages/api/teams/[teamId]/branding.ts b/pages/api/teams/[teamId]/branding.ts
index 57500e2e..84f4a428 100644
--- a/pages/api/teams/[teamId]/branding.ts
+++ b/pages/api/teams/[teamId]/branding.ts
@@ -4,8 +4,6 @@ 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,
@@ -56,41 +54,33 @@ export default async function handle(
return res.status(200).json(brand);
} else if (req.method === "POST") {
// POST /api/teams/:teamId/branding
- const { logo, brandColor, accentColor, isNewLogo } = req.body as {
+ const { logo, brandColor, accentColor } = 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,
+ logo: logo,
brandColor,
accentColor,
teamId: teamId,
},
});
+ await fetch(
+ `${process.env.NEXTAUTH_URL}/api/revalidate?secret=${process.env.REVALIDATE_TOKEN}&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 {
+ const { logo, brandColor, accentColor } = req.body as {
logo?: string;
brandColor?: string;
accentColor?: string;
- isNewLogo: boolean;
};
const brand = await prisma.brand.update({
@@ -104,10 +94,14 @@ export default async function handle(
},
});
+ await fetch(
+ `${process.env.NEXTAUTH_URL}/api/revalidate?secret=${process.env.REVALIDATE_TOKEN}&teamId=${teamId}`,
+ );
+
return res.status(200).json(brand);
} else {
// We only allow GET and DELETE requests
- res.setHeader("Allow", ["GET", "DELETE"]);
+ res.setHeader("Allow", ["GET", "POST", "PUT"]);
return res.status(405).end(`Method ${req.method} Not Allowed`);
}
}
diff --git a/pages/settings/branding.tsx b/pages/settings/branding.tsx
index 6d4fb780..16ec643e 100644
--- a/pages/settings/branding.tsx
+++ b/pages/settings/branding.tsx
@@ -1,22 +1,12 @@
-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 { Card, CardContent, CardFooter } 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";
@@ -25,9 +15,8 @@ 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";
+import { convertDataUrlToFile, uploadImage } from "@/lib/utils";
export default function Branding() {
const { brand } = useBrand();
@@ -35,7 +24,6 @@ export default function Branding() {
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);
@@ -46,8 +34,8 @@ export default function Branding() {
setFileError(null);
const file = e.target.files[0];
if (file) {
- if (file.size / 1024 / 1024 > 5) {
- setFileError("File size too big (max 5MB)");
+ 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 {
@@ -56,7 +44,6 @@ export default function Branding() {
setLogo(e.target?.result as string);
};
reader.readAsDataURL(file);
- setLogoFile(file);
}
}
},
@@ -70,29 +57,24 @@ export default function Branding() {
}
}, [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);
+ // Upload the image if it's a data URL
+ let blobUrl: string | null = logo && logo.startsWith("data:") ? null : logo;
+ if (logo && logo.startsWith("data:")) {
+ // Convert the data URL to a blob
+ const blob = convertDataUrlToFile({ dataUrl: logo });
+ // Upload the blob to vercel storage
+ blobUrl = await uploadImage(blob);
+ setLogo(blobUrl);
}
const data = {
brandColor: brandColor,
- logo: newLogo,
- isNewLogo: newLogo !== brand?.logo,
+ logo: blobUrl,
};
const res = await fetch(
@@ -106,7 +88,7 @@ export default function Branding() {
},
);
if (res.ok) {
- mutate("/api/teams");
+ mutate(`/api/teams/${teamInfo?.currentTeam?.id}/branding`);
setIsLoading(false);
toast.success("Branding updated successfully");
}
@@ -190,7 +172,6 @@ export default function Branding() {
const reader = new FileReader();
reader.onload = (e) => {
setLogo(e.target?.result as string);
- setLogoFile(file);
};
reader.readAsDataURL(file);
}