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

🔥Ida & Jing #5

Open
wants to merge 44 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
44 commits
Select commit Hold shift + click to select a range
15c4339
ran yarn
idago123 Jan 19, 2021
d4d611f
created Video and VideoList Components
idago123 Jan 19, 2021
e96784b
create customer component
Jing-321 Jan 19, 2021
7e5be46
add return to customer and customerCollection
Jing-321 Jan 19, 2021
a55ba4f
updated VideoList and App and proptypes
idago123 Jan 19, 2021
730e6e5
updated Video component to render details and proptypes
idago123 Jan 20, 2021
421019d
deleted comments
idago123 Jan 20, 2021
7981218
Merge pull request #1 from Jing-321/video
idago123 Jan 20, 2021
a832c9c
added route to video list
idago123 Jan 20, 2021
69dbce9
cleaned up some code and comments
idago123 Jan 20, 2021
0c519d7
Merge pull request #2 from Jing-321/renderVideo
idago123 Jan 20, 2021
a639bf3
change app return and add hard code customer list
Jing-321 Jan 20, 2021
6d23580
Merge branch 'master' into jing
Jing-321 Jan 20, 2021
8a39ace
Merge pull request #3 from Jing-321/jing
Jing-321 Jan 20, 2021
22f6d64
update return on App, add NavBar
Jing-321 Jan 20, 2021
ab1fb1b
add route to App
Jing-321 Jan 20, 2021
2daba8a
Merge pull request #4 from Jing-321/jing
Jing-321 Jan 20, 2021
eec7e19
baisc structure set up for pages
Jing-321 Jan 20, 2021
1c59c69
Merge pull request #5 from Jing-321/jing
Jing-321 Jan 20, 2021
9860fe3
deleted node modules folder and re ran yarn install
idago123 Jan 20, 2021
3607cc3
reran yarn install
idago123 Jan 20, 2021
d9c1862
fix yarn.lock bug
Jing-321 Jan 20, 2021
75c29e4
Merge pull request #6 from Jing-321/jing
Jing-321 Jan 20, 2021
7fcc3e9
fix yarn.lock bug again
Jing-321 Jan 20, 2021
87bc26c
Merge pull request #7 from Jing-321/jing
Jing-321 Jan 20, 2021
2233330
deleted package-lock.json file
idago123 Jan 20, 2021
8962116
updated api url base variable
idago123 Jan 20, 2021
e596aaf
updated VideoList
idago123 Jan 20, 2021
2ee7926
created Search page component
idago123 Jan 20, 2021
43db4c9
Renamed Search component to SearchForm, updated component to render s…
idago123 Jan 21, 2021
e39528c
dried up code in App and SearchForm components
idago123 Jan 21, 2021
252a149
updated SearchForm component, added button to add a video to library …
idago123 Jan 21, 2021
e20e33b
cleaned up and deleted comments and unnecessary code
idago123 Jan 21, 2021
c727b5d
updated search results to show overview and release date
idago123 Jan 21, 2021
0a59d0b
Merge pull request #8 from Jing-321/search
idago123 Jan 21, 2021
d37728b
add Cart, able to select and unselect customer and video
Jing-321 Jan 21, 2021
d9da03f
Merge branch 'master' into jing
Jing-321 Jan 21, 2021
02844e7
Merge pull request #9 from Jing-321/jing
Jing-321 Jan 21, 2021
0d96c9e
change name of selectvideo function to fix a bug
Jing-321 Jan 21, 2021
2b3aa54
Merge pull request #10 from Jing-321/jing
Jing-321 Jan 21, 2021
9fc36a8
able to checkout video to a customer
Jing-321 Jan 21, 2021
c39fc9f
Merge pull request #11 from Jing-321/jing
Jing-321 Jan 21, 2021
53b62b9
created post request for add to library functionality
idago123 Jan 21, 2021
d1b1720
deleted comments and dried up code
idago123 Jan 21, 2021
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
13,534 changes: 0 additions & 13,534 deletions package-lock.json

This file was deleted.

9 changes: 7 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,20 @@
"version": "0.1.1",
"private": true,
"dependencies": {
"axios": "^0.21.1",
"bootstrap": "^4.6.0",
"node-sass": "^5.0.0",
"react": "^17.0.1",
"react-bootstrap": "^1.4.3",
"react-dom": "^17.0.1",
"react-router-dom": "^5.2.0",
"react-scripts": "4.0.1"
},
"devDependencies": {
"gh-pages": "^3.1.0",
"@testing-library/jest-dom": "^5.11.9",
"@testing-library/react": "^11.2.3",
"@testing-library/user-event": "^12.6.0"
"@testing-library/user-event": "^12.6.0",
"gh-pages": "^3.1.0"
},
"scripts": {
"start": "PORT=3001 react-scripts start",
Expand Down
2 changes: 2 additions & 0 deletions src/App.css
Original file line number Diff line number Diff line change
Expand Up @@ -26,3 +26,5 @@
from { transform: rotate(0deg); }
to { transform: rotate(360deg); }
}

@import "bootstrap/dist/css/bootstrap.min.css";
183 changes: 167 additions & 16 deletions src/App.js
Original file line number Diff line number Diff line change
@@ -1,21 +1,172 @@
import React, { Component } from 'react';
import logo from './logo.svg';
import React, { useState, useEffect } from 'react';
import axios from 'axios';
import VideoList from './components/VideoList';
import SearchForm from './components/SearchForm';
import { Route, Link } from 'react-router-dom';
import CustomerCollection from './components/CustomerCollection';
import NavBar from './components/NavBar';
import Cart from './components/Cart';
import { Container, Row, Col, Alert } from 'react-bootstrap';
import './App.css';
import { useLocation } from 'react-router-dom';

class App extends Component {
render() {
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>
const API_URL_BASE = 'http://localhost:3000/videos';

const App = () => {
const [videoList, setVideoList] = useState([]);
const [customerList, setCustomerList] = useState([]);
const [errorMessage, setErrorMessage] = useState(null);
const [selectedCustomer, setSelectedCustomer] = useState('');
const [selectedVideo, setSelectedVideo] = useState('');
const [videoResults, setVideoResults] = useState([]);

useEffect(() => {
axios
.get(API_URL_BASE)
.then((response) => {
const apiVideoList = response.data;
setVideoList(apiVideoList);
})
.catch((error) => {
setErrorMessage(error.message);
});

axios
.get('http://localhost:3000/customers')
.then((response) => {
const apiCustomerList = response.data;
console.log(apiCustomerList);
setCustomerList(apiCustomerList);
})
.catch((error) => {
setErrorMessage(error.message);
console.log(error.message);
});
}, []);

const selectCustomerToCart = (customer) => {
setSelectedCustomer(customer);
};
const selectVideoToCart = (video) => {
setSelectedVideo(video);
};

const checkout = (customer, video) => {
const params = {};
params['customer_id'] = customer.id;
params['due_date'] = '2/1/2022';

console.log(params);
axios
.post(`http://localhost:3000/rentals/${video.title}/check-out`, params)
.then((response) => {
setErrorMessage(`Checkout ${video.title} to ${customer.name}.`);
})
.catch((error) => {
setErrorMessage(error.message);
});

setSelectedCustomer('');
setSelectedVideo('');
};

const searchVideo = (query) => {
axios
.get(`${API_URL_BASE}?query=${query}`)
.then((response) => {
const searchResults = response.data;
setVideoResults(searchResults);
setErrorMessage('');
})
.catch((error) => {
setErrorMessage(error.message);
});
};

const selectVideo = (video) => {
axios
.post(`${API_URL_BASE}`, video)
.then((response) => {
setErrorMessage(`Succesfully added ${video.title} to the library.`);
})
.catch((error) => {
setErrorMessage(error.message);
});
};

return (
<main>
<header>
<h1>
<Link to={'/'}>Aloha Video Store</Link>
</h1>
</header>
<div>
<Alert variant="info">{errorMessage}</Alert>
</div>
);
}
}
<nav>
<NavBar location={useLocation()} />
</nav>

<Container>
<Row>
<Col>
<Route
exact={true}
path={'/'}
render={() => <h2>Welcome to Aloha Video Store!</h2>}
/>

<Route
path={'/library'}
render={(props) => (
<VideoList
{...props}
videoList={videoList}
selectedVideo={selectedVideo}
onClickSelect={selectVideoToCart}
/>
)}
/>
<Route
path={'/customers'}
render={(props) => (
<CustomerCollection
{...props}
customerList={customerList}
selectedCustomer={selectedCustomer}
onClickSelect={selectCustomerToCart}
/>
)}
/>
</Col>
<Col md="auto"></Col>
<Col xs lg="2">
<Cart
customer={selectedCustomer}
video={selectedVideo}
onClickCheckout={checkout}
/>
</Col>
</Row>
</Container>

<Route
path={'/search'}
render={(props) => (
<SearchForm
{...props}
videoList={videoList}
searchVideoCallback={searchVideo}
videoResults={videoResults}
videoSelectionCallback={selectVideo}
/>
)}
/>

<footer>Copyright</footer>
</main>
);
};

export default App;
21 changes: 21 additions & 0 deletions src/components/Cart.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import React from 'react';
import { Container, Row, Col, Button, Card} from 'react-bootstrap';

const Cart = (props) => {

return (
<div>
<Card>
<Card.Body>
<Card.Title>{props.customer?.name}</Card.Title>
<Card.Img src={props.video?.image_url} />
<Card.Text>{props.video?.title}</Card.Text>
<Button variant='primary' onClick={()=> props.onClickCheckout(props.customer,props.video)} >checkout</Button>
</Card.Body>
</Card>
</div>

)
};

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

const Customer = (props) => {
const onSelectButtonClick = () => {
if (props.customer.name !== props.selectedCustomer?.name) {
props.onClickSelect(props.customer)
} else {
props.onClickSelect('')
};
};

return (
<tr>
<td>{props.customer.id}</td>
<td>{props.customer.name}</td>
<td>{props.customer.phone}</td>
<td><Button variant="info" onClick={onSelectButtonClick} >
{props.customer.name === props.selectedCustomer?.name ? 'unselect' : 'select'}
</Button></td>
</tr>
);
};

// Customer.PropTypes = {

// };

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

const CustomerCollection = (props) => {

const customerList = props.customerList.map((customer, i) => {
return (
<Customer customer={customer}
selectedCustomer={props.selectedCustomer}
onClickSelect={props.onClickSelect}
/>
);
});

return (
<Table striped bordered hover size="sm">
<thead>
<tr>
<th>#</th>
<th>Name</th>
<th>phone</th>
<th>select a customer</th>
</tr>
</thead>

<tbody>
{customerList}
</tbody>

</Table>
);
};

// CustomerCollection.PropTypes = {

// };

export default CustomerCollection
23 changes: 23 additions & 0 deletions src/components/NavBar.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import React from 'react';
import PropTypes from 'prop-types';
import {BrowserRouter, Link} from 'react-router-dom';
import {Row, Col, Nav} from 'react-bootstrap';

const NavBar = (props) => {

return (
<Nav fill variant="tabs" defaultActiveKey={props.location?.pathname}>
<Nav.Item>
<Nav.Link as={Link} to="/library">all videos</Nav.Link>
</Nav.Item>
<Nav.Item>
<Nav.Link as={Link} to="/customers">all customers</Nav.Link>
</Nav.Item>
<Nav.Item>
<Nav.Link as={Link} to="/search">search for a video</Nav.Link>
</Nav.Item>
</Nav>
);
};

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

const Search = (props) => {
const [title, setTitle] = useState('');

const onFormSubmit = (event) => {
event.preventDefault();

props.searchVideoCallback(title);
setTitle('');
};

const renderVideoDetails = () => {
return props.videoResults.map((result) => (
<>
<div> title: {result.title} </div>
<div> overview: {result.overview} </div>
<div> release date: {result.release_date} </div>
<button onClick={() => props.videoSelectionCallback(result)}>
Add to Library
</button>
</>
));
};

return (
<div>
<form
className="new-search-form"
onSubmit={onFormSubmit}
data-testid="NewSearchForm--form"
>
<div>
<label htmlFor="text">Title:</label>
<input
id="title"
name="title"
onChange={(event) => setTitle(event.target.value)}
value={title}
className="title"
/>
</div>
<input type="submit" value="Find Video" />
</form>
<p> {renderVideoDetails()} </p>
</div>
);
};
export default Search;
3 changes: 3 additions & 0 deletions src/components/Video.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
.video-details {
list-style-type: none;
}
Loading