asdf
This commit is contained in:
@@ -25,10 +25,21 @@ const Properties = () => {
|
|||||||
try {
|
try {
|
||||||
setLoading(true);
|
setLoading(true);
|
||||||
const response = await propertiesAPI.getAll();
|
const response = await propertiesAPI.getAll();
|
||||||
setProperties(response.data.data || []);
|
console.log('Properties API response:', response);
|
||||||
|
|
||||||
|
// Handle different possible response structures
|
||||||
|
let propertiesData = [];
|
||||||
|
if (response.data?.data) {
|
||||||
|
propertiesData = Array.isArray(response.data.data) ? response.data.data : [];
|
||||||
|
} else if (response.data) {
|
||||||
|
propertiesData = Array.isArray(response.data) ? response.data : [];
|
||||||
|
}
|
||||||
|
|
||||||
|
setProperties(propertiesData);
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error('Failed to fetch properties:', error);
|
console.error('Failed to fetch properties:', error);
|
||||||
toast.error('Failed to load properties');
|
toast.error('Failed to load properties');
|
||||||
|
setProperties([]); // Ensure it's always an array
|
||||||
} finally {
|
} finally {
|
||||||
setLoading(false);
|
setLoading(false);
|
||||||
}
|
}
|
||||||
@@ -176,7 +187,7 @@ const Properties = () => {
|
|||||||
)}
|
)}
|
||||||
|
|
||||||
{/* Properties List */}
|
{/* Properties List */}
|
||||||
{properties.length === 0 ? (
|
{!Array.isArray(properties) || properties.length === 0 ? (
|
||||||
<div className="card text-center py-12">
|
<div className="card text-center py-12">
|
||||||
<MapPinIcon className="h-16 w-16 text-gray-300 mx-auto mb-4" />
|
<MapPinIcon className="h-16 w-16 text-gray-300 mx-auto mb-4" />
|
||||||
<h3 className="text-lg font-medium text-gray-900 mb-2">No Properties Yet</h3>
|
<h3 className="text-lg font-medium text-gray-900 mb-2">No Properties Yet</h3>
|
||||||
@@ -190,7 +201,7 @@ const Properties = () => {
|
|||||||
</div>
|
</div>
|
||||||
) : (
|
) : (
|
||||||
<div className="grid grid-cols-1 md:grid-cols-2 lg:grid-cols-3 gap-6">
|
<div className="grid grid-cols-1 md:grid-cols-2 lg:grid-cols-3 gap-6">
|
||||||
{properties.map((property) => (
|
{Array.isArray(properties) && properties.map((property) => (
|
||||||
<div key={property.id} className="card">
|
<div key={property.id} className="card">
|
||||||
<div className="flex justify-between items-start mb-4">
|
<div className="flex justify-between items-start mb-4">
|
||||||
<div>
|
<div>
|
||||||
|
|||||||
Reference in New Issue
Block a user