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

Day 1 #1

Merged
merged 7 commits into from
Dec 17, 2019
Merged
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
7,229 changes: 4,276 additions & 2,953 deletions package-lock.json

Large diffs are not rendered by default.

22 changes: 19 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,30 @@
"version": "0.1.0",
"private": true,
"dependencies": {
"react": "^16.8.6",
"react-dom": "^16.8.6",
"react-scripts": "3.0.1"
"axios": "^0.19.0",
"bootstrap": "^4.4.1",
"react": "^16.12.0",
"react-bootstrap": "^1.0.0-beta.16",
"react-dom": "^16.12.0",
"react-router-dom": "^5.1.2",
"react-scripts": "^3.3.0"
},
"scripts": {
"start": "react-scripts start",
"build": "react-scripts build",
"test": "react-scripts test --env=jsdom",
"eject": "react-scripts eject"
},
"browserslist": {
"production": [
">0.2%",
"not dead",
"not op_mini all"
],
"development": [
"last 1 chrome version",
"last 1 firefox version",
"last 1 safari version"
]
}
}
5 changes: 5 additions & 0 deletions src/App.css
Original file line number Diff line number Diff line change
Expand Up @@ -26,3 +26,8 @@
from { transform: rotate(0deg); }
to { transform: rotate(360deg); }
}

table {
max-width: 96%;
margin: 2%
}
68 changes: 60 additions & 8 deletions src/App.js
Original file line number Diff line number Diff line change
@@ -1,19 +1,71 @@
import React, { Component } from 'react';
import logo from './logo.svg';
import './App.css';
import Nav from './components/Nav';
import Checkout from './components/Checkout';
import axios from 'axios';
import 'bootstrap/dist/css/bootstrap.min.css';

class App extends Component {
constructor(props) {
super(props);

this.state = {
customers: [],
movies: [],
errors: '',
currentCustomer: '',
currentMovie: '',
};
}

componentDidMount() {
this.fetchCustomers();
this.fetchMovies();
}

fetchMovies() {
axios.get('http://localhost:3000/movies')
.then((response) => {
this.setState({
movies: response.data
})
})
.catch((error) => {
this.setState({
errors: error
});
});
}


fetchCustomers() {
axios.get('http://localhost:3000/customers')
.then((response) => {
this.setState({
customers: response.data
})
})
.catch((error) => {
this.setState({
errors: error
});
});
}

onCheckout() {

}

render() {
return (
<div className="App">
<section className="App">
<header className="App-header">
<img src={logo} className="App-logo" alt="logo" />
<h1 className="App-title">Welcome to React</h1>
<h1 className="App-title">Welcome to our Page Wazzzzup</h1>
</header>
<p className="App-intro">
To get started, edit <code>src/App.js</code> and save to reload.
</p>
</div>
<Nav movies={this.state.movies} customers={this.state.customers} />
<Checkout movie={this.state.currentMovie} customer={this.state.currentCustomer} onCheckout={this.onCheckout} />
<h2>{this.state.errors}</h2>
</section>
);
}
}
Expand Down
26 changes: 26 additions & 0 deletions src/components/Checkout.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import React, { Component } from 'react';
import PropTypes from 'prop-types';
import axios from 'axios';

class Checkout extends Component {
constructor(props) {
super(props);

this.state = {
};
}


render() {
return ('Checkout')
}
}


Checkout.propTypes = {
movies: PropTypes.object.isRequired,
customers: PropTypes.object.isRequired,
onCheckout: PropTypes.func.isRequired
};

export default Checkout;
35 changes: 35 additions & 0 deletions src/components/Customer.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
import React, { Component } from 'react';
import PropTypes from 'prop-types';

class Customer extends Component {
constructor(props) {
super(props);

this.state = {
};
}

formatDate(string) {
var options = { year: 'numeric', month: 'long', day: 'numeric' };
return new Date(string).toLocaleDateString([],options);
}

render() {
return (
<tr>
<td>{this.formatDate(this.props.registered)}</td>
<td>{this.props.name}</td>
<td>{this.props.phone}</td>
<td>{this.props.streetAddress}</td>
<td>{this.props.cityState}</td>
</tr>
)
}
}


Customer.propTypes = {

};

export default Customer;
36 changes: 36 additions & 0 deletions src/components/CustomerList.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
import React, { Component } from 'react';
import PropTypes from 'prop-types';
import Customer from './Customer';

class CustomerList extends Component {
constructor(props) {
super(props);
}

render() {
const customers = this.props.customers.map((customer, i) => {
return <Customer registered={customer.registered_at} name={customer.name} phone={customer.phone} streetAddress={customer.address} cityState={`${customer.city}, ${customer.state} ${customer.postal_code}`}/>
});

return (
<table className="table">
<thead className="thead-dark">
<th>Registered</th>
<th>Name</th>
<th>Phone</th>
<th>Address</th>
<th>City/State</th>
</thead>
<tbody>
{customers}
</tbody>
</table>
)
}
}

CustomerList.propTypes = {
customers: PropTypes.array.isRequired
};

export default CustomerList;
18 changes: 18 additions & 0 deletions src/components/Home.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import React, { Component } from 'react';

class Home extends Component {
render() {
return (
<section>
HOMEPAGE
</section>
);
}
}


Home.propTypes = {

};

export default Home;
28 changes: 28 additions & 0 deletions src/components/Movie.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import React, { Component } from 'react';
import PropTypes from 'prop-types';

class Movie extends Component {
constructor(props) {
super(props);

this.state = {
};
}

render() {
return (
<tr>
<td><img src={this.props.image_url} alt={this.props.title}/></td>
<td>{this.props.title}</td>
<td>{this.props.overview}</td>
</tr>
)
}
}


Movie.propTypes = {

};

export default Movie;
36 changes: 36 additions & 0 deletions src/components/MovieList.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
import React, { Component } from 'react';
import PropTypes from 'prop-types';
import Movie from './Movie';


class MovieList extends Component {
constructor(props) {
super(props);
}

render() {
const movies = this.props.movies.map((movie, i) => {
return <Movie title={movie.title} overview={movie.overview} image_url={movie.image_url} />
});

return (
<table className="table">
<thead className="thead-dark">
<th></th>
<th>Title</th>
<th>Overview</th>
</thead>
<tbody>
{movies}
</tbody>
</table>
)
}
}


MovieList.propTypes = {
movies: PropTypes.array.isRequired
};

export default MovieList;
51 changes: 51 additions & 0 deletions src/components/Nav.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
import React from "react";
import {
BrowserRouter as Router,
Switch,
Route,
Link
} from "react-router-dom";
import CustomerList from './CustomerList';
import MovieList from './MovieList';
import Home from './Home';
import PropTypes from 'prop-types';


const Nav = (props) => {
return (
<Router>
<nav className='navbar navbar-expand navbar-light bg-light'>
<ul className="navbar-nav">
<li className='nav-item'>
<Link to="/" className="nav-link">Home</Link>
</li>
<li className='nav-item'>
<Link to="/library" className="nav-link">Movie List</Link>
</li>
<li className='nav-item'>
<Link to="/customers" className="nav-link">Customers</Link>
</li>
</ul>
</nav>

<Switch>
<Route path="/library">
<MovieList movies={props.movies}/>
</Route>
<Route path="/customers">
<CustomerList customers={props.customers} />
</Route>
<Route path="/">
<Home />
</Route>
</Switch>
</Router>
);
}

Nav.propTypes = {
movies: PropTypes.array.isRequired,
customers: PropTypes.array.isRequired,
};

export default Nav;