Skip to content

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

team scoped: post requests

Aashish-Upadhyay-1010f69c0e043d3
diff --git a/components/billing/upgrade-plan-modal.tsx b/components/billing/upgrade-plan-modal.tsx
index 1a08cf34..a8780ecb 100644
--- a/components/billing/upgrade-plan-modal.tsx
+++ b/components/billing/upgrade-plan-modal.tsx
@@ -1,12 +1,5 @@
-import {
- useMemo,
- useState,
-} from "react";
-import {
- Dialog,
- DialogContent,
- DialogTrigger,
-} from "@/components/ui/dialog";
+import { useMemo, useState } from "react";
+import { Dialog, DialogContent, DialogTrigger } from "@/components/ui/dialog";
import { Button } from "@/components/ui/button";
import { motion } from "framer-motion";
import { STAGGER_CHILD_VARIANTS } from "@/lib/constants";
@@ -15,12 +8,14 @@ import { capitalize } from "@/lib/utils";
import { PLANS } from "@/lib/stripe/utils";
import { getStripe } from "@/lib/stripe/client";
import { Badge } from "../ui/badge";
-
+import { useTeam } from "@/context/team-context";
export function UpgradePlanModal({ children }: { children: React.ReactNode }) {
const [plan, setPlan] = useState<"Pro">("Pro");
const [period, setPeriod] = useState<"monthly" | "yearly">("monthly");
const [clicked, setClicked] = useState<boolean>(false);
+ const teamInfo = useTeam();
+
const features = useMemo(() => {
return [
"Custom domain",
@@ -44,8 +39,7 @@ export function UpgradePlanModal({ children }: { children: React.ReactNode }) {
}}
initial="hidden"
animate="show"
- className="flex flex-col items-center justify-center space-y-3 border-b border-border px-4 py-8 sm:px-16"
- >
+ className="flex flex-col items-center justify-center space-y-3 border-b border-border px-4 py-8 sm:px-16">
<motion.div variants={STAGGER_CHILD_VARIANTS}>
<p className="text-2xl font-bold tracking-tighter text-foreground">
Papermark
@@ -53,14 +47,12 @@ export function UpgradePlanModal({ children }: { children: React.ReactNode }) {
</motion.div>
<motion.h3
className="text-lg font-medium"
- variants={STAGGER_CHILD_VARIANTS}
- >
+ variants={STAGGER_CHILD_VARIANTS}>
Upgrade to {plan}
</motion.h3>
<motion.p
className="text-center text-sm text-muted-foreground"
- variants={STAGGER_CHILD_VARIANTS}
- >
+ variants={STAGGER_CHILD_VARIANTS}>
Enjoy higher limits and extra features with our {plan} plan.
</motion.p>
</motion.div>
@@ -69,8 +61,7 @@ export function UpgradePlanModal({ children }: { children: React.ReactNode }) {
className="flex flex-col space-y-3"
variants={STAGGER_CHILD_VARIANTS}
initial="hidden"
- animate="show"
- >
+ animate="show">
<div className="mb-4">
<div className="mb-4 flex items-center justify-between">
<div className="flex items-center space-x-2">
@@ -79,8 +70,7 @@ export function UpgradePlanModal({ children }: { children: React.ReactNode }) {
</h4>
<Badge
variant="outline"
- className="text-sm font-normal normal-case"
- >{`$${
+ className="text-sm font-normal normal-case">{`$${
PLANS.find((p) => p.name === plan)!.price[period].amount
}/${period.replace("ly", "")}`}</Badge>
</div>
@@ -88,8 +78,7 @@ export function UpgradePlanModal({ children }: { children: React.ReactNode }) {
onClick={() => {
setPeriod(period === "monthly" ? "yearly" : "monthly");
}}
- className="text-xs text-muted-foreground underline underline-offset-4 transition-colors hover:text-gray-800 hover:dark:text-muted-foreground/80"
- >
+ className="text-xs text-muted-foreground underline underline-offset-4 transition-colors hover:text-gray-800 hover:dark:text-muted-foreground/80">
{period === "monthly"
? "Get 2 months free 🎁"
: "Switch to monthly"}
@@ -105,14 +94,12 @@ export function UpgradePlanModal({ children }: { children: React.ReactNode }) {
}}
initial="hidden"
animate="show"
- className="flex flex-col space-y-2"
- >
+ className="flex flex-col space-y-2">
{features.map((feature, i) => (
<motion.div
key={i}
variants={STAGGER_CHILD_VARIANTS}
- className="flex items-center space-x-2 text-sm text-muted-foreground"
- >
+ className="flex items-center space-x-2 text-sm text-muted-foreground">
<CheckCircle2 className="h-5 w-5 text-emerald-500" />
<span>{feature}</span>
</motion.div>
@@ -124,7 +111,9 @@ export function UpgradePlanModal({ children }: { children: React.ReactNode }) {
onClick={() => {
setClicked(true);
fetch(
- `/api/billing/upgrade?priceId=${
+ `/api/teams/${
+ teamInfo?.currentTeam?.id
+ }/billing/upgrade?priceId=${
PLANS.find((p) => p.name === plan)!.price[period].priceIds[
process.env.NEXT_PUBLIC_VERCEL_ENV === "production"
? "production"
@@ -145,11 +134,10 @@ export function UpgradePlanModal({ children }: { children: React.ReactNode }) {
alert(err);
setClicked(false);
});
- }}
- >{`Upgrade to ${plan} ${capitalize(period)}`}</Button>
+ }}>{`Upgrade to ${plan} ${capitalize(period)}`}</Button>
</motion.div>
</div>
</DialogContent>
</Dialog>
);
-}
\ No newline at end of file
+}
diff --git a/components/domains/add-domain-modal.tsx b/components/domains/add-domain-modal.tsx
index fcc47713..2fe90cd1 100644
--- a/components/domains/add-domain-modal.tsx
+++ b/components/domains/add-domain-modal.tsx
@@ -10,6 +10,7 @@ import {
} from "@/components/ui/dialog";
import { Input } from "@/components/ui/input";
import { Label } from "@/components/ui/label";
+import { useTeam } from "@/context/team-context";
import { useState } from "react";
import { toast } from "sonner";
@@ -27,6 +28,8 @@ export function AddDomainModal({
const [domain, setDomain] = useState<string>("");
const [loading, setLoading] = useState<boolean>(false);
+ const teamInfo = useTeam();
+
const handleSubmit = async (event: any) => {
event.preventDefault();
event.stopPropagation();
@@ -34,15 +37,18 @@ export function AddDomainModal({
if (domain == "") return;
setLoading(true);
- const response = await fetch("/api/domains", {
- method: "POST",
- headers: {
- "Content-Type": "application/json",
- },
- body: JSON.stringify({
- domain: domain,
- }),
- });
+ const response = await fetch(
+ `/api/teams/${teamInfo?.currentTeam?.id}/domains`,
+ {
+ method: "POST",
+ headers: {
+ "Content-Type": "application/json",
+ },
+ body: JSON.stringify({
+ domain: domain,
+ }),
+ }
+ );
if (!response.ok) {
const error = await response.json();
@@ -54,7 +60,7 @@ export function AddDomainModal({
const newDomain = await response.json();
- toast.success("Domain added successfully! πŸŽ‰")
+ toast.success("Domain added successfully! πŸŽ‰");
// console.log(newDomain);
@@ -65,7 +71,7 @@ export function AddDomainModal({
setLoading(false);
- !onAddition && window.open("/settings/domains", "_blank")
+ !onAddition && window.open("/settings/domains", "_blank");
};
return (
diff --git a/pages/api/teams/[teamId]/domains/index.ts b/pages/api/teams/[teamId]/domains/index.ts
index 911e1754..694a70d7 100644
--- a/pages/api/teams/[teamId]/domains/index.ts
+++ b/pages/api/teams/[teamId]/domains/index.ts
@@ -79,6 +79,7 @@ export default async function handle(
data: {
slug: domain,
userId,
+ teamId,
},
});
await addDomainToVercel(domain);
diff --git a/pages/documents/[id].tsx b/pages/documents/[id].tsx
index ac56e71f..d371254a 100644
--- a/pages/documents/[id].tsx
+++ b/pages/documents/[id].tsx
@@ -21,6 +21,7 @@ import {
} from "@/components/ui/dropdown-menu";
import { useRouter } from "next/router";
import MoreVertical from "@/components/shared/icons/more-vertical";
+import { useTeam } from "@/context/team-context";
export default function DocumentPage() {
const { document: prismaDocument, primaryVersion, error } = useDocument();
@@ -35,6 +36,8 @@ export default function DocumentPage() {
const enterPressedRef = useRef<boolean>(false);
const dropdownRef = useRef<HTMLDivElement | null>(null);
+ const teamInfo = useTeam();
+
const handleNameSubmit = async () => {
if (enterPressedRef.current) {
enterPressedRef.current = false;
@@ -45,7 +48,9 @@ export default function DocumentPage() {
if (newName !== prismaDocument!.name) {
const response = await fetch(
- `/api/documents/${prismaDocument!.id}/update-name`,
+ `/api/teams/${teamInfo?.currentTeam?.id}/documents/${
+ prismaDocument!.id
+ }/update-name`,
{
method: "POST",
headers: {
diff --git a/pages/settings/billing.tsx b/pages/settings/billing.tsx
index 80bcce01..b00ae8ac 100644
--- a/pages/settings/billing.tsx
+++ b/pages/settings/billing.tsx
@@ -3,6 +3,7 @@ import AppLayout from "@/components/layouts/app";
import Navbar from "@/components/settings/navbar";
import { Badge } from "@/components/ui/badge";
import { Button } from "@/components/ui/button";
+import { useTeam } from "@/context/team-context";
import { useBilling } from "@/lib/swr/use-billing";
import { formattedDate, getFirstAndLastDay } from "@/lib/utils";
import { useRouter } from "next/router";
@@ -11,9 +12,11 @@ import { toast } from "sonner";
export default function Billing() {
const router = useRouter();
- const { plan, startsAt, endsAt } = useBilling()
+ const { plan, startsAt, endsAt } = useBilling();
const [clicked, setClicked] = useState<boolean>(false);
+ const teamInfo = useTeam();
+
useEffect(() => {
if (router.query.success) {
toast.success("Upgrade success!");
@@ -26,7 +29,7 @@ export default function Billing() {
// }, 1000);
}
}, [router.query.success]);
-
+
return (
<AppLayout>
<Navbar current="Billing" />
@@ -162,9 +165,12 @@ export default function Billing() {
<Button
onClick={() => {
setClicked(true);
- fetch(`/api/billing/manage`, {
- method: "POST",
- })
+ fetch(
+ `/api/teams/${teamInfo?.currentTeam?.id}/billing/manage`,
+ {
+ method: "POST",
+ }
+ )
.then(async (res) => {
const url = await res.json();
router.push(url);
@@ -174,8 +180,7 @@ export default function Billing() {
setClicked(false);
});
}}
- loading={clicked}
- >
+ loading={clicked}>
Manage Subscription
</Button>
)
diff --git a/pages/settings/people.tsx b/pages/settings/people.tsx
index 008817f1..af0c9998 100644
--- a/pages/settings/people.tsx
+++ b/pages/settings/people.tsx
@@ -1,3 +1,4 @@
+import { useState } from "react";
import AppLayout from "@/components/layouts/app";
import Navbar from "@/components/settings/navbar";
import { Button } from "@/components/ui/button";
@@ -6,12 +7,21 @@ import Folder from "@/components/shared/icons/folder";
import { useGetTeam } from "@/lib/swr/use-team";
import { Skeleton } from "@/components/ui/skeleton";
import { AddTeamMembers } from "@/components/teams/add-team-member-modal";
-import { useState } from "react";
+import {
+ DropdownMenu,
+ DropdownMenuContent,
+ DropdownMenuItem,
+ DropdownMenuLabel,
+ DropdownMenuTrigger,
+} from "@/components/ui/dropdown-menu";
+import { useSession } from "next-auth/react";
+import { CustomUser } from "@/lib/types";
export default function Billing() {
const [isTeamMemberInviteModalOpen, setTeamMemberInviteModalOpen] =
useState<boolean>(false);
+ const { data: session } = useSession();
const { team, loading } = useGetTeam();
const getUserDocumentCount = (userId: string) => {
@@ -21,6 +31,12 @@ export default function Billing() {
return documents?.length;
};
+ const isUserAdmin = (userId: string) => {
+ if ((session?.user as CustomUser).id === userId) {
+ return true;
+ }
+ };
+
return (
<AppLayout>
<Navbar current="People" />
@@ -92,7 +108,20 @@ export default function Billing() {
<span className="text-sm text-foreground capitalize">
{member.role.toLowerCase()}
</span>
- <MoreVertical className="w-4 h-4" />
+ <DropdownMenu>
+ <DropdownMenuTrigger asChild>
+ <Button variant="ghost" className="h-8 w-8 p-0">
+ <span className="sr-only">Open menu</span>
+ <MoreVertical className="h-4 w-4" />
+ </Button>
+ </DropdownMenuTrigger>
+ <DropdownMenuContent align="end">
+ <DropdownMenuLabel>Actions</DropdownMenuLabel>
+ <DropdownMenuItem className="text-red-500 focus:bg-destructive focus:text-destructive-foreground">
+ Remove teammate
+ </DropdownMenuItem>
+ </DropdownMenuContent>
+ </DropdownMenu>
</div>
</li>
))}