Initial commit

This commit is contained in:
Jason Ross
2022-01-03 09:43:32 -06:00
commit 9488d09f07
46 changed files with 42001 additions and 0 deletions
+23
View File
@@ -0,0 +1,23 @@
# See https://help.github.com/articles/ignoring-files/ for more about ignoring files.
# dependencies
/node_modules
/.pnp
.pnp.js
# testing
/coverage
# production
/build
# misc
.DS_Store
.env.local
.env.development.local
.env.test.local
.env.production.local
npm-debug.log*
yarn-debug.log*
yarn-error.log*
+68
View File
@@ -0,0 +1,68 @@
This project was bootstrapped with [Create React App](https://github.com/facebook/create-react-app).
## Available Scripts
In the project directory, you can run:
### `npm start`
Runs the app in the development mode.<br />
Open [http://localhost:3000](http://localhost:3000) to view it in the browser.
The page will reload if you make edits.<br />
You will also see any lint errors in the console.
### `npm test`
Launches the test runner in the interactive watch mode.<br />
See the section about [running tests](https://facebook.github.io/create-react-app/docs/running-tests) for more information.
### `npm build`
Builds the app for production to the `build` folder.<br />
It correctly bundles React in production mode and optimizes the build for the best performance.
The build is minified and the filenames include the hashes.<br />
Your app is ready to be deployed!
See the section about [deployment](https://facebook.github.io/create-react-app/docs/deployment) for more information.
### `npm eject`
**Note: this is a one-way operation. Once you `eject`, you can’t go back!**
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.
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.
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.
## Learn More
You can learn more in the [Create React App documentation](https://facebook.github.io/create-react-app/docs/getting-started).
To learn React, check out the [React documentation](https://reactjs.org/).
### Code Splitting
This section has moved here: https://facebook.github.io/create-react-app/docs/code-splitting
### Analyzing the Bundle Size
This section has moved here: https://facebook.github.io/create-react-app/docs/analyzing-the-bundle-size
### Making a Progressive Web App
This section has moved here: https://facebook.github.io/create-react-app/docs/making-a-progressive-web-app
### Advanced Configuration
This section has moved here: https://facebook.github.io/create-react-app/docs/advanced-configuration
### Deployment
This section has moved here: https://facebook.github.io/create-react-app/docs/deployment
### `npm build` fails to minify
This section has moved here: https://facebook.github.io/create-react-app/docs/troubleshooting#npm-run-build-fails-to-minify
+40523
View File
File diff suppressed because it is too large Load Diff
+33
View File
@@ -0,0 +1,33 @@
{
"name": "nashville-kennels",
"version": "0.1.0",
"private": true,
"dependencies": {
"@testing-library/jest-dom": "^5.14.1",
"@testing-library/react": "^11.2.7",
"@testing-library/user-event": "^12.8.3",
"react": "^17.0.2",
"react-dom": "^17.0.2",
"react-router-dom": "^5.3.0",
"react-scripts": "4.0.3",
"web-vitals": "^1.1.2"
},
"scripts": {
"start": "react-scripts start",
"build": "react-scripts build",
"test": "react-scripts test",
"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"
]
}
}
Binary file not shown.

After

Width:  |  Height:  |  Size: 3.1 KiB

+43
View File
@@ -0,0 +1,43 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8" />
<link rel="icon" href="%PUBLIC_URL%/favicon.ico" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<meta name="theme-color" content="#000000" />
<meta
name="description"
content="Web site created using create-react-app"
/>
<link rel="apple-touch-icon" href="%PUBLIC_URL%/logo192.png" />
<!--
manifest.json provides metadata used when your web app is installed on a
user's mobile device or desktop. See https://developers.google.com/web/fundamentals/web-app-manifest/
-->
<link rel="manifest" href="%PUBLIC_URL%/manifest.json" />
<!--
Notice the use of %PUBLIC_URL% in the tags above.
It will be replaced with the URL of the `public` folder during the build.
Only files inside the `public` folder can be referenced from the HTML.
Unlike "/favicon.ico" or "favicon.ico", "%PUBLIC_URL%/favicon.ico" will
work correctly both with client-side routing and a non-root public URL.
Learn how to configure a non-root public URL by running `npm run build`.
-->
<title>React App</title>
</head>
<body>
<noscript>You need to enable JavaScript to run this app.</noscript>
<div id="root"></div>
<!--
This HTML file is a template.
If you open it directly in the browser, you will see an empty page.
You can add webfonts, meta tags, or analytics to this file.
The build step will place the bundled scripts into the <body> tag.
To begin the development, run `npm start` or `yarn start`.
To create a production bundle, use `npm run build` or `yarn build`.
-->
</body>
</html>
Binary file not shown.

After

Width:  |  Height:  |  Size: 5.2 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 9.4 KiB

+25
View File
@@ -0,0 +1,25 @@
{
"short_name": "React App",
"name": "Create React App Sample",
"icons": [
{
"src": "favicon.ico",
"sizes": "64x64 32x32 24x24 16x16",
"type": "image/x-icon"
},
{
"src": "logo192.png",
"type": "image/png",
"sizes": "192x192"
},
{
"src": "logo512.png",
"type": "image/png",
"sizes": "512x512"
}
],
"start_url": ".",
"display": "standalone",
"theme_color": "#000000",
"background_color": "#ffffff"
}
+3
View File
@@ -0,0 +1,3 @@
# https://www.robotstxt.org/robotstxt.html
User-agent: *
Disallow:
+63
View File
@@ -0,0 +1,63 @@
import React from "react"
import { Route } from "react-router-dom"
import { LocationList } from "./location/LocationList"
import { AnimalList } from "./animal/AnimalList"
import { CustomerList } from "./customer/CustomerList.js"
import { EmployeeList } from "./employee/EmployeeList";
import { EmployeeForm } from "./employee/EmployeeForm.js"
import { AnimalForm } from "./animal/AnimalForm.js"
import { EmployeeDetail } from "./employee/EmployeeDetail.js"
import { LocationDetail } from "./location/LocationDetail.js"
import { AnimalDetails } from "./animal/AnimalDetail.js"
export const ApplicationViews = () => {
return (
<>
<Route exact path="/">
<LocationList />
</Route>
<Route path="/locations/:locationId(\d+)">
<LocationDetail />
</Route>
<Route exact path="/animals">
<>
<main className="animalContainer">
<h1>Animals</h1>
<AnimalList />
</main>
</>
</Route>
<Route exact path="/animals/create">
<AnimalForm />
</Route>
<Route path="/animals/:animalId(\d+)">
<AnimalDetails />
</Route>
<Route path="/animals/edit/:animalId(\d+)">
<AnimalForm />
</Route>
<Route path="/customers">
<CustomerList />
</Route>
<Route path="/employees/create">
<EmployeeForm />
</Route>
<Route path="/employees/:employeeId(\d+)">
<EmployeeDetail />
</Route>
<Route exact path="/employees">
<EmployeeList />
</Route>
</>
)
}
+39
View File
@@ -0,0 +1,39 @@
/* Import the google web fonts you want to use */
@import url("https://fonts.googleapis.com/css?family=Comfortaa|Patua+One");
/*Typography
--------------------------------------------------------------*/
body,
button,
input,
select,
textarea {
color: #404040;
font-family: "Comfortaa", Arial, sans-serif;
font-size: 14px;
line-height: 1.5;
}
h1,
h2,
h3,
h4,
h5,
h6 {
font-family: "Patua One", serif;
letter-spacing: 2px;
}
p {
margin-bottom: 1.5em;
color: #d6fcff;
color: darkslateblue;
}
strong {
font-weight: bold;
}
address {
margin: 0 0 1.5em;
}
+27
View File
@@ -0,0 +1,27 @@
import React from "react"
import { Route, Redirect } from "react-router-dom"
import { ApplicationViews } from "./ApplicationViews"
import { NavBar } from "./nav/NavBar"
import { Login } from "./auth/Login"
import { Register } from "./auth/Register"
import "./Kennel.css"
export const Kennel = () => (
<>
<Route render={() => {
if (localStorage.getItem("kennel_customer")) {
return (
<>
<Route render={props => <NavBar {...props} />} />
<Route render={props => <ApplicationViews {...props} />} />
</>
)
} else {
return <Redirect to="/login" />
}
}} />
<Route path="/login" render={props => <Login {...props} />} />
<Route path="/register" render={props => <Register {...props} />} />
</>
)
+14
View File
@@ -0,0 +1,14 @@
import React from "react"
import "./Animals.css"
import { Link } from "react-router-dom"
export default ({ animal }) => (
<section className="animal">
<h3 className="animal__name">
<Link to={`/animals/${animal.id}`}>
{ animal.name }
</Link>
</h3>
<div className="animal__breed">{ animal.breed }</div>
</section>
)
+32
View File
@@ -0,0 +1,32 @@
import React, { useEffect, useState } from "react"
import { useParams, useHistory } from "react-router-dom"
import { getAnimalById, releaseAnimal } from "./AnimalManager"
import "./Animals.css"
export const AnimalDetails = () => {
const [animal, setAnimal] = useState({ location: {}, customer: {} })
const { animalId } = useParams()
const history = useHistory()
useEffect(() => {
getAnimalById(animalId)
.then(setAnimal)
}, [])
return (
<section className="animal">
<h3 className="animal__name">{animal.name}</h3>
<div className="animal__breed">{animal.breed}</div>
<div className="animal__location">Location: {animal.location?.name}</div>
<div className="animal__owner">Customer: {animal.customer?.name}</div>
<div className="animal__treatment">Treatment: {animal.treatment}</div>
<button onClick={() => releaseAnimal(animal.id).then(() => history.push("/animals"))} >Release Animal</button>
<button onClick={() => {
history.push(`/animals/edit/${animal.id}`)
}}>Edit</button>
</section>
)
}
+128
View File
@@ -0,0 +1,128 @@
import React, { useState, useEffect } from "react"
import { addAnimal, updateAnimal, getAnimalById } from "./AnimalManager"
import { getLocations } from "../location/LocationManager"
import { useParams, useHistory } from 'react-router-dom'
export const AnimalForm = () => {
// Use the required context providers for data
const [ locations, setLocations ] = useState([])
const { animalId } = useParams()
// Component state
const [animal, setAnimal] = useState({})
const history = useHistory()
// Is there a a URL parameter??
const editMode = animalId ? true : false // true or false
const handleControlledInputChange = (event) => {
/*
When changing a state object or array, always create a new one
and change state instead of modifying current one
*/
const newAnimal = Object.assign({}, animal) // Create copy
newAnimal[event.target.name] = event.target.value // Modify copy
setAnimal(newAnimal) // Set copy as new state
}
// Get animals from API when component initializes
useEffect(() => {
if (editMode) {
getAnimalById(animalId).then((res) => {
setAnimal(res)
})
}
getLocations().then(locationsData => setLocations(locationsData))
}, [])
const constructNewAnimal = () => {
const locationId = parseInt(animal.locationId)
if (locationId === 0) {
window.alert("Please select a location")
} else {
if (editMode) {
// PUT
updateAnimal({
id: animal.id,
name: animal.name,
breed: animal.breed,
locationId: locationId,
treatment: animal.treatment,
customerId: parseInt(localStorage.getItem("kennel_customer"))
})
.then(() => history.push("/animals"))
} else {
// POST
addAnimal({
name: animal.name,
breed: animal.breed,
locationId: locationId,
treatment: animal.treatment,
customerId: parseInt(localStorage.getItem("kennel_customer"))
})
.then(() => history.push("/animals"))
}
}
}
return (
<form className="animalForm">
<h2 className="animalForm__title">{editMode ? "Update Animal" : "Admit Animal"}</h2>
<fieldset>
<div className="form-group">
<label htmlFor="name">Animal name: </label>
<input type="text" name="name" required autoFocus className="form-control"
placeholder="Animal name"
defaultValue={animal.name}
onChange={handleControlledInputChange}
/>
</div>
</fieldset>
<fieldset>
<div className="form-group">
<label htmlFor="breed">Animal breed: </label>
<input type="text" name="breed" required className="form-control"
placeholder="Animal breed"
defaultValue={animal.breed}
onChange={handleControlledInputChange}
/>
</div>
</fieldset>
<fieldset>
<div className="form-group">
<label htmlFor="locationId">Location: </label>
<select name="locationId" className="form-control"
value={animal.location_id}
onChange={handleControlledInputChange}>
<option value="0">Select a location</option>
{
locations.map(e => (
<option key={e.id} value={e.id}>
{e.name}
</option>
))
}
</select>
</div>
</fieldset>
<fieldset>
<div className="form-group">
<label htmlFor="treatment">Treatments: </label>
<textarea type="text" name="treatment" className="form-control"
value={animal.treatment}
onChange={handleControlledInputChange}>
</textarea>
</div>
</fieldset>
<button type="submit"
onClick={evt => {
evt.preventDefault()
constructNewAnimal()
}}
className="btn btn-primary">
{editMode ? "Save Updates" : "Make Reservation"}
</button>
</form>
)
}
+42
View File
@@ -0,0 +1,42 @@
import React, { useState, useEffect } from "react"
import { useHistory } from 'react-router-dom'
import { getAnimals, getAnimalsBySearchTerm } from "./AnimalManager"
import Animal from "./Animal"
import "./Animals.css"
import { AnimalSearch } from "./AnimalSearch"
export const AnimalList = () => {
const [ animals, setAnimals ] = useState([])
const [ searchTerm, setSearchTerm ] = useState('')
const history = useHistory()
// Initialization effect hook -> Go get animal data
useEffect(()=> {
if (searchTerm.length > 1) {
getAnimalsBySearchTerm(searchTerm).then((animalsData) => setAnimals(animalsData))
} else {
getAnimals().then((animalsData) => setAnimals(animalsData))
}
}, [searchTerm])
const onSearchTermChange = (value) => {
setSearchTerm(value)
}
return (
<>
<AnimalSearch onSearchTermChange={onSearchTermChange} searchTerm={searchTerm} />
<div style={{ marginTop: "2rem"}}>
<button onClick={() => history.push("/animals/create")}>
Make Reservation
</button>
<div className="animals">
{
animals.map(animal => <Animal key={animal.id} animal={animal} />)
}
</div>
</div>
</>
)
}
+47
View File
@@ -0,0 +1,47 @@
export const getAnimals = () => {
return fetch("http://localhost:8088/animals")
.then(res => res.json())
}
export const getAnimalsBySearchTerm = (searchTerm) => {
return fetch(`http://localhost:8088/animals?search=${searchTerm}`)
.then(res => res.json())
}
export const getAnimalById = (id) => {
return fetch(`http://localhost:8088/animals/${id}`)
.then(res => res.json())
}
export const addAnimal = animal => {
return fetch("http://localhost:8088/animals", {
method: "POST",
headers: {
"Content-Type": "application/json"
},
body: JSON.stringify(animal)
})
.then(getAnimals)
}
export const updateAnimal = animal => {
return fetch(`http://localhost:8088/animals/${animal.id}`, {
method: "PUT",
headers: {
"Content-Type": "application/json"
},
body: JSON.stringify(animal)
})
.then(getAnimals)
}
export const releaseAnimal = (animalId) => {
return fetch(`http://localhost:8088/animals/${animalId}`, {
method: "DELETE"
})
.then(getAnimals)
}
+18
View File
@@ -0,0 +1,18 @@
import React from "react"
export const AnimalSearch = ({searchTerms, onSearchTermChange}) => {
return (
<>
<div>Search for an animal</div>
<input type="text" className="animals__search"
value={searchTerms}
onChange={
(changeEvent) => {
onSearchTermChange(changeEvent.target.value)
}
}
placeholder="Enter search string here..." />
</>
)
}
+21
View File
@@ -0,0 +1,21 @@
.animalContainer {
margin: 0 5rem;
}
.animals {
display: flex;
flex-wrap: wrap;
justify-content: space-between;
margin-top: 1rem;
}
.animal {
flex-basis: 24%;
margin: 0.5rem 1em;
padding: 0.5rem 1rem;
border: 1px solid goldenrod;
}
.animals__search {
width: 25rem;
}
+69
View File
@@ -0,0 +1,69 @@
.h1, h1 {
font-size: 2.5rem;
}
fieldset {
min-width: 0;
padding: 1rem 0;
margin: 0;
border: 0;
}
.form--login {
display: inline-block;
margin: 0 auto;
text-align: left;
}
.form--login > fieldset > input[type="email"],
.form--login > fieldset > input[type="password"] {
width: 25em;
}
.label--login {
width: 8rem;
display: inline-block;
}
.form-control {
display: block;
width: 94%;
height: calc(1.5em + .75rem + 2px);
padding: .375rem .75rem;
font-size: 1rem;
font-weight: 400;
line-height: 1.5;
color: #495057;
background-color: #fff;
background-clip: padding-box;
border: 1px solid #ced4da;
border-radius: .25rem;
-webkit-transition: border-color .15s ease-in-out,box-shadow .15s ease-in-out;
transition: border-color .15s ease-in-out,box-shadow .15s ease-in-out;
}
.container--login {
text-align: center;
}
.form--login {
background-position-x: right;
background-image: url(logo.png);
z-index: 1;
min-height: 25rem;
min-width: 45rem;
background-color: hsla(0,0%,100%,0.40);
background-blend-mode: overlay;
background-repeat: no-repeat;
}
.button--close {
position: relative;
bottom: -2rem;
}
.dialog {
min-width: 15rem;
min-height: 5rem;
}
+70
View File
@@ -0,0 +1,70 @@
import React, { useRef } from "react"
import { Link, useHistory } from "react-router-dom";
import "./Login.css"
export const Login = () => {
const email = useRef()
const password = useRef()
const history = useHistory()
const existingUserCheck = () => {
return fetch(`http://localhost:8088/customers?email=${email.current.value}`)
.then(res => res.json())
.then(user => user.length ? user[0] : false)
}
const handleLogin = (e) => {
e.preventDefault()
existingUserCheck()
.then(exists => {
if (exists && exists.password === password.current.value) {
localStorage.setItem("kennel_customer", exists.id)
history.push("/")
} else if (exists && exists.password !== password.current.value) {
alert('Password does not match')
} else if (!exists) {
alert('User does not exist')
}
})
}
return (
<main className="container--login">
<section>
<form className="form--login" onSubmit={handleLogin}>
<h1>Nashville Kennels</h1>
<h2>Please sign in</h2>
<fieldset>
<label htmlFor="inputEmail"> Email address </label>
<input ref={email} type="email"
id="email"
defaultValue="steve@stevebrownlee.com"
className="form-control"
placeholder="Email address"
required autoFocus />
</fieldset>
<fieldset>
<label htmlFor="inputPassword"> Password </label>
<input ref={password} type="password"
id="password"
defaultValue="me"
className="form-control"
placeholder="Password"
required />
</fieldset>
<fieldset>
<button type="submit">
Sign in
</button>
</fieldset>
</form>
</section>
<section className="link--register">
<Link to="/register">Not a member yet?</Link>
</section>
</main>
)
}
+102
View File
@@ -0,0 +1,102 @@
import React, { useRef } from "react"
import { useHistory } from 'react-router-dom'
import "./Login.css"
export const Register = () => {
const firstName = useRef()
const lastName = useRef()
const email = useRef()
const password = useRef()
const verifyPassword = useRef()
const history = useHistory()
const existingUserCheck = () => {
return fetch(`http://localhost:8088/customers?email=${email.current.value}`)
.then(res => res.json())
.then(user => !!user.length)
}
const handleRegister = (e) => {
e.preventDefault()
if (password.current.value === verifyPassword.current.value) {
existingUserCheck()
.then(() => {
fetch("http://localhost:8088/customers", {
method: "POST",
headers: {
"Content-Type": "application/json"
},
body: JSON.stringify({
email: email.current.value,
password: password.current.value,
name: `${firstName.current.value} ${lastName.current.value}`
})
})
.then(_ => _.json())
.then(createdUser => {
if (createdUser.hasOwnProperty("id")) {
localStorage.setItem("kennel_customer", createdUser.id)
history.push("/")
}
})
})
} else {
alert('Passwords do not match')
}
}
return (
<main style={{ textAlign: "center" }}>
<form className="form--login" onSubmit={handleRegister}>
<h1 className="h3 mb-3 font-weight-normal">Please Register for NSS Kennels</h1>
<fieldset>
<label htmlFor="firstName"> First Name </label>
<input ref={firstName} type="text"
name="firstName"
className="form-control"
placeholder="First name"
required autoFocus />
</fieldset>
<fieldset>
<label htmlFor="lastName"> Last Name </label>
<input ref={lastName} type="text"
name="lastName"
className="form-control"
placeholder="Last name"
required />
</fieldset>
<fieldset>
<label htmlFor="inputEmail"> Email address </label>
<input ref={email} type="email"
name="email"
className="form-control"
placeholder="Email address"
required />
</fieldset>
<fieldset>
<label htmlFor="inputPassword"> Password </label>
<input ref={password} type="password"
name="password"
className="form-control"
placeholder="Password"
required />
</fieldset>
<fieldset>
<label htmlFor="verifyPassword"> Verify Password </label>
<input ref={verifyPassword} type="password"
name="verifyPassword"
className="form-control"
placeholder="Verify password"
required />
</fieldset>
<fieldset>
<button type="submit">
Sign in
</button>
</fieldset>
</form>
</main>
)
}
Binary file not shown.

After

Width:  |  Height:  |  Size: 173 KiB

+8
View File
@@ -0,0 +1,8 @@
import React from "react"
import "./Customers.css"
export const Customer = () => (
<section className="customer">
<h3 className="customer__name">Sarah Langholt</h3>
</section>
)
+34
View File
@@ -0,0 +1,34 @@
import React, { useEffect, useState } from "react"
import { getAnimals } from "../animal/AnimalManager";
import { getCustomers } from "./CustomerManager";
import "./Customers.css"
export const CustomerList = () => {
const [ animals, setAnimals ] = useState([])
const [ customers, setCustomers ] = useState([])
useEffect(() => {
getCustomers().then(customersData => setCustomers(customersData))
getAnimals().then(animalsData => setAnimals(animalsData))
}, [])
return (
<div style={{ margin: "0rem 3rem"}}>
<h1>Customers</h1>
<article className="customers">
{
customers.map(customer => {
customer.animals = animals.filter(a => customer.id === a.customer_id) || []
return <section key={customer.id} className="customer">
<h2>{customer.name}</h2>
<div>{customer.address}</div>
<h4>Animals</h4>
{ customer.animals && customer.animals.map(a => <div key={`animal--${a.id}`}>{a.name} ({a.breed})</div>)}
</section>
})
}
</article>
</div>
)
}
@@ -0,0 +1,17 @@
export const getCustomers = () => {
return fetch("http://localhost:8088/customers")
.then(res => res.json())
}
export const addCustomer = customer => {
return fetch("http://localhost:8088/customers", {
method: "POST",
headers: {
"Content-Type": "application/json"
},
body: JSON.stringify(customer)
})
.then(getCustomers)
}
+12
View File
@@ -0,0 +1,12 @@
.customers {
display: flex;
flex-wrap: wrap;
justify-content: space-between;
}
.customer {
flex-basis: 28%;
margin: 1em;
padding: 1em;
border: 1px solid goldenrod;
}
+9
View File
@@ -0,0 +1,9 @@
import React from "react"
import "./Employees.css"
export const Employee = () => (
<section className="employee">
<h3 className="employee__name">Aja Washington</h3>
<div className="employee__location">Nashville North</div>
</section>
)
+30
View File
@@ -0,0 +1,30 @@
import React, { useState, useEffect } from "react"
import { useParams } from 'react-router-dom'
import { getEmployeeById } from "./EmployeeManager"
import "./Employees.css"
export const EmployeeDetail = () => {
const { employeeId } = useParams()
const [employee, setEmployee] = useState({})
useEffect(() => {
getEmployeeById(employeeId).then(employeeData => setEmployee(employeeData))
}, [employeeId])
return (
<section className="employee">
<h3 className="employee__name">{employee.name}</h3>
<div>Currently working at { employee.location?.name }</div>
<div>
{
(employee.animal === undefined)
? "Not assigned to an animal"
: `Currently taking care of ${employee.animal?.name}`
}
</div>
</section>
)
}
+93
View File
@@ -0,0 +1,93 @@
import React, { useState, useRef, useEffect } from "react"
import { useHistory } from 'react-router-dom'
import { addEmployee } from "./EmployeeManager"
import { getLocations } from "../location/LocationManager"
import { getAnimals } from "../animal/AnimalManager"
import "./Employees.css"
export const EmployeeForm = () => {
const name = useRef(null)
const location = useRef(null)
const animal = useRef(null)
const history = useHistory()
const [animals, setAnimals] = useState([])
const [locations, setLocations] = useState([])
/*
Get animal state and location state on initialization.
*/
useEffect(() => {
getAnimals().then(animalsData => setAnimals(animalsData))
getLocations().then(locationsData => setLocations(locationsData))
}, [])
const constructNewEmployee = () => {
/*
The `location` and `animal` variables below are
the references attached to the input fields. You
can't just ask for the `.value` property directly,
but rather `.current.value` now in React.
*/
const locationId = parseInt(location.current.value)
const animalId = parseInt(animal.current.value)
if (locationId === 0) {
window.alert("Please select a location")
} else {
addEmployee({
name: name.current.value,
locationId,
animalId
})
.then(() => history.push("/employees"))
}
}
return (
<form className="employeeForm">
<h2 className="employeeForm__title">New Employee</h2>
<fieldset>
<div className="form-group">
<label htmlFor="employeeName">Employee name: </label>
<input type="text" id="employeeName" ref={name} required autoFocus className="form-control" placeholder="Employee name" />
</div>
</fieldset>
<fieldset>
<div className="form-group">
<label htmlFor="location">Assign to location: </label>
<select defaultValue="" name="location" ref={location} id="employeeLocation" className="form-control" >
<option value="0">Select a location</option>
{locations.map(e => (
<option key={e.id} value={e.id}>
{e.name}
</option>
))}
</select>
</div>
</fieldset>
<fieldset>
<div className="form-group">
<label htmlFor="location">Caretaker for: </label>
<select defaultValue="" name="animal" ref={animal} id="employeeAnimal" className="form-control" >
<option value="0">Select an animal</option>
{animals.map(e => (
<option key={e.id} value={e.id}>
{e.name}
</option>
))}
</select>
</div>
</fieldset>
<button type="submit"
onClick={evt => {
evt.preventDefault() // Prevent browser from submitting the form
constructNewEmployee()
}}
className="btn btn-primary">
Save Employee
</button>
</form>
)
}
+35
View File
@@ -0,0 +1,35 @@
import React, { useState, useEffect } from "react"
import { Link, useHistory } from "react-router-dom"
import { getEmployees } from "./EmployeeManager"
import "./Employees.css"
export const EmployeeList = () => {
const [ employees, setEmployees ] = useState([])
const history = useHistory()
useEffect(() => {
getEmployees().then(employeesData => setEmployees(employeesData))
}, [])
return (
<div style={{ margin: "0rem 3rem"}}>
<h1>Employees</h1>
<button onClick={() => history.push("/employees/create")}>
Add Employee
</button>
<article className="employees">
{
employees.map(employee => {
return <section className="employee" key={employee.id}>
<Link to={`/employees/${employee.id}`}>
<h3>{employee.name}</h3>
</Link>
</section>
})
}
</article>
</div>
)
}
@@ -0,0 +1,21 @@
export const getEmployees = () => {
return fetch("http://localhost:8088/employees")
.then(res => res.json())
}
export const getEmployeeById = (id) => {
return fetch(`http://localhost:8088/employees/${id}`)
.then(res => res.json())
}
export const addEmployee = employee => {
return fetch("http://localhost:8088/employees", {
method: "POST",
headers: {
"Content-Type": "application/json"
},
body: JSON.stringify(employee)
})
.then(getEmployees)
}
+12
View File
@@ -0,0 +1,12 @@
.employees {
display: flex;
flex-wrap: wrap;
justify-content: space-between;
}
.employee {
flex-basis: 28%;
margin: 1em;
padding: 1em;
border: 1px solid goldenrod;
}
+8
View File
@@ -0,0 +1,8 @@
import React from "react"
import "./Locations.css"
export const Location = () => (
<section className="location">
<h3 className="location__name">Nashville North</h3>
</section>
)
+26
View File
@@ -0,0 +1,26 @@
import React from "react"
import { useLocation } from 'react-router-dom'
import "./Locations.css"
export const LocationDetail = () => {
const location = useLocation()
return (
<section className="location">
<h2 className="location__name">{location.state.chosenLocation.name}</h2>
<address className="location__address">{location.state.chosenLocation.address}</address>
<div>
<h4>Employees</h4>
{
location.state.chosenLocation.employees?.map(e => e.name).join(", ")
}
</div>
<div>
<h4>Current Residents</h4>
{
location.state.chosenLocation.animals?.map(a => a.name).join(", ")
}
</div>
</section>
)
}
+63
View File
@@ -0,0 +1,63 @@
import React, { useState, useEffect } from "react"
import { getEmployees } from "../employee/EmployeeManager"
import { getLocations } from "./LocationManager"
import { getAnimals } from "../animal/AnimalManager"
import { Link } from "react-router-dom"
import "./Locations.css"
export const LocationList = () => {
const [locations, setLocations] = useState([])
const [employees, setEmployees] = useState([])
const [animals, setAnimals] = useState([])
useEffect(() => {
getEmployees().then(employeesData => setEmployees(employeesData))
getAnimals().then(animalsData => setAnimals(animalsData))
}, [])
useEffect(() => {
if (employees && animals) {
getLocations().then(locationsData => {
const combined = locationsData.map(location => {
location.employees = employees.filter(e => e.location_id === location.id)
location.animals = animals.filter(a => a.location_id === location.id)
return location
})
setLocations(combined)
})
}
}, [employees, animals])
return (
<div style={{ margin: "0rem 3rem" }}>
<h1>Locations</h1>
<div className="locations">
{
locations.map(location => {
return <article key={`location--${location.id}`} className="card location" style={{ width: `18rem` }}>
<section className="card-body">
<Link className="card-link"
to={{
pathname: `/locations/${location.id}`,
state: { chosenLocation: location }
}}>
<h2 className="card-title">{location.name}</h2>
</Link>
</section>
<section>
{`${location.employees.length} ${location.employees.length === 1 ? "employee" : "employees"}`}
</section>
<section>
{`${location.animals.length} ${location.animals.length === 1 ? "animal" : "animals"}`}
</section>
</article>
})
}
</div>
</div>
)
}
@@ -0,0 +1,16 @@
export const getLocations = () => {
return fetch("http://localhost:8088/locations")
.then(res => res.json())
}
export const addLocation = location => {
return fetch("http://localhost:8088/locations", {
method: "POST",
headers: {
"Content-Type": "application/json"
},
body: JSON.stringify(location)
})
.then(getLocations)
}
+12
View File
@@ -0,0 +1,12 @@
.locations {
display: flex;
flex-wrap: wrap;
justify-content: space-between;
}
.location {
flex-basis: 28%;
margin: 1em;
padding: 1em;
border: 1px solid goldenrod;
}
+10
View File
@@ -0,0 +1,10 @@
.navbar {
display: flex;
flex-wrap: nowrap;
justify-content: left;
}
.navbar__item {
flex-basis: 20%;
list-style-type: none;
}
+25
View File
@@ -0,0 +1,25 @@
import React from "react"
import { Link } from "react-router-dom"
import "./NavBar.css"
export const NavBar = () => {
return (
<ul className="navbar">
<li className="navbar__item active">
<Link className="navbar__link" to="/">NSS Kennels</Link>
</li>
<li className="navbar__item">
<Link className="navbar__link" to="/animals">Animals</Link>
</li>
<li className="navbar__item">
<Link className="navbar__link" to="/customers">Customers</Link>
</li>
<li className="navbar__item">
<Link className="navbar__link" to="/employees">Employees</Link>
</li>
<li className="navbar__item">
<Link className="navbar__link" to="/login" onClick={() => localStorage.removeItem("kennel_customer")}>Logout</Link>
</li>
</ul>
)
}
+13
View File
@@ -0,0 +1,13 @@
body {
margin: 0;
font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'Roboto', 'Oxygen',
'Ubuntu', 'Cantarell', 'Fira Sans', 'Droid Sans', 'Helvetica Neue',
sans-serif;
-webkit-font-smoothing: antialiased;
-moz-osx-font-smoothing: grayscale;
}
code {
font-family: source-code-pro, Menlo, Monaco, Consolas, 'Courier New',
monospace;
}
+14
View File
@@ -0,0 +1,14 @@
import React from "react"
import ReactDOM from "react-dom"
import { BrowserRouter as Router } from "react-router-dom"
import { Kennel } from "./components/Kennel.js"
import "./index.css"
ReactDOM.render(
<React.StrictMode>
<Router>
<Kennel />
</Router>
</React.StrictMode>,
document.getElementById("root")
)
+7
View File
@@ -0,0 +1,7 @@
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 841.9 595.3">
<g fill="#61DAFB">
<path d="M666.3 296.5c0-32.5-40.7-63.3-103.1-82.4 14.4-63.6 8-114.2-20.2-130.4-6.5-3.8-14.1-5.6-22.4-5.6v22.3c4.6 0 8.3.9 11.4 2.6 13.6 7.8 19.5 37.5 14.9 75.7-1.1 9.4-2.9 19.3-5.1 29.4-19.6-4.8-41-8.5-63.5-10.9-13.5-18.5-27.5-35.3-41.6-50 32.6-30.3 63.2-46.9 84-46.9V78c-27.5 0-63.5 19.6-99.9 53.6-36.4-33.8-72.4-53.2-99.9-53.2v22.3c20.7 0 51.4 16.5 84 46.6-14 14.7-28 31.4-41.3 49.9-22.6 2.4-44 6.1-63.6 11-2.3-10-4-19.7-5.2-29-4.7-38.2 1.1-67.9 14.6-75.8 3-1.8 6.9-2.6 11.5-2.6V78.5c-8.4 0-16 1.8-22.6 5.6-28.1 16.2-34.4 66.7-19.9 130.1-62.2 19.2-102.7 49.9-102.7 82.3 0 32.5 40.7 63.3 103.1 82.4-14.4 63.6-8 114.2 20.2 130.4 6.5 3.8 14.1 5.6 22.5 5.6 27.5 0 63.5-19.6 99.9-53.6 36.4 33.8 72.4 53.2 99.9 53.2 8.4 0 16-1.8 22.6-5.6 28.1-16.2 34.4-66.7 19.9-130.1 62-19.1 102.5-49.9 102.5-82.3zm-130.2-66.7c-3.7 12.9-8.3 26.2-13.5 39.5-4.1-8-8.4-16-13.1-24-4.6-8-9.5-15.8-14.4-23.4 14.2 2.1 27.9 4.7 41 7.9zm-45.8 106.5c-7.8 13.5-15.8 26.3-24.1 38.2-14.9 1.3-30 2-45.2 2-15.1 0-30.2-.7-45-1.9-8.3-11.9-16.4-24.6-24.2-38-7.6-13.1-14.5-26.4-20.8-39.8 6.2-13.4 13.2-26.8 20.7-39.9 7.8-13.5 15.8-26.3 24.1-38.2 14.9-1.3 30-2 45.2-2 15.1 0 30.2.7 45 1.9 8.3 11.9 16.4 24.6 24.2 38 7.6 13.1 14.5 26.4 20.8 39.8-6.3 13.4-13.2 26.8-20.7 39.9zm32.3-13c5.4 13.4 10 26.8 13.8 39.8-13.1 3.2-26.9 5.9-41.2 8 4.9-7.7 9.8-15.6 14.4-23.7 4.6-8 8.9-16.1 13-24.1zM421.2 430c-9.3-9.6-18.6-20.3-27.8-32 9 .4 18.2.7 27.5.7 9.4 0 18.7-.2 27.8-.7-9 11.7-18.3 22.4-27.5 32zm-74.4-58.9c-14.2-2.1-27.9-4.7-41-7.9 3.7-12.9 8.3-26.2 13.5-39.5 4.1 8 8.4 16 13.1 24 4.7 8 9.5 15.8 14.4 23.4zM420.7 163c9.3 9.6 18.6 20.3 27.8 32-9-.4-18.2-.7-27.5-.7-9.4 0-18.7.2-27.8.7 9-11.7 18.3-22.4 27.5-32zm-74 58.9c-4.9 7.7-9.8 15.6-14.4 23.7-4.6 8-8.9 16-13 24-5.4-13.4-10-26.8-13.8-39.8 13.1-3.1 26.9-5.8 41.2-7.9zm-90.5 125.2c-35.4-15.1-58.3-34.9-58.3-50.6 0-15.7 22.9-35.6 58.3-50.6 8.6-3.7 18-7 27.7-10.1 5.7 19.6 13.2 40 22.5 60.9-9.2 20.8-16.6 41.1-22.2 60.6-9.9-3.1-19.3-6.5-28-10.2zM310 490c-13.6-7.8-19.5-37.5-14.9-75.7 1.1-9.4 2.9-19.3 5.1-29.4 19.6 4.8 41 8.5 63.5 10.9 13.5 18.5 27.5 35.3 41.6 50-32.6 30.3-63.2 46.9-84 46.9-4.5-.1-8.3-1-11.3-2.7zm237.2-76.2c4.7 38.2-1.1 67.9-14.6 75.8-3 1.8-6.9 2.6-11.5 2.6-20.7 0-51.4-16.5-84-46.6 14-14.7 28-31.4 41.3-49.9 22.6-2.4 44-6.1 63.6-11 2.3 10.1 4.1 19.8 5.2 29.1zm38.5-66.7c-8.6 3.7-18 7-27.7 10.1-5.7-19.6-13.2-40-22.5-60.9 9.2-20.8 16.6-41.1 22.2-60.6 9.9 3.1 19.3 6.5 28.1 10.2 35.4 15.1 58.3 34.9 58.3 50.6-.1 15.7-23 35.6-58.4 50.6zM320.8 78.4z"/>
<circle cx="420.9" cy="296.5" r="45.7"/>
<path d="M520.5 78.1z"/>
</g>
</svg>

After

Width:  |  Height:  |  Size: 2.6 KiB

+141
View File
@@ -0,0 +1,141 @@
// This optional code is used to register a service worker.
// register() is not called by default.
// This lets the app load faster on subsequent visits in production, and gives
// it offline capabilities. However, it also means that developers (and users)
// will only see deployed updates on subsequent visits to a page, after all the
// existing tabs open on the page have been closed, since previously cached
// resources are updated in the background.
// To learn more about the benefits of this model and instructions on how to
// opt-in, read https://bit.ly/CRA-PWA
const isLocalhost = Boolean(
window.location.hostname === 'localhost' ||
// [::1] is the IPv6 localhost address.
window.location.hostname === '[::1]' ||
// 127.0.0.0/8 are considered localhost for IPv4.
window.location.hostname.match(
/^127(?:\.(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)){3}$/
)
);
export function register(config) {
if (process.env.NODE_ENV === 'production' && 'serviceWorker' in navigator) {
// The URL constructor is available in all browsers that support SW.
const publicUrl = new URL(process.env.PUBLIC_URL, window.location.href);
if (publicUrl.origin !== window.location.origin) {
// Our service worker won't work if PUBLIC_URL is on a different origin
// from what our page is served on. This might happen if a CDN is used to
// serve assets; see https://github.com/facebook/create-react-app/issues/2374
return;
}
window.addEventListener('load', () => {
const swUrl = `${process.env.PUBLIC_URL}/service-worker.js`;
if (isLocalhost) {
// This is running on localhost. Let's check if a service worker still exists or not.
checkValidServiceWorker(swUrl, config);
// Add some additional logging to localhost, pointing developers to the
// service worker/PWA documentation.
navigator.serviceWorker.ready.then(() => {
console.log(
'This web app is being served cache-first by a service ' +
'worker. To learn more, visit https://bit.ly/CRA-PWA'
);
});
} else {
// Is not localhost. Just register service worker
registerValidSW(swUrl, config);
}
});
}
}
function registerValidSW(swUrl, config) {
navigator.serviceWorker
.register(swUrl)
.then(registration => {
registration.onupdatefound = () => {
const installingWorker = registration.installing;
if (installingWorker == null) {
return;
}
installingWorker.onstatechange = () => {
if (installingWorker.state === 'installed') {
if (navigator.serviceWorker.controller) {
// At this point, the updated precached content has been fetched,
// but the previous service worker will still serve the older
// content until all client tabs are closed.
console.log(
'New content is available and will be used when all ' +
'tabs for this page are closed. See https://bit.ly/CRA-PWA.'
);
// Execute callback
if (config && config.onUpdate) {
config.onUpdate(registration);
}
} else {
// At this point, everything has been precached.
// It's the perfect time to display a
// "Content is cached for offline use." message.
console.log('Content is cached for offline use.');
// Execute callback
if (config && config.onSuccess) {
config.onSuccess(registration);
}
}
}
};
};
})
.catch(error => {
console.error('Error during service worker registration:', error);
});
}
function checkValidServiceWorker(swUrl, config) {
// Check if the service worker can be found. If it can't reload the page.
fetch(swUrl, {
headers: { 'Service-Worker': 'script' },
})
.then(response => {
// Ensure service worker exists, and that we really are getting a JS file.
const contentType = response.headers.get('content-type');
if (
response.status === 404 ||
(contentType != null && contentType.indexOf('javascript') === -1)
) {
// No service worker found. Probably a different app. Reload the page.
navigator.serviceWorker.ready.then(registration => {
registration.unregister().then(() => {
window.location.reload();
});
});
} else {
// Service worker found. Proceed as normal.
registerValidSW(swUrl, config);
}
})
.catch(() => {
console.log(
'No internet connection found. App is running in offline mode.'
);
});
}
export function unregister() {
if ('serviceWorker' in navigator) {
navigator.serviceWorker.ready
.then(registration => {
registration.unregister();
})
.catch(error => {
console.error(error.message);
});
}
}
+5
View File
@@ -0,0 +1,5 @@
// jest-dom adds custom jest matchers for asserting on DOM nodes.
// allows you to do things like:
// expect(element).toHaveTextContent(/react/i)
// learn more: https://github.com/testing-library/jest-dom
import '@testing-library/jest-dom/extend-expect';