-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Can post new jobs through the jobs form and do GraphQL mutations
Also add specific react-error-overlay dependency to fix facebook/create-react-app#11773 (comment)
- Loading branch information
1 parent
0967b24
commit ddb57d1
Showing
7 changed files
with
86 additions
and
71 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains 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 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 |
---|---|---|
@@ -1,65 +1,48 @@ | ||
import React, { Component } from "react"; | ||
import React from "react"; | ||
import { postNewJob } from "./requests"; | ||
import { useHistory } from "react-router-dom"; | ||
|
||
export class JobForm extends Component { | ||
constructor(props) { | ||
super(props); | ||
this.state = { title: "", description: "" }; | ||
} | ||
|
||
handleChange(event) { | ||
const { name, value } = event.target; | ||
this.setState({ [name]: value }); | ||
} | ||
|
||
handleClick(event) { | ||
export function JobForm() { | ||
const history = useHistory(); | ||
async function handleSubmit(event) { | ||
event.preventDefault(); | ||
console.log("should post a new job:", this.state); | ||
const { | ||
title: { value: titleValue }, | ||
description: { value: descriptionValue }, | ||
} = event.target; | ||
const { id } = await postNewJob(titleValue, descriptionValue); | ||
history.push(`/jobs/${id}`); | ||
} | ||
|
||
render() { | ||
const { title, description } = this.state; | ||
return ( | ||
<div> | ||
<h1 className="title">New Job</h1> | ||
<div className="box"> | ||
<form> | ||
<div className="field"> | ||
<label className="label">Title</label> | ||
<div className="control"> | ||
<input | ||
className="input" | ||
type="text" | ||
name="title" | ||
value={title} | ||
onChange={this.handleChange.bind(this)} | ||
/> | ||
</div> | ||
return ( | ||
<div> | ||
<h1 className="title">New Job</h1> | ||
<div className="box"> | ||
<form onSubmit={handleSubmit}> | ||
<div className="field"> | ||
<label className="label">Title</label> | ||
<div className="control"> | ||
<input className="input" type="text" name="title" id="title" /> | ||
</div> | ||
<div className="field"> | ||
<label className="label">Description</label> | ||
<div className="control"> | ||
<textarea | ||
className="input" | ||
style={{ height: "10em" }} | ||
name="description" | ||
value={description} | ||
onChange={this.handleChange.bind(this)} | ||
/> | ||
</div> | ||
</div> | ||
<div className="field"> | ||
<label className="label">Description</label> | ||
<div className="control"> | ||
<textarea | ||
className="input" | ||
style={{ height: "10em" }} | ||
name="description" | ||
id="description" | ||
/> | ||
</div> | ||
<div className="field"> | ||
<div className="control"> | ||
<button | ||
className="button is-link" | ||
onClick={this.handleClick.bind(this)} | ||
> | ||
Submit | ||
</button> | ||
</div> | ||
</div> | ||
<div className="field"> | ||
<div className="control"> | ||
<input type="submit" className="button is-link" /> | ||
</div> | ||
</form> | ||
</div> | ||
</div> | ||
</form> | ||
</div> | ||
); | ||
} | ||
</div> | ||
); | ||
} |
This file contains 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 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 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 |
---|---|---|
@@ -1,18 +1,24 @@ | ||
const db = require("./db"); | ||
|
||
const Query = { | ||
job: (root, args) => db.jobs.get(args.id), | ||
job: (parent, args) => db.jobs.get(args.id), | ||
jobs: () => db.jobs.list(), | ||
company: (root, args) => db.companies.get(args.id), | ||
company: (parent, args) => db.companies.get(args.id), | ||
}; | ||
|
||
const Mutation = { | ||
createJob: (parent, { newJob }) => { | ||
const newJobId = db.jobs.create(newJob); | ||
return db.jobs.get(newJobId); | ||
}, | ||
}; | ||
|
||
const Job = { | ||
company: (job) => db.companies.get(job.companyId), | ||
company: (parent) => db.companies.get(parent.companyId), | ||
}; | ||
|
||
const Company = { | ||
jobs: (company) => | ||
db.jobs.list().filter((job) => job.companyId === company.id), | ||
jobs: (parent) => db.jobs.list().filter((job) => job.companyId === parent.id), | ||
}; | ||
|
||
module.exports = { Company, Job, Query }; | ||
module.exports = { Company, Job, Query, Mutation }; |
This file contains 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