Skip to content
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

Master #4

Open
wants to merge 16 commits into
base: implement-design-and-routing
Choose a base branch
from
Open
Show file tree
Hide file tree
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
59 changes: 43 additions & 16 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
"@fortawesome/free-solid-svg-icons": "^5.6.0",
"@fortawesome/react-fontawesome": "^0.1.3",
"date-fns": "^1.30.1",
"prop-types": "^15.7.2",
"react": "^16.6.3",
"react-dom": "^16.6.3",
"react-router-dom": "^4.3.1",
Expand Down
8 changes: 8 additions & 0 deletions src/AddFolder/AddFolder.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@

.AddFolder {
color: #dedede;
}

.AddFolder h2 {
margin-left: 16px;
}
72 changes: 72 additions & 0 deletions src/AddFolder/AddFolder.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
import React, { Component } from 'react'
import NotefulForm from '../NotefulForm/NotefulForm'
import ErrorMessage from '../ErrorMessage'
import ApiContext from '../ApiContext'
import config from '../config'
import './AddFolder.css'

export default class AddFolder extends Component {
state = {
errorMessage: "",
}

static defaultProps = {
history: {
push: () => { }
},
}
static contextType = ApiContext;

handleSubmit = e => {
e.preventDefault()
const folder = {
folder_name: e.target['folder-name'].value
}
if (folder.name === ""){
this.setState({errorMessage: "Folder name is required."});
}
else {
fetch(`${config.API_ENDPOINT}/folders`, {
method: 'POST',
headers: {
'content-type': 'application/json'
},
body: JSON.stringify(folder),
})
.then(res => {
if (!res.ok)
return res.json().then(e => Promise.reject(e))
return res.json()
})
.then(folder => {
this.context.addFolder(folder)
this.props.history.push(`/folder/${folder.id}`)
})
.catch(error => {
console.error({ error })
})
}
}

render() {
return (
<section className='AddFolder'>
<h2>Create a folder</h2>
<NotefulForm onSubmit={this.handleSubmit}>
<div className='field'>
<label htmlFor='folder-name-input'>
Name
</label>
<input type='text' id='folder-name-input' name='folder-name' />
</div>
<ErrorMessage errorMessage={this.state.errorMessage} />
<div className='buttons'>
<button type='submit'>
Add folder
</button>
</div>
</NotefulForm>
</section>
)
}
}
11 changes: 11 additions & 0 deletions src/AddFolder/AddFolder.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import React from 'react';
import { shallow } from 'enzyme'
import toJson from 'enzyme-to-json'
import AddFolder from './AddFolder'

describe(`AddItemForm component`, () => {
it('renders the complete form', () => {
const wrapper = shallow(<AddFolder />)
expect(toJson(wrapper)).toMatchSnapshot()
})
})
35 changes: 35 additions & 0 deletions src/AddFolder/__snapshots__/AddFolder.test.js.snap
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`AddItemForm component renders the complete form 1`] = `
<section
className="AddFolder"
>
<h2>
Create a folder
</h2>
<NotefulForm>
<div
className="field"
>
<label
htmlFor="folder-name-input"
>
Name
</label>
<input
id="folder-name-input"
type="text"
/>
</div>
<div
className="buttons"
>
<button
type="submit"
>
Add folder
</button>
</div>
</NotefulForm>
</section>
`;
8 changes: 8 additions & 0 deletions src/AddNote/AddNote.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@

.AddNote {
color: #dedede;
}

.AddNote h2 {
margin-left: 16px;
}
Loading