2025-08-05 22:53:11 +00:00
|
|
|
import { useState } from 'react';
|
2025-07-24 12:11:32 -07:00
|
|
|
import { type RecipeSmall } from "../types/Recipe"
|
2025-07-08 14:33:28 -07:00
|
|
|
import Modal from '../components/Modal.tsx'
|
2025-08-05 18:11:03 +00:00
|
|
|
import DemoModal from '../components/DemoModal.tsx'
|
2025-07-29 09:34:33 -07:00
|
|
|
import { Link } from 'react-router-dom';
|
2025-07-08 10:40:49 -07:00
|
|
|
|
|
|
|
interface CookbookRecipeTileProps {
|
2025-07-24 12:11:32 -07:00
|
|
|
recipe: RecipeSmall;
|
2025-07-08 10:40:49 -07:00
|
|
|
handleDelete: (id: number | undefined) => void;
|
|
|
|
}
|
|
|
|
|
|
|
|
function CookbookRecipeTile({ recipe, handleDelete }: CookbookRecipeTileProps) {
|
2025-08-05 18:11:03 +00:00
|
|
|
const [showConfirmModal, setShowConfirmModal] = useState(false);
|
|
|
|
const [showDemoModal, setShowDemoModal] = useState(false);
|
2025-07-08 14:33:28 -07:00
|
|
|
|
2025-08-05 18:11:03 +00:00
|
|
|
const openModal = () => { setShowConfirmModal(true) };
|
|
|
|
const closeModal = () => { setShowConfirmModal(false) };
|
2025-07-08 14:33:28 -07:00
|
|
|
const confirmDelete = () => {
|
2025-08-05 18:11:03 +00:00
|
|
|
if (process.env.NODE_ENV === 'demo') {
|
|
|
|
closeModal();
|
|
|
|
setShowDemoModal(true);
|
|
|
|
} else {
|
|
|
|
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 (
|
2025-07-11 17:06:41 -07:00
|
|
|
<div className="recipe-card m-2 bg-amber-300 p-4 rounded shadow">
|
|
|
|
<div className="flex justify-between items-center recipe-name">
|
2025-07-29 09:34:33 -07:00
|
|
|
<h3 className="font-bold"><Link to={`/recipe/${recipe.id}`} className="text-blue-500">{recipe.name}</Link></h3>
|
2025-07-11 17:06:41 -07:00
|
|
|
<button onClick={openModal} className="text-red-500 focus:outline-none">
|
|
|
|
<svg xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 24 24" strokeWidth="1.5" stroke="currentColor" className="w-6 h-6">
|
|
|
|
<path strokeLinecap="round" strokeLinejoin="round" d="M6 18L18 6M6 6l12 12" />
|
|
|
|
</svg>
|
|
|
|
</button>
|
2025-07-08 10:40:49 -07:00
|
|
|
</div>
|
2025-07-08 14:33:28 -07:00
|
|
|
<Modal
|
2025-08-05 18:11:03 +00:00
|
|
|
isOpen={showConfirmModal}
|
2025-07-08 14:33:28 -07:00
|
|
|
onClose={closeModal}
|
|
|
|
message="Are you sure you want to delete this recipe?"
|
|
|
|
confirmAction={confirmDelete}
|
|
|
|
cancelAction={closeModal}
|
|
|
|
/>
|
2025-08-05 18:11:03 +00:00
|
|
|
{showDemoModal && (
|
|
|
|
<DemoModal
|
|
|
|
isOpen={showDemoModal}
|
|
|
|
onClose={() => setShowDemoModal(false)}
|
|
|
|
closeModal={() => setShowDemoModal(false)}
|
|
|
|
/>
|
|
|
|
)}
|
2025-07-08 14:33:28 -07:00
|
|
|
</div>
|
2025-07-08 10:40:49 -07:00
|
|
|
);
|
2025-07-11 17:06:41 -07:00
|
|
|
};
|
2025-07-08 10:40:49 -07:00
|
|
|
|
|
|
|
export default CookbookRecipeTile;
|