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.

finalize workspace selector

Steven Tey6a710edfdc6d
diff --git a/apps/web/app/app.dub.co/(dashboard)/[slug]/links/[...link]/page-client.tsx b/apps/web/app/app.dub.co/(dashboard)/[slug]/links/[...link]/page-client.tsx
index 079886feeb..5ffe7f2631 100644
--- a/apps/web/app/app.dub.co/(dashboard)/[slug]/links/[...link]/page-client.tsx
+++ b/apps/web/app/app.dub.co/(dashboard)/[slug]/links/[...link]/page-client.tsx
@@ -40,6 +40,7 @@ export function LinkPageClient() {
const domain = linkParts[0];
const slug = linkParts.length > 1 ? linkParts.slice(1).join("/") : "_root";
+ const router = useRouter();
const workspace = useWorkspace();
const { link } = useLink(
@@ -49,6 +50,11 @@ export function LinkPageClient() {
},
{
keepPreviousData: true,
+ onError: (error) => {
+ if (error.status === 401 || error.status === 404) {
+ router.push(`/${workspace.slug}/links`);
+ }
+ },
},
);
diff --git a/apps/web/ui/layout/sidebar/workspace-dropdown.tsx b/apps/web/ui/layout/sidebar/workspace-dropdown.tsx
index 4abccecdd3..c80a247739 100644
--- a/apps/web/ui/layout/sidebar/workspace-dropdown.tsx
+++ b/apps/web/ui/layout/sidebar/workspace-dropdown.tsx
@@ -170,9 +170,8 @@ function WorkspaceList({
setOpenPopover: (open: boolean) => void;
}) {
const { setShowAddWorkspaceModal } = useContext(ModalContext);
- const { domain, key, programId } = useParams() as {
- domain?: string;
- key?: string;
+ const { link, programId } = useParams() as {
+ link: string | string[];
programId?: string;
};
const pathname = usePathname();
@@ -182,15 +181,18 @@ function WorkspaceList({
const href = useCallback(
(slug: string) => {
- if (domain || key || programId || selected.slug === "/") {
- // if we're on a link or program page, navigate back to the workspace root
+ if (link || selected.slug === "/") {
+ // if we're on a link page, navigate back to the workspace root
return `/${slug}`;
+ } else if (programId) {
+ // if we're on a program page, navigate to the program page
+ return `/${slug}/programs`;
} else {
// else, we keep the path but remove all query params
return pathname?.replace(selected.slug, slug).split("?")[0] || "/";
}
},
- [domain, key, programId, pathname, selected.slug],
+ [link, programId, pathname, selected.slug],
);
return (