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

FIRE - Pauline and Tram #9

Open
wants to merge 57 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
57 commits
Select commit Hold shift + click to select a range
917a0ff
added the react router
trambui09 Jan 20, 2021
004f1ff
fixed double quote imports to single
ghostfruitleaf Jan 20, 2021
ef11fda
put yarn.lock into gitignore
trambui09 Jan 20, 2021
6953029
added empty component files
ghostfruitleaf Jan 20, 2021
06d0406
changed the single quote
trambui09 Jan 20, 2021
d522b2b
pauline added the routes as components
trambui09 Jan 20, 2021
4d305a3
laid on the groundworks with react router:
trambui09 Jan 20, 2021
7d9ea48
added useEffect
trambui09 Jan 20, 2021
4913930
started on skeleton to video all videos on /videos
ghostfruitleaf Jan 20, 2021
530c3d7
no axios in project??? hopefully doesn't cause merge conflict
ghostfruitleaf Jan 20, 2021
be615ba
can list all videos in /library
ghostfruitleaf Jan 20, 2021
2cca655
styling added
ghostfruitleaf Jan 20, 2021
0500551
can select video, needs styling
ghostfruitleaf Jan 20, 2021
4caf56d
some formatting for selected video
ghostfruitleaf Jan 20, 2021
cf21901
something changed but idk what?:
ghostfruitleaf Jan 20, 2021
09003a6
added package-lock.json into gitignore and rendered customer list in …
trambui09 Jan 20, 2021
dbb7a50
add the css files and button to customer comp
trambui09 Jan 20, 2021
8d83352
added button to choose selected customer and persist it
trambui09 Jan 20, 2021
cbec8ec
styling on the customer and customers comps
trambui09 Jan 20, 2021
3d3a748
updated css for customer comp
trambui09 Jan 20, 2021
2289bbf
added .env to gitignore
trambui09 Jan 20, 2021
d794170
search bar functionality
trambui09 Jan 20, 2021
1daa0ef
debugged previous edits, results are pulling but not rendering
ghostfruitleaf Jan 21, 2021
714c173
results need to render upon submit
ghostfruitleaf Jan 21, 2021
0d69531
updated, but still fixing
ghostfruitleaf Jan 21, 2021
5356d91
search now working, need add to video functionality
ghostfruitleaf Jan 21, 2021
458fb8a
videoList moved up to App.js
ghostfruitleaf Jan 21, 2021
322d594
checkout functionality
trambui09 Jan 21, 2021
49a2146
seach funtionality and css
trambui09 Jan 21, 2021
57c69fc
videoList moved up to App.js
ghostfruitleaf Jan 21, 2021
f294810
resolved merge conflicts
trambui09 Jan 21, 2021
584682d
getting ready to put in add functionality
ghostfruitleaf Jan 21, 2021
d0f3eb6
Merge branch 'master' of https://github.com/PaulineChane/video-store-…
ghostfruitleaf Jan 21, 2021
f6dacff
conditional buttons on search result videos working
ghostfruitleaf Jan 21, 2021
665d3d9
alert to pop up
trambui09 Jan 21, 2021
32f5236
paulines edits
trambui09 Jan 21, 2021
384dce7
saving work
ghostfruitleaf Jan 21, 2021
6ff1af0
Merge branch 'master' of https://github.com/PaulineChane/video-store-…
ghostfruitleaf Jan 21, 2021
d98d16a
new package added
ghostfruitleaf Jan 21, 2021
466135f
useState for inventory drop down
ghostfruitleaf Jan 21, 2021
9fee2fc
added option to select inventory
ghostfruitleaf Jan 21, 2021
4884ace
still need to style buttons
ghostfruitleaf Jan 21, 2021
7609eac
successfully can add videos, but getting a strange warning in rails api
ghostfruitleaf Jan 21, 2021
46e1d95
now updates library when new video successfully added
ghostfruitleaf Jan 21, 2021
95dfbeb
retains flash messages while updating videos
ghostfruitleaf Jan 21, 2021
7caf485
finally fixed video update without a million re renderings
ghostfruitleaf Jan 21, 2021
c179944
still cannot identify extra parameter created
ghostfruitleaf Jan 21, 2021
8c04121
disregarding phantom videos param, seems to work overall
ghostfruitleaf Jan 21, 2021
f584a90
added error message for rental of movie with no available inventory
ghostfruitleaf Jan 21, 2021
383f057
needed to fix test to account for react-alert
ghostfruitleaf Jan 21, 2021
5af850b
added note on test to print to console regarding react-alert
ghostfruitleaf Jan 21, 2021
d482f64
navbar styling css
trambui09 Jan 21, 2021
5e201b9
search page form to be in the center
trambui09 Jan 21, 2021
1ae8b80
fixed the persisting problem of router
trambui09 Jan 21, 2021
22bb7c7
nav_bar completed
trambui09 Jan 21, 2021
9cba029
rental section css
trambui09 Jan 21, 2021
71cdea4
homepage banner and footer
trambui09 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
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -21,3 +21,6 @@
npm-debug.log*
yarn-debug.log*
yarn-error.log*
yarn.lock
package-lock.json
.env
11,649 changes: 7,469 additions & 4,180 deletions package-lock.json

Large diffs are not rendered by default.

8 changes: 6 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,19 @@
"version": "0.1.1",
"private": true,
"dependencies": {
"axios": "^0.21.1",
"react": "^17.0.1",
"react-alert": "^7.0.2",
"react-alert-template-basic": "^1.0.0",
"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
76 changes: 74 additions & 2 deletions src/App.css
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@
text-align: center;
}

.App-logo {
/* .App-logo {
animation: App-logo-spin infinite 20s linear;
height: 80px;
}
} */

.App-header {
background-color: #222;
Expand All @@ -26,3 +26,75 @@
from { transform: rotate(0deg); }
to { transform: rotate(360deg); }
}

.validation-errors-display {
text-align: center;
margin-bottom: 2em;
background-color: #ffdbd9;
}

.validation-errors-display__list {
list-style-type: none;
padding: 0;
}

.navbar {
background-color: #333;
overflow: hidden;
padding: 20px;
}

.navbar a {
float: left;
color: #f2f2f2;
text-align: center;
padding: 14px 16px;
text-decoration: none;
font-size: 17px;
}

.navbar a:hover {
background-color: #ddd;
color: black;
}

.navbar a.active {
background-color: #4CAF50;
color: white;
}

.checkout__select {
background-color: #4CAF50;
border: none;
color: white;
padding: 0.5em;
text-align: center;
text-decoration: none;
display: inline-block;
font-size: 16px;
}

.checkout__select:hover {
background-color: #3f3f3f;
}

.checkout__bar {
display: flex;
justify-content: space-around;
align-items: center;
width: 100%;
background-color: #ededed;
}

/* .checkout__bar-rentals {
background-image: url('rentals-movie.png');
background-repeat: no-repeat;
} */

.footer {
background-color: #333;
overflow: hidden;
padding: 20px;
color: white;
text-align: center;
}
168 changes: 151 additions & 17 deletions src/App.js
Original file line number Diff line number Diff line change
@@ -1,21 +1,155 @@
import React, { Component } from 'react';
import logo from './logo.svg';
import './App.css';

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>
import React, {Component, useState, useEffect} from 'react';
import {
BrowserRouter as Router,
Switch,
Route,
Link,
} from 'react-router-dom';
import Customers from './Components/Customers'
import Library from './Components/Library'
import Search from './Components/Search'
import Home from './Components/Home'
import './App.css'
import axios from 'axios';
import { useAlert } from 'react-alert'

export default function App() {
// BASE URL FOR API
const BASE_URL = 'http://localhost:3000/'
// error state
const [errorMessage, setErrorMessage] = useState('');
// errors
const allErrors = (errorData) => {
const errors = [];

console.log(errorData)
for(const error of errorData) {
errors.push(<li>{error}</li>);
}

return errors;
}

const [vidAdded, setVidAdded] = useState(false); // used to update list without losing error messages

// state variables
const [videoList, setVideoList] = useState([]);
const alert = useAlert();

// get all videos
useEffect(() => {
console.log(`${BASE_URL}videos`);
axios.get(`${BASE_URL}videos`)
.then((response) => {
setVideoList(response.data);
setErrorMessage(null);
})
.catch((error) => {
setErrorMessage([error.message, 'failed to retrieve videos in library.'])
console.log(error.message);
});
}, [vidAdded]);

// state for selected video
const [currentVideo, setVideo] = useState({id: NaN, title: '', imgUrl: 'favicon.ico'});
const getCurrentVideo = (curId, curTitle, curImg) => {
setVideo({id: curId, title: curTitle, imgUrl: curImg});
}

// state for selected customer
const [currentCustomer, setCurrentCustomer] = useState({id: NaN, name: ''})
const getCurrentCustomer = (custId, custName) => {
setCurrentCustomer({
id: custId,
name: custName
})
}

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

console.log('checking out')
// axios post request goes here

const dueDate = new Date(new Date().getTime()+(7*24*60*60*1000));

axios.post(`${BASE_URL}rentals/${currentVideo.title}/check-out`, {
// eslint-disable-next-line camelcase
customer_id: currentCustomer.id,
// eslint-disable-next-line camelcase
due_date: dueDate
})
.then((response) => {
console.log(response);
alert.show(`${currentVideo.title} successfully checked out to ${currentCustomer.name}!`)
})
.catch((error) => {
console.log(error);
setErrorMessage([error.message.toLowerCase(), 'rental failed - please check inventory and that customer and video are valid']);
alert.show(`${errorMessage}`)
});

setVideo({id: NaN, title: '', imgUrl: 'favicon.ico'})
setCurrentCustomer({id: NaN, name: ''})

}

return (
<Router>
<div>
<header>
<nav className='navbar'>
<Link to="/">Home</Link>
<Link to="/search">Search</Link>
<Link to="/library">Video Library</Link>
<Link to="/customers">Customer List</Link>
</nav>
</header>
<p className="App-intro">
To get started, edit <code>src/App.js</code> and save to reload.
</p>
<section className='checkout__bar'>
<article className='checkout__bar-rentals'>
<h1>Rentals</h1>
{currentCustomer.name && currentVideo.title ? <button onClick={onCheckOut} className='checkout__select'>Check-out</button> : null }
</article>
<article>
<h1>current customer</h1>
<h4>{currentCustomer.name ? currentCustomer.name : 'none selected'}</h4>
</article>
<article>
<h1>current video</h1>
<h4>{currentVideo.title ? currentVideo.title : 'none selected'}</h4>
<img src = {currentVideo.imgUrl} alt = {`Poster for ${currentVideo.title}`}/>
</article>

</section>
<article className = 'validation-errors-display'>
<h3>{errorMessage ? 'errors detected!' : ''}</h3>
<ul className = 'validation-errors-display__list'>
{errorMessage ? allErrors(errorMessage) : ''}
</ul>
</article>
<Switch>
<Route path="/customers">
<Customers url = {BASE_URL} curCustomer = {getCurrentCustomer} />
</Route>
<Route path="/library">
<Library url = {`${BASE_URL}videos`} curVid = {getCurrentVideo} videoList = {videoList}/>
</Route>
<Route path="/search">
<Search curVid = {getCurrentVideo} setError = {setErrorMessage} videoList = {videoList} vidAdded = {vidAdded} setVidAdded = {setVidAdded}/>
</Route>
<Route path="/">
<Home />
</Route>
</Switch>

<footer className='footer'>
Copyrighted © by Pauline and Tram 2021
</footer>
{/* A <Switch> looks through its children <Route>s and
renders the first one that matches the current URL. */}

</div>
);
}
</Router>
);
}

export default App;
8 changes: 7 additions & 1 deletion src/App.test.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,15 @@
import React from 'react';
import ReactDOM from 'react-dom';
import App from './App';
import { transitions, positions, Provider as AlertProvider } from 'react-alert'
import AlertTemplate from 'react-alert-template-basic'

// AlertProvider needs to wrap App in order to work; therefore must be included in test
it('renders without crashing', () => {
const div = document.createElement('div');
ReactDOM.render(<App />, div);
console.log('ATTENTION!! This App uses react-alert, meaning App.test.js will look different to account for the implementation of this package.')
ReactDOM.render( <AlertProvider template={AlertTemplate}>
<App />
</AlertProvider>, div);
ReactDOM.unmountComponentAtNode(div);
});
45 changes: 45 additions & 0 deletions src/Components/Customer.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
.customer {
background-color: #ededed;

padding: 1em 0;
margin: 0.5rem;

min-height: 250px;
min-width: 225px;
flex-basis: 18%;

border-radius: 5px;

display: grid;
grid-template-columns: 1fr 5fr 1fr;
align-items: center;
}

.customer__content {
grid-column-start: 2;

display: flex;
flex-direction: column;
justify-content: space-around;

text-align: center;
font-weight: 100;
overflow: hidden;
}

.customer__select {
align-self: flex-start ;
font-family: 'Permanent Marker', Helvetica, sans-serif;
background-color: #4CAF50;
border: none;
color: white;
padding: 0.5em;
text-align: center;
text-decoration: none;
/* display: inline-block; */
font-size: 16px;
}

.customer__select:hover {
background-color: #3f3f3f;
}
29 changes: 29 additions & 0 deletions src/Components/Customer.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
import React, { Component } from 'react';
import PropTypes from 'prop-types';
import './Customer.css';

const Customer = (props) => {

const onSelectCustomer = () => {
props.curCustomer(props.id, props.name)
}


return (
<div className='customer'>
<section className='customer__content'>
<h3>ID: {props.id}</h3>
<h4>{props.name}</h4>
<h4>Videos Checked Out: {props.videosCheckedOut}</h4>

</section>
<button className='customer__select' onClick={onSelectCustomer}>Select Customer</button>
</div>
)
}

Customer.propTypes = {

};

export default Customer;
4 changes: 4 additions & 0 deletions src/Components/Customers.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
.customers {
display: flex;
flex-wrap: wrap;
}
Loading