Skip to content

fix: Use /projects as the landing page #72

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jan 26, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 22 additions & 0 deletions site/components/Redirect.test.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import { render, waitFor } from "@testing-library/react"
import singletonRouter from "next/router"
import mockRouter from "next-router-mock"
import React from "react"
import { Redirect } from "./Redirect"

describe("Redirect", () => {
// Reset the router to '/' before every test
beforeEach(() => {
mockRouter.setCurrentUrl("/")
})

it("performs client-side redirect on render", async () => {
// When
render(<Redirect to="/workspaces/v2" />)

// Then
await waitFor(() => {
expect(singletonRouter).toMatchObject({ asPath: "/workspaces/v2" })
})
})
})
23 changes: 23 additions & 0 deletions site/components/Redirect.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import React, { useEffect } from "react"
import { useRouter } from "next/router"

export interface RedirectProps {
/**
* The path to redirect to
* @example '/projects'
*/
to: string
}

/**
* Helper component to perform a client-side redirect
*/
export const Redirect: React.FC<RedirectProps> = ({ to }) => {
const router = useRouter()

useEffect(() => {
void router.replace(to)
}, [])

return null
}
1 change: 1 addition & 0 deletions site/components/index.tsx
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
export * from "./Button"
export * from "./EmptyState"
export * from "./Page"
export * from "./Redirect"
78 changes: 9 additions & 69 deletions site/pages/index.tsx
Original file line number Diff line number Diff line change
@@ -1,78 +1,18 @@
import React from "react"
import Box from "@material-ui/core/Box"
import { makeStyles } from "@material-ui/core/styles"
import Paper from "@material-ui/core/Paper"
import AddWorkspaceIcon from "@material-ui/icons/AddToQueue"

import { EmptyState, SplitButton } from "../components"
import { Navbar } from "../components/Navbar"
import { Footer } from "../components/Page"
import { useUser } from "../contexts/UserContext"
import { Redirect } from "../components"
import { FullScreenLoader } from "../components/Loader/FullScreenLoader"
import { useUser } from "../contexts/UserContext"

const WorkspacesPage: React.FC = () => {
const styles = useStyles()
const { me, signOut } = useUser(true)

if (!me) {
return <FullScreenLoader />
}

const createWorkspace = () => {
alert("create")
}
const IndexPage: React.FC = () => {
const { me } = useUser(/* redirectOnError */ true)

const button = {
children: "New Workspace",
onClick: createWorkspace,
if (me) {
// Once the user is logged in, just redirect them to /projects as the landing page
return <Redirect to="/projects" />
}

return (
<div className={styles.root}>
<Navbar user={me} onSignOut={signOut} />
<div className={styles.header}>
<SplitButton<string>
color="primary"
onClick={createWorkspace}
options={[
{
label: "New workspace",
value: "custom",
},
{
label: "New workspace from template",
value: "template",
},
]}
startIcon={<AddWorkspaceIcon />}
textTransform="none"
/>
</div>

<Paper style={{ maxWidth: "1380px", margin: "1em auto", width: "100%" }}>
<Box pt={4} pb={4}>
<EmptyState message="No workspaces available." button={button} />
</Box>
</Paper>
<Footer />
</div>
)
return <FullScreenLoader />
}

const useStyles = makeStyles((theme) => ({
root: {
display: "flex",
flexDirection: "column",
},
header: {
display: "flex",
flexDirection: "row-reverse",
justifyContent: "space-between",
margin: "1em auto",
maxWidth: "1380px",
padding: theme.spacing(2, 6.25, 0),
width: "100%",
},
}))

export default WorkspacesPage
export default IndexPage