diff --git a/packages/components/FormModal/ItemForm/index.js b/packages/components/FormModal/ItemForm/index.js new file mode 100644 index 0000000..75b56f0 --- /dev/null +++ b/packages/components/FormModal/ItemForm/index.js @@ -0,0 +1,101 @@ +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, setIsValidated ] = useState(false); + + const [ title, setTitle ] = useState(props.title); + + const handleSubmit = (event) => { + const form = event.currentTarget; + event.preventDefault(); + event.stopPropagation(); + + const formIsValid = form.checkValidity(); + + if (!formIsValid) { + setIsValidated(true); + } else if (formIsValid) { + setIsValidated(true); + const editedProject = { + title: title, + description: description, + id: props.id + }; + + props.handleSaveForm(editedProject); + } + }; + + return ( + +
+ + Title + setTitle(e.target.value) } + /> + + Choose a title + + Looks good! + + Please choose a title + + + + + Description + setDescription(e.target.value) } + /> + + Choose an optional description + + Looks good! + + + + +
+ ); +}; + +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; diff --git a/packages/components/FormModal/index.js b/packages/components/FormModal/index.js new file mode 100644 index 0000000..d8adb07 --- /dev/null +++ b/packages/components/FormModal/index.js @@ -0,0 +1,43 @@ +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.showModal); + + return ( + toggleShowModal(!showModal) }> + + {props.modalTitle} + + + + + + ); +}; + +ItemFormModal.propTypes = { + id: PropTypes.number.isRequired, + title: PropTypes.string, + description: PropTypes.string, + showModal: 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; diff --git a/packages/components/FormModal/stories/index.stories.js b/packages/components/FormModal/stories/index.stories.js new file mode 100644 index 0000000..bde4f7b --- /dev/null +++ b/packages/components/FormModal/stories/index.stories.js @@ -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, + showModal: true, + title: 'Example Transcript Title', + description: 'This is a sample card description. This is fun!', + url: '/projects/1/transcripts/1234', + modalTitle: 'Edit Project', +}, { + showModal: true, + modalTitle: 'New Project', + id: 2 +} ]; + +export const modalActions = actions({ handleSaveForm: 'Form saved' }); + +storiesOf('Form Modal', module) + .addDecorator(StoryRouter()) + .add('Edit project', () => { + return ( +
+ +
+ ); + }) + .add('New project', () => { + return ( +
+ +
+ ); + }); + +storiesOf('Form Modal / Item Form', module) + .addDecorator(StoryRouter()) + .add('Edit Project', () => { + return ( +
+ +
+ ); + }); diff --git a/packages/components/SearchBar/index.js b/packages/components/List/SearchBar/index.js similarity index 100% rename from packages/components/SearchBar/index.js rename to packages/components/List/SearchBar/index.js diff --git a/packages/components/List/index.js b/packages/components/List/index.js index a41c5a9..6791b56 100644 --- a/packages/components/List/index.js +++ b/packages/components/List/index.js @@ -1,8 +1,7 @@ import React, { useState } from 'react'; import PropTypes from 'prop-types'; import SimpleCard from '../SimpleCard'; -import SearchBar from '../SearchBar'; -import TranscriptCard from '../TranscriptCard'; +import SearchBar from './SearchBar'; const List = ({ projectItems, handleEdit, handleDelete }) => { diff --git a/packages/components/List/stories/index.stories.js b/packages/components/List/stories/index.stories.js index 0ff46ee..82f5f93 100644 --- a/packages/components/List/stories/index.stories.js +++ b/packages/components/List/stories/index.stories.js @@ -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'; import { transcriptItems } from '../../TranscriptCard/stories/index.stories.js';