Skip to content

Commit

Permalink
fix: Use /projects as the landing page (#72)
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
bryphe-coder committed Jan 26, 2022
1 parent 3047f25 commit 0c46cbf
Show file tree
Hide file tree
Showing 4 changed files with 55 additions and 69 deletions.
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

0 comments on commit 0c46cbf

Please sign in to comment.