Skip to content

Commit

Permalink
adding edit/delete parts buttons
Browse files Browse the repository at this point in the history
  • Loading branch information
is2ac2 committed Jun 12, 2024
1 parent ec3865e commit 7300cc8
Showing 1 changed file with 81 additions and 0 deletions.
81 changes: 81 additions & 0 deletions frontend/src/pages/PartDetails.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -27,16 +27,21 @@ const PartDetails = () => {
const { addAlert } = useAlertQueue();
const auth = useAuthentication();
const auth_api = new api(auth.api);
const [userId, setUserId] = useState<string | null>(null);
const { id } = useParams();
const [show, setShow] = useState(false);
const [ownerEmail, setOwnerEmail] = useState<string | null>(null);
const [part, setPart] = useState<PartDetailsResponse | null>(null);
const [imageIndex, setImageIndex] = useState(0);
const [error, setError] = useState<string | null>(null);
const [showDelete, setShowDelete] = useState(false);

const handleClose = () => setShow(false);
const handleShow = () => setShow(true);

const handleShowDelete = () => setShowDelete(true);
const handleCloseDelete = () => setShowDelete(false);

useEffect(() => {
const fetchPart = async () => {
try {
Expand Down Expand Up @@ -219,6 +224,82 @@ const PartDetails = () => {
</ButtonGroup>
</Modal.Footer>
</Modal>
<>
{/* {part.owner === userId && ( */}
{part.owner === part.owner && (
<>
<Row className="justify-content-end mt-2">
<Col md={3} sm={12}>
<Button
variant="primary"
size="lg"
style={{
backgroundColor: "light-green",
borderColor: "",
padding: "10px",
width: "100%",
}}
onClick={() => {
navigate(`/edit-part/${id}/`);
}}
>
Edit Robot
</Button>
</Col>
<Col md={3} sm={12}>
<Button
variant="danger"
size="lg"
style={{
backgroundColor: "light-green",
borderColor: "",
padding: "10px",
width: "100%",
}}
onClick={() => {
handleShowDelete();
}}
>
Delete Part
</Button>
</Col>
</Row>
<Modal
show={showDelete}
onHide={handleCloseDelete}
fullscreen="md-down"
centered
size="lg"
scrollable
>
<Modal.Header closeButton>
<Modal.Title>
Are you sure you want to delete this part?
</Modal.Title>
</Modal.Header>
<Modal.Footer className="d-flex justify-content-start">
<Button
variant="danger"
onClick={async () => {
// await auth_api.deletePart(id);
navigate(`/parts/`);
}}
>
Delete Part
</Button>
<Button
variant="outline-secondary"
onClick={() => {
handleCloseDelete();
}}
>
Cancel
</Button>
</Modal.Footer>
</Modal>
</>
)}
</>
</>
);
};
Expand Down

0 comments on commit 7300cc8

Please sign in to comment.