merge new_starr_app@qas history into apps/web
git-subtree-dir: apps/web git-subtree-mainline:eaa6d2276agit-subtree-split:459af9d46a
This commit is contained in:
@@ -0,0 +1,104 @@
|
||||
// modules/client/pages/AdvertisementLandingPage.jsx
|
||||
//
|
||||
// Destination for an advertisement's own click-through when no redirect_link
|
||||
// was set — the internal page authored in the "Page Builder" wizard step
|
||||
// (Step 3 of Add Advertisement). Resolved by uuid via
|
||||
// GET /api/client/advertisements/uuid/:uuid.
|
||||
|
||||
import { useEffect, useState } from "react";
|
||||
import { useParams, useNavigate } from "react-router-dom";
|
||||
import { Megaphone, ArrowLeft } from "lucide-react";
|
||||
import { Button } from "@/components/ui/button";
|
||||
import { Skeleton } from "@/components/ui/skeleton";
|
||||
import { PageMeta } from "@/contexts/MetadataContext";
|
||||
import { resolveAssetSrc } from "@/utils/media.util";
|
||||
import api from "@/utils/api.util";
|
||||
|
||||
export default function AdvertisementLandingPage() {
|
||||
const { uuid } = useParams();
|
||||
const navigate = useNavigate();
|
||||
const [ad, setAd] = useState(null);
|
||||
const [loading, setLoading] = useState(true);
|
||||
const [notFound, setNotFound] = useState(false);
|
||||
|
||||
useEffect(() => {
|
||||
setLoading(true);
|
||||
setNotFound(false);
|
||||
api.get(`/client/advertisements/uuid/${uuid}`)
|
||||
.then(({ data }) => setAd(data?.data?.data ?? null))
|
||||
.catch(() => setNotFound(true))
|
||||
.finally(() => setLoading(false));
|
||||
}, [uuid]);
|
||||
|
||||
if (loading) {
|
||||
return (
|
||||
<div className="my-20 lg:container lg:mx-auto max-w-3xl px-4 space-y-4">
|
||||
<Skeleton className="h-8 w-2/3" />
|
||||
<Skeleton className="h-56 w-full rounded-lg" />
|
||||
<Skeleton className="h-4 w-full" />
|
||||
<Skeleton className="h-4 w-5/6" />
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
if (notFound || !ad) {
|
||||
return (
|
||||
<div className="my-20 lg:container lg:mx-auto max-w-3xl px-4 flex flex-col items-center text-center gap-3 py-16">
|
||||
<Megaphone className="size-8 text-muted-foreground" />
|
||||
<p className="font-medium">This advertisement is no longer available.</p>
|
||||
<Button variant="outline" onClick={() => navigate("/dashboard")}>
|
||||
<ArrowLeft className="size-4" /> Go back
|
||||
</Button>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
const page = ad.landing_page ?? {};
|
||||
const imageSrc = resolveAssetSrc(ad.image) || ad.image_url || null;
|
||||
const links = Array.isArray(page.links) ? page.links : [];
|
||||
|
||||
return (
|
||||
<div className="my-20 lg:container lg:mx-auto max-w-3xl px-4 space-y-6 pb-16">
|
||||
<PageMeta title={page.title ? `${page.title} - STARR` : undefined} description={page.description} />
|
||||
|
||||
<Button variant="ghost" size="sm" className="w-fit -ml-2" onClick={() => navigate("/dashboard")}>
|
||||
<ArrowLeft className="size-4" /> Back
|
||||
</Button>
|
||||
|
||||
{imageSrc && (
|
||||
<div className="rounded-lg overflow-hidden border h-56 sm:h-72">
|
||||
<img src={imageSrc} alt={page.title || ad.headline || "Advertisement"} className="w-full h-full object-cover" />
|
||||
</div>
|
||||
)}
|
||||
|
||||
<div className="space-y-2">
|
||||
<h1 className="text-2xl sm:text-3xl font-bold tracking-tight">{page.title || ad.headline || "Advertisement"}</h1>
|
||||
{page.description && <p className="text-muted-foreground text-lg">{page.description}</p>}
|
||||
</div>
|
||||
|
||||
{page.body && (
|
||||
<div className="prose prose-sm sm:prose max-w-none dark:prose-invert whitespace-pre-wrap">
|
||||
{page.body}
|
||||
</div>
|
||||
)}
|
||||
|
||||
{links.length > 0 && (
|
||||
<div className="flex flex-wrap gap-2 pt-2">
|
||||
{links.map((l, i) => (
|
||||
<Button
|
||||
key={i}
|
||||
variant={i === 0 ? "default" : "outline"}
|
||||
onClick={() => {
|
||||
if (!l.link) return;
|
||||
if (/^https?:\/\//.test(l.link)) window.open(l.link, "_blank", "noopener,noreferrer");
|
||||
else navigate(l.link);
|
||||
}}
|
||||
>
|
||||
{l.label || l.link}
|
||||
</Button>
|
||||
))}
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
);
|
||||
}
|
||||
Reference in New Issue
Block a user