fixed getSaleProperiesById and make login type is email
All checks were successful
Build frontend / build (push) Successful in 1m46s
All checks were successful
Build frontend / build (push) Successful in 1m46s
This commit is contained in:
@ -5,7 +5,7 @@ import { useTranslation } from "react-i18next";
|
||||
import { motion, AnimatePresence } from "framer-motion";
|
||||
import toast, { Toaster } from "react-hot-toast";
|
||||
import Link from "next/link";
|
||||
import { useParams, useRouter } from "next/navigation";
|
||||
import { useParams, useRouter, useSearchParams } from "next/navigation";
|
||||
import {
|
||||
MapPin,
|
||||
Bed,
|
||||
@ -244,9 +244,10 @@ function mapApiDetail(item) {
|
||||
};
|
||||
}
|
||||
|
||||
export default function PropertyDetailsPage() {
|
||||
export default function PropertyDetailsPage({type}) {
|
||||
const { t, i18n } = useTranslation();
|
||||
const params = useParams();
|
||||
|
||||
const router = useRouter();
|
||||
const { isFavorite, addFavorite, removeFavorite } = useFavorites();
|
||||
|
||||
@ -271,6 +272,7 @@ export default function PropertyDetailsPage() {
|
||||
|
||||
useEffect(() => {
|
||||
const id = params.id;
|
||||
|
||||
if (!id) return;
|
||||
setLoading(true);
|
||||
|
||||
@ -278,7 +280,7 @@ export default function PropertyDetailsPage() {
|
||||
try {
|
||||
let data = null;
|
||||
try {
|
||||
data = await getRentProperty(id);
|
||||
data = type==="rent"?await getRentProperty(id):(await getSalePropertyById(id)) || (await getSaleProperty(id));
|
||||
} catch {}
|
||||
if (!data) {
|
||||
try {
|
||||
|
||||
@ -1,15 +1,20 @@
|
||||
import PropertyDetail from "./PropertyDetail";
|
||||
|
||||
// Server-side API fetch for metadata (runs at request time on server)
|
||||
async function fetchPropertyForMeta(id) {
|
||||
async function fetchPropertyForMeta(id, type) {
|
||||
try {
|
||||
const res = await fetch(`http://45.93.137.91/api/RentProperties/GetRentProperties`, {
|
||||
const endpoint = type === "sale" ? "http://45.93.137.91/api/SaleProperties/GetSaleProperties" : "http://45.93.137.91/api/RentProperties/GetRentProperties";
|
||||
|
||||
const res = await fetch(endpoint, {
|
||||
next: { revalidate: 60 },
|
||||
});
|
||||
|
||||
if (!res.ok) return null;
|
||||
|
||||
const text = await res.text();
|
||||
const json = JSON.parse(text);
|
||||
|
||||
const items = Array.isArray(json?.data) ? json.data : Array.isArray(json) ? json : [];
|
||||
|
||||
return items.find((p) => p.id == id) || items[0] || null;
|
||||
} catch {
|
||||
return null;
|
||||
@ -18,7 +23,9 @@ async function fetchPropertyForMeta(id) {
|
||||
|
||||
function mapProperty(item) {
|
||||
const info = item.propertyInformation || item.PropertyInformation || {};
|
||||
|
||||
let details = {};
|
||||
|
||||
if (typeof info.detailsJSON === "object" && info.detailsJSON) {
|
||||
details = info.detailsJSON;
|
||||
} else if (typeof info.DetailsJSON === "object" && info.DetailsJSON) {
|
||||
@ -30,10 +37,25 @@ function mapProperty(item) {
|
||||
}
|
||||
|
||||
const price = item.monthlyRent || item.MonthlyRent || item.dailyRent || item.DailyRent || 0;
|
||||
|
||||
const priceUnit = item.monthlyRent || item.MonthlyRent ? "monthly" : "daily";
|
||||
|
||||
const buildingType = info.buildingType ?? info.BuildingType ?? 0;
|
||||
const type = { 0: "apartment", 1: "villa", 2: "house" }[buildingType] || "apartment";
|
||||
const typeLabel = { 0: "apartment", 1: "villa", 2: "house" }[buildingType] || "apartment";
|
||||
|
||||
const type =
|
||||
{
|
||||
0: "apartment",
|
||||
1: "villa",
|
||||
2: "house",
|
||||
}[buildingType] || "apartment";
|
||||
|
||||
const typeLabel =
|
||||
{
|
||||
0: "apartment",
|
||||
1: "villa",
|
||||
2: "house",
|
||||
}[buildingType] || "apartment";
|
||||
|
||||
const address = info.address || info.Address || "";
|
||||
const bedrooms = info.numberOfBedRooms || info.NumberOfBedRooms || 0;
|
||||
const bathrooms = info.numberOfBathRooms || info.NumberOfBathRooms || 0;
|
||||
@ -56,9 +78,13 @@ function mapProperty(item) {
|
||||
};
|
||||
}
|
||||
|
||||
export async function generateMetadata({ params }) {
|
||||
export async function generateMetadata({ params, searchParams }) {
|
||||
const { id } = await params;
|
||||
const raw = await fetchPropertyForMeta(id);
|
||||
const { type } = await searchParams;
|
||||
|
||||
console.log("Property type:", type);
|
||||
|
||||
const raw = await fetchPropertyForMeta(id, type);
|
||||
|
||||
if (!raw) {
|
||||
return {
|
||||
@ -68,11 +94,13 @@ export async function generateMetadata({ params }) {
|
||||
}
|
||||
|
||||
const p = mapProperty(raw);
|
||||
const priceStr = `${p.price.toLocaleString()} ل.س / ${p.priceUnit === "daily" ? "يوم" : "شهر"}`;
|
||||
const propertyImage = p.image ? (p.image.startsWith("http") ? p.image : `http://45.93.137.91${p.image}`) : "";
|
||||
const logoUrl = `http://45.93.137.91/logo.png`;
|
||||
|
||||
// Use property image if available, otherwise logo
|
||||
const priceStr = `${p.price.toLocaleString()} ل.س / ${p.priceUnit === "daily" ? "يوم" : "شهر"}`;
|
||||
|
||||
const propertyImage = p.image ? (p.image.startsWith("http") ? p.image : `http://45.93.137.91${p.image}`) : "";
|
||||
|
||||
const logoUrl = "http://45.93.137.91/logo.png";
|
||||
|
||||
const ogImages = propertyImage
|
||||
? [
|
||||
{ url: propertyImage, width: 1200, height: 630 },
|
||||
@ -83,14 +111,16 @@ export async function generateMetadata({ params }) {
|
||||
return {
|
||||
title: `${p.title} - ${priceStr}`,
|
||||
description: p.description,
|
||||
|
||||
openGraph: {
|
||||
title: `${p.title} - ${priceStr}`,
|
||||
description: p.description,
|
||||
images: ogImages,
|
||||
url: `http://45.93.137.91/property/${id}`,
|
||||
url: `http://45.93.137.91/property/${id}?type=${type}`,
|
||||
type: "website",
|
||||
siteName: "SweetHome",
|
||||
},
|
||||
|
||||
twitter: {
|
||||
card: "summary_large_image",
|
||||
title: `${p.title} - ${priceStr}`,
|
||||
@ -100,6 +130,8 @@ export async function generateMetadata({ params }) {
|
||||
};
|
||||
}
|
||||
|
||||
export default function PropertyPage({ params }) {
|
||||
return <PropertyDetail params={params} />;
|
||||
export default async function PropertyPage({ params, searchParams }) {
|
||||
const { type } = await searchParams;
|
||||
|
||||
return <PropertyDetail params={params} type={type} />;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user