Skip to content

Commit 0c46cbf

Browse files
authored
fix: Use /projects as the landing page (#72)
Previously, there was a pseudo-workspaces page that was leftover from prototyping, but doesn't make sense in the revised flow. Now, we have a `/projects` page, and after logging in, the user should be taken to that page: ![2022-01-25 20 13 58](https://user-images.githubusercontent.com/88213859/151102949-e756c995-eb43-42db-948d-931c2f0a1fca.gif) This implements a client-side redirect to land on our `/projects` route.
1 parent 3047f25 commit 0c46cbf

File tree

4 files changed

+55
-69
lines changed

4 files changed

+55
-69
lines changed

site/components/Redirect.test.tsx

+22
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
import { render, waitFor } from "@testing-library/react"
2+
import singletonRouter from "next/router"
3+
import mockRouter from "next-router-mock"
4+
import React from "react"
5+
import { Redirect } from "./Redirect"
6+
7+
describe("Redirect", () => {
8+
// Reset the router to '/' before every test
9+
beforeEach(() => {
10+
mockRouter.setCurrentUrl("/")
11+
})
12+
13+
it("performs client-side redirect on render", async () => {
14+
// When
15+
render(<Redirect to="/workspaces/v2" />)
16+
17+
// Then
18+
await waitFor(() => {
19+
expect(singletonRouter).toMatchObject({ asPath: "/workspaces/v2" })
20+
})
21+
})
22+
})

site/components/Redirect.tsx

+23
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
import React, { useEffect } from "react"
2+
import { useRouter } from "next/router"
3+
4+
export interface RedirectProps {
5+
/**
6+
* The path to redirect to
7+
* @example '/projects'
8+
*/
9+
to: string
10+
}
11+
12+
/**
13+
* Helper component to perform a client-side redirect
14+
*/
15+
export const Redirect: React.FC<RedirectProps> = ({ to }) => {
16+
const router = useRouter()
17+
18+
useEffect(() => {
19+
void router.replace(to)
20+
}, [])
21+
22+
return null
23+
}

site/components/index.tsx

+1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
export * from "./Button"
22
export * from "./EmptyState"
33
export * from "./Page"
4+
export * from "./Redirect"

site/pages/index.tsx

+9-69
Original file line numberDiff line numberDiff line change
@@ -1,78 +1,18 @@
11
import React from "react"
2-
import Box from "@material-ui/core/Box"
3-
import { makeStyles } from "@material-ui/core/styles"
4-
import Paper from "@material-ui/core/Paper"
5-
import AddWorkspaceIcon from "@material-ui/icons/AddToQueue"
62

7-
import { EmptyState, SplitButton } from "../components"
8-
import { Navbar } from "../components/Navbar"
9-
import { Footer } from "../components/Page"
10-
import { useUser } from "../contexts/UserContext"
3+
import { Redirect } from "../components"
114
import { FullScreenLoader } from "../components/Loader/FullScreenLoader"
5+
import { useUser } from "../contexts/UserContext"
126

13-
const WorkspacesPage: React.FC = () => {
14-
const styles = useStyles()
15-
const { me, signOut } = useUser(true)
16-
17-
if (!me) {
18-
return <FullScreenLoader />
19-
}
20-
21-
const createWorkspace = () => {
22-
alert("create")
23-
}
7+
const IndexPage: React.FC = () => {
8+
const { me } = useUser(/* redirectOnError */ true)
249

25-
const button = {
26-
children: "New Workspace",
27-
onClick: createWorkspace,
10+
if (me) {
11+
// Once the user is logged in, just redirect them to /projects as the landing page
12+
return <Redirect to="/projects" />
2813
}
2914

30-
return (
31-
<div className={styles.root}>
32-
<Navbar user={me} onSignOut={signOut} />
33-
<div className={styles.header}>
34-
<SplitButton<string>
35-
color="primary"
36-
onClick={createWorkspace}
37-
options={[
38-
{
39-
label: "New workspace",
40-
value: "custom",
41-
},
42-
{
43-
label: "New workspace from template",
44-
value: "template",
45-
},
46-
]}
47-
startIcon={<AddWorkspaceIcon />}
48-
textTransform="none"
49-
/>
50-
</div>
51-
52-
<Paper style={{ maxWidth: "1380px", margin: "1em auto", width: "100%" }}>
53-
<Box pt={4} pb={4}>
54-
<EmptyState message="No workspaces available." button={button} />
55-
</Box>
56-
</Paper>
57-
<Footer />
58-
</div>
59-
)
15+
return <FullScreenLoader />
6016
}
6117

62-
const useStyles = makeStyles((theme) => ({
63-
root: {
64-
display: "flex",
65-
flexDirection: "column",
66-
},
67-
header: {
68-
display: "flex",
69-
flexDirection: "row-reverse",
70-
justifyContent: "space-between",
71-
margin: "1em auto",
72-
maxWidth: "1380px",
73-
padding: theme.spacing(2, 6.25, 0),
74-
width: "100%",
75-
},
76-
}))
77-
78-
export default WorkspacesPage
18+
export default IndexPage

0 commit comments

Comments
 (0)