Skip to content

Commit

Permalink
Added the integration with BE
Browse files Browse the repository at this point in the history
  • Loading branch information
souljja committed Jul 16, 2024
1 parent 4132a75 commit dd5b334
Show file tree
Hide file tree
Showing 8 changed files with 387 additions and 265 deletions.
4 changes: 2 additions & 2 deletions src/__generated__/gql.ts

Large diffs are not rendered by default.

51 changes: 45 additions & 6 deletions src/__generated__/graphql.ts

Large diffs are not rendered by default.

4 changes: 4 additions & 0 deletions src/app/[locale]/[slug]/page.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { Fragment } from "react";
import { notFound } from "next/navigation";
import { SecondarySection } from "@/features/secondary-section/secondary-section.tsx";
import { getClient } from "@/utils/apollo-client";
import { isNotNull } from "@/utils/type-guards/is-not-null";
import { GET_LAYOUT_DATA } from "@/queries/get-layout-data";
Expand Down Expand Up @@ -79,6 +80,9 @@ const renderSection = (section?: PagePageSectionsDynamicZone | null) => {
/>
);
}
case "ComponentSectionsSecondaryBanner": {
return <SecondarySection data={section} />;
}
case "ComponentSectionsColumnsWithTabs": {
return <CategorizedNews data={section} />;
}
Expand Down
54 changes: 33 additions & 21 deletions src/components/secondary-card/secondary-card.tsx
Original file line number Diff line number Diff line change
@@ -1,37 +1,49 @@
import Image from "next/image";
import { Button } from "@/components/button/button.tsx";
import { ButtonLink } from "@/components/button-link/button-link.tsx";
import { Title } from "@/components/title/title.tsx";
import { Typography } from "@/components/typography/typography.tsx";
import coverImage from "@/assets/images/secondary.png";
import { getWavyCardTheme } from "@/components/secondary-card/utils.ts";
import { ComponentSectionsSecondaryBanner } from "@/__generated__/graphql.ts";
import "./secondary-card.scss";

export interface SecondaryCardProps {
theme?: "primary" | "secondary" | "tertiary";
data: ComponentSectionsSecondaryBanner;
}

export const SecondaryCard = ({ theme = "primary" }: SecondaryCardProps) => {
export const SecondaryCard = ({ data }: SecondaryCardProps) => {
return (
<div className="secondary-card" data-theme={theme}>
<div className="secondary-card" style={getWavyCardTheme(data)}>
<div className="secondary-card-info">
<Title className="secondary-card-title">Through equipment</Title>
<Typography className="secondary-card-body">
Connect-ed plays a crucial role in leveling the educational playing
field by providing underprivileged students with donated electronic
equipment, such as laptops. This support enables students to access
essential educational resources, facilitating their learning and
empowering them for a brighter future.
</Typography>
<Title className="secondary-card-title">{data.name}</Title>
<Typography className="secondary-card-body">{data.text}</Typography>
<div className="secondary-card-actions">
<Button variant="inverted" theme={theme}>
Find out more
</Button>
<Button variant="inverted" theme={theme}>
Donate today
</Button>
{data.cta1 && (
<ButtonLink
variant={data.cta1.type ?? undefined}
href={data.cta1.url ?? ""}
// @ts-expect-error - theme should be changed for the button
theme={data?.backgroundColor}
>
{data.cta1.label}
</ButtonLink>
)}
{data.cta2 && (
<ButtonLink
variant={data.cta2.type ?? undefined}
href={data.cta2.url ?? ""}
// @ts-expect-error - theme should be changed for the button
theme={data?.backgroundColor}
>
{data.cta2.label}
</ButtonLink>
)}
</div>
</div>
<div className="secondary-card-image-wrapper">
<Image alt="" fill src={coverImage} className="secondary-card-image" />
<img
alt={data?.image.altText ?? ""}
src={data.image.image?.data?.attributes?.url ?? undefined}
className="secondary-card-image"
/>
</div>
</div>
);
Expand Down
5 changes: 5 additions & 0 deletions src/components/secondary-card/utils.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import { getThemeStyle } from "@/utils/get-theme-style.ts";
import { ComponentSectionsSecondaryBanner } from "@/__generated__/graphql.ts";

export const getWavyCardTheme = (data?: ComponentSectionsSecondaryBanner) =>
getThemeStyle([["--background-color", data?.backgroundColor]]);
32 changes: 30 additions & 2 deletions src/components/section-base/title/section-base-title.tsx
Original file line number Diff line number Diff line change
@@ -1,15 +1,42 @@
"use client";

import { useEffect, useRef } from "react";
import { ElementType, HTMLAttributes, useEffect, useRef } from "react";
import cc from "classcat";
import { Title, TitleProps } from "@/components/title/title";
import "./section-base-title.scss";

type SectionBaseTitleProps = Omit<TitleProps, "as"> & {
level?: number;
};

const getTitleTag = (
level: number,
): ElementType<
HTMLAttributes<HTMLHeadingElement>,
"h1" | "h2" | "h3" | "h4" | "h5"
> => {
switch (level) {
case 1:
return "h1";
case 2:
return "h2";
case 3:
return "h3";
case 4:
return "h4";
case 5:
return "h5";
default:
return "h3";
}
};

export const SectionBaseTitle = ({
className,
children,
level = 3,
...delegatedProps
}: TitleProps) => {
}: SectionBaseTitleProps) => {
const ref = useRef<HTMLHeadingElement>(null);

useEffect(() => {
Expand Down Expand Up @@ -39,6 +66,7 @@ export const SectionBaseTitle = ({
<Title
ref={ref}
{...delegatedProps}
as={getTitleTag(level)}
className={cc(["section-base-title", className])}
>
{children}
Expand Down
17 changes: 7 additions & 10 deletions src/features/secondary-section/secondary-section.tsx
Original file line number Diff line number Diff line change
@@ -1,27 +1,24 @@
import { SecondaryCard } from "@/components/secondary-card/secondary-card.tsx";
import { SectionBase } from "@/components/section-base/section-base.tsx";
import { WavyCard } from "@/components/wavy-card/wavy-card.tsx";
import { ComponentSectionsSecondaryBanner } from "@/__generated__/graphql.ts";
import { SectionBaseTitle } from "@/components/section-base";
import "./secondary-section.scss";

export interface SecondarySectionProps {
items?: { theme?: "primary" | "secondary" | "tertiary" }[];
data: ComponentSectionsSecondaryBanner;
}

export const SecondarySection = ({ items }: SecondarySectionProps) => {
export const SecondarySection = ({ data }: SecondarySectionProps) => {
return (
<SectionBase className="secondary-section">
<SectionBaseTitle className="secondary-section-title">
How we’re helping
{data?.title?.text}
</SectionBaseTitle>
<ul className="secondary-section-list">
{items?.map((item, index) => (
// TODO: use id or title instead of index
// eslint-disable-next-line react/no-array-index-key
<WavyCard key={index} as="li" theme={item.theme}>
<SecondaryCard theme={item.theme} />
</WavyCard>
))}
<WavyCard as="li" theme={data.backgroundColor}>
<SecondaryCard data={data} />
</WavyCard>
</ul>
</SectionBase>
);
Expand Down
Loading

0 comments on commit dd5b334

Please sign in to comment.