|
| 1 | +import { BookText, Eye, Handshake, History } from "lucide-react"; |
| 2 | + |
| 3 | +import { Media } from "@/payload-types"; |
| 4 | + |
| 5 | +import DesktopCard from "./DesktopCard"; |
| 6 | +import PhoneCard from "./PhoneCard"; |
| 7 | + |
| 8 | +type CardProps = { |
| 9 | + background: Media | string | null; |
| 10 | + title: string; |
| 11 | + summary: string; |
| 12 | + description?: string; |
| 13 | + sponsorLogos?: { logo: Media | string | null }[] | null; |
| 14 | +}; |
| 15 | + |
| 16 | +type CardLayoutProps = { |
| 17 | + content: { |
| 18 | + vision: CardProps; |
| 19 | + story: CardProps; |
| 20 | + constitution: CardProps; |
| 21 | + sponsorsAndPartnerships: CardProps; |
| 22 | + constitutionLink?: string | null; |
| 23 | + }; |
| 24 | +}; |
| 25 | + |
| 26 | +const CardLayout = ({ content }: CardLayoutProps) => { |
| 27 | + const getImageUrl = (image: Media | string | null | undefined): string | null => { |
| 28 | + if (!image) return null; // handle undefined or null |
| 29 | + if (typeof image === "string") return image; // if it's already a string URL |
| 30 | + if (typeof image === "object" && image.url) return image.url; // if it's a Media object, extract the URL |
| 31 | + return null; |
| 32 | + }; |
| 33 | + |
| 34 | + const getImageAlt = (image: Media | string | null | undefined, fallback: string): string => { |
| 35 | + if (!image) return fallback; // handle undefined or null |
| 36 | + if (typeof image === "object" && image?.alt) return image.alt; // if it's a Media object, extract the alt text |
| 37 | + return fallback; |
| 38 | + }; |
| 39 | + |
| 40 | + const constitutionLink = |
| 41 | + content.constitutionLink ?? |
| 42 | + "https://auckland.campuslabs.com/engage/organization/auckland-university-student-chamber-orchestra"; |
| 43 | + |
| 44 | + return ( |
| 45 | + <section className="flex w-full flex-col"> |
| 46 | + {/* Desktop Layout: md and above */} |
| 47 | + <div className="mx-auto hidden w-full max-w-6xl flex-col items-center gap-6 px-6 md:flex"> |
| 48 | + {/* First Row: Vision & Story */} |
| 49 | + <div className="flex w-full flex-row items-center gap-6"> |
| 50 | + <div className="w-3/5"> |
| 51 | + <DesktopCard |
| 52 | + icon={<Eye className="h-12 w-12" />} |
| 53 | + background={getImageUrl(content.vision.background)} |
| 54 | + alt={getImageAlt(content.vision.background, "Vision Background")} |
| 55 | + title={content.vision.title} |
| 56 | + summary={content.vision.summary} |
| 57 | + description={content.vision.description} |
| 58 | + link={""} |
| 59 | + /> |
| 60 | + </div> |
| 61 | + |
| 62 | + <div className="w-2/5"> |
| 63 | + <DesktopCard |
| 64 | + icon={<History className="h-12 w-12" />} |
| 65 | + background={getImageUrl(content.story.background)} |
| 66 | + alt={getImageAlt(content.story.background, "Story Background")} |
| 67 | + title={content.story.title} |
| 68 | + summary={content.story.summary} |
| 69 | + description={`View ${content.story.title}`} |
| 70 | + link={"https://ausco.wdcc.co.nz/ourstory"} |
| 71 | + /> |
| 72 | + </div> |
| 73 | + </div> |
| 74 | + |
| 75 | + {/* Second Row: Constitution & Sponsors/Partnerships */} |
| 76 | + <div className="flex w-full flex-row items-center gap-6"> |
| 77 | + <div className="w-2/5"> |
| 78 | + <DesktopCard |
| 79 | + icon={<BookText className="h-12 w-12" />} |
| 80 | + background={getImageUrl(content.constitution.background)} |
| 81 | + alt={getImageAlt(content.constitution.background, "Constitution Background")} |
| 82 | + title={content.constitution.title} |
| 83 | + summary={content.constitution.summary} |
| 84 | + description={`View ${content.constitution.title}`} |
| 85 | + link={constitutionLink} |
| 86 | + /> |
| 87 | + </div> |
| 88 | + |
| 89 | + <div className="w-3/5"> |
| 90 | + <DesktopCard |
| 91 | + icon={<Handshake className="h-12 w-12" />} |
| 92 | + background={getImageUrl(content.sponsorsAndPartnerships.background)} |
| 93 | + alt={getImageAlt( |
| 94 | + content.sponsorsAndPartnerships.background, |
| 95 | + "Sponsors and Partnerships Background", |
| 96 | + )} |
| 97 | + title={content.sponsorsAndPartnerships.title} |
| 98 | + summary={content.sponsorsAndPartnerships.summary} |
| 99 | + description={content.sponsorsAndPartnerships.description} |
| 100 | + link={""} |
| 101 | + sponsorLogos={content.sponsorsAndPartnerships.sponsorLogos} |
| 102 | + /> |
| 103 | + </div> |
| 104 | + </div> |
| 105 | + </div> |
| 106 | + |
| 107 | + {/* Mobile Layout: below md */} |
| 108 | + <div className="flex w-full flex-col bg-(--lightblue) text-(--navy) md:hidden"> |
| 109 | + <div className="flex flex-col"> |
| 110 | + <PhoneCard type="vision" content={content.vision.description} /> |
| 111 | + |
| 112 | + <div className="mx-6 h-px bg-(--navy) md:hidden" /> |
| 113 | + |
| 114 | + <PhoneCard |
| 115 | + type="sponsors" |
| 116 | + content={content.sponsorsAndPartnerships.description} |
| 117 | + sponsorLogos={content.sponsorsAndPartnerships.sponsorLogos} |
| 118 | + /> |
| 119 | + |
| 120 | + <div className="mx-6 h-px bg-(--navy) md:hidden" /> |
| 121 | + |
| 122 | + <PhoneCard type="story" link="/ourstory" /> |
| 123 | + |
| 124 | + <div className="mx-6 h-px bg-(--navy) md:hidden" /> |
| 125 | + |
| 126 | + <PhoneCard type="constitution" link={constitutionLink} /> |
| 127 | + </div> |
| 128 | + </div> |
| 129 | + </section> |
| 130 | + ); |
| 131 | +}; |
| 132 | + |
| 133 | +export default CardLayout; |
0 commit comments