diff --git a/src/app/(main)/listings-for-sale/page.tsx b/src/app/(main)/listings-for-sale/page.tsx new file mode 100644 index 0000000..b9757ba --- /dev/null +++ b/src/app/(main)/listings-for-sale/page.tsx @@ -0,0 +1,95 @@ +import HeroImage from "@/components/HeroImage"; +import Pagination from "@/components/Pagination"; +import CardProperty from "@/components/properties/CardProperty"; +import FilterProperty from "@/components/properties/FilterProperty"; +import { FetchPropertyParams } from "@/schema/services/property"; +import { fetchProperty } from "@/services/payload/property"; +import { getDefaultMetadata } from "@/utils/metadata"; +import { sanitizeNumber, sanitizePageNumber } from "@/utils/sanitize"; +import { Metadata } from "next"; + +const metaDesc = "Explore the latest properties on the Dynamic Realty."; + +export async function generateMetadata(): Promise { + const metadata = await getDefaultMetadata(); + metadata.title = `Listings For Sale - ${metadata.openGraph?.siteName}`; + metadata.description = metaDesc; + + return metadata; +} + +export default async function ListingsForRent(props: { + searchParams?: Promise<{ [P in keyof FetchPropertyParams]: string }>; +}) { + const searchParams = await props?.searchParams; + const page = sanitizePageNumber(searchParams?.page); + const minPrice = sanitizeNumber(searchParams?.min_price); + const maxPrice = sanitizeNumber(searchParams?.max_price); + const minArea = sanitizeNumber(searchParams?.min_area); + const maxArea = sanitizeNumber(searchParams?.max_area); + + const propertiesData = await fetchProperty({ + property_type: "sell", + page, + name: searchParams?.name, + min_price: minPrice, + max_price: maxPrice, + min_area: minArea, + max_area: maxArea, + location: searchParams?.location, + }); + const isEmpty = propertiesData.formattedData.length <= 0; + + return ( + <> + + +
+
+
+
+
+
+ {isEmpty && ( +
+

No Properties Found

+

Looks like we couldn’t find any listings that match your search.

+
+ )} + {!isEmpty && ( +
+ {propertiesData.formattedData.map((p, idx) => ( + + ))} +
+ )} +
+ + {/* Pagination */} + {propertiesData.totalPages > 1 && ( +
+ +
+ )} + {/* End Pagination */} +
+
+ +
+
+
+ +
+
+
+
+
+
+ + ); +} diff --git a/src/app/(main)/listings-for-rent/[slug]/page.tsx b/src/app/(main)/property/[slug]/page.tsx similarity index 99% rename from src/app/(main)/listings-for-rent/[slug]/page.tsx rename to src/app/(main)/property/[slug]/page.tsx index 03ecd66..c2e0c13 100644 --- a/src/app/(main)/listings-for-rent/[slug]/page.tsx +++ b/src/app/(main)/property/[slug]/page.tsx @@ -61,7 +61,7 @@ export async function generateMetadata(props: { params: Promise<{ slug: string } return metadata; } -export default async function ListingsForRentDetail({ params }: { params: Promise<{ slug: string }> }) { +export default async function PropertyDetail({ params }: { params: Promise<{ slug: string }> }) { const slug = (await params).slug; const propertyDetail = await fetchPropertyDetail({ slug }); if (!propertyDetail) return notFound(); diff --git a/src/components/layouts/Header.tsx b/src/components/layouts/Header.tsx index ac8c3fd..304c89e 100644 --- a/src/components/layouts/Header.tsx +++ b/src/components/layouts/Header.tsx @@ -113,7 +113,7 @@ export default function Header() {
  • - + LISTINGS FOR SALE
  • diff --git a/src/components/properties/CardProperty.tsx b/src/components/properties/CardProperty.tsx index 8433d18..7bfce0e 100644 --- a/src/components/properties/CardProperty.tsx +++ b/src/components/properties/CardProperty.tsx @@ -8,7 +8,7 @@ type CardPropertyProps = { }; export default function CardProperty({ data }: CardPropertyProps) { - const href = data?.propertyType === "rent" ? `/listings-for-rent/${data.slug}` : `/listings-for-sell/${data.slug}`; + const href = data?.propertyType === "rent" ? `/property/${data.slug}` : `/property/${data.slug}`; return (