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

Item form modal #17

Merged
merged 15 commits into from
Sep 9, 2019
Merged
Show file tree
Hide file tree
Changes from 6 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
100 changes: 100 additions & 0 deletions packages/components/FormModal/ItemForm/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
import React, { useState } from 'react';
import PropTypes from 'prop-types';
import Form from 'react-bootstrap/Form';
import Button from 'react-bootstrap/Button';
import Modal from 'react-bootstrap/Modal';

const ItemForm = (props) => {

const [ description, setDescription ] = useState(props.description);

const [ isValidated, setFormValidation ] = useState(false);

const [ title, setTitle ] = useState(props.title);

const handleSubmit = (event) => {
const form = event.currentTarget;
if (form.checkValidity() === false) {
event.preventDefault();
event.stopPropagation();
setFormValidation(true);
} else if (form.checkValidity() === true) {
event.preventDefault();
event.stopPropagation();
setFormValidation(true);
const editedProject = {
title: title,
description: description,
id: props.id
};

props.handleSaveForm(editedProject);
}
};

return (

<Form noValidate validated={ isValidated }
onSubmit={ handleSubmit }
>
<Form.Group controlId="formBasicEmail">
<Form.Label>Title</Form.Label>
<Form.Control
required
type="text"
name="title"
placeholder="Enter a project title"
value={ title }
onChange={ (e) => setTitle(e.target.value) }
/>
<Form.Text className="text-muted">
Chose a title
</Form.Text>
<Form.Control.Feedback>Looks good!</Form.Control.Feedback>
<Form.Control.Feedback type="invalid">
Please chose a title
</Form.Control.Feedback>
</Form.Group>

<Form.Group controlId="formBasicEmail">
<Form.Label>Description</Form.Label>
<Form.Control
type="text"
placeholder="Enter a project description"
value={ description }
name="description"
onChange={ (e) => setDescription(e.target.value) }
/>
<Form.Text className="text-muted">
Chose an optional description
</Form.Text>
<Form.Control.Feedback>Looks good!</Form.Control.Feedback>
</Form.Group>
<Modal.Footer>
<Button variant="primary" type="submit">
Save
</Button>
</Modal.Footer>
</Form>
);
};

ItemForm.propTypes = {
id: PropTypes.number.isRequired,
title: PropTypes.string,
description: PropTypes.string,
isNewItemModalShow: PropTypes.bool.isRequired,
modalTitle: PropTypes.string.isRequired,
handleSaveForm: PropTypes.func.isRequired,
};

ItemForm.defaultProps = {
handleSaveForm: () => {
console.log('Handling a project save');
},
id: 1,
isNewItemModalShow: false,
modalTitle: 'New Project',
};

export default ItemForm;
42 changes: 42 additions & 0 deletions packages/components/FormModal/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
import React, { useState } from 'react';
import PropTypes from 'prop-types';
import Modal from 'react-bootstrap/Modal';
import ItemForm from './ItemForm/index.js';

const ItemFormModal = (props) => {

const [ showModal, toggleShowModal ] = useState(props.isNewItemModalShow);

return (
<Modal show={ showModal } onHide={ () => toggleShowModal(!showModal) }>
<Modal.Header closeButton>
<Modal.Title>{props.modalTitle}</Modal.Title>
</Modal.Header>
<Modal.Body>
<ItemForm
{ ...props }
/>
</Modal.Body>
</Modal>
);
};

ItemFormModal.propTypes = {
id: PropTypes.number.isRequired,
title: PropTypes.string,
description: PropTypes.string,
isNewItemModalShow: PropTypes.bool.isRequired,
modalTitle: PropTypes.string.isRequired,
handleSaveForm: PropTypes.func.isRequired,
};

ItemFormModal.defaultProps = {
handleSaveForm: () => {
console.log('Handling a project save');
},
id: 1,
isNewItemModalShow: false,
modalTitle: 'New Project',
};

export default ItemFormModal;
58 changes: 58 additions & 0 deletions packages/components/FormModal/stories/index.stories.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
import React from 'react';

import { storiesOf } from '@storybook/react';
import { actions } from '@storybook/addon-actions';
import StoryRouter from 'storybook-react-router';
import FormModal from '../index.js';
import ItemForm from '../ItemForm';

export const modalItems = [ {
id: 1,
isNewItemModalShow: true,
title: 'Example Transcript Title',
description: 'This is a sample card description. This is fun!',
url: '/projects/1/transcripts/1234',
modalTitle: 'Edit Project',
}, {
isNewItemModalShow: true,
modalTitle: 'New Project',
id: 2
} ];

export const modalActions = actions({ handleSaveForm: 'Form saved' });

storiesOf('Form Modal', module)
.addDecorator(StoryRouter())
.add('Edit project', () => {
return (
<section style={ { height: '90vh', overflow: 'scroll' } }>
<FormModal
{ ...modalActions }
{ ...modalItems[0] }
/>
</section>
);
})
.add('New project', () => {
return (
<section style={ { height: '90vh', overflow: 'scroll' } }>
<FormModal
{ ...modalActions }
{ ...modalItems[1] }
/>
</section>
);
});

storiesOf('Form Modal / Item Form', module)
.addDecorator(StoryRouter())
.add('Edit Project', () => {
return (
<section style={ { height: '90vh', overflow: 'scroll' } }>
<ItemForm
{ ...modalActions }
{ ...modalItems[0] }
/>
</section>
);
});
2 changes: 1 addition & 1 deletion packages/components/List/index.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import React, { useState } from 'react';
import PropTypes from 'prop-types';
import SimpleCard from '../SimpleCard';
import SearchBar from '../SearchBar';
import SearchBar from './SearchBar';

const List = ({ projectItems, handleEdit, handleDelete }) => {

Expand Down
2 changes: 1 addition & 1 deletion packages/components/List/stories/index.stories.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { storiesOf } from '@storybook/react';
import { actions } from '@storybook/addon-actions';
import StoryRouter from 'storybook-react-router';
import List from '../index.js';
import SearchBar from '../../SearchBar';
import SearchBar from '../SearchBar';

import { item, cardActions } from '../../SimpleCard/stories/index.stories.js';

Expand Down