From ead2b6ad83a3d1ccd4d45db8a3a5575e7751c0d9 Mon Sep 17 00:00:00 2001 From: Brian Cho Date: Sat, 22 Jul 2017 00:56:28 +0900 Subject: [PATCH] brian-react-test submission --- package.json | 2 + src/actions/contact.js | 31 +++++ src/actions/types.js | 5 + src/app/app.jsx | 42 ++++-- src/app/app.scss | 39 ++++++ src/components/controls/button.jsx | 10 +- src/components/controls/contact-edit.jsx | 77 +++++++++++ src/components/controls/contact-list.jsx | 35 +++++ src/components/controls/contact.jsx | 53 ++++++++ src/components/controls/index.js | 6 +- src/components/controls/modal.jsx | 126 ++++++++++++++++++ src/components/index.js | 2 +- src/containers/contact-delete-button.jsx | 19 +++ src/containers/contact-favourite-button.jsx | 18 +++ src/containers/contact-save-button.jsx | 23 ++++ src/containers/contact-unfavourite-button.jsx | 18 +++ src/containers/contacts.jsx | 15 +++ src/containers/favourites.jsx | 15 +++ src/containers/index.js | 15 +++ src/index.jsx | 10 +- src/reducer/contact.jsx | 92 +++++++++++++ src/reducer/index.js | 8 ++ 22 files changed, 645 insertions(+), 16 deletions(-) create mode 100644 src/actions/contact.js create mode 100644 src/actions/types.js create mode 100644 src/components/controls/contact-edit.jsx create mode 100644 src/components/controls/contact-list.jsx create mode 100644 src/components/controls/contact.jsx create mode 100644 src/components/controls/modal.jsx create mode 100644 src/containers/contact-delete-button.jsx create mode 100644 src/containers/contact-favourite-button.jsx create mode 100644 src/containers/contact-save-button.jsx create mode 100644 src/containers/contact-unfavourite-button.jsx create mode 100644 src/containers/contacts.jsx create mode 100644 src/containers/favourites.jsx create mode 100644 src/containers/index.js create mode 100644 src/reducer/contact.jsx create mode 100644 src/reducer/index.js diff --git a/package.json b/package.json index c6d9612..fd61de2 100644 --- a/package.json +++ b/package.json @@ -13,12 +13,14 @@ "debug": "^2.2.0", "evil-icons": "^1.8.0", "express": "^4.13.4", + "prop-types": "^15.5.10", "react": "^15.1.0", "react-dom": "^15.1.0", "react-evil-icons": "^0.4.0", "react-redux": "^5.0.5", "redux": "^3.5.2", "sancus": "^1.0.3", + "universal-cookie": "^2.0.8", "webpack": "^3.3.0", "webpack-dev-middleware": "^1.6.1", "webpack-dev-server": "^2.5.1", diff --git a/src/actions/contact.js b/src/actions/contact.js new file mode 100644 index 0000000..31b2130 --- /dev/null +++ b/src/actions/contact.js @@ -0,0 +1,31 @@ +import * as types from './types'; + +export const addContact = (name, phone, email) => ({ + type: types.ADD_CONTACT, + name, + phone, + email +}); + +export const deleteContact = id => ({ + type: types.DELETE_CONTACT, + id +}); + +export const saveContact = (id, name, phone, email) => ({ + type: types.SAVE_CONTACT, + id, + name, + phone, + email +}); + +export const addFavourite = id => ({ + type: types.ADD_FAVOURITE, + id +}); + +export const deleteFavourite = id => ({ + type: types.DELETE_FAVOURITE, + id +}); diff --git a/src/actions/types.js b/src/actions/types.js new file mode 100644 index 0000000..5bc5647 --- /dev/null +++ b/src/actions/types.js @@ -0,0 +1,5 @@ +export const ADD_CONTACT = 'ADD_CONTACT'; +export const DELETE_CONTACT = 'DELETE_CONTACT'; +export const SAVE_CONTACT = 'SAVE_CONTACT'; +export const ADD_FAVOURITE = 'ADD_FAVOURITE'; +export const DELETE_FAVOURITE = 'DELETE_FAVOURITE'; diff --git a/src/app/app.jsx b/src/app/app.jsx index b1474ec..3add506 100644 --- a/src/app/app.jsx +++ b/src/app/app.jsx @@ -1,16 +1,40 @@ import React from 'react'; import './app.scss'; -import { Column, Row, Title, Button } from '../components'; +import { Column, Row, Title, ContactEdit, Modal, Button } from '../components'; +import { Contacts, Favourites } from '../containers'; -const onAddClick = (event) => { -}; +class App extends React.Component { + constructor(props) { + super(props); + this.state = { + editModalVisible: false + }; + } -const App = () => ( - - Contact Book - +const Button = ({ className, children, label, onClick }) => ( + ); Button.propTypes = { children: PropTypes.string, label: PropTypes.string, - onClick: PropTypes.func.isRequired + onClick: PropTypes.func.isRequired, + className: PropTypes.string.isRequired }; Button.defaultProps = { label: null, - children: null + children: null, + className: 'button' }; export default Button; diff --git a/src/components/controls/contact-edit.jsx b/src/components/controls/contact-edit.jsx new file mode 100644 index 0000000..1cbe786 --- /dev/null +++ b/src/components/controls/contact-edit.jsx @@ -0,0 +1,77 @@ +import React from 'react'; +import PropTypes from 'prop-types'; + +import '../../app/app.scss'; +import { Column, Row } from '../grid'; +import { Button } from '../controls'; +import { ContactSaveButton, ContactDeleteButton } from '../../containers'; + +class ContactEdit extends React.Component { + constructor(props) { + super(props); + this.state = { + name: this.props.contact.name, + phone: this.props.contact.phone, + email: this.props.contact.email + }; + } + + render = () => ( + + + + { this.setState({ name: e.target.value }); }} + /> + + + { this.setState({ phone: e.target.value }); }} + /> + + + { this.setState({ email: e.target.value }); }} + /> + +