qudoco-fe/components/landing-page/service.tsx

114 lines
4.1 KiB
TypeScript
Raw Normal View History

2026-02-17 09:05:22 +00:00
import Image from "next/image";
2026-04-10 07:21:29 +00:00
import type { CmsServiceContent } from "@/types/cms-landing";
2026-02-17 09:05:22 +00:00
2026-04-10 07:21:29 +00:00
const DEFAULT_HEADING = "Innovative solutions for your business growth.";
const DEFAULT_BODY =
"Professional services tailored to your organization. Update this text from the CMS admin under Content Website → Our Services.";
2026-02-17 09:05:22 +00:00
2026-04-10 07:21:29 +00:00
function bannerUrl(s: CmsServiceContent) {
return s.images?.[0]?.image_url?.trim() || "/image/s1.png";
}
2026-02-17 09:05:22 +00:00
2026-04-10 07:21:29 +00:00
export default function ServiceSection({
services,
}: {
services?: CmsServiceContent[] | null;
}) {
const list = services?.filter((s) => s.id) ?? [];
2026-02-17 09:05:22 +00:00
2026-04-10 07:21:29 +00:00
if (list.length === 0) {
const imgSrc = "/image/s1.png";
return (
<section className="bg-white py-20">
<div className="container mx-auto px-6">
<div className="mb-16 text-center">
<p className="text-sm uppercase tracking-widest text-gray-400">Our Services</p>
<h2 className="mt-2 text-3xl font-bold text-gray-900 md:text-4xl whitespace-pre-line">
{DEFAULT_HEADING}
</h2>
2026-02-17 09:05:22 +00:00
</div>
2026-04-10 07:21:29 +00:00
<div className="grid items-center gap-12 md:grid-cols-2">
<div className="overflow-hidden rounded-2xl shadow-lg">
<Image
src={imgSrc}
alt="Service"
width={600}
height={400}
className="h-auto w-full object-cover"
/>
</div>
<div>
<p className="leading-relaxed text-gray-600 whitespace-pre-line">{DEFAULT_BODY}</p>
</div>
2026-02-17 09:05:22 +00:00
</div>
</div>
2026-04-10 07:21:29 +00:00
</section>
);
}
2026-02-17 09:05:22 +00:00
2026-04-10 07:21:29 +00:00
return (
<section className="bg-white py-20">
<div className="container mx-auto px-6">
<div className="mb-16 text-center">
<p className="text-sm uppercase tracking-widest text-gray-400">Our Services</p>
<h2 className="mt-2 text-3xl font-bold text-gray-900 md:text-4xl whitespace-pre-line">
{list.length > 1 ? "What we deliver" : list[0]?.primary_title?.trim() || DEFAULT_HEADING}
</h2>
{list.length > 1 && list[0]?.secondary_title?.trim() ? (
<p className="mx-auto mt-4 max-w-2xl text-gray-600">
{list[0].secondary_title.trim()}
2026-02-17 09:05:22 +00:00
</p>
2026-04-10 07:21:29 +00:00
) : list.length === 1 && list[0]?.secondary_title?.trim() ? (
<p className="mx-auto mt-4 max-w-2xl text-gray-600">
{list[0].secondary_title.trim()}
2026-02-17 09:05:22 +00:00
</p>
2026-04-10 07:21:29 +00:00
) : null}
2026-02-17 09:05:22 +00:00
</div>
2026-04-10 07:21:29 +00:00
<div className="grid gap-8 sm:grid-cols-2 lg:grid-cols-4">
{list.map((s) => {
const imgSrc = bannerUrl(s);
const external = /^https?:\/\//i.test(imgSrc);
const body = s.description?.trim() || DEFAULT_BODY;
return (
<div
key={s.id}
className="flex flex-col overflow-hidden rounded-2xl border border-gray-100 bg-white shadow-md"
>
<div className="relative aspect-video w-full overflow-hidden bg-gray-100">
{external ? (
// eslint-disable-next-line @next/next/no-img-element
<img
src={imgSrc}
alt=""
width={600}
height={400}
className="h-full w-full object-cover"
/>
) : (
<Image
src={imgSrc}
alt=""
width={600}
height={400}
className="h-full w-full object-cover"
/>
)}
</div>
<div className="flex flex-1 flex-col p-5">
<h3 className="text-lg font-bold text-gray-900 whitespace-pre-line">
{s.primary_title?.trim() || "Service"}
</h3>
<p className="mt-2 line-clamp-4 text-sm leading-relaxed text-gray-600 whitespace-pre-line">
{body}
</p>
</div>
</div>
);
})}
2026-02-17 09:05:22 +00:00
</div>
</div>
</section>
);
}