Skip to content

armgit / dub

Public Imported from GitHub
0

The modern link attribution platform. Loved by world-class engineering teams at Twilio, Zillow, Jobber, Vercel, Raycast, and more.

Invitation flow updates (#3322)

Tim Wilson7b12816a8252
diff --git a/apps/web/app/app.dub.co/(dashboard)/[slug]/auth.tsx b/apps/web/app/app.dub.co/(dashboard)/[slug]/auth.tsx
index 860f631f97..2d63e974f8 100644
--- a/apps/web/app/app.dub.co/(dashboard)/[slug]/auth.tsx
+++ b/apps/web/app/app.dub.co/(dashboard)/[slug]/auth.tsx
@@ -1,19 +1,29 @@
"use client";
+import { ErrorCodes } from "@/lib/api/error-codes";
import useWorkspace from "@/lib/swr/use-workspace";
import LayoutLoader from "@/ui/layout/layout-loader";
-import { notFound } from "next/navigation";
+import { notFound, redirect, useParams } from "next/navigation";
import { ReactNode } from "react";
export default function WorkspaceAuth({ children }: { children: ReactNode }) {
+ const { slug } = useParams();
const { loading, error } = useWorkspace();
if (loading) {
return <LayoutLoader />;
}
- if (error && error.status === 404) {
- notFound();
+ if (error) {
+ if (error.status === ErrorCodes.not_found) {
+ notFound();
+ } else if (
+ [ErrorCodes.invite_pending, ErrorCodes.invite_expired].includes(
+ error.status,
+ )
+ ) {
+ redirect(`/${slug}/invite`);
+ }
}
return children;
diff --git a/apps/web/app/app.dub.co/(invites)/[slug]/invite/accept-invite-button.tsx b/apps/web/app/app.dub.co/(invites)/[slug]/invite/accept-invite-button.tsx
new file mode 100644
index 0000000000..88ba30bdc1
--- /dev/null
+++ b/apps/web/app/app.dub.co/(invites)/[slug]/invite/accept-invite-button.tsx
@@ -0,0 +1,67 @@
+"use client";
+
+import { mutatePrefix } from "@/lib/swr/mutate";
+import { Button, useKeyboardShortcut } from "@dub/ui";
+import { useSession } from "next-auth/react";
+import { useParams, useRouter } from "next/navigation";
+import posthog from "posthog-js";
+import { useState } from "react";
+import { toast } from "sonner";
+
+export function AcceptInviteButton() {
+ const { slug } = useParams<{ slug: string }>();
+ const { data: session } = useSession();
+ const router = useRouter();
+
+ const [isAccepting, setIsAccepting] = useState(false);
+
+ const acceptInvite = async () => {
+ setIsAccepting(true);
+
+ try {
+ const response = await fetch(`/api/workspaces/${slug}/invites/accept`, {
+ method: "POST",
+ headers: { "Content-Type": "application/json" },
+ });
+
+ if (!response.ok) {
+ const error = await response.json();
+ toast.error(error.message || "Failed to accept invite.");
+ setIsAccepting(false);
+ return;
+ }
+
+ if (session?.user) {
+ posthog.identify(session.user["id"], {
+ email: session.user.email,
+ name: session.user.name,
+ });
+ }
+
+ posthog.capture("accepted_workspace_invite", {
+ workspace: slug,
+ });
+
+ await mutatePrefix(["/api/workspaces", "/api/programs"]);
+ router.replace(`/${slug}`);
+ toast.success("You now are a part of this workspace!");
+ } catch (e) {
+ console.error("Failed to accept invite", e);
+ setIsAccepting(false);
+ }
+ };
+
+ useKeyboardShortcut("a", acceptInvite, {
+ enabled: !isAccepting,
+ });
+
+ return (
+ <Button
+ onClick={acceptInvite}
+ loading={isAccepting}
+ text="Accept invite"
+ shortcut="A"
+ className="h-9 rounded-lg [&>div]:flex-initial"
+ />
+ );
+}
diff --git a/apps/web/app/app.dub.co/(invites)/[slug]/invite/close-invite-button.tsx b/apps/web/app/app.dub.co/(invites)/[slug]/invite/close-invite-button.tsx
new file mode 100644
index 0000000000..2c5a0a816c
--- /dev/null
+++ b/apps/web/app/app.dub.co/(invites)/[slug]/invite/close-invite-button.tsx
@@ -0,0 +1,30 @@
+import { X } from "@/ui/shared/icons";
+import { Button } from "@dub/ui";
+import Link from "next/link";
+
+export function CloseInviteButton({
+ goToOnboarding,
+ variant = "x",
+}: {
+ goToOnboarding?: boolean;
+ variant?: "x" | "full";
+}) {
+ return (
+ <Link href={goToOnboarding ? "/onboarding" : "/"}>
+ <Button
+ variant={variant === "x" ? "outline" : "primary"}
+ icon={
+ variant === "x" ? (
+ <X className="text-content-subtle size-5" />
+ ) : undefined
+ }
+ className={
+ variant === "x"
+ ? "size-8 p-0 active:scale-95"
+ : "h-9 w-fit rounded-lg"
+ }
+ text={variant === "x" ? undefined : "Go back"}
+ />
+ </Link>
+ );
+}
diff --git a/apps/web/app/app.dub.co/(invites)/[slug]/invite/invite-confetti.tsx b/apps/web/app/app.dub.co/(invites)/[slug]/invite/invite-confetti.tsx
new file mode 100644
index 0000000000..332904680e
--- /dev/null
+++ b/apps/web/app/app.dub.co/(invites)/[slug]/invite/invite-confetti.tsx
@@ -0,0 +1,23 @@
+"use client";
+
+import Confetti from "canvas-confetti";
+import { memo, useEffect } from "react";
+
+export const InviteConfetti = memo(() => {
+ useEffect(() => {
+ [0.25, 0.5, 0.75].forEach((x) =>
+ Confetti({
+ particleCount: 50,
+ startVelocity: 90,
+ spread: 120,
+ ticks: 1000,
+ origin: { x, y: 0 },
+ disableForReducedMotion: true,
+ }),
+ );
+
+ return () => Confetti.reset();
+ }, []);
+
+ return null;
+});
diff --git a/apps/web/app/app.dub.co/(invites)/[slug]/invite/page.tsx b/apps/web/app/app.dub.co/(invites)/[slug]/invite/page.tsx
new file mode 100644
index 0000000000..8f4cdab962
--- /dev/null
+++ b/apps/web/app/app.dub.co/(invites)/[slug]/invite/page.tsx
@@ -0,0 +1,380 @@
+import { getSession } from "@/lib/auth";
+import { prisma } from "@dub/prisma";
+import { Project, ProjectInvite, User } from "@dub/prisma/client";
+import {
+ Avatar,
+ Book2Fill,
+ CircleCheckFill,
+ CircleHalfDottedClock,
+ DubLinksIcon,
+ DubPartnersIcon,
+ LifeRingFill,
+ MsgsFill,
+ Tooltip,
+ Wordmark,
+} from "@dub/ui";
+import { OG_AVATAR_URL, cn } from "@dub/utils";
+import Link from "next/link";
+import { redirect } from "next/navigation";
+import { AcceptInviteButton } from "./accept-invite-button";
+import { CloseInviteButton } from "./close-invite-button";
+import { InviteConfetti } from "./invite-confetti";
+
+const MAX_TEAM_DISPLAY = 4;
+
+export default async function WorkspaceInvitePage({
+ params,
+}: {
+ params: Promise<{ slug: string }>;
+}) {
+ const { slug } = await params;
+
+ const session = await getSession();
+
+ if (!session) redirect(`/login?next=/${slug}/invite`);
+
+ const [user, invite] = await Promise.all([
+ prisma.user.findUniqueOrThrow({
+ select: {
+ id: true,
+ name: true,
+ image: true,
+ _count: {
+ select: {
+ projects: true,
+ },
+ },
+ },
+ where: {
+ id: session.user.id,
+ },
+ }),
+ prisma.projectInvite.findFirst({
+ where: {
+ email: session.user.email,
+ project: {
+ slug,
+ },
+ },
+ include: {
+ project: {
+ select: {
+ name: true,
+ logo: true,
+ defaultProgramId: true,
+ users: {
+ select: {
+ user: {
+ select: {
+ id: true,
+ name: true,
+ email: true,
+ image: true,
+ },
+ },
+ },
+ where: {
+ user: {
+ isMachine: false,
+ },
+ },
+ orderBy: {
+ createdAt: "asc",
+ },
+ },
+ },
+ },
+ },
+ }),
+ ]);
+
+ if (!invite) redirect(`/${slug}`);
+
+ if (invite.expires < new Date()) {
+ // Expired invite
+ return (
+ <>
+ <div className="z-10 flex items-center justify-end p-4">
+ <CloseInviteButton goToOnboarding={user._count.projects === 0} />
+ </div>
+ <div className="-mt-16 flex grow flex-col items-center justify-center">
+ <Hero isExpired invite={invite} user={user} />
+ </div>
+ </>
+ );
+ }
+
+ return (
+ <div>
+ <div className="flex items-center justify-end p-4">
+ <CloseInviteButton goToOnboarding={user._count.projects === 0} />
+ </div>
+ <div className="flex w-full flex-col items-center justify-center px-4 py-10">
+ <Hero invite={invite} user={user} isExpired={false} />
+ <div className="flex w-full flex-col items-center">
+ <div
+ className={cn(
+ "mt-8 flex w-full max-w-[400px] flex-col gap-3",
+ "animate-slide-up-fade motion-reduce:animate-fade-in [--offset:10px] [animation-delay:150ms] [animation-duration:0.5s] [animation-fill-mode:both]",
+ )}
+ >
+ <h3 className="text-content-default font-semibold">
+ Products {invite.project.name} uses
+ </h3>
+
+ <div className="divide-border-subtle border-border-subtle bg-bg-muted flex flex-col divide-y rounded-lg border">
+ {[
+ {
+ icon: (
+ <div className="flex size-5 items-center justify-center rounded bg-orange-400">
+ <DubLinksIcon className="size-3 text-orange-900" />
+ </div>
+ ),
+ title: "Dub Links",
+ href: "https://dub.co/links",
+ cta: "Learn more",
+ },
+ ...(invite.project.defaultProgramId
+ ? [
+ {
+ icon: (
+ <div className="flex size-5 items-center justify-center rounded bg-violet-400">
+ <DubPartnersIcon className="size-3 text-violet-900" />
+ </div>
+ ),
+ title: "Dub Partners",
+ href: "https://dub.co/partners",
+ cta: "Learn more",
+ },
+ ]
+ : []),
+ ].map(({ icon, title, href, cta }) => (
+ <div
+ key={href}
+ className="flex items-center justify-between gap-2 px-2.5 py-2"
+ >
+ <div className="flex min-w-0 items-center gap-2">
+ {icon}
+ <div className="text-content-default text-sm font-medium">
+ {title}
+ </div>
+ </div>
+
+ <Link
+ href={href}
+ target="_blank"
+ className="border-subtle bg-bg-inverted hover:bg-bg-inverted/90 flex h-7 items-center rounded-lg border px-2.5 text-sm text-white transition-transform active:scale-[0.98]"
+ >
+ {cta}
+ </Link>
+ </div>
+ ))}
+ </div>
+ </div>
+
+ <div
+ className={cn(
+ "mt-8 flex w-full max-w-[400px] flex-col gap-3",
+ "animate-slide-up-fade motion-reduce:animate-fade-in [--offset:10px] [animation-delay:150ms] [animation-duration:0.5s] [animation-fill-mode:both]",
+ )}
+ >
+ <h3 className="text-content-default font-semibold">The team</h3>
+
+ <div className="relative overflow-hidden">
+ <div
+ className={cn(
+ "border-border-subtle bg-bg-muted divide-border-subtle relative flex flex-col divide-y rounded-lg border",
+ invite.project.users.length > MAX_TEAM_DISPLAY &&
+ "[mask-image:linear-gradient(0deg,transparent,black_45px)]",
+ )}
+ >
+ {invite.project.users
+ .slice(0, MAX_TEAM_DISPLAY)
+ .map(({ user: { id, name, email, image } }) => (
+ <div
+ key={id}
+ className="flex items-center justify-between gap-2 px-2.5 py-2"
+ >
+ <div className="flex min-w-0 items-center gap-2">
+ <Avatar user={{ id, name, image }} className="size-6" />
+ <span className="text-content-default min-w-0 truncate text-sm font-medium">
+ {name || email}
+ </span>
+ </div>
+ </div>
+ ))}
+ </div>
+
+ {invite.project.users.length > MAX_TEAM_DISPLAY && (
+ <div className="absolute inset-x-0 bottom-0 flex items-center justify-center">
+ <span className="text-content-subtle select-none text-xs font-medium">
+ +{invite.project.users.length - MAX_TEAM_DISPLAY} more
+ </span>
+ </div>
+ )}
+ </div>
+ </div>
+
+ <div
+ className={cn(
+ "mt-8 flex w-full max-w-[400px] flex-col gap-3",
+ "animate-slide-up-fade motion-reduce:animate-fade-in [--offset:10px] [animation-delay:250ms] [animation-duration:0.5s] [animation-fill-mode:both]",
+ )}
+ >
+ <h3 className="text-content-default font-semibold">
+ Additional resources
+ </h3>
+
+ <div className="divide-border-subtle border-border-subtle bg-bg-muted flex flex-col divide-y rounded-lg border">
+ {[
+ {
+ icon: LifeRingFill,
+ title: "Help center",
+ description: "Answers to your questions",
+ href: "https://dub.co/help",
+ cta: "Read",
+ },
+ {
+ icon: Book2Fill,
+ title: "Docs",
+ description: "Platform documentation",
+ href: "https://dub.co/docs",
+ cta: "Learn",
+ },
+ {
+ icon: MsgsFill,
+ title: "Support",
+ description: "Product support or help requests",
+ href: "https://dub.co/contact/support",
+ cta: "Chat",
+ },
+ ].map(({ icon: Icon, title, description, href, cta }) => (
+ <div
+ key={href}
+ className="flex items-center justify-between gap-2 px-2.5 py-2"
+ >
+ <div className="flex min-w-0 items-center gap-2">
+ <div className="flex size-8 items-center justify-center rounded-md bg-black/5">
+ <Icon className="size-4" />
+ </div>
+ <div className="min-w-0">
+ <div className="text-content-default text-sm font-medium">
+ {title}
+ </div>
+ <p className="text-content-subtle truncate text-xs font-medium">
+ {description}
+ </p>
+ </div>
+ </div>
+
+ <Link
+ href={href}
+ target="_blank"
+ className="border-subtle bg-bg-default hover:bg-bg-muted flex h-7 items-center rounded-lg border px-2.5 text-sm font-medium transition-transform active:scale-[0.98]"
+ >
+ {cta}
+ </Link>
+ </div>
+ ))}
+ </div>
+ </div>
+ </div>
+ </div>
+ <InviteConfetti />
+ </div>
+ );
+}
+
+function Hero({
+ invite,
+ user,
+ isExpired,
+}: {
+ invite: Pick<ProjectInvite, "role" | "expires"> & {
+ project: Pick<Project, "logo" | "name">;
+ };
+ user: Pick<User, "id" | "image" | "name"> & { _count: { projects: number } };
+ isExpired: boolean;
+}) {
+ return (
+ <>
+ <div className="animate-slide-up-fade motion-reduce:animate-fade-in [--offset:10px] [animation-duration:0.5s] [animation-fill-mode:both]">
+ <Wordmark className="h-8" />
+ </div>
+
+ <div
+ className={cn(
+ "relative z-0 mt-8 flex items-center",
+ "animate-slide-up-fade motion-reduce:animate-fade-in [--offset:10px] [animation-delay:50ms] [animation-duration:0.5s] [animation-fill-mode:both]",
+ )}
+ >
+ <img
+ src={invite.project.logo || `${OG_AVATAR_URL}${invite.project.name}`}
+ alt={invite.project.name}
+ className="z-10 size-20 rotate-[-15deg] rounded-full drop-shadow-md"
+ />
+ <img
+ src={user?.image || `${OG_AVATAR_URL}${user?.id}`}
+ alt={user?.name || "Your avatar"}
+ className="-ml-4 size-20 rotate-[15deg] rounded-full drop-shadow-md"
+ />
+ <div className="absolute -bottom-2 left-1/2 z-10 -translate-x-1/2 rounded-full bg-white p-0.5">
+ {isExpired ? (
+ <div className="rounded-full bg-neutral-200 p-1">
+ <CircleHalfDottedClock className="size-5 text-neutral-500" />
+ </div>
+ ) : (
+ <CircleCheckFill className="size-8 text-green-500" />
+ )}
+ </div>
+ </div>
+
+ <div
+ className={cn(
+ "flex w-full flex-col items-center text-center",
+ "animate-slide-up-fade motion-reduce:animate-fade-in [--offset:10px] [animation-delay:100ms] [animation-duration:0.5s] [animation-fill-mode:both]",
+ !isExpired ? "max-w-[400px]" : "max-w-[440px]",
+ )}
+ >
+ <h2 className="text-content-default mt-4 text-pretty text-lg font-semibold">
+ {!isExpired ? (
+ <>Welcome to the {invite.project.name} workspace</>
+ ) : (
+ <>Your invite to the {invite.project.name} workspace has expired</>
+ )}
+ </h2>
+ <p className="text-content-subtle text-pretty text-base font-medium">
+ {!isExpired ? (
+ <>
+ You've been added as a{invite.role === "owner" ? "n" : ""}{" "}
+ <Tooltip
+ content={
+ invite.role === "owner"
+ ? "You have the highest workspace permissions. [Learn more](https://dub.co/help/article/workspace-roles#member-role)"
+ : "You have limited workspace permissions. [Learn more](https://dub.co/help/article/workspace-roles#member-role)"
+ }
+ >
+ <span className="underline decoration-dotted underline-offset-2">
+ {invite.role}
+ </span>
+ </Tooltip>
+ </>
+ ) : (
+ <>Please contact the owner to request another invite.</>
+ )}
+ </p>
+
+ <div className="mt-4 flex w-full justify-center">
+ {!isExpired ? (
+ <AcceptInviteButton />
+ ) : (
+ <CloseInviteButton
+ goToOnboarding={user._count.projects === 0}
+ variant="full"
+ />
+ )}
+ </div>
+ </div>
+ </>
+ );
+}
diff --git a/apps/web/app/app.dub.co/(invites)/layout.tsx b/apps/web/app/app.dub.co/(invites)/layout.tsx
new file mode 100644
index 0000000000..795003392b
--- /dev/null
+++ b/apps/web/app/app.dub.co/(invites)/layout.tsx
@@ -0,0 +1,11 @@
+import { ReactNode } from "react";
+
+export default function InvitesLayout({ children }: { children: ReactNode }) {
+ return (
+ <div className="bg-bg-emphasis min-h-screen w-full sm:p-2">
+ <div className="bg-bg-default relative flex min-h-[calc(100vh-1rem)] flex-col sm:rounded-xl">
+ {children}
+ </div>
+ </div>
+ );
+}
diff --git a/apps/web/lib/api/error-codes.ts b/apps/web/lib/api/error-codes.ts
index 2ca87e06d2..939baf74f8 100644
--- a/apps/web/lib/api/error-codes.ts
+++ b/apps/web/lib/api/error-codes.ts
@@ -1,15 +1,19 @@
import * as z from "zod/v4";
-export const ErrorCode = z.enum([
- "bad_request",
- "not_found",
- "internal_server_error",
- "unauthorized",
- "forbidden",
- "rate_limit_exceeded",
- "invite_expired",
- "invite_pending",
- "exceeded_limit",
- "conflict",
- "unprocessable_entity",
-]);
+export const ErrorCodes = {
+ bad_request: 400,
+ unauthorized: 401,
+ forbidden: 403,
+ exceeded_limit: 403,
+ not_found: 404,
+ conflict: 409,
+ invite_pending: 409,
+ invite_expired: 410,
+ unprocessable_entity: 422,
+ rate_limit_exceeded: 429,
+ internal_server_error: 500,
+} as const;
+
+export const ErrorCode = z.enum(
+ Object.keys(ErrorCodes) as [string, ...string[]],
+);
diff --git a/apps/web/lib/api/errors.ts b/apps/web/lib/api/errors.ts
index f6bec4e708..ec0d40e5c4 100644
--- a/apps/web/lib/api/errors.ts
+++ b/apps/web/lib/api/errors.ts
@@ -4,21 +4,7 @@ import { generateErrorMessage } from "zod-error";
import { ZodOpenApiResponseObject } from "zod-openapi";
import * as z from "zod/v4";
import { logger } from "../axiom/server";
-import { ErrorCode } from "./error-codes";
-
-const errorCodeToHttpStatus: Record<z.infer<typeof ErrorCode>, number> = {
- bad_request: 400,
- unauthorized: 401,
- forbidden: 403,
- exceeded_limit: 403,
- not_found: 404,
- conflict: 409,
- invite_pending: 409,
- invite_expired: 410,
- unprocessable_entity: 422,
- rate_limit_exceeded: 429,
- internal_server_error: 500,
-};
+import { ErrorCode, ErrorCodes } from "./error-codes";
const speakeasyErrorOverrides: Record<z.infer<typeof ErrorCode>, string> = {
bad_request: "BadRequest",
@@ -114,7 +100,7 @@ function handleApiError(error: any): ErrorResponse & { status: number } {
if (error instanceof z.ZodError) {
return {
...fromZodError(error),
- status: errorCodeToHttpStatus.unprocessable_entity,
+ status: ErrorCodes.unprocessable_entity,
};
}
@@ -126,7 +112,7 @@ function handleApiError(error: any): ErrorResponse & { status: number } {
message: error.message,
doc_url: error.docUrl,
},
- status: errorCodeToHttpStatus[error.code],
+ status: ErrorCodes[error.code],
};
}
diff --git a/apps/web/lib/api/users.ts b/apps/web/lib/api/users.ts
index 41259abc78..028931bb52 100644
--- a/apps/web/lib/api/users.ts
+++ b/apps/web/lib/api/users.ts
@@ -53,7 +53,7 @@ export async function inviteUser({
});
const params = new URLSearchParams({
- callbackUrl: `${process.env.NEXTAUTH_URL}/${workspace.slug}?invite=1`,
+ callbackUrl: `${process.env.NEXTAUTH_URL}/${workspace.slug}/invite`,
email,
token,
});
diff --git a/apps/web/lib/middleware/workspaces.ts b/apps/web/lib/middleware/workspaces.ts
index 012d403978..6451475fd9 100644
--- a/apps/web/lib/middleware/workspaces.ts
+++ b/apps/web/lib/middleware/workspaces.ts
@@ -42,13 +42,10 @@ export async function WorkspacesMiddleware(req: NextRequest, user: UserProps) {
);
}
- // Redirect user to the accept invite modal if they have a pending invite
+ // Redirect user to the accept invite page if they have a pending invite
const projectInvite = await prismaEdge.projectInvite.findFirst({
where: {
email: user.email,
- expires: {
- gte: new Date(),
- },
},
select: {
project: {
@@ -61,7 +58,7 @@ export async function WorkspacesMiddleware(req: NextRequest, user: UserProps) {
if (projectInvite) {
return NextResponse.redirect(
- new URL(`/${projectInvite.project.slug}?invite=1`, req.url),
+ new URL(`/${projectInvite.project.slug}/invite`, req.url),
);
}
diff --git a/apps/web/ui/modals/accept-invite-modal.tsx b/apps/web/ui/modals/accept-invite-modal.tsx
deleted file mode 100644
index 5d5eba8261..0000000000
--- a/apps/web/ui/modals/accept-invite-modal.tsx
+++ /dev/null
@@ -1,172 +0,0 @@
-import { mutatePrefix } from "@/lib/swr/mutate";
-import useWorkspace from "@/lib/swr/use-workspace";
-import { Button, Logo, Modal } from "@dub/ui";
-import { useSession } from "next-auth/react";
-import { useParams, useRouter } from "next/navigation";
-import posthog from "posthog-js";
-import {
- Dispatch,
- SetStateAction,
- useCallback,
- useMemo,
- useState,
-} from "react";
-import { toast } from "sonner";
-
-function AcceptInviteModal({
- showAcceptInviteModal,
- setShowAcceptInviteModal,
-}: {
- showAcceptInviteModal: boolean;
- setShowAcceptInviteModal: Dispatch<SetStateAction<boolean>>;
-}) {
- const { slug } = useParams<{ slug: string }>();
- const { error } = useWorkspace();
- const { data: session } = useSession();
- const router = useRouter();
-
- const [accepting, setAccepting] = useState(false);
- const [declining, setDeclining] = useState(false);
-
- const acceptInvite = async () => {
- setAccepting(true);
-
- try {
- const response = await fetch(`/api/workspaces/${slug}/invites/accept`, {
- method: "POST",
- headers: { "Content-Type": "application/json" },
- });
-
- if (!response.ok) {
- const error = await response.json();
- toast.error(error.message || "Failed to accept invite.");
- return;
- }
-
- if (session?.user) {
- posthog.identify(session.user["id"], {
- email: session.user.email,
- name: session.user.name,
- });
- }
-
- posthog.capture("accepted_workspace_invite", {
- workspace: slug,
- });
-
- await mutatePrefix(["/api/workspaces", "/api/programs"]);
- router.replace(`/${slug}`);
- setShowAcceptInviteModal(false);
- toast.success("You now are a part of this workspace!");
- } finally {
- setAccepting(false);
- }
- };
-
- const declineInvite = async () => {
- setDeclining(true);
-
- try {
- const response = await fetch(`/api/workspaces/${slug}/invites/decline`, {
- method: "POST",
- headers: { "Content-Type": "application/json" },
- });
-
- if (!response.ok) {
- const error = await response.json();
- toast.error(error.message || "Failed to decline invite.");
- return;
- }
-
- await mutatePrefix("/api/workspaces");
- router.replace("/workspaces");
- setShowAcceptInviteModal(false);
- toast.success("You have declined the invite.");
- } finally {
- setDeclining(false);
- }
- };
-
- return (
- <Modal
- showModal={showAcceptInviteModal}
- setShowModal={setShowAcceptInviteModal}
- preventDefaultClose
- >
- {error?.status === 409 ? (
- <>
- <div className="flex flex-col items-center justify-center space-y-3 border-b border-neutral-200 px-4 py-4 pt-8 sm:px-16">
- <Logo />
- <h3 className="text-lg font-medium">Workspace Invitation</h3>
- <p className="text-center text-sm text-neutral-500">
- You've been invited to join and collaborate on the{" "}
- <span className="font-mono text-purple-600">
- {slug || "......"}
- </span>{" "}
- workspace on {process.env.NEXT_PUBLIC_APP_NAME}
- </p>
- </div>
- <div className="flex gap-2 bg-neutral-50 px-4 py-8 text-left sm:px-16">
- <Button
- variant="secondary"
- onClick={declineInvite}
- loading={declining}
- text="Decline invite"
- disabled={accepting}
- className="w-fit"
- />
-
- <Button
- onClick={acceptInvite}
- loading={accepting}
- text="Accept invite"
- disabled={declining}
- />
- </div>
- </>
- ) : (
- <>
- <div className="flex flex-col items-center justify-center space-y-3 border-b border-neutral-200 px-4 py-4 pt-8 sm:px-16">
- <Logo />
- <h3 className="text-lg font-medium">
- Workspace Invitation Expired
- </h3>
- <p className="text-center text-sm text-neutral-500">
- This invite has expired or is no longer valid.
- </p>
- </div>
- <div className="flex flex-col space-y-6 bg-neutral-50 px-4 py-8 text-left sm:px-16">
- <Button
- text="Back to dashboard"
- onClick={() => {
- router.push("/");
- setShowAcceptInviteModal(false);
- }}
- />
- </div>
- </>
- )}
- </Modal>
- );
-}
-
-export function useAcceptInviteModal() {
- const [showAcceptInviteModal, setShowAcceptInviteModal] = useState(false);
-
- const AcceptInviteModalCallback = useCallback(() => {
- return (
- <AcceptInviteModal
- showAcceptInviteModal={showAcceptInviteModal}
- setShowAcceptInviteModal={setShowAcceptInviteModal}
- />
- );
- }, [showAcceptInviteModal, setShowAcceptInviteModal]);
-
- return useMemo(
- () => ({
- setShowAcceptInviteModal,
- AcceptInviteModal: AcceptInviteModalCallback,
- }),
- [setShowAcceptInviteModal, AcceptInviteModalCallback],
- );
-}
diff --git a/apps/web/ui/modals/modal-provider.tsx b/apps/web/ui/modals/modal-provider.tsx
index 804f56772b..9d58d39df0 100644
--- a/apps/web/ui/modals/modal-provider.tsx
+++ b/apps/web/ui/modals/modal-provider.tsx
@@ -4,7 +4,6 @@ import { mutatePrefix } from "@/lib/swr/mutate";
import useWorkspace from "@/lib/swr/use-workspace";
import useWorkspaces from "@/lib/swr/use-workspaces";
import { SimpleLinkProps } from "@/lib/types";
-import { useAcceptInviteModal } from "@/ui/modals/accept-invite-modal";
import { useAddEditDomainModal } from "@/ui/modals/add-edit-domain-modal";
import { useAddWorkspaceModal } from "@/ui/modals/add-workspace-modal";
import { useImportBitlyModal } from "@/ui/modals/import-bitly-modal";
@@ -84,8 +83,6 @@ function ModalProviderClient({ children }: { children: ReactNode }) {
const { AddWorkspaceModal, setShowAddWorkspaceModal } =
useAddWorkspaceModal();
- const { AcceptInviteModal, setShowAcceptInviteModal } =
- useAcceptInviteModal();
const { setShowAddEditDomainModal, AddEditDomainModal } =
useAddEditDomainModal();
const { setShowLinkBuilder, LinkBuilder } = useLinkBuilder(
@@ -153,13 +150,6 @@ function ModalProviderClient({ children }: { children: ReactNode }) {
}
}, [hashes, workspaceId]);
- // handle invite and oauth modals
- useEffect(() => {
- if (error && (error.status === 409 || error.status === 410)) {
- setShowAcceptInviteModal(true);
- }
- }, [error]);
-
// handle ?newWorkspace and ?newLink query params
useEffect(() => {
if (searchParams.has("newWorkspace")) {
@@ -210,7 +200,6 @@ function ModalProviderClient({ children }: { children: ReactNode }) {
}}
>
<AddWorkspaceModal />
- <AcceptInviteModal />
<AddEditDomainModal />
<LinkBuilder />
<AddEditTagModal />
diff --git a/packages/ui/src/icons/nucleo/index.ts b/packages/ui/src/icons/nucleo/index.ts
index 050d9bd184..8bf449bcb8 100644
--- a/packages/ui/src/icons/nucleo/index.ts
+++ b/packages/ui/src/icons/nucleo/index.ts
@@ -178,6 +178,7 @@ export * from "./money-bills2";
export * from "./msg";
export * from "./msgs";
export * from "./msgs-dotted";
+export * from "./msgs-fill";
export * from "./note";
export * from "./office-building";
export * from "./page2";
diff --git a/packages/ui/src/icons/nucleo/msgs-fill.tsx b/packages/ui/src/icons/nucleo/msgs-fill.tsx
new file mode 100644
index 0000000000..dbb1397def
--- /dev/null
+++ b/packages/ui/src/icons/nucleo/msgs-fill.tsx
@@ -0,0 +1,26 @@
+import { SVGProps } from "react";
+
+export function MsgsFill(props: SVGProps<SVGSVGElement>) {
+ return (
+ <svg
+ height="18"
+ width="18"
+ viewBox="0 0 18 18"
+ xmlns="http://www.w3.org/2000/svg"
+ {...props}
+ >
+ <g fill="currentColor">
+ <path
+ d="M0.750144 8.24811C0.750144 4.53189 3.76213 1.51971 7.47752 1.51971C9.72359 1.51971 11.7066 2.62469 12.926 4.31153C13.1686 4.64723 13.0932 5.11607 12.7575 5.35873C12.4218 5.60138 11.953 5.52595 11.7103 5.19026C10.7592 3.8745 9.21906 3.01971 7.47752 3.01971C4.59072 3.01971 2.25014 5.36014 2.25014 8.24811C2.25014 9.19752 2.50714 10.0857 2.95215 10.8551C3.11955 11.1695 3.18281 11.5513 3.18367 11.8704C3.18456 12.1998 3.13279 12.5477 3.04455 12.8835C3.01026 13.014 2.96935 13.1468 2.92188 13.2796C2.93032 13.2772 2.93876 13.2748 2.94719 13.2723C3.44691 13.1268 3.8643 12.938 4.08659 12.7937C4.32308 12.6401 4.62573 12.6322 4.86995 12.7731C5.1494 12.9344 5.55723 13.1367 6.0758 13.2825C6.47456 13.3946 6.70694 13.8087 6.59485 14.2075C6.48275 14.6062 6.06862 14.8386 5.66986 14.7265C5.20995 14.5972 4.81844 14.4338 4.50273 14.2773C4.17031 14.4421 3.77417 14.5938 3.36658 14.7125C2.77647 14.8843 2.08958 15.0083 1.45981 14.9744C1.16413 14.9585 0.9055 14.7701 0.799676 14.4935C0.693852 14.217 0.760646 13.9041 0.970163 13.6948C1.22943 13.4359 1.46666 12.9861 1.5938 12.5023C1.65555 12.2673 1.68415 12.0504 1.68368 11.8744C1.68321 11.7022 1.6552 11.6147 1.64341 11.5883C1.07853 10.6048 0.750144 9.46533 0.750144 8.24811Z"
+ fill="currentColor"
+ fillRule="evenodd"
+ />
+ <path
+ d="M12.4449 6.99872C12.4631 6.99738 12.4815 6.9967 12.4999 6.9967C15.1227 6.9967 17.2495 9.12339 17.2495 11.7463C17.2495 12.5976 17.0222 13.3935 16.6323 14.0824C16.63 14.0939 16.6252 14.1227 16.6251 14.1736C16.6249 14.2658 16.6402 14.3892 16.6772 14.5299C16.7547 14.825 16.8965 15.0828 17.0303 15.2168C17.2393 15.4262 17.3057 15.7389 17.1998 16.0152C17.0939 16.2915 16.8354 16.4796 16.54 16.4956C16.0803 16.5205 15.591 16.4301 15.1813 16.3106C14.9411 16.2406 14.7036 16.1534 14.4911 16.0564C14.1966 16.1931 13.8224 16.3304 13.3781 16.415C13.0937 16.4689 12.7991 16.4976 12.4991 16.4976C9.8753 16.4976 7.74951 14.3708 7.74951 11.748C7.74951 9.14318 9.84695 7.02779 12.4449 6.99872Z"
+ fill="currentColor"
+ fillRule="evenodd"
+ />
+ </g>
+ </svg>
+ );
+}