Skip to content

Commit 0d7ec71

Browse files
committed
Add Redirect component; use on Index page
1 parent 3047f25 commit 0d7ec71

File tree

3 files changed

+27
-69
lines changed

3 files changed

+27
-69
lines changed

site/components/Redirect.tsx

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
import React, { useEffect } from "react"
2+
import { useRouter } from "next/router"
3+
4+
export interface RedirectProps {
5+
to: string
6+
}
7+
8+
export const Redirect: React.FC<RedirectProps> = ({ to }) => {
9+
const router = useRouter()
10+
11+
useEffect(() => {
12+
void router.replace(to)
13+
}, [])
14+
15+
return null
16+
}

site/components/index.tsx

Lines changed: 1 addition & 0 deletions
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

Lines changed: 10 additions & 69 deletions
Original file line numberDiff line numberDiff line change
@@ -1,78 +1,19 @@
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"
4+
import { ErrorSummary } from "../components/ErrorSummary"
115
import { FullScreenLoader } from "../components/Loader/FullScreenLoader"
6+
import { useUser } from "../contexts/UserContext"
127

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-
}
8+
const IndexPage: React.FC = () => {
9+
const { me } = useUser(/* redirectOnError */ true)
2410

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

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-
)
16+
return <FullScreenLoader />
6017
}
6118

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
19+
export default IndexPage

0 commit comments

Comments
 (0)