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

Delete availability front end-Miguel-Cabral #18

Merged
merged 3 commits into from
Mar 22, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
34 changes: 34 additions & 0 deletions client/src/components/DeleteAvailability.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
import React from "react";
import Button from "react-bootstrap/Button";

const DeleteAvailability = ({ availability, onDelete }) => {
const handleDelete = () => {
onDelete(availability);
fetch(`/api/`,
{
method: "DELETE",
headers: {
"Content-Type": "application/json",
},
body: JSON.stringify(),
})
.then((res) => res.json())
.then((data) => {
if (data.error) {
alert(data.error);
} else {
alert("your availability is deleted!");
window.location.reload();
}
})
.catch((err) => console.log(err));
};

return (
<Button variant="danger" size="sm" onClick={handleDelete}>
Delete
</Button>
);
};

export default DeleteAvailability;
15 changes: 15 additions & 0 deletions client/src/components/InputAvailabilitiesPage.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { useState, useEffect } from "react";
import { useLocation } from "react-router-dom";
import { Container, Row, Col, Button, Form, Card, Table } from "react-bootstrap";
import "bootstrap/dist/css/bootstrap.min.css";
import DeleteAvailability from "./DeleteAvailability";

const InputAvailabilitiesPage = () => {
const [date, setDate] = useState("");
Expand Down Expand Up @@ -140,6 +141,20 @@ const InputAvailabilitiesPage = () => {
<td>{availability.date}</td>
<td>{availability.fromTime}</td>
<td>{availability.toTime}</td>
<td>
<DeleteAvailability
availability={availability}
onDelete={(availabilityToDelete) =>
setAvailabilities(
availabilities.filter(
(availability) =>
availability !== availabilityToDelete
)
)
}
/>
</td>

</tr>
))}
</tbody>
Expand Down