fixed getSaleProperiesById and make login type is email
All checks were successful
Build frontend / build (push) Successful in 1m46s

This commit is contained in:
hamzaobed7
2026-08-11 16:04:09 +03:00
parent 4924e7c2f3
commit 00dde588cb
10 changed files with 421 additions and 394 deletions

View File

@ -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} />;
}