Skip to content

Commit 8ed381d

Browse files
committed
cta and org errors resolved
1 parent 8ad2874 commit 8ed381d

1 file changed

Lines changed: 38 additions & 22 deletions

File tree

src/components/SupportUsButton.tsx

Lines changed: 38 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,9 @@ function getButtonClasses(buttonVariant: ButtonVariant): string {
4949
}
5050

5151
// Main component function that renders the support us button, taking in various props for customization and rendering different sections such as hero, organization information, sponsors, and call-to-action based on the provided data and selected theme and button variant
52-
function SupportUsButton({
52+
function SupportUsButton(
53+
54+
{
5355
Theme = "AOSSIE",
5456
pattern = "AOSSIE",
5557
hero = {
@@ -70,8 +72,23 @@ function SupportUsButton({
7072
},
7173
buttonVariant = "AOSSIE",
7274
}: supportUsButtonProps): React.JSX.Element {
75+
// Ensure required props are provided to prevent runtime crashes
7376

77+
if (!organizationInformation) {
78+
console.warn(
79+
"SupportUsButton: 'organizationInformation' is required."
80+
);
81+
}
82+
83+
if (!ctaSection) {
84+
console.warn(
85+
"SupportUsButton: 'ctaSection' is required."
86+
);
87+
}
7488

89+
// Defensive fallback to handle unexpected missing props at runtime
90+
const org = organizationInformation ?? null;
91+
const cta = ctaSection ?? null;
7592
return (
7693
// Container for the support us button, with dynamic classes based on the selected theme and custom class names
7794
<div
@@ -132,7 +149,7 @@ function SupportUsButton({
132149

133150
{/* Organization information section */}
134151
{/* Avoid rendering empty organization section when data is not provided */}
135-
{organizationInformation ? (
152+
{org && (
136153
<div className="w-full flex justify-center p-10 mb-50">
137154
<div
138155
className={`${classNames.organizationInformation}
@@ -167,21 +184,21 @@ function SupportUsButton({
167184

168185
{/* Organization logo */}
169186
<div>
170-
{typeof organizationInformation.logo === "string" ? (
187+
{typeof org.logo === "string" ? (
171188
<span
172189
className="block h-fit w-fit p-4 bg-black text-white rounded-2xl"
173-
title={organizationInformation.logo}
190+
title={org.logo}
174191
>
175192
<b className="text-2xl italic">
176-
{organizationInformation.logo}
193+
{org.logo}
177194
</b>
178195
</span>
179196
) : (
180197
<img
181198
className="w-24 h-24 bg-white/80 pointer-none:cursor-none select-none rounded-2xl object-cover object-center"
182-
src={organizationInformation.logo?.src}
183-
alt={organizationInformation.logo?.alt}
184-
title={organizationInformation.logo?.alt}
199+
src={org.logo?.src}
200+
alt={org.logo?.alt}
201+
title={org.logo?.alt}
185202
draggable={false}
186203
/>
187204
)}
@@ -190,15 +207,15 @@ function SupportUsButton({
190207
{/* Organization name and description */}
191208
<div className="flex flex-col gap-4">
192209
<h2 className={`font-extrabold text-4xl md:text-5xl lg:text-6xl`}>
193-
{organizationInformation.name}
210+
{org.name}
194211
</h2>
195212
<p className="font-[650] text-lg">
196-
{organizationInformation.description}
213+
{org.description}
197214
</p>
198215
</div>
199216

200217
{/* Line */}
201-
{organizationInformation.projectInformation && (
218+
{org.projectInformation && (
202219
<div
203220
className={`
204221
border
@@ -211,7 +228,7 @@ function SupportUsButton({
211228
)}
212229

213230
{/* Project information */}
214-
{organizationInformation.projectInformation && (
231+
{org.projectInformation && (
215232
<div className="flex flex-col gap-2">
216233
<h3
217234
className={`font-bold w-fit uppercase text-sm p-2 rounded-lg
@@ -222,7 +239,7 @@ function SupportUsButton({
222239
${Theme === "corporate" && "bg-blue-600/50"}`}
223240
>
224241
ABOUT PROJECT:{" "}
225-
{organizationInformation.projectInformation.name}
242+
{org.projectInformation.name}
226243
</h3>
227244
<p
228245
className={`italic font-semibold
@@ -233,17 +250,14 @@ function SupportUsButton({
233250
${Theme === "corporate" && "text-blue-600/80"}
234251
`}
235252
>
236-
"{organizationInformation.projectInformation.description}"
253+
"{org.projectInformation.description}"
237254
</p>
238255
</div>
239256
)}
240257
</div>
241258
</div>
242259
</div>
243-
) : (
244-
<p className="text-center text-gray-500 mt-10">
245-
Organization details are not available.
246-
</p>
260+
247261
)}
248262

249263
{/* Sponsors section */}
@@ -427,21 +441,23 @@ function SupportUsButton({
427441
</div>
428442

429443
{/* Call-to-action section with title, description, and sponsor links */}
444+
{cta && (
445+
430446
<div
431447
className={`w-full flex justify-center p-10 ${(Theme === "light" || Theme === "dark") && classAccordingToTheme(Theme)} ${classNames.ctaSection}`}
432448
>
433449
<div className="w-4/5 flex flex-col items-center gap-5 py-20 border border-primary rounded-sm mt-20 mb-20">
434450
<h2 className={`font-extrabold text-4xl md:text-5xl lg:text-6xl`}>
435-
{ctaSection.title}
451+
{cta.title}
436452
</h2>
437453
<p
438454
className={`font-semibold
439455
${Theme === "light" ? "text-gray-600" : "text-gray-400"}`}
440456
>
441-
{ctaSection.description}
457+
{cta.description}
442458
</p>
443459
<div className="flex flex-wrap justify-center items-center gap-5 mt-8">
444-
{ctaSection.sponsorLink.map((link, index) => (
460+
{cta.sponsorLink.map((link, index) => (
445461
<a
446462
href={link.url}
447463
key={index}
@@ -459,7 +475,7 @@ function SupportUsButton({
459475
))}
460476
</div>
461477
</div>
462-
</div>
478+
</div>)}
463479
</div>
464480
);
465481
}

0 commit comments

Comments
 (0)