diff --git a/apps/web/src/routes/dashboard/index.tsx b/apps/web/src/routes/dashboard/index.tsx index 0a5c8aa..ec351d0 100644 --- a/apps/web/src/routes/dashboard/index.tsx +++ b/apps/web/src/routes/dashboard/index.tsx @@ -508,21 +508,29 @@ function NewProjectDialog(props: { onCreated: () => void }) { setPending(true); setError(null); - const project = await createProjectServerFn({ - data: { name, slug }, - }); + try { + const project = await createProjectServerFn({ + data: { name, slug }, + }); - setPending(false); + if (!project) { + setError("Unable to create project. Please try again."); + return; + } - if (!project) { - setError("Unable to create project. Please try again."); - return; + setName(""); + setSlug(""); + setOpen(false); + props.onCreated(); + } catch (cause) { + setError( + cause instanceof Error + ? cause.message + : "Unable to create project. Please try again.", + ); + } finally { + setPending(false); } - - setName(""); - setSlug(""); - setOpen(false); - props.onCreated(); } return ( diff --git a/apps/web/src/routes/dashboard/route.tsx b/apps/web/src/routes/dashboard/route.tsx index b79cde8..b845995 100644 --- a/apps/web/src/routes/dashboard/route.tsx +++ b/apps/web/src/routes/dashboard/route.tsx @@ -78,6 +78,7 @@ function DashboardLayout() { const { user, hasWorkspace } = useRouteContext({ from: "/dashboard" }); const navigate = useNavigate(); const [profileOpen, setProfileOpen] = useState(false); + const [workspaceOpen, setWorkspaceOpen] = useState(false); const orgQuery = useQuery(organizationQueryOptions()); const projectsQuery = useQuery({ ...projectsQueryOptions(), @@ -88,11 +89,11 @@ function DashboardLayout() { const currentPath = typeof window === "undefined" ? "" - : window.location.pathname; - const currentSearch = typeof window === "undefined" - ? new URLSearchParams() - : new URLSearchParams(window.location.search); - const currentProjectId = currentSearch.get("projectId") ?? ""; + : window.location.pathname.replace(/\/$/, ""); + const rawSearch = typeof window === "undefined" + ? "" + : window.location.search; + const currentProjectId = new URLSearchParams(rawSearch).get("projectId") ?? ""; useEffect(() => { if (!hasWorkspace) { @@ -131,18 +132,18 @@ function DashboardLayout() { return; } - const params = new URLSearchParams(currentSearch); + const params = new URLSearchParams(rawSearch); params.set("projectId", preferredProjectId); if (currentPath === "/dashboard/analytics" && !params.get("range")) { params.set("range", "30d"); } - window.history.replaceState({}, "", `${currentPath}?${params.toString()}`); - window.dispatchEvent(new PopStateEvent("popstate")); + window.history.replaceState(window.history.state, "", `${currentPath}?${params.toString()}`); + window.dispatchEvent(new PopStateEvent("popstate", { state: window.history.state })); } }, [ currentPath, currentProjectId, - currentSearch, + rawSearch, hasWorkspace, navigate, organization, @@ -154,7 +155,7 @@ function DashboardLayout() { writeStoredProjectId(organization.id, projectId); } - const params = new URLSearchParams(currentSearch); + const params = new URLSearchParams(rawSearch); if (projectId) { params.set("projectId", projectId); } else { @@ -166,8 +167,8 @@ function DashboardLayout() { } const query = params.toString(); - window.history.replaceState({}, "", query ? `${currentPath}?${query}` : currentPath); - window.dispatchEvent(new PopStateEvent("popstate")); + window.history.replaceState(window.history.state, "", query ? `${currentPath}?${query}` : currentPath); + window.dispatchEvent(new PopStateEvent("popstate", { state: window.history.state })); } return ( @@ -281,21 +282,58 @@ function DashboardLayout() {
- {organization?.name ?? "Create workspace"} -
-- {organization?.slug ?? "Workspace required before creating a project"} -
-+ {organization?.name ?? "No workspace"} +
++ {organization?.slug ?? ""} +
++ {organization?.name ?? "Create workspace"} +
++ {organization?.slug ?? "Workspace required"} +
+