The modern link attribution platform. Loved by world-class engineering teams at Twilio, Zillow, Jobber, Vercel, Raycast, and more.
TypeScript clickhousemysqlnextjsopen-sourceplanetscaleprismatailwindcsstinybirdtypescriptupstashvercel
add create workspace modal to OAuth flow
Steven Tey03c2baef9af3
diff --git a/apps/web/app/app.dub.co/(auth)/oauth/authorize/authorize-form.tsx b/apps/web/app/app.dub.co/(auth)/oauth/authorize/authorize-form.tsxindex 2d41a6c302..db95326bab 100644--- a/apps/web/app/app.dub.co/(auth)/oauth/authorize/authorize-form.tsx+++ b/apps/web/app/app.dub.co/(auth)/oauth/authorize/authorize-form.tsx@@ -3,7 +3,9 @@import useWorkspaces from "@/lib/swr/use-workspaces";import z from "@/lib/zod";import { authorizeRequestSchema } from "@/lib/zod/schemas/oauth";+import { useAddWorkspaceModal } from "@/ui/modals/add-workspace-modal";import { Button, InputSelect, InputSelectItemProps } from "@dub/ui";+import { OfficeBuilding } from "@dub/ui/src/icons";import { DICEBEAR_AVATAR_URL } from "@dub/utils";import { useSession } from "next-auth/react";import { useEffect, useMemo, useState } from "react";@@ -24,6 +26,8 @@ export const AuthorizeForm = ({}: AuthorizeFormProps) => {const { data: session } = useSession();const { workspaces } = useWorkspaces();+ const { AddWorkspaceModal, setShowAddWorkspaceModal } =+ useAddWorkspaceModal();const [submitting, setSubmitting] = useState(false);const [selectedWorkspace, setSelectedWorkspace] =useState<InputSelectItemProps | null>(null);@@ -91,52 +95,64 @@ export const AuthorizeForm = ({};return (- <form onSubmit={onAuthorize}>- <input type="hidden" name="client_id" value={client_id} />- <input type="hidden" name="redirect_uri" value={redirect_uri} />- <input type="hidden" name="response_type" value={response_type} />- <input type="hidden" name="scope" value={scope.join(",")} />- {state && <input type="hidden" name="state" value={state} />}- {code_challenge && (- <input type="hidden" name="code_challenge" value={code_challenge} />- )}- {code_challenge_method && (- <input- type="hidden"- name="code_challenge_method"- value={code_challenge_method}- />- )}- <p className="text-sm text-gray-500">- Select a workspace to grant API access to- </p>- <div className="max-w-md py-2">- <InputSelect- items={selectOptions}- selectedItem={selectedWorkspace}- setSelectedItem={setSelectedWorkspace}- adjustForMobile- disabled={submitting}- />- </div>- <div className="mt-4 flex justify-between gap-4">- <Button- text="Decline"- type="button"- onClick={onDecline}- variant="secondary"- disabled={submitting}- />- <Button- text="Authorize"- type="submit"- loading={submitting}- disabled={!selectedWorkspace}- disabledTooltip={- !selectedWorkspace ? "Please select a workspace to continue" : ""- }- />- </div>- </form>+ <>+ <AddWorkspaceModal />+ <form onSubmit={onAuthorize}>+ <input type="hidden" name="client_id" value={client_id} />+ <input type="hidden" name="redirect_uri" value={redirect_uri} />+ <input type="hidden" name="response_type" value={response_type} />+ <input type="hidden" name="scope" value={scope.join(",")} />+ {state && <input type="hidden" name="state" value={state} />}+ {code_challenge && (+ <input type="hidden" name="code_challenge" value={code_challenge} />+ )}+ {code_challenge_method && (+ <input+ type="hidden"+ name="code_challenge_method"+ value={code_challenge_method}+ />+ )}+ <p className="text-sm text-gray-500">+ Select a workspace to grant API access to+ </p>+ <div className="max-w-md py-2">+ <InputSelect+ items={selectOptions}+ selectedItem={selectedWorkspace}+ setSelectedItem={setSelectedWorkspace}+ adjustForMobile+ disabled={submitting}+ noItemsElement={+ <Button+ icon={<OfficeBuilding className="size-4" />}+ text="Create new workspace"+ variant="outline"+ onClick={() => setShowAddWorkspaceModal(true)}+ className="justify-start text-gray-700"+ />+ }+ />+ </div>+ <div className="mt-4 flex justify-between gap-4">+ <Button+ text="Decline"+ type="button"+ onClick={onDecline}+ variant="secondary"+ disabled={submitting}+ />+ <Button+ text="Authorize"+ type="submit"+ loading={submitting}+ disabled={!selectedWorkspace}+ disabledTooltip={+ !selectedWorkspace ? "Please select a workspace to continue" : ""+ }+ />+ </div>+ </form>+ </>);};diff --git a/apps/web/ui/layout/workspace-switcher.tsx b/apps/web/ui/layout/workspace-switcher.tsxindex a1999bde86..7cd0a3d0c3 100644--- a/apps/web/ui/layout/workspace-switcher.tsx+++ b/apps/web/ui/layout/workspace-switcher.tsx@@ -5,8 +5,9 @@ import { PlanProps, WorkspaceProps } from "@/lib/types";import { ModalContext } from "@/ui/modals/modal-provider";import PlanBadge from "@/ui/workspaces/plan-badge";import { BlurImage, Popover, Tick } from "@dub/ui";+import { OfficeBuilding } from "@dub/ui/src/icons";import { DICEBEAR_AVATAR_URL } from "@dub/utils";-import { ChevronsUpDown, PlusCircle } from "lucide-react";+import { ChevronsUpDown } from "lucide-react";import { useSession } from "next-auth/react";import Link from "next/link";import { useParams, usePathname } from "next/navigation";@@ -154,7 +155,7 @@ function WorkspaceList({return (<Linkkey={slug}- className={`relative flex w-full items-center space-x-2 rounded-md px-2 py-1.5 hover:bg-gray-100 active:bg-gray-200 ${+ className={`relative flex w-full items-center gap-x-2 rounded-md px-2 py-1.5 hover:bg-gray-100 active:bg-gray-200 ${selected.slug === slug ? "font-medium" : ""} transition-all duration-75`}href={href(slug)}@@ -166,7 +167,7 @@ function WorkspaceList({width={20}height={20}alt={id}- className="h-7 w-7 shrink-0 overflow-hidden rounded-full"+ className="size-7 shrink-0 overflow-hidden rounded-full"/><spanclassName={`block truncate text-sm sm:max-w-[140px] ${@@ -177,7 +178,7 @@ function WorkspaceList({</span>{selected.slug === slug ? (<span className="absolute inset-y-0 right-0 flex items-center pr-3 text-black">- <Tick className="h-5 w-5" aria-hidden="true" />+ <Tick className="size-5" aria-hidden="true" /></span>) : null}</Link>@@ -189,10 +190,12 @@ function WorkspaceList({setOpenPopover(false);setShowAddWorkspaceModal(true);}}- className="flex w-full cursor-pointer items-center space-x-2 rounded-md p-2 transition-all duration-75 hover:bg-gray-100"+ className="group flex w-full cursor-pointer items-center gap-x-2 rounded-md p-2 transition-all duration-75 hover:bg-gray-100">- <PlusCircle className="h-6 w-6 text-gray-500" />- <span className="block truncate">Add a new workspace</span>+ <div className="flex size-7 items-center justify-center rounded-full border border-gray-200 bg-gradient-to-t from-gray-100 group-hover:bg-white">+ <OfficeBuilding className="size-4 text-gray-700" />+ </div>+ <span className="block truncate">Create new workspace</span></button></div>);diff --git a/apps/web/ui/modals/add-workspace-modal.tsx b/apps/web/ui/modals/add-workspace-modal.tsxindex f071429929..36a71c09e2 100644--- a/apps/web/ui/modals/add-workspace-modal.tsx+++ b/apps/web/ui/modals/add-workspace-modal.tsx@@ -56,6 +56,7 @@ function AddWorkspaceModalHelper({}, [name]);const welcomeFlow = pathname === "/welcome";+ const oauthFlow = pathname.startsWith("/oauth/authorize");const searchParams = useSearchParams();const { queryParams } = useRouterStuff();@@ -113,6 +114,9 @@ function AddWorkspaceModalHelper({await mutate("/api/workspaces");if (welcomeFlow) {router.push(`/welcome?step=upgrade&slug=${slug}`);+ } else if (oauthFlow) {+ router.refresh();+ setShowAddWorkspaceModal(false);} else {router.push(`/${slug}`);toast.success("Successfully created workspace!");