From fe9a3656a029c14d94bfca6924ff1e1695d4c5e0 Mon Sep 17 00:00:00 2001 From: Gowthami mudam Date: Wed, 11 Feb 2026 23:41:17 +0530 Subject: [PATCH 1/2] Added confirmation modal before deleting listings --- frontend/src/pages/HostListings.jsx | 75 ++++++++++++++++++++++++----- 1 file changed, 64 insertions(+), 11 deletions(-) diff --git a/frontend/src/pages/HostListings.jsx b/frontend/src/pages/HostListings.jsx index 06bd1eb..a25bb26 100644 --- a/frontend/src/pages/HostListings.jsx +++ b/frontend/src/pages/HostListings.jsx @@ -16,6 +16,19 @@ const HostListings = () => { const [imgErrors, setImgErrors] = useState({}); // Track loading state for image const [isLoading, setIsLoading] = useState(true); + // Modal state +const [isModalOpen, setIsModalOpen] = useState(false); +const [selectedListingId, setSelectedListingId] = useState(null); + +const handleConfirmDelete = () => { + if (selectedListingId) { + deleteListing(selectedListingId); + setIsModalOpen(false); + setSelectedListingId(null); + } +}; + + // Handle image load errors const handleImageError = (listingId) => { @@ -379,19 +392,55 @@ const HostListings = () => { // Loading state while fetching listings if (loading) { - return ( -
-
- - Loading your listings... + return ( +
+
+ + {/* all your listings code here */} + +
+ + {/* 👇 PASTE MODAL HERE 👇 */} + + {isModalOpen && ( +
+
+

+ Confirm Delete +

+

+ Are you sure you want to delete this listing? +

+ +
+ + + +
- ); + )} + +
+); + } return (
+ + {/* Page header with title and Add new listing button */}

@@ -611,11 +660,15 @@ const HostListings = () => { {/* Delete listing button */} + onClick={() => { + setSelectedListingId(listing.id); + setIsModalOpen(true); + }} + className="inline-flex items-center px-3 py-1.5 border border-neutral-300 text-sm font-medium rounded-md text-red-700 bg-white hover:bg-red-50 hover:border-red-300" +> + Delete + +

From cc60592cd43b1caa7d6ae95ac2f9d8b922b7b1a5 Mon Sep 17 00:00:00 2001 From: Gowthami mudam Date: Thu, 12 Feb 2026 00:40:51 +0530 Subject: [PATCH 2/2] Add reusable Loading and EmptyState components in HostListings --- frontend/src/components/EmptyState.jsx | 16 +++++ frontend/src/components/Loading.jsx | 12 ++++ frontend/src/pages/HostListings.jsx | 83 ++++++++------------------ 3 files changed, 52 insertions(+), 59 deletions(-) create mode 100644 frontend/src/components/EmptyState.jsx create mode 100644 frontend/src/components/Loading.jsx diff --git a/frontend/src/components/EmptyState.jsx b/frontend/src/components/EmptyState.jsx new file mode 100644 index 0000000..4e64748 --- /dev/null +++ b/frontend/src/components/EmptyState.jsx @@ -0,0 +1,16 @@ +import React from "react"; + +const EmptyState = ({ title, description }) => { + return ( +
+

+ {title} +

+

+ {description} +

+
+ ); +}; + +export default EmptyState; diff --git a/frontend/src/components/Loading.jsx b/frontend/src/components/Loading.jsx new file mode 100644 index 0000000..754f10f --- /dev/null +++ b/frontend/src/components/Loading.jsx @@ -0,0 +1,12 @@ +import React from "react"; + +const Loading = ({ message = "Loading..." }) => { + return ( +
+
+

{message}

+
+ ); +}; + +export default Loading; diff --git a/frontend/src/pages/HostListings.jsx b/frontend/src/pages/HostListings.jsx index a25bb26..c406902 100644 --- a/frontend/src/pages/HostListings.jsx +++ b/frontend/src/pages/HostListings.jsx @@ -1,5 +1,8 @@ import React, { useState, useEffect } from "react"; import { Link } from "react-router-dom"; +import Loading from "../components/Loading"; +import EmptyState from "../components/EmptyState"; + // Fallback image in case property image fails to load const FALLBACK_IMAGE_URL = @@ -391,8 +394,10 @@ const handleConfirmDelete = () => { }; // Loading state while fetching listings - if (loading) { - return ( + if (loading) { + return ; + +
@@ -432,9 +437,7 @@ const handleConfirmDelete = () => { )}
-); - } return (
@@ -666,8 +669,8 @@ const handleConfirmDelete = () => { }} className="inline-flex items-center px-3 py-1.5 border border-neutral-300 text-sm font-medium rounded-md text-red-700 bg-white hover:bg-red-50 hover:border-red-300" > - Delete - + Delete +
@@ -712,60 +715,22 @@ const handleConfirmDelete = () => { )) ) : ( // Empty state when no listings match the current filter -
- - - - {/* Empty state title */} -

- No listings found -

- {/* Empty state description */} -

- {activeTab === "all" - ? "Get started by creating a new listing" - : `You don't have any ${activeTab} listings`} -

- {/* Call-to-action button to add a new listing */} -
- - - - - Add new listing - -
+ + )} + +
- )} +
-
- - ); -}; + ); + }; + } export default HostListings;