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.

fix invite teammate flow

Steven Teybb02223cf507
diff --git a/apps/web/lib/api/users.ts b/apps/web/lib/api/users.ts
index 2bf3905cc1..21d1bdcb68 100644
--- a/apps/web/lib/api/users.ts
+++ b/apps/web/lib/api/users.ts
@@ -52,7 +52,7 @@ export async function inviteUser({
});
const params = new URLSearchParams({
- callbackUrl: `${process.env.NEXTAUTH_URL}/${workspace.slug}?invite=true`,
+ callbackUrl: `${process.env.NEXTAUTH_URL}/${workspace.slug}?invite=1`,
email,
token,
});
diff --git a/apps/web/lib/middleware/app.ts b/apps/web/lib/middleware/app.ts
index eab8091951..e5c9b03315 100644
--- a/apps/web/lib/middleware/app.ts
+++ b/apps/web/lib/middleware/app.ts
@@ -11,7 +11,8 @@ import WorkspacesMiddleware from "./workspaces";
export default async function AppMiddleware(req: NextRequest) {
const { path, fullPath } = parse(req);
const user = await getUserViaToken(req);
- const isWorkspaceInvite = req.nextUrl.searchParams.get("invite");
+ const isWorkspaceInvite =
+ req.nextUrl.searchParams.get("invite") || path.startsWith("/invites/");
// if there's no user and the path isn't /login or /register, redirect to /login
if (
@@ -47,6 +48,7 @@ export default async function AppMiddleware(req: NextRequest) {
new Date(user.createdAt).getTime() > Date.now() - 60 * 60 * 24 * 1000 &&
!isWorkspaceInvite &&
!path.startsWith("/onboarding") &&
+ !(await getDefaultWorkspace(user)) &&
(await getOnboardingStep(user)) !== "completed"
) {
let step = await getOnboardingStep(user);
diff --git a/apps/web/ui/modals/accept-invite-modal.tsx b/apps/web/ui/modals/accept-invite-modal.tsx
index 03ff173d9b..18be07adcd 100644
--- a/apps/web/ui/modals/accept-invite-modal.tsx
+++ b/apps/web/ui/modals/accept-invite-modal.tsx
@@ -1,8 +1,7 @@
import useWorkspace from "@/lib/swr/use-workspace";
-import { LoadingDots, Logo, Modal } from "@dub/ui";
+import { Button, Logo, Modal } from "@dub/ui";
import { useSession } from "next-auth/react";
-import Link from "next/link";
-import { useParams } from "next/navigation";
+import { useParams, useRouter } from "next/navigation";
import posthog from "posthog-js";
import {
Dispatch,
@@ -25,7 +24,7 @@ function AcceptInviteModal({
const [accepting, setAccepting] = useState(false);
const { error } = useWorkspace();
const { data: session } = useSession();
-
+ const router = useRouter();
return (
<Modal
showModal={showAcceptInviteModal}
@@ -46,7 +45,7 @@ function AcceptInviteModal({
</p>
</div>
<div className="flex flex-col space-y-6 bg-gray-50 px-4 py-8 text-left sm:px-16">
- <button
+ <Button
onClick={() => {
setAccepting(true);
fetch(`/api/workspaces/${slug}/invites/accept`, {
@@ -66,19 +65,14 @@ function AcceptInviteModal({
mutate("/api/workspaces"),
mutate(`/api/workspaces/${slug}`),
]);
+ router.replace(`/${slug}`);
setShowAcceptInviteModal(false);
toast.success("You now are a part of this workspace!");
});
}}
- disabled={accepting}
- className={`${
- accepting
- ? "cursor-not-allowed border-gray-200 bg-gray-100 text-gray-400"
- : "border-black bg-black text-white hover:bg-white hover:text-black"
- } flex h-10 w-full items-center justify-center rounded-md border text-sm transition-all focus:outline-none`}
- >
- {accepting ? <LoadingDots /> : <p>Accept invite</p>}
- </button>
+ loading={accepting}
+ text="Accept invite"
+ />
</div>
</>
) : (
@@ -93,12 +87,13 @@ function AcceptInviteModal({
</p>
</div>
<div className="flex flex-col space-y-6 bg-gray-50 px-4 py-8 text-left sm:px-16">
- <Link
- href="/"
- className="flex h-10 w-full items-center justify-center rounded-md border border-black bg-black text-sm text-white transition-all hover:bg-white hover:text-black focus:outline-none"
- >
- Back to dashboard
- </Link>
+ <Button
+ text="Back to dashboard"
+ onClick={() => {
+ router.push("/");
+ setShowAcceptInviteModal(false);
+ }}
+ />
</div>
</>
)}
diff --git a/apps/web/ui/modals/modal-provider.tsx b/apps/web/ui/modals/modal-provider.tsx
index 9834b26e53..320a487eea 100644
--- a/apps/web/ui/modals/modal-provider.tsx
+++ b/apps/web/ui/modals/modal-provider.tsx
@@ -145,10 +145,8 @@ function ModalProviderClient({ children }: { children: ReactNode }) {
// handle invite and oauth modals
useEffect(() => {
- if (error && (error.status === 409 || error.status === 410)) {
- setShowAcceptInviteModal(true);
- }
- }, [error]);
+ setShowAcceptInviteModal(true);
+ }, []);
// handle ?newWorkspace and ?newLink query params
useEffect(() => {
diff --git a/apps/web/ui/workspaces/invite-teammates-form.tsx b/apps/web/ui/workspaces/invite-teammates-form.tsx
index 4587dc0502..f37cf265ad 100644
--- a/apps/web/ui/workspaces/invite-teammates-form.tsx
+++ b/apps/web/ui/workspaces/invite-teammates-form.tsx
@@ -71,10 +71,9 @@ export function InviteTeammatesForm({
() => <InviteSavedToast teammates={teammates.length} />,
{ duration: 7000 },
);
- } else
+ } else {
toast.success(`${pluralize("Invitation", teammates.length)} sent!`);
- if (!saveOnly) {
teammates.forEach(({ email }) =>
posthog.capture("teammate_invited", {
workspace: slug,