recipe_app/frontend/src/components/CookbookRecipeTile.tsx

40 lines
1 KiB
TypeScript
Raw Normal View History

2025-07-08 14:33:28 -07:00
import React, { useState } from 'react';
2025-07-08 10:40:49 -07:00
import { type Recipe } from "../types/Recipe"
2025-07-08 14:33:28 -07:00
import Modal from '../components/Modal.tsx'
2025-07-08 10:40:49 -07:00
interface CookbookRecipeTileProps {
recipe: Recipe;
handleDelete: (id: number | undefined) => void;
}
function CookbookRecipeTile({ recipe, handleDelete }: CookbookRecipeTileProps) {
2025-07-08 14:33:28 -07:00
const [isModalOpen, setIsModalOpen] = useState(false);
const openModal = () => setIsModalOpen(true);
const closeModal = () => setIsModalOpen(false);
const confirmDelete = () => {
handleDelete(recipe.id);
closeModal();
2025-07-08 10:40:49 -07:00
};
2025-07-08 14:33:28 -07:00
2025-07-08 10:40:49 -07:00
return (
<div className="recipe-card">
<div className="recipe-info">
<h3><a href={`/recipe/${recipe.id}`}>{recipe.name}</a></h3>
2025-07-08 14:33:28 -07:00
<button onClick={openModal}>Delete Recipe</button>
2025-07-08 10:40:49 -07:00
</div>
2025-07-08 14:33:28 -07:00
<Modal
isOpen={isModalOpen}
onClose={closeModal}
message="Are you sure you want to delete this recipe?"
confirmAction={confirmDelete}
cancelAction={closeModal}
/>
</div>
2025-07-08 10:40:49 -07:00
);
}
export default CookbookRecipeTile;