Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
35 commits
Select commit Hold shift + click to select a range
11badde
Imported react-router-dom
njch5 Dec 16, 2019
b2ace27
Created new components
njch5 Dec 16, 2019
95a6288
Created selectMovie and componentDidMount functions
njch5 Dec 17, 2019
59c785c
customer and customer compenents functions
iamsammysam Dec 17, 2019
2d8ef92
updated app with customer componentDidMount
iamsammysam Dec 17, 2019
0b59eb6
small changes on add and customer component
iamsammysam Dec 17, 2019
3b30c95
fixed small typos
iamsammysam Dec 17, 2019
29b0bd4
Merge pull request #1 from njch5/consumer
iamsammysam Dec 17, 2019
df4aae5
Edited fields for movie to show image and external ID
njch5 Dec 17, 2019
88998aa
Merge pull request #2 from njch5/njc/movie
njch5 Dec 17, 2019
8e9d3c5
Added search bar component and incorporated to App.js file
njch5 Dec 17, 2019
4c864e6
Attempted to do get request for axios
njch5 Dec 17, 2019
b7baeec
Installed and imported Bootstrap
njch5 Dec 17, 2019
52ca6eb
Working on getting the search query to work
njch5 Dec 18, 2019
30046c7
added bootstrap and css files
iamsammysam Dec 18, 2019
7559c20
merging
iamsammysam Dec 18, 2019
ae3b882
finalized seach functionality
iamsammysam Dec 18, 2019
8a64e26
searchBar and some Css
iamsammysam Dec 18, 2019
58dc710
added logic to clear search
iamsammysam Dec 18, 2019
613305c
Added addMovieCallback function (add to library not working yet)
njch5 Dec 18, 2019
e779f9f
Moved addMovie function to SearchBar component
njch5 Dec 18, 2019
47907e3
Created rental details component to render both selected customer and…
njch5 Dec 18, 2019
614fc0a
Created MovieList component and refactored code in App.js
njch5 Dec 19, 2019
6ad95cd
Added react-flash-message
njch5 Dec 19, 2019
bff22b6
Removed extra comments and attempted to use flash messages
njch5 Dec 19, 2019
79967e3
general styling and css files
iamsammysam Dec 19, 2019
44fb89a
Added flash message and fixed CSS for movie list
njch5 Dec 19, 2019
4717ef9
added homepage component, general css and conditional for rental details
iamsammysam Dec 19, 2019
332819d
Added conditional statement for displaying selected customer & movie …
njch5 Dec 19, 2019
5f94ddc
merging master
iamsammysam Dec 19, 2019
23569a3
merging master
iamsammysam Dec 19, 2019
0abd8ed
general css and styling
iamsammysam Dec 19, 2019
0bb125e
Added alert messages for adding a movie to library
njch5 Dec 20, 2019
de87e22
Removed comments
njch5 Dec 20, 2019
eadd370
Minor typo
njch5 Dec 20, 2019
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
1,101 changes: 1,083 additions & 18 deletions package-lock.json

Large diffs are not rendered by default.

19 changes: 19 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,33 @@
"version": "0.1.0",
"private": true,
"dependencies": {
"axios": "^0.19.0",
"bootstrap": "^4.4.1",
"node-sass": "^4.13.0",
"react": "^16.8.6",
"react-bootstrap": "^1.0.0-beta.16",
"react-dom": "^16.8.6",
"react-flash-message": "^1.0.2",
"react-router": "^5.1.2",
"react-router-dom": "^5.1.2",
"react-scripts": "3.0.1"
},
"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"
]
}
}
49 changes: 33 additions & 16 deletions src/App.css
Original file line number Diff line number Diff line change
@@ -1,28 +1,45 @@
.App {
.app {
text-align: center;
font-family: 'Courier New', Courier, monospace;
}

.App-logo {
animation: App-logo-spin infinite 20s linear;
height: 80px;
.app-nav {
background-color: lightblue;
display: flex;
font-weight: bold;
justify-content: space-around;
border-style: ridge;
}

.App-header {
background-color: #222;
height: 150px;
padding: 20px;
color: white;
.app-header {
/* font-weight: bold; */
grid-area: header;
color: lightgoldenrodyellow;
background-color: grey;
padding: 15px;
}

.App-title {
font-size: 1.5em;
.rental-details {
background-color: lightgoldenrodyellow;
font-weight: bold;
border-style: double;
border-color: lightslategray;
}

.App-intro {
font-size: large;
.success{
color: white;
background-color: green;
font-size: 1.5rem;
text-align: center
}

@keyframes App-logo-spin {
from { transform: rotate(0deg); }
to { transform: rotate(360deg); }
.error{
color: white;
background-color: red;
font-size: 1.5rem;
text-align: center
}

/* .search-results {
margin-top: 20%;
} */
203 changes: 192 additions & 11 deletions src/App.js
Original file line number Diff line number Diff line change
@@ -1,21 +1,202 @@
import axios from 'axios';
import React, { Component } from 'react';
import logo from './logo.svg';
import CustomerCollection from './components/CustomerCollection';
import SearchBar from './components/SearchBar';
import MovieList from './components/MovieList';
import RentalDetails from './components/RentalDetails';
import Homepage from './components/Homepage';
import Alert from 'react-bootstrap/Alert';

import {
BrowserRouter as Router,
Switch,
Route,
Link
} from "react-router-dom";

import './App.css';
import 'bootstrap/dist/css/bootstrap.min.css';

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

this.state = {
movieCollection: [],
customerCollection: [],
currentMovie: '',
currentCustomer: '',
searchMovie: undefined,
movieResults: [],
rentals: [],
alertText: '',
alertVariant: '',
};
}

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

selectMovie = (movieList, movieId) => {

const currentMovie = movieList.find((movie) => {
return movie.external_id === movieId;
});

this.setState({ currentMovie, });
}

selectCustomer = (customerId) => {
const { customerCollection } = this.state;

const currentCustomer = customerCollection.find((customer) => {
return customer.id === customerId;
});
this.setState({ currentCustomer, });
}

filterMovies = (searchMovie) => {
this.setState({
searchMovie,
});

if (searchMovie !== ''){
axios.get(`http://localhost:3000/movies?query=${searchMovie}`)

.then((response) => {
if (searchMovie === this.state.searchMovie) {
this.setState({ movieResults: response.data });
}
})
.catch((error) => {
this.setState({ error: error.message });
});

} else {
this.setState({ movieResults: [] })
}
}

addRental = (movie, customer) => {
let tenDaysLater = new Date(
new Date().getTime() + 10 * 24 * 60 * 60 * 1000
);

const queryParams = {
customer_id: customer.id,
due_date: tenDaysLater
};

axios
.post(
`http://localhost:3000/rentals/${movie.title}/check-out`,
queryParams
)
.then(response => {
console.log("Success!")
this.setState({
alertText: "Rental successfully created!",
alertVariant: "success"
});
})
.catch(error => {
console.log("FAILED!")
this.setState({
error: error.message,
alertText: `An error occurred: ${error.message}`,
alertVariant: "danger"
});
});

const newState = { currentCustomer: "", currentMovie: "" };
this.setState(newState);
};

render() {
const videoAlert = () => {
return(
<Alert
variant={this.state.alertVariant}
onClose={() => this.setState({alertText: undefined, alertVariant: undefined})}
dismissible
>
{this.state.alertText}
</Alert>
)
}
// Returns the entire state
// console.log(this.state);
return (
<div className="App">
<header className="App-header">
<img src={logo} className="App-logo" alt="logo" />
<h1 className="App-title">Welcome to React</h1>
</header>
<p className="App-intro">
To get started, edit <code>src/App.js</code> and save to reload.
</p>

<main className="app">
<header className="app-header">
<h1>Cool Video Store</h1>
</header>

<section className="rental-details">
<RentalDetails
currentCustomer={this.state.currentCustomer}
currentMovie={this.state.currentMovie}
addRentalCallback={this.addRental}
/>
</section>

<Router>
{this.state.alertText ? videoAlert() : "" }
<div>
<section>
<nav className="app-nav">
<h5><strong><Link to="/">Home</Link></strong></h5>
<h5><strong><Link to="/customers">Customers</Link></strong></h5>
<h5><strong><Link to="/library">Library</Link></strong></h5>
<h5><strong><Link to="/search">Search</Link></strong></h5>
</nav>
</section>

<div className="main-routes">

<Switch>

<Route
path="/search">
<SearchBar
movies={this.state.movieResults}
searchChangeCallback={this.filterMovies}
searchMovie={this.state.searchMovie}
/>
</Route>
<Route
path="/library">
<MovieList

selectMovieCallback={this.selectMovie}
/>
</Route>
<Route
path="/customers">
<CustomerCollection
customers={this.state.customerCollection}
selectCustomerCallback={this.selectCustomer}
/>
</Route>
<Route
path="/">
<Homepage/>
</Route>
</Switch>
</div>
</div>
);
}
</Router>
</main>
);
}
}

export default App;
Binary file added src/_DSC2759.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
8 changes: 8 additions & 0 deletions src/components/Customer.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
.customer--header {
margin-top: 2%;
margin-bottom: 10%;
margin-left: 10%;
margin-right:10%;
border: double;
border-radius: 10%;
}
46 changes: 46 additions & 0 deletions src/components/Customer.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
import React from 'react';
import PropTypes from 'prop-types';

import 'bootstrap/dist/css/bootstrap.min.css';
import '../components/Customer.css';

const Customer = (props) => {
const { id, name, registered_at, address, city, state, postal_code, phone, account_credit, selectCustomerCallback } = props;

return(
<div className="customer-card">

<section className="customer--header">
<p><strong>{name}</strong></p>
<p>{registered_at}</p>
<p>{address}</p>
<p>{city}</p>
<p>{state}</p>
<p>{postal_code}</p>
<p>{phone}</p>
{/* <p>{account_credit}</p> */}

<button
className="btn btn-primary customer"
onClick={() => {selectCustomerCallback(id)}}>
Select Customer
</button>
</section>
</div>
);
}

Customer.propTypes = {
id: PropTypes.number.isRequired,
name: PropTypes.string.isRequired,
registered_at: PropTypes.string,
address: PropTypes.string,
city: PropTypes.string,
state: PropTypes.string,
postal_code: PropTypes.string,
phone: PropTypes.string,
account_credit: PropTypes.number,
selectCustomerCallback: PropTypes.func,
}

export default Customer;
6 changes: 6 additions & 0 deletions src/components/CustomerCollection.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
.card-group {
display: grid;
grid-template-columns: 1fr 1fr 1fr 1fr;
width: 100%;
text-align: center;
}
Loading