├── .gitignore ├── README.md ├── package-lock.json ├── package.json ├── public ├── favicon.ico ├── index.html ├── logo192.png ├── logo512.png ├── manifest.json └── robots.txt └── src ├── actions └── contactActions.js ├── components ├── App.jsx ├── contacts │ ├── AddContact.jsx │ ├── Contact.jsx │ ├── Contacts.jsx │ └── EditContact.jsx ├── layout │ ├── Header.jsx │ └── TextInputGroup.jsx └── pages │ ├── About.jsx │ └── NotFound.jsx ├── index.js ├── reducers ├── contactReducer.js └── index.js └── store.js /.gitignore: -------------------------------------------------------------------------------- 1 | node_modules -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | This project was bootstrapped with [Create React App](https://github.com/facebook/create-react-app). 2 | 3 | ## Available Scripts 4 | 5 | In the project directory, you can run: 6 | 7 | ### `npm start` 8 | 9 | Runs the app in the development mode.
10 | Open [http://localhost:3000](http://localhost:3000) to view it in the browser. 11 | 12 | The page will reload if you make edits.
13 | You will also see any lint errors in the console. 14 | 15 | ### `npm test` 16 | 17 | Launches the test runner in the interactive watch mode.
18 | See the section about [running tests](https://facebook.github.io/create-react-app/docs/running-tests) for more information. 19 | 20 | ### `npm run build` 21 | 22 | Builds the app for production to the `build` folder.
23 | It correctly bundles React in production mode and optimizes the build for the best performance. 24 | 25 | The build is minified and the filenames include the hashes.
26 | Your app is ready to be deployed! 27 | 28 | See the section about [deployment](https://facebook.github.io/create-react-app/docs/deployment) for more information. 29 | 30 | ### `npm run eject` 31 | 32 | **Note: this is a one-way operation. Once you `eject`, you can’t go back!** 33 | 34 | If you aren’t satisfied with the build tool and configuration choices, you can `eject` at any time. This command will remove the single build dependency from your project. 35 | 36 | Instead, it will copy all the configuration files and the transitive dependencies (Webpack, Babel, ESLint, etc) right into your project so you have full control over them. All of the commands except `eject` will still work, but they will point to the copied scripts so you can tweak them. At this point you’re on your own. 37 | 38 | You don’t have to ever use `eject`. The curated feature set is suitable for small and middle deployments, and you shouldn’t feel obligated to use this feature. However we understand that this tool wouldn’t be useful if you couldn’t customize it when you are ready for it. 39 | 40 | ## Learn More 41 | 42 | You can learn more in the [Create React App documentation](https://facebook.github.io/create-react-app/docs/getting-started). 43 | 44 | To learn React, check out the [React documentation](https://reactjs.org/). 45 | 46 | ### Code Splitting 47 | 48 | This section has moved here: https://facebook.github.io/create-react-app/docs/code-splitting 49 | 50 | ### Analyzing the Bundle Size 51 | 52 | This section has moved here: https://facebook.github.io/create-react-app/docs/analyzing-the-bundle-size 53 | 54 | ### Making a Progressive Web App 55 | 56 | This section has moved here: https://facebook.github.io/create-react-app/docs/making-a-progressive-web-app 57 | 58 | ### Advanced Configuration 59 | 60 | This section has moved here: https://facebook.github.io/create-react-app/docs/advanced-configuration 61 | 62 | ### Deployment 63 | 64 | This section has moved here: https://facebook.github.io/create-react-app/docs/deployment 65 | 66 | ### `npm run build` fails to minify 67 | 68 | This section has moved here: https://facebook.github.io/create-react-app/docs/troubleshooting#npm-run-build-fails-to-minify 69 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "contactmanager", 3 | "version": "0.1.0", 4 | "homepage": "https://devmahmud.github.io/ContactManager", 5 | "private": true, 6 | "dependencies": { 7 | "axios": "^0.19.0", 8 | "bootstrap": "^4.3.1", 9 | "classnames": "^2.2.6", 10 | "gh-pages": "^2.1.1", 11 | "react": "^16.10.2", 12 | "react-dom": "^16.10.2", 13 | "react-redux": "^7.1.1", 14 | "react-router-dom": "^5.1.2", 15 | "react-scripts": "3.2.0", 16 | "redux": "^4.0.4", 17 | "redux-thunk": "^2.3.0", 18 | "uuid": "^3.3.3" 19 | }, 20 | "scripts": { 21 | "deploy": "npm run build&&gh-pages -d build", 22 | "start": "react-scripts start", 23 | "build": "react-scripts build", 24 | "test": "react-scripts test", 25 | "eject": "react-scripts eject" 26 | }, 27 | "eslintConfig": { 28 | "extends": "react-app" 29 | }, 30 | "browserslist": { 31 | "production": [ 32 | ">0.2%", 33 | "not dead", 34 | "not op_mini all" 35 | ], 36 | "development": [ 37 | "last 1 chrome version", 38 | "last 1 firefox version", 39 | "last 1 safari version" 40 | ] 41 | } 42 | } -------------------------------------------------------------------------------- /public/favicon.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/devmahmud/ContactManager/7d7578188ba7e9fff2aa7dc6ce1f227fdbd2039f/public/favicon.ico -------------------------------------------------------------------------------- /public/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 15 | 16 | 25 | 26 | Contact Manager 27 | 28 | 29 | 30 | 31 |
32 | 33 | 34 | -------------------------------------------------------------------------------- /public/logo192.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/devmahmud/ContactManager/7d7578188ba7e9fff2aa7dc6ce1f227fdbd2039f/public/logo192.png -------------------------------------------------------------------------------- /public/logo512.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/devmahmud/ContactManager/7d7578188ba7e9fff2aa7dc6ce1f227fdbd2039f/public/logo512.png -------------------------------------------------------------------------------- /public/manifest.json: -------------------------------------------------------------------------------- 1 | { 2 | "short_name": "React App", 3 | "name": "Create React App Sample", 4 | "icons": [ 5 | { 6 | "src": "favicon.ico", 7 | "sizes": "64x64 32x32 24x24 16x16", 8 | "type": "image/x-icon" 9 | }, 10 | { 11 | "src": "logo192.png", 12 | "type": "image/png", 13 | "sizes": "192x192" 14 | }, 15 | { 16 | "src": "logo512.png", 17 | "type": "image/png", 18 | "sizes": "512x512" 19 | } 20 | ], 21 | "start_url": ".", 22 | "display": "standalone", 23 | "theme_color": "#000000", 24 | "background_color": "#ffffff" 25 | } 26 | -------------------------------------------------------------------------------- /public/robots.txt: -------------------------------------------------------------------------------- 1 | # https://www.robotstxt.org/robotstxt.html 2 | User-agent: * 3 | -------------------------------------------------------------------------------- /src/actions/contactActions.js: -------------------------------------------------------------------------------- 1 | import axios from "axios"; 2 | 3 | export const getContacts = () => async dispatch => { 4 | const response = await axios.get( 5 | "https://jsonplaceholder.typicode.com/users" 6 | ); 7 | dispatch({ 8 | type: "GET_CONTACTS", 9 | payload: response.data 10 | }); 11 | }; 12 | 13 | export const getContact = id => async dispatch => { 14 | const response = await axios.get( 15 | `https://jsonplaceholder.typicode.com/users/${id}` 16 | ); 17 | dispatch({ 18 | type: "GET_CONTACT", 19 | payload: response.data 20 | }); 21 | }; 22 | 23 | export const deleteContact = id => async dispatch => { 24 | await axios.delete(`https://jsonplaceholder.typicode.com/users/${id}`); 25 | dispatch({ 26 | type: "DELETE_CONTACT", 27 | payload: id 28 | }); 29 | }; 30 | 31 | export const addContact = contact => async dispatch => { 32 | const response = await axios.post( 33 | "https://jsonplaceholder.typicode.com/users/", 34 | contact 35 | ); 36 | dispatch({ 37 | type: "ADD_CONTACT", 38 | payload: response.data 39 | }); 40 | }; 41 | 42 | export const updateContact = contact => async dispatch => { 43 | const response = await axios.put( 44 | `https://jsonplaceholder.typicode.com/users/${contact.id}`, 45 | contact 46 | ); 47 | dispatch({ 48 | type: "UPDATE_CONTACT", 49 | payload: response.data 50 | }); 51 | }; 52 | -------------------------------------------------------------------------------- /src/components/App.jsx: -------------------------------------------------------------------------------- 1 | import React, { Component } from "react"; 2 | import { HashRouter as Router, Switch, Route } from "react-router-dom"; 3 | import { Provider } from "react-redux"; 4 | import store from "../store"; 5 | 6 | import Contacts from "./contacts/Contacts"; 7 | import Header from "./layout/Header"; 8 | import About from "./pages/About"; 9 | import AddContact from "./contacts/AddContact"; 10 | import NotFound from "./pages/NotFound"; 11 | import EditContact from "./contacts/EditContact"; 12 | 13 | class App extends Component { 14 | state = {}; 15 | render() { 16 | return ( 17 | 18 | 19 | 20 |
21 |
22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 |
30 | 31 | 32 | 33 | ); 34 | } 35 | } 36 | 37 | export default App; 38 | -------------------------------------------------------------------------------- /src/components/contacts/AddContact.jsx: -------------------------------------------------------------------------------- 1 | import React, { Component } from "react"; 2 | import { connect } from "react-redux"; 3 | import TextInputGroup from "../layout/TextInputGroup"; 4 | import { addContact } from "../../actions/contactActions"; 5 | 6 | class AddContact extends Component { 7 | state = { 8 | name: "", 9 | email: "", 10 | phone: "", 11 | errors: {} 12 | }; 13 | 14 | onSubmit = e => { 15 | e.preventDefault(); 16 | 17 | const { name, email, phone } = this.state; 18 | 19 | // Check For Errors 20 | if (name === "") { 21 | this.setState({ errors: { name: "Name is required" } }); 22 | return; 23 | } 24 | 25 | if (email === "") { 26 | this.setState({ errors: { email: "Email is required" } }); 27 | return; 28 | } 29 | 30 | if (phone === "") { 31 | this.setState({ errors: { phone: "Phone is required" } }); 32 | return; 33 | } 34 | 35 | const newContact = { 36 | name, 37 | email, 38 | phone 39 | }; 40 | 41 | //// SUBMIT CONTACT //// 42 | this.props.addContact(newContact); 43 | 44 | // Clear State 45 | this.setState({ 46 | name: "", 47 | email: "", 48 | phone: "", 49 | errors: {} 50 | }); 51 | 52 | //Redirect to home 53 | this.props.history.push("/"); 54 | }; 55 | 56 | onChange = e => this.setState({ [e.target.name]: e.target.value }); 57 | 58 | render() { 59 | const { name, email, phone, errors } = this.state; 60 | 61 | return ( 62 |
63 |
Add Contact
64 |
65 |
66 | 74 | 83 | 91 | 96 | 97 |
98 |
99 | ); 100 | } 101 | } 102 | 103 | export default connect( 104 | null, 105 | { addContact } 106 | )(AddContact); 107 | -------------------------------------------------------------------------------- /src/components/contacts/Contact.jsx: -------------------------------------------------------------------------------- 1 | import React, { Component } from "react"; 2 | import { Link } from "react-router-dom"; 3 | import { connect } from "react-redux"; 4 | import { deleteContact } from "../../actions/contactActions"; 5 | 6 | class Contact extends Component { 7 | state = { 8 | showContactInfo: false 9 | }; 10 | 11 | render() { 12 | const { id, name, email, phone } = this.props.contact; 13 | return ( 14 |
15 |
16 |

17 | {name} 18 | 22 | this.setState({ 23 | showContactInfo: !this.state.showContactInfo 24 | }) 25 | } 26 | > 27 | this.props.deleteContact(id)} 31 | > 32 | 33 | 42 | 43 |

44 |
45 | {this.state.showContactInfo ? ( 46 |
47 |
    48 |
  • Email: {email}
  • 49 |
  • Phone: {phone}
  • 50 |
51 |
52 | ) : null} 53 |
54 | ); 55 | } 56 | } 57 | 58 | export default connect( 59 | null, 60 | { deleteContact } 61 | )(Contact); 62 | -------------------------------------------------------------------------------- /src/components/contacts/Contacts.jsx: -------------------------------------------------------------------------------- 1 | import React, { Component } from "react"; 2 | import { connect } from "react-redux"; 3 | import Contact from "./Contact"; 4 | import { getContacts } from "../../actions/contactActions"; 5 | 6 | class Contacts extends Component { 7 | componentDidMount() { 8 | this.props.getContacts(); 9 | } 10 | 11 | render() { 12 | return ( 13 | 14 |

15 | Contact List 16 |

17 | {this.props.contacts.map(contact => ( 18 | 19 | ))} 20 |
21 | ); 22 | } 23 | } 24 | 25 | const mapStateToProps = state => ({ 26 | contacts: state.contact.contacts 27 | }); 28 | 29 | export default connect( 30 | mapStateToProps, 31 | { getContacts } 32 | )(Contacts); 33 | -------------------------------------------------------------------------------- /src/components/contacts/EditContact.jsx: -------------------------------------------------------------------------------- 1 | import React, { Component } from "react"; 2 | import TextInputGroup from "../layout/TextInputGroup"; 3 | import PropTypes from "prop-types"; 4 | import { connect } from "react-redux"; 5 | import { getContact, updateContact } from "../../actions/contactActions"; 6 | 7 | class EditContact extends Component { 8 | state = { 9 | name: "", 10 | email: "", 11 | phone: "", 12 | errors: {} 13 | }; 14 | 15 | UNSAFE_componentWillReceiveProps(nextProps, nextState) { 16 | const { name, email, phone } = nextProps.contact; 17 | this.setState({ 18 | name, 19 | email, 20 | phone 21 | }); 22 | } 23 | 24 | componentDidMount() { 25 | const { id } = this.props.match.params; 26 | this.props.getContact(id); 27 | } 28 | 29 | onSubmit = e => { 30 | e.preventDefault(); 31 | 32 | const { name, email, phone } = this.state; 33 | 34 | // Check For Errors 35 | if (name === "") { 36 | this.setState({ errors: { name: "Name is required" } }); 37 | return; 38 | } 39 | 40 | if (email === "") { 41 | this.setState({ errors: { email: "Email is required" } }); 42 | return; 43 | } 44 | 45 | if (phone === "") { 46 | this.setState({ errors: { phone: "Phone is required" } }); 47 | return; 48 | } 49 | 50 | const { id } = this.props.match.params; 51 | 52 | const updContact = { 53 | id, 54 | name, 55 | email, 56 | phone 57 | }; 58 | 59 | this.props.updateContact(updContact); 60 | 61 | // Clear State 62 | this.setState({ 63 | name: "", 64 | email: "", 65 | phone: "", 66 | errors: {} 67 | }); 68 | 69 | this.props.history.push("/"); 70 | }; 71 | 72 | onChange = e => this.setState({ [e.target.name]: e.target.value }); 73 | 74 | render() { 75 | const { name, email, phone, errors } = this.state; 76 | 77 | return ( 78 |
79 |
Edit Contact
80 |
81 |
82 | 90 | 99 | 107 | 112 | 113 |
114 |
115 | ); 116 | } 117 | } 118 | 119 | EditContact.propTypes = { 120 | contact: PropTypes.object.isRequired, 121 | getContact: PropTypes.func.isRequired 122 | }; 123 | 124 | const mapStateToProps = state => ({ 125 | contact: state.contact.contact 126 | }); 127 | 128 | export default connect( 129 | mapStateToProps, 130 | { getContact, updateContact } 131 | )(EditContact); 132 | -------------------------------------------------------------------------------- /src/components/layout/Header.jsx: -------------------------------------------------------------------------------- 1 | import React from "react"; 2 | import { Link } from "react-router-dom"; 3 | 4 | const Header = props => { 5 | return ( 6 | 31 | ); 32 | }; 33 | 34 | Header.defaultProps = { 35 | header: "Contact Manager" 36 | }; 37 | 38 | export default Header; 39 | -------------------------------------------------------------------------------- /src/components/layout/TextInputGroup.jsx: -------------------------------------------------------------------------------- 1 | import React from "react"; 2 | import PropTypes from "prop-types"; 3 | import classnames from "classnames"; 4 | 5 | const TextInputGroup = ({ 6 | label, 7 | name, 8 | value, 9 | placeholder, 10 | type, 11 | onChange, 12 | error 13 | }) => { 14 | return ( 15 |
16 | 17 | 27 | {error &&
{error}
} 28 |
29 | ); 30 | }; 31 | 32 | TextInputGroup.propTypes = { 33 | label: PropTypes.string.isRequired, 34 | name: PropTypes.string.isRequired, 35 | placeholder: PropTypes.string.isRequired, 36 | value: PropTypes.string.isRequired, 37 | type: PropTypes.string.isRequired, 38 | onChange: PropTypes.func.isRequired, 39 | error: PropTypes.string 40 | }; 41 | 42 | TextInputGroup.defaultProps = { 43 | type: "text" 44 | }; 45 | 46 | export default TextInputGroup; 47 | -------------------------------------------------------------------------------- /src/components/pages/About.jsx: -------------------------------------------------------------------------------- 1 | import React from "react"; 2 | 3 | export default function About() { 4 | return ( 5 |
6 |

About Contact Manager

7 |

Simple React App to manage contacts

8 |

Version 1.0.0

9 |
10 | ); 11 | } 12 | -------------------------------------------------------------------------------- /src/components/pages/NotFound.jsx: -------------------------------------------------------------------------------- 1 | import React from "react"; 2 | 3 | export default function NotFound() { 4 | return ( 5 |
6 |

7 | 404 Page Not Found 8 |

9 |

This Page you are looking doesn't exists !!!

10 |
11 | ); 12 | } 13 | -------------------------------------------------------------------------------- /src/index.js: -------------------------------------------------------------------------------- 1 | import React from "react"; 2 | import ReactDOM from "react-dom"; 3 | import App from "./components/App"; 4 | import "bootstrap/dist/css/bootstrap.css"; 5 | 6 | ReactDOM.render(, document.querySelector("#root")); 7 | -------------------------------------------------------------------------------- /src/reducers/contactReducer.js: -------------------------------------------------------------------------------- 1 | const initialState = { 2 | contacts: [], 3 | contact: {} 4 | }; 5 | 6 | export default function(state = initialState, action) { 7 | switch (action.type) { 8 | case "GET_CONTACTS": 9 | return { ...state, contacts: action.payload }; 10 | case "GET_CONTACT": 11 | return { ...state, contact: action.payload }; 12 | case "DELETE_CONTACT": 13 | return { 14 | ...state, 15 | contacts: state.contacts.filter( 16 | contact => contact.id !== action.payload 17 | ) 18 | }; 19 | case "ADD_CONTACT": 20 | return { ...state, contacts: [action.payload, ...state.contacts] }; 21 | case "UPDATE_CONTACT": 22 | return { 23 | ...state, 24 | contacts: state.contacts.map(contact => 25 | contact.id === action.payload.id 26 | ? (contact = action.payload) 27 | : contact 28 | ) 29 | }; 30 | default: 31 | return state; 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /src/reducers/index.js: -------------------------------------------------------------------------------- 1 | import { combineReducers } from "redux"; 2 | import contactReducer from "./contactReducer"; 3 | 4 | export default combineReducers({ 5 | contact: contactReducer 6 | }); 7 | -------------------------------------------------------------------------------- /src/store.js: -------------------------------------------------------------------------------- 1 | import { createStore, applyMiddleware } from "redux"; 2 | import thunk from "redux-thunk"; 3 | 4 | import rootReducer from "./reducers"; 5 | 6 | const initialState = {}; 7 | 8 | const middleware = [thunk]; 9 | 10 | const store = createStore( 11 | rootReducer, 12 | initialState, 13 | applyMiddleware(...middleware) 14 | ); 15 | 16 | export default store; 17 | --------------------------------------------------------------------------------