Skip to content

Commit

Permalink
Merge pull request #58 from FACN7/natasha
Browse files Browse the repository at this point in the history
 cancelButton functionality
  • Loading branch information
kira-abl authored Dec 1, 2019
2 parents 8e70ac5 + b52aae2 commit 9ed8728
Show file tree
Hide file tree
Showing 5 changed files with 37 additions and 8 deletions.
5 changes: 3 additions & 2 deletions barberia/src/App/pages/Confirmation.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,10 @@ import moment from "moment";

import "./confirmation.css";


function Confirmation({ time, formDate, baseDate, ...props }) {
//states that store form's user information
let [name, setName] = useState(null);
const [name, setName] = useState(null);
const [email, setEmail] = useState(null);
const [phone, setPhone] = useState(null);
const [error_ms, setError_ms] = useState("");
Expand Down Expand Up @@ -132,7 +133,7 @@ function Confirmation({ time, formDate, baseDate, ...props }) {
</form>
<p>date picked is {moment(formDate.toJSON()).format("MMM Do YY")}</p>
<p>
time picked is {time} <br />
time picked is {time.toString()} <br />
</p>
</div>
);
Expand Down
19 changes: 15 additions & 4 deletions barberia/src/App/pages/Congratulation.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,24 @@ import "./congratulation.css";

function congratulation({ ...props }) {
const userData = JSON.parse(localStorage.getItem("confirmationData"));
const { email, phone } = userData;
const { email, phone, name } = userData;

const moveTo = destination => {
window.location.assign(destination);
const moveTo = home => {
window.location.assign(home);
};

const deleteLastBooking = () => {};
const deleteLastBooking = () => {

return fetch("/api/cancelbooking", {
method: "POST",
headers: {
"Content-Type": "application/json"
},
body: JSON.stringify(userData)
})
.then(window.location.assign("/"))
.catch(err => console.log(err));
};

return (
<div>
Expand Down
7 changes: 6 additions & 1 deletion src/controllers/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,13 @@ router.post("/savenewbooking", (req, res) => {
queries.saveNewBooking(data).catch(err => console.log(err));
});

router.post("/cancelbooking", (req, res) => {
const data = req.body;

queries.cancelbooking(data).catch(err => console.log(err));
});

router.get("*", (req, res) => {
console.log("you arrived at a none query page");
res.sendFile(path.join(__dirname + "/barberia/build/index.html"));
});

Expand Down
10 changes: 10 additions & 0 deletions src/queries/cancelbooking.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
const databaseConnection = require("../database/db_connection.js");

const cancelbooking = rawData => {
const data = rawData;
return databaseConnection.query(
`DELETE FROM bookings WHERE (booking_date='${data.date}' AND booking_time='${data.time}' AND customer_name='${data.name}')`
);
};

module.exports = cancelbooking;
4 changes: 3 additions & 1 deletion src/queries/index.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
const getAllBookings = require("./getAllBookings");
const saveNewBooking = require("./saveNewBooking");
const cancelbooking = require("./cancelbooking");

module.exports = {
getAllBookings,
saveNewBooking
saveNewBooking,
cancelbooking
};

0 comments on commit 9ed8728

Please sign in to comment.