-
Notifications
You must be signed in to change notification settings - Fork 582
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: Update routes for project page, workspace creation page, and wor…
…kspace page (#415) Some API routes were updated in #401, which impacted the UX - the flow is currently broken when trying to navigate to a project: ![2022-03-08 15 30 59](https://user-images.githubusercontent.com/88213859/157343533-3d08edf1-70d5-433b-b4a0-fe68875b1928.gif) This fixes all the routes so that the complete project -> create workspace -> workspace page flow works: ![2022-03-08 16 18 57](https://user-images.githubusercontent.com/88213859/157348186-b9bde553-c602-484e-89bc-208a1d97f703.gif) Because this had to touch a bunch of UI routes, I also opportunistically fixed #380 as part of this change. Fixes #380
- Loading branch information
1 parent
ac387a1
commit 9f19041
Showing
9 changed files
with
152 additions
and
97 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
import React from "react" | ||
import useSWR from "swr" | ||
import { makeStyles } from "@material-ui/core/styles" | ||
import { useRouter } from "next/router" | ||
import { Navbar } from "../../components/Navbar" | ||
import { Footer } from "../../components/Page" | ||
import { useUser } from "../../contexts/UserContext" | ||
import { firstOrItem } from "../../util/array" | ||
import { ErrorSummary } from "../../components/ErrorSummary" | ||
import { FullScreenLoader } from "../../components/Loader/FullScreenLoader" | ||
import { Workspace } from "../../components/Workspace" | ||
import { unsafeSWRArgument } from "../../util" | ||
import * as API from "../../api" | ||
|
||
const WorkspacesPage: React.FC = () => { | ||
const styles = useStyles() | ||
const router = useRouter() | ||
const { me, signOut } = useUser(true) | ||
|
||
const { workspace: workspaceQueryParam } = router.query | ||
|
||
const { data: workspace, error: workspaceError } = useSWR<API.Workspace, Error>(() => { | ||
const workspaceParam = firstOrItem(workspaceQueryParam, null) | ||
|
||
return `/api/v2/workspaces/${workspaceParam}` | ||
}) | ||
|
||
// Fetch parent project | ||
const { data: project, error: projectError } = useSWR<API.Project, Error>(() => { | ||
return `/api/v2/projects/${unsafeSWRArgument(workspace).project_id}` | ||
}) | ||
|
||
const { data: organization, error: organizationError } = useSWR<API.Project, Error>(() => { | ||
return `/api/v2/organizations/${unsafeSWRArgument(project).organization_id}` | ||
}) | ||
|
||
if (workspaceError) { | ||
return <ErrorSummary error={workspaceError} /> | ||
} | ||
|
||
if (projectError) { | ||
return <ErrorSummary error={projectError} /> | ||
} | ||
|
||
if (organizationError) { | ||
return <ErrorSummary error={organizationError} /> | ||
} | ||
|
||
if (!me || !workspace || !project || !organization) { | ||
return <FullScreenLoader /> | ||
} | ||
|
||
return ( | ||
<div className={styles.root}> | ||
<Navbar user={me} onSignOut={signOut} /> | ||
|
||
<div className={styles.inner}> | ||
<Workspace organization={organization} project={project} workspace={workspace} /> | ||
</div> | ||
|
||
<Footer /> | ||
</div> | ||
) | ||
} | ||
|
||
const useStyles = makeStyles(() => ({ | ||
root: { | ||
display: "flex", | ||
flexDirection: "column", | ||
}, | ||
inner: { | ||
maxWidth: "1380px", | ||
margin: "1em auto", | ||
width: "100%", | ||
}, | ||
})) | ||
|
||
export default WorkspacesPage |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
export * from "./array" | ||
export * from "./swr" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
/** | ||
* unsafeSWRArgument | ||
* | ||
* Helper function for working with SWR / useSWR in the TypeScript world. | ||
* TypeScript is helpful in enforcing type-safety, but SWR is designed to | ||
* with the expectation that, if the argument is not available, an exception | ||
* will be thrown. | ||
* | ||
* This just helps in abiding by those rules, explicitly, and lets us suppress | ||
* the lint warning in a single place. | ||
*/ | ||
export const unsafeSWRArgument = <T>(arg: T | null | undefined): T => { | ||
if (typeof arg === "undefined" || arg === null) { | ||
throw "SWR: Expected exception because the argument is not available" | ||
} | ||
return arg | ||
} |