diff --git a/frontend/src/pages/EditPlant/index.tsx b/frontend/src/pages/EditPlant/index.tsx index bf2fa95..f656f3f 100644 --- a/frontend/src/pages/EditPlant/index.tsx +++ b/frontend/src/pages/EditPlant/index.tsx @@ -4,11 +4,12 @@ import { NewPlant, Plant, addPlant, + deletePlant, getPlantById, updatePlant, } from '../../services/plantsService'; import { SubmitHandler, useForm } from 'react-hook-form'; -import { FaSeedling } from 'react-icons/fa6'; +import { FaSeedling, FaTrash } from 'react-icons/fa6'; import { Toaster } from 'react-hot-toast'; import { formatDate } from '../../utils/dateUtils'; import SubmitButton from '../../components/UI/SubmitButton'; @@ -24,6 +25,7 @@ const EditPlant = () => { const { user } = useAuth(); const { setHouseholds } = useHouseholds(); + const plantBeingEdited = searchParams.get('plant'); const { register, handleSubmit, @@ -33,7 +35,6 @@ const EditPlant = () => { useEffect(() => { const fetchPlant = async () => { - const plantBeingEdited = searchParams.get('plant'); if (plantBeingEdited) { const plant = await getPlantById(plantBeingEdited); setPlant(plant); @@ -59,7 +60,6 @@ const EditPlant = () => { if (user) { let response; const updatedData = { ...data, lastWateredBy: user.firstName }; - console.log(updatedData); if (plant) { response = await updatePlant(plant.id, householdId!, updatedData); navigate(`/${householdId}/plants/${response?.id}?saved=true`); @@ -73,6 +73,17 @@ const EditPlant = () => { } }; + const deletePlantFromHousehold = async () => { + if (plantBeingEdited) { + await deletePlant(plantBeingEdited); + navigate(`/${householdId}/plants/?deletedPlant=${plant?.name}`); + } + }; + + const closeModal = (id: string) => { + (document.getElementById(id) as HTMLDialogElement | null)?.close(); + }; + return (