|
| 1 | +// import ArticleCard from "@/app/components/Articles/ArticleCard"; |
| 2 | +import { API_ENDPOINTS } from "@/config/endpoints"; |
| 3 | +import { getData } from "@/lib/helpers/dataFetchHelper"; |
| 4 | +import { ApiResponse, Article } from "@/types/CommonTypes"; |
| 5 | +import Image from "next/image"; |
| 6 | +import Link from "next/link"; |
| 7 | + |
| 8 | +export default async function Page({ |
| 9 | + params, |
| 10 | +}: { |
| 11 | + params: { article: string; category: string; subcategory: string }; |
| 12 | +}) { |
| 13 | + const { category, subcategory } = await params; |
| 14 | + |
| 15 | + const articleSlug = (await params).article; |
| 16 | + |
| 17 | + const response: ApiResponse<Article> = await getData( |
| 18 | + `${API_ENDPOINTS.ARTICLES}?filters[slug][$eq]=${articleSlug}` |
| 19 | + ); |
| 20 | + const [{ title, publishedAt, description }] = response.data; // select first object in array, and destructure properties |
| 21 | + |
| 22 | + const publishedDate = new Date(publishedAt).toLocaleDateString("en-US", { |
| 23 | + year: "numeric", |
| 24 | + month: "short", |
| 25 | + day: "numeric", |
| 26 | + }); |
| 27 | + |
| 28 | + return ( |
| 29 | + <> |
| 30 | + <section className="flex flex-col items-start h-auto bg-gradient-to-r from-blue-100 to-white p-10"> |
| 31 | + {/* Breadcrumbs Section */} |
| 32 | + <nav className="text-sm text-gray-600 mb-4"> |
| 33 | + <ul className="flex items-center gap-2"> |
| 34 | + <li> |
| 35 | + <Link href={`/${category}`} className="hover:text-blue-600"> |
| 36 | + {category} |
| 37 | + </Link> |
| 38 | + </li> |
| 39 | + <li className="text-lg">{">"}</li> |
| 40 | + <li> |
| 41 | + <Link |
| 42 | + href={`/${category}/${subcategory}`} |
| 43 | + className="hover:text-blue-600" |
| 44 | + > |
| 45 | + {subcategory} |
| 46 | + </Link> |
| 47 | + </li> |
| 48 | + <li className="text-lg">{">"}</li> |
| 49 | + <li className="text-gray-800 font-semibold">{title}</li> |
| 50 | + </ul> |
| 51 | + </nav> |
| 52 | + |
| 53 | + {/* Article Header Section */} |
| 54 | + <h1 className="text-4xl font-bold text-gray-800 mb-4 text-left"> |
| 55 | + {title} |
| 56 | + </h1> |
| 57 | + <div className="flex flex-wrap justify-between items-center w-full mb-4"> |
| 58 | + <p className="text-lg text-gray-600 max-w-2xl text-left"> |
| 59 | + {publishedDate} | by Dr. Nishantha Perera |
| 60 | + </p> |
| 61 | + |
| 62 | + <div className="flex items-center gap-4"> |
| 63 | + <p className="text-lg text-gray-600 max-w-2xl text-left"> |
| 64 | + Select Language |
| 65 | + </p> |
| 66 | + <button |
| 67 | + className=" flex items-center gap-2 text-white text-lg px-3 py-1 rounded-md shadow hover:brightness-110 transition" |
| 68 | + style={{ backgroundColor: "#2F7CC4" }} |
| 69 | + > |
| 70 | + English |
| 71 | + <svg |
| 72 | + xmlns="http://www.w3.org/2000/svg" |
| 73 | + viewBox="0 0 24 24" |
| 74 | + fill="currentColor" |
| 75 | + className="size-6" |
| 76 | + > |
| 77 | + <path |
| 78 | + fillRule="evenodd" |
| 79 | + d="M12.53 16.28a.75.75 0 0 1-1.06 0l-7.5-7.5a.75.75 0 0 1 1.06-1.06L12 14.69l6.97-6.97a.75.75 0 1 1 1.06 1.06l-7.5 7.5Z" |
| 80 | + clipRule="evenodd" |
| 81 | + /> |
| 82 | + </svg> |
| 83 | + </button> |
| 84 | + </div> |
| 85 | + </div> |
| 86 | + |
| 87 | + <div className="w-full"> |
| 88 | + <Image |
| 89 | + src="/nurse.avif" |
| 90 | + alt="Doctor providing medical advice" |
| 91 | + width={550} |
| 92 | + height={550} |
| 93 | + className="w-full h-[300px] object-cover rounded-lg shadow-md mb-4" |
| 94 | + priority |
| 95 | + /> |
| 96 | + </div> |
| 97 | + |
| 98 | + <p className="text-lg text-gray-600 mb-4 text-left">{description}</p> |
| 99 | + |
| 100 | + <section className="flex flex-col items-center justify-center w-full h-[200px] bg-blue-200 rounded-lg p-10"> |
| 101 | + <h1 className="text-3xl font-bold text-blue-700 mb-8 text-left"> |
| 102 | + To view the full article, please download. |
| 103 | + </h1> |
| 104 | + <button |
| 105 | + className=" flex gap-2 text-white text-lg px-8 py-3 rounded-md shadow hover:brightness-110 transition" |
| 106 | + style={{ backgroundColor: "#2F7CC4" }} |
| 107 | + > |
| 108 | + Download PDF |
| 109 | + <svg |
| 110 | + xmlns="http://www.w3.org/2000/svg" |
| 111 | + viewBox="0 0 24 24" |
| 112 | + fill="currentColor" |
| 113 | + className="size-6" |
| 114 | + > |
| 115 | + <path |
| 116 | + fillRule="evenodd" |
| 117 | + d="M12 2.25a.75.75 0 0 1 .75.75v11.69l3.22-3.22a.75.75 0 1 1 1.06 1.06l-4.5 4.5a.75.75 0 0 1-1.06 0l-4.5-4.5a.75.75 0 1 1 1.06-1.06l3.22 3.22V3a.75.75 0 0 1 .75-.75Zm-9 13.5a.75.75 0 0 1 .75.75v2.25a1.5 1.5 0 0 0 1.5 1.5h13.5a1.5 1.5 0 0 0 1.5-1.5V16.5a.75.75 0 0 1 1.5 0v2.25a3 3 0 0 1-3 3H5.25a3 3 0 0 1-3-3V16.5a.75.75 0 0 1 .75-.75Z" |
| 118 | + clipRule="evenodd" |
| 119 | + /> |
| 120 | + </svg> |
| 121 | + </button> |
| 122 | + </section> |
| 123 | + </section> |
| 124 | + </> |
| 125 | + ); |
| 126 | +} |
0 commit comments