Papermark is the open-source DocSend alternative and secure data rooms with built-in analytics and custom domains.
refactor: settings change team name
Marc Seitz27c5602b8e39
diff --git a/components/navigation-menu.tsx b/components/navigation-menu.tsxindex f2aeb057..908d1d34 100644--- a/components/navigation-menu.tsx+++ b/components/navigation-menu.tsx@@ -24,7 +24,9 @@ export const NavMenu: React.FC<React.PropsWithChildren<Props>> = ({className,}) => {return (- <nav className={cn("sticky top-0 bg-background", className)}>+ <nav+ className={cn("sticky top-0 bg-background dark:bg-gray-900", className)}+ ><div className="flex w-full items-center overflow-x-auto pl-1"><ul className="flex flex-row gap-4">{navigation.map(({ label, href, segment, tag }) => (@@ -65,7 +67,7 @@ const NavItem: React.FC<Props["navigation"][0]> = ({<Linkhref={href}className={cn(- "text-content-subtle hover:bg-background-subtle -mx-3 flex items-center gap-1 rounded-md px-3 py-2 text-sm font-medium hover:text-primary",+ "text-content-subtle hover:bg-background-subtle -mx-3 flex items-center gap-1 rounded-lg px-3 py-2 text-sm font-medium hover:bg-muted hover:text-primary",{"text-primary": active,},diff --git a/components/settings/navbar.tsx b/components/settings/navbar.tsxdeleted file mode 100644index cbd1a6e8..00000000--- a/components/settings/navbar.tsx+++ /dev/null@@ -1,49 +0,0 @@-import Link from "next/link";--import { cn } from "@/lib/utils";--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" },-];--export default function Navbar({ current }: { current?: string }) {- return (- <div className="p-4 sm:m-4 sm:p-4">- <div className="mb-4 flex items-center justify-between md:mb-8 lg:mb-12">- <div className="space-y-1">- <h2 className="text-2xl font-semibold tracking-tight text-foreground">- Settings- </h2>- <p className="text-sm text-muted-foreground">- Manage your account settings- </p>- </div>- </div>- <div className="block">- <div className="border-b border-gray-600">- <nav className="-mb-px flex space-x-8" aria-label="Tabs">- {tabs.map((tab) => (- <Link- key={tab.name}- href={tab.href}- className={cn(- current === tab.name- ? "border-foreground text-foreground"- : "border-transparent text-muted-foreground hover:border-foreground hover:text-foreground",- "whitespace-nowrap border-b-2 px-1 py-4 text-sm font-medium",- )}- aria-current={current === tab.name ? "page" : undefined}- >- {tab.name}- </Link>- ))}- </nav>- </div>- </div>- </div>- );-}diff --git a/components/settings/settings-header.tsx b/components/settings/settings-header.tsxnew file mode 100644index 00000000..cd48cb87--- /dev/null+++ b/components/settings/settings-header.tsx@@ -0,0 +1,48 @@+import { NavMenu } from "../navigation-menu";++export function SettingsHeader() {+ return (+ <header>+ <section className="mb-4 flex items-center justify-between md:mb-8 lg:mb-12">+ <div className="space-y-1">+ <h1 className="text-xl font-semibold tracking-tight text-foreground sm:text-2xl">+ Settings+ </h1>+ <p className="text-xs text-muted-foreground sm:text-sm">+ Manage your account settings+ </p>+ </div>+ </section>++ <NavMenu+ navigation={[+ {+ label: "Overview",+ href: `/settings/general`,+ segment: `general`,+ },+ {+ label: "People",+ href: `/settings/people`,+ segment: "people",+ },+ {+ label: "Domains",+ href: `/settings/domains`,+ segment: "domains",+ },+ {+ label: "Branding",+ href: `/settings/branding`,+ segment: "branding",+ },+ {+ label: "Billing",+ href: `/settings/billing`,+ segment: "billing",+ },+ ]}+ />+ </header>+ );+}diff --git a/components/ui/form.tsx b/components/ui/form.tsxindex db1f232b..546c1ef6 100644--- a/components/ui/form.tsx+++ b/components/ui/form.tsx@@ -46,9 +46,9 @@ export function Form({});setSaving(false);}}- className="rounded-lg bg-background"+ className="rounded-lg">- <Card>+ <Card className="bg-transparent"><CardHeader><CardTitle>{title}</CardTitle><CardDescription>{description}</CardDescription>@@ -62,7 +62,7 @@ export function Form({disabled={disabledTooltip ? true : false}onChange={(e) => setValue(e.target.value)}className={cn(- "w-full max-w-md focus:border-gray-500 focus:outline-none focus:ring-gray-500 ",+ "w-full max-w-md focus:border-gray-500 focus:outline-none focus:ring-gray-500",{"cursor-not-allowed bg-gray-100 text-gray-400":disabledTooltip,diff --git a/components/ui/input.tsx b/components/ui/input.tsxindex e8db54d5..2a8956b4 100644--- a/components/ui/input.tsx+++ b/components/ui/input.tsx@@ -11,7 +11,8 @@ const Input = React.forwardRef<HTMLInputElement, InputProps>(<inputtype={type}className={cn(- "flex h-10 w-full rounded-md border border-input bg-background px-3 py-2 text-sm file:border-0 file:bg-transparent file:text-sm file:font-medium placeholder:text-muted-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring disabled:cursor-not-allowed disabled:opacity-50",+ // "flex h-10 w-full rounded-md border border-input px-3 py-2 text-sm file:border-0 file:bg-transparent file:text-sm file:font-medium placeholder:text-muted-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring disabled:cursor-not-allowed disabled:opacity-50",+ "flex w-full rounded-md border border-input bg-white text-foreground placeholder-muted-foreground focus:border-muted-foreground focus:outline-none focus:ring-muted-foreground dark:border-gray-500 dark:bg-gray-800 focus:dark:bg-transparent sm:text-sm",// "flex h-10 w-full rounded-md border-0 ring-1 ring-border bg-background px-3 py-2 text-sm transition-colors file:border-0 file:bg-transparent file:text-sm file:font-medium placeholder:text-muted-foreground focus-visible:outline-none focus-visible:ring-1 focus-visible:ring-ring disabled:cursor-not-allowed disabled:opacity-50",className,)}diff --git a/pages/api/teams/[teamId]/update-name.ts b/pages/api/teams/[teamId]/update-name.tsindex b8bff649..03fe7eda 100644--- a/pages/api/teams/[teamId]/update-name.ts+++ b/pages/api/teams/[teamId]/update-name.ts@@ -2,7 +2,6 @@ import { NextApiRequest, NextApiResponse } from "next";import { getServerSession } from "next-auth";-import { errorhandler } from "@/lib/errorHandler";import prisma from "@/lib/prisma";import { CustomUser } from "@/lib/types";@@ -12,7 +11,7 @@ export default async function handle(req: NextApiRequest,res: NextApiResponse,) {- if (req.method === "POST") {+ if (req.method === "PATCH") {// POST /api/teams/:teamId/update-nameconst session = await getServerSession(req, res, authOptions);if (!session) {diff --git a/pages/settings/general.tsx b/pages/settings/general.tsxindex cc7c7ebe..02bbd461 100644--- a/pages/settings/general.tsx+++ b/pages/settings/general.tsx@@ -1,5 +1,3 @@-import { useRef, useState } from "react";-import { useTeam } from "@/context/team-context";import {type CredentialCreationOptionsJSON,@@ -9,45 +7,13 @@ import { toast } from "sonner";import { mutate } from "swr";import AppLayout from "@/components/layouts/app";-import Navbar from "@/components/settings/navbar";+import { SettingsHeader } from "@/components/settings/settings-header";import Passkey from "@/components/shared/icons/passkey";import { Button } from "@/components/ui/button";-import { Input } from "@/components/ui/input";+import { Form } from "@/components/ui/form";export default function General() {const teamInfo = useTeam();- const teamNameInputRef = useRef<HTMLInputElement>(null);- const [isTeamNameChanging, setTeamNameChanging] = useState<boolean>(false);-- const changeTeamName = async () => {- if (teamInfo?.currentTeam?.name === teamNameInputRef.current?.value) return;-- setTeamNameChanging(true);-- const response = await fetch(- `/api/teams/${teamInfo?.currentTeam?.id}/update-name`,- {- method: "POST",- headers: {- "Content-Type": "application/json",- },- body: JSON.stringify({- name: teamNameInputRef.current?.value,- }),- },- );-- if (response.ok) {- const message = await response.json();- toast.success(message);- } else {- const message = await response.json();- toast.error(message);- }-- await mutate("/api/teams");- setTeamNameChanging(false);- };async function registerPasskey() {const createOptionsResponse = await fetch("/api/passkeys/register", {@@ -78,8 +44,9 @@ export default function General() {return (<AppLayout>- <Navbar current="General" />- <div className="p-4 sm:m-4 sm:p-4">+ <main className="relative mx-2 mb-10 mt-4 space-y-8 overflow-hidden px-1 sm:mx-3 md:mx-5 md:mt-5 lg:mx-7 lg:mt-8 xl:mx-10">+ <SettingsHeader />+<div className="mb-4 flex items-center justify-between md:mb-8 lg:mb-12"><div className="space-y-1"><h3 className="text-2xl font-semibold tracking-tight text-foreground">@@ -88,27 +55,38 @@ export default function General() {<p className="text-sm text-muted-foreground">Manage your team</p></div></div>- <div className="space-y-8">- <div className="flex items-center justify-between rounded-lg border border-border bg-secondary p-10">- <div className="flex flex-col">- <h2 className="text-xl font-medium">Team Name</h2>- <p className="mt-3 text-sm text-secondary-foreground">- This is the name of your team on Papermark.- </p>- <Input- ref={teamNameInputRef}- className="mt-6"- defaultValue={teamInfo?.currentTeam?.name}- />- </div>- <Button- size={"lg"}- onClick={changeTeamName}- loading={isTeamNameChanging}- >- {isTeamNameChanging ? "Saving..." : "Save changes"}- </Button>- </div>+ <div className="space-y-6">+ <Form+ title="Team Name"+ description="This is the name of your team on Papermark."+ inputAttrs={{+ name: "name",+ defaultValue: teamInfo?.currentTeam?.name,+ placeholder: "My Personal Team",+ maxLength: 32,+ }}+ helpText="Max 32 characters."+ handleSubmit={(updateData) =>+ fetch(`/api/teams/${teamInfo?.currentTeam?.id}/update-name`, {+ method: "PATCH",+ headers: {+ "Content-Type": "application/json",+ },+ body: JSON.stringify(updateData),+ }).then(async (res) => {+ if (res.status === 200) {+ await Promise.all([+ mutate(`/api/teams/${teamInfo?.currentTeam?.id}`),+ mutate(`/api/teams`),+ ]);+ toast.success("Successfully updated team name!");+ } else {+ const { error } = await res.json();+ toast.error(error.message);+ }+ })+ }+ /><div className="rounded-lg border border-muted p-10"><div className="space-y-6">@@ -129,7 +107,7 @@ export default function General() {</div></div></div>- </div>+ </main></AppLayout>);}