Skip to content

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

feat: reset brand

Marc Seitz13078ac5d4f6
diff --git a/pages/api/teams/[teamId]/branding.ts b/pages/api/teams/[teamId]/branding.ts
index 74735ebc..4b30b865 100644
--- a/pages/api/teams/[teamId]/branding.ts
+++ b/pages/api/teams/[teamId]/branding.ts
@@ -4,6 +4,7 @@ import prisma from "@/lib/prisma";
import { CustomUser } from "@/lib/types";
import { authOptions } from "../../auth/[...nextauth]";
import { errorhandler } from "@/lib/errorHandler";
+import { del } from "@vercel/blob";
export default async function handle(
req: NextApiRequest,
@@ -72,7 +73,7 @@ export default async function handle(
return res.status(200).json(brand);
} else if (req.method === "PUT") {
- // POST /api/teams/:teamId/branding
+ // PUT /api/teams/:teamId/branding
const { logo, brandColor, accentColor } = req.body as {
logo?: string;
brandColor?: string;
@@ -91,6 +92,28 @@ export default async function handle(
});
return res.status(200).json(brand);
+ } else if (req.method === "DELETE") {
+ // DELETE /api/teams/:teamId/branding
+ const brand = await prisma.brand.findFirst({
+ where: {
+ teamId: teamId,
+ },
+ select: { id: true, logo: true },
+ });
+
+ if (brand && brand.logo) {
+ // delete the logo from vercel blob
+ await del(brand.logo);
+ }
+
+ // delete the branding from database
+ await prisma.brand.delete({
+ where: {
+ id: brand?.id,
+ },
+ });
+
+ return res.status(200).json("Branding deleted");
} else {
// We only allow GET and DELETE requests
res.setHeader("Allow", ["GET", "POST", "PUT"]);
diff --git a/pages/settings/branding.tsx b/pages/settings/branding.tsx
index 16ec643e..c27d2f52 100644
--- a/pages/settings/branding.tsx
+++ b/pages/settings/branding.tsx
@@ -17,10 +17,12 @@ import { PlusIcon } from "lucide-react";
import { useBrand } from "@/lib/swr/use-brand";
import { toast } from "sonner";
import { convertDataUrlToFile, uploadImage } from "@/lib/utils";
+import { useRouter } from "next/router";
export default function Branding() {
const { brand } = useBrand();
const teamInfo = useTeam();
+ const router = useRouter();
const [brandColor, setBrandColor] = useState<string>("#000000");
const [logo, setLogo] = useState<string | null>(null);
@@ -94,6 +96,27 @@ export default function Branding() {
}
};
+ const handleDelete = async () => {
+ setIsLoading(true);
+
+ const res = await fetch(
+ `/api/teams/${teamInfo?.currentTeam?.id}/branding`,
+ {
+ method: "DELETE",
+ headers: {
+ "Content-Type": "application/json",
+ },
+ },
+ );
+ if (res.ok) {
+ setLogo(null);
+ setBrandColor("#000000");
+ setIsLoading(false);
+ toast.success("Branding reset successfully");
+ router.reload();
+ }
+ };
+
return (
<AppLayout>
<Navbar current="Branding" />
@@ -209,7 +232,7 @@ export default function Branding() {
id="image"
name="image"
type="file"
- accept="image/*"
+ accept="image/jpeg,image/png"
className="sr-only"
onChange={onChangeLogo}
/>
@@ -246,6 +269,11 @@ export default function Branding() {
<Button onClick={saveBranding} loading={isLoading}>
Save changes
</Button>
+
+ {/* delete button */}
+ <Button variant="link" onClick={handleDelete} disabled={!brand}>
+ Reset branding
+ </Button>
</CardFooter>
</Card>
</div>