Skip to content

Commit

Permalink
Got very basic ability to add new spaces #18
Browse files Browse the repository at this point in the history
  • Loading branch information
jpaten committed Nov 27, 2022
1 parent 4f76ea4 commit 73f9c7b
Show file tree
Hide file tree
Showing 4 changed files with 97 additions and 60 deletions.
9 changes: 0 additions & 9 deletions parkshark/src/components/Listings/bookingForm.js
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,6 @@ useEffect( () => {
fetch(`/users/${USER_ID}`)
.then((response) => response.json())
.then((userData) => {
console.log(userData.renter_bookings_id, allListingBookings);
for(let checkId in userData.renter_bookings_id){
if(allListingBookings.includes(userData.renter_bookings_id[checkId])){
setBookingId(checkId);
Expand All @@ -75,7 +74,6 @@ useEffect( () => {
arrivalDate.setSeconds(0);
}
setTimeDelta(departureDate.getTime()-arrivalDate.getTime()-330)
console.log("ArrivalDate", arrivalDate, timeDelta/1000)
}, [arrivalTime, arrivalDate]);

useEffect( () => {
Expand All @@ -87,7 +85,6 @@ useEffect( () => {
departureDate.setSeconds(0);
}
setTimeDelta(departureDate.getTime()-arrivalDate.getTime()-330)
console.log("DepartureDate", departureDate, timeDelta/1000)
}, [departureTime, departureDate]);


Expand Down Expand Up @@ -116,7 +113,6 @@ useEffect( () => {
}
}
const submitBooking = () => {
console.log(arrivalDate);
if(isNaN(arrivalDate.getDay())
|| isNaN(departureDate.getDay())
|| arrivalTime === ""
Expand All @@ -127,7 +123,6 @@ useEffect( () => {
setHasSubmitted(true)
}
else {
console.log("hi!")

let newBooking = {
renter_id: USER_ID,
Expand All @@ -136,17 +131,14 @@ useEffect( () => {
start_time: arrivalDate,
end_time: departureDate,
};
console.log(JSON.stringify((newBooking)));
fetch("/bookings", {
method: "POST",
headers: {'Content-Type': 'application/json'},
body: JSON.stringify(newBooking),
})
.then((response) => response.json())
.then((data) => {
console.log(data);
setBookingId(data._id);
console.log(bookingId);
setHasSubmitted(true);
setHasBooked(true);

Expand All @@ -162,7 +154,6 @@ useEffect( () => {
})
.then((response) => response.json())
.then((data) => {
console.log(data);
setHasBooked(false);
setHasSubmitted(false);
});
Expand Down
2 changes: 1 addition & 1 deletion parkshark/src/components/Listings/listingPage.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,11 @@ export function ListingPage() {
for(const i in data){
apiData[i] = data[i];
}
console.log(data);
});
}, []);


console.log(apiData);
return (
<div>
<BookingForm/>
Expand Down
144 changes: 94 additions & 50 deletions parkshark/src/components/Listings/newListingForm.js
Original file line number Diff line number Diff line change
@@ -1,66 +1,110 @@
import {useState} from "react";
import {TextField, Typography} from "@mui/material";
import Calendar from "react-calendar";

export function NewListingForm () {
export function NewListing () {
const [addressState, setAddressState] = useState("");
const [addressCity, setAddressCity] = useState("");
const [addressPostalCode, setAddressPostalCode] = useState("");
const [addressLine1, setAddressLine1] = useState("");
const [addressLine2, setAddressLine2] = useState("");
const [description, setDescription] = useState("");
const [price, setPrice] = useState("");
console.log(addressPostalCode)

const [availabilityStartDate, setAvailabilityStartDate] = useState(new Date());
const [availabilityEndDate, setAvailabilityEndDate] = useState(new Date());

const addListing = () => {

const listingData = {
address: {
state: addressState,
city: addressCity,
postal_code: addressPostalCode,
line_1: addressLine1,
line_2: addressLine2,
},
availability: [{
start_time: availabilityStartDate,
end_time: availabilityEndDate}],
description: description,
image: "TEST",
price: parseInt(price),
location:{
type: "Point",
coordinates: [
1,1
]
}
}


fetch("listings/",
{
method: "POST",
headers: {'Content-Type': 'application/json'},
body: JSON.stringify(listingData),
})
.then((response) => response.text())
.then((data) => console.log(data));
}

return (
<div>
<form>
<label>
<p>Description</p>
<TextField
name={"description"}
label={"Description"}
onChange={(event) => setDescription(event.target.value)}
multiline={true}
/>
</label>
<label>
<p>Availability</p>
<p>Add calendar here</p>
</label>
<label>
<p>Address</p>
<TextField
label={"Line 1"}
placeholder={"415 Portola Plaza"}
onChange={(event) => setAddressLine1(event.target.value)}/>
<TextField
label={"Line 2"}
placeholder={"A28"}
onChange={(event) => setAddressLine2(event.target.value)}/>
<TextField
label={"City"}
placeholder={"Los Angeles"}
onChange={(event) => setAddressCity(event.target.value)}/>
<TextField
label={"State"}
placeholder={"California"}
onChange={(event) => setAddressState(event.target.value)}/>
<TextField
label={"Zip Code"}
error={(isNaN(addressPostalCode) || (addressPostalCode.length !== 5 && addressPostalCode.length !== 0))}
placeholder={"90095"}
onChange={(event) => setAddressPostalCode(event.target.value)}/>
</label>
<label>
<Typography>Details</Typography>
<TextField
label={"Hourly Price"}
placeholder={10}
InputProps={{startAdornment: <p>$</p>}}/>
onChange={(event) => setPrice(event.target.value)}/>
</label>
</form>
<div>
<p>Description</p>
<TextField
name={"description"}
label={"Description"}
onChange={(event) => setDescription(event.target.value)}
multiline={true}
/>
</div>
<div>
<p>Availability</p>
<Calendar
onChange={(value) => {
setAvailabilityStartDate(value[0]);
setAvailabilityEndDate(value[1]);
}}
selectRange={true}
/>
<p>Address</p>
<TextField
label={"Line 1"}
placeholder={"415 Portola Plaza"}
onChange={(event) => setAddressLine1(event.target.value)}/>
<TextField
label={"Line 2"}
placeholder={"A28"}
onChange={(event) => setAddressLine2(event.target.value)}/>
<TextField
label={"City"}
placeholder={"Los Angeles"}
onChange={(event) => setAddressCity(event.target.value)}/>
<TextField
label={"State"}
placeholder={"California"}
onChange={(event) => setAddressState(event.target.value)}/>
<TextField
label={"Zip Code"}
error={(isNaN(addressPostalCode) || (addressPostalCode.length !== 5 && addressPostalCode.length !== 0))}
placeholder={"90095"}
onChange={(event) => setAddressPostalCode(event.target.value)}/>
</div>
<div>
<Typography>Details</Typography>
<TextField
label={"Hourly Price"}
placeholder={10}
InputProps={{startAdornment: <p>$</p>}}
onChange={(event) => setPrice(event.target.value)}/>
</div>
<div>
<button onClick={addListing}>Add listing!</button>
</div>
</div>
)
}

export default NewListingForm;
export default NewListing;
2 changes: 2 additions & 0 deletions parkshark/src/components/SignIn/LoginPage.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import Profile from "../Profile/Profile";
import About from "../About/About";
import Navbar2 from "../Navbar/Navbar2";
import './LoginPage.css';
import NewListing from "../Listings/newListingForm";
function LoginPage() {

//set up the initial states//
Expand Down Expand Up @@ -126,6 +127,7 @@ function LoginPage() {
<Route path="/Login" component={LoginPage} />
<Route path="/Listings" component={Listings} />
<Route path="/Listing/:id" component={ListingPage}/>
<Route path="/New" component={NewListing}/>
<Route path="/About" component={About} />
<Route path="/Profile" component={Profile} />
</Switch>
Expand Down

0 comments on commit 73f9c7b

Please sign in to comment.