- Notifications
You must be signed in to change notification settings - Fork1k
feat: Add Create Workspace Form#73
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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.
Already on GitHub?Sign in to your account
Merged
Uh oh!
There was an error while loading.Please reload this page.
Merged
Changes fromall commits
Commits
Show all changes
11 commits Select commitHold shift + click to select a range
f3ca520
Add CreateWorkspaceForm
bryphe-coder8cca73e
bump
bryphe-coder07313e9
Clean-up
bryphe-coder1728d93
Fix mutate timing
bryphe-coderbe12ef4
Formatting
bryphe-coder08207a2
Merge branch 'main' into bryphe/feat/38/create-workspace-page
bryphe-coder1758460
Merge branch 'main' into bryphe/feat/38/create-workspace-page
bryphe-coderdd9a88d
Merge branch 'main' into bryphe/feat/38/create-workspace-page
bryphe-coderc3e2a0f
Merge branch 'main' into bryphe/feat/38/create-workspace-page
bryphe-coder0528a94
Add CreateWorkspaceForm component
bryphe-coderd45c4bf
Merge branch 'main' into bryphe/feat/38/create-workspace-page
bryphe-coderFile filter
Filter by extension
Conversations
Failed to load comments.
Loading
Uh oh!
There was an error while loading.Please reload this page.
Jump to
Jump to file
Failed to load files.
Loading
Uh oh!
There was an error while loading.Please reload this page.
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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,20 @@ | ||
import { render, screen } from "@testing-library/react" | ||
import React from "react" | ||
import { CreateWorkspaceForm } from "./CreateWorkspaceForm" | ||
import { MockProject, MockWorkspace } from "./../test_helpers" | ||
describe("CreateWorkspaceForm", () => { | ||
it("renders", async () => { | ||
// Given | ||
const onSubmit = () => Promise.resolve(MockWorkspace) | ||
const onCancel = () => Promise.resolve() | ||
// When | ||
render(<CreateWorkspaceForm project={MockProject} onSubmit={onSubmit} onCancel={onCancel} />) | ||
// Then | ||
// Simple smoke test to verify form renders | ||
const element = await screen.findByText("Create Workspace") | ||
expect(element).toBeDefined() | ||
}) | ||
}) |
This file contains hidden or 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,97 @@ | ||
import Button from "@material-ui/core/Button" | ||
import { makeStyles } from "@material-ui/core/styles" | ||
import { FormikContextType, useFormik } from "formik" | ||
import React from "react" | ||
import * as Yup from "yup" | ||
import { FormTextField, FormTitle, FormSection } from "../components/Form" | ||
import { LoadingButton } from "../components/Button" | ||
import { Project, Workspace, CreateWorkspaceRequest } from "../api" | ||
export interface CreateWorkspaceForm { | ||
project: Project | ||
onSubmit: (request: CreateWorkspaceRequest) => Promise<Workspace> | ||
onCancel: () => void | ||
} | ||
const validationSchema = Yup.object({ | ||
name: Yup.string().required("Name is required"), | ||
}) | ||
export const CreateWorkspaceForm: React.FC<CreateWorkspaceForm> = ({ project, onSubmit, onCancel }) => { | ||
const styles = useStyles() | ||
const form: FormikContextType<{ name: string }> = useFormik<{ name: string }>({ | ||
initialValues: { | ||
name: "", | ||
}, | ||
enableReinitialize: true, | ||
validationSchema: validationSchema, | ||
onSubmit: ({ name }) => { | ||
return onSubmit({ | ||
project_id: project.id, | ||
name: name, | ||
}) | ||
}, | ||
}) | ||
return ( | ||
<div className={styles.root}> | ||
<FormTitle | ||
title="Create Workspace" | ||
detail={ | ||
<span> | ||
for project <strong>{project.name}</strong> | ||
</span> | ||
} | ||
/> | ||
<FormSection title="Name"> | ||
<FormTextField | ||
form={form} | ||
formFieldName="name" | ||
fullWidth | ||
helperText="A unique name describing your workspace." | ||
label="Workspace Name" | ||
placeholder="my-workspace" | ||
required | ||
/> | ||
</FormSection> | ||
<div className={styles.footer}> | ||
<Button className={styles.button} onClick={onCancel} variant="outlined"> | ||
Cancel | ||
</Button> | ||
<LoadingButton | ||
loading={form.isSubmitting} | ||
className={styles.button} | ||
onClick={form.submitForm} | ||
variant="contained" | ||
color="primary" | ||
type="submit" | ||
> | ||
Submit | ||
</LoadingButton> | ||
</div> | ||
</div> | ||
) | ||
} | ||
const useStyles = makeStyles(() => ({ | ||
root: { | ||
maxWidth: "1380px", | ||
width: "100%", | ||
display: "flex", | ||
flexDirection: "column", | ||
alignItems: "center", | ||
}, | ||
footer: { | ||
display: "flex", | ||
flex: "0", | ||
flexDirection: "row", | ||
justifyContent: "center", | ||
alignItems: "center", | ||
}, | ||
button: { | ||
margin: "1em", | ||
}, | ||
})) |
This file contains hidden or 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,56 @@ | ||
import React from "react" | ||
import { makeStyles } from "@material-ui/core/styles" | ||
import { useRouter } from "next/router" | ||
import useSWR from "swr" | ||
import * as API from "../../../../api" | ||
import { useUser } from "../../../../contexts/UserContext" | ||
import { ErrorSummary } from "../../../../components/ErrorSummary" | ||
import { FullScreenLoader } from "../../../../components/Loader/FullScreenLoader" | ||
import { CreateWorkspaceForm } from "../../../../forms/CreateWorkspaceForm" | ||
const CreateWorkspacePage: React.FC = () => { | ||
const router = useRouter() | ||
const styles = useStyles() | ||
const { me } = useUser(/* redirectOnError */ true) | ||
const { organization, project: projectName } = router.query | ||
const { data: project, error: projectError } = useSWR<API.Project, Error>( | ||
`/api/v2/projects/${organization}/${projectName}`, | ||
) | ||
if (projectError) { | ||
return <ErrorSummary error={projectError} /> | ||
} | ||
if (!me || !project) { | ||
return <FullScreenLoader /> | ||
} | ||
const onCancel = async () => { | ||
await router.push(`/projects/${organization}/${project}`) | ||
} | ||
const onSubmit = async (req: API.CreateWorkspaceRequest) => { | ||
const workspace = await API.Workspace.create(req) | ||
await router.push(`/workspaces/${workspace.id}`) | ||
return workspace | ||
} | ||
return ( | ||
<div className={styles.root}> | ||
<CreateWorkspaceForm onCancel={onCancel} onSubmit={onSubmit} project={project} /> | ||
</div> | ||
) | ||
} | ||
const useStyles = makeStyles((theme) => ({ | ||
root: { | ||
display: "flex", | ||
flexDirection: "column", | ||
alignItems: "center", | ||
height: "100vh", | ||
backgroundColor: theme.palette.background.paper, | ||
}, | ||
})) | ||
export default CreateWorkspacePage |
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.