Skip to content

Commit

Permalink
Merge branch 'v3' into v3-hero
Browse files Browse the repository at this point in the history
  • Loading branch information
anemne committed Dec 10, 2024
2 parents da73340 + 25a0955 commit 7f81382
Show file tree
Hide file tree
Showing 13 changed files with 175 additions and 89 deletions.
26 changes: 17 additions & 9 deletions src/components/employeeCard/EmployeeCard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,14 @@ export interface EmployeeCardProps {
employee: ChewbaccaEmployee;
employeePageSlug?: string;
language: string;
overrideTitle?: string;
}

export default function EmployeeCard({
employee,
employeePageSlug,
language,
overrideTitle,
}: EmployeeCardProps) {
const t = useTranslations("employee_card");
return (
Expand Down Expand Up @@ -51,16 +53,22 @@ export default function EmployeeCard({
</Text>

<div className={styles.employeeRole}>
{employee.competences.map((competence) => (
<Text
className={styles.employeeRoleDot}
type="labelRegular"
key={competence}
as="span"
>
{t(competence)}
{overrideTitle ? (
<Text type="labelRegular" as="span">
{overrideTitle}
</Text>
))}
) : (
employee.competences.map((competence) => (
<Text
className={styles.employeeRoleDot}
type="labelRegular"
key={competence}
as="span"
>
{t(competence)}
</Text>
))
)}
</div>

<Text type="bodyExtraSmall" className={styles.employeeEmail}>
Expand Down
8 changes: 8 additions & 0 deletions src/components/employeeCard/employeeCard.module.css
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@
flex-direction: column;
justify-content: space-between;
gap: 0.375rem;

overflow: hidden;
}

.contactInfo {
Expand All @@ -27,6 +29,12 @@
.employeePhone a {
color: currentColor;
}
.employeeEmail a {
display: block;
white-space: nowrap;
overflow: hidden;
text-overflow: ellipsis;
}

.employeeWrapper {
container-type: inline-size;
Expand Down
2 changes: 1 addition & 1 deletion src/components/sections/article/Article.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ const Article = ({ article }: ArticleProps) => {
)}
<div className={styles.content}>
<div>
<Text type="labelSmall">{article.tag}</Text>
<Text type="labelRegular">{article.tag}</Text>
<Text type="h2">{article.basicTitle}</Text>
</div>
{article.richText && <RichText value={article.richText} />}
Expand Down
44 changes: 8 additions & 36 deletions src/components/sections/contact-box/ContactBox.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,11 @@ import { Suspense } from "react";

import { EmployeeCardSkeleton } from "src/components/employeeCard/EmployeeCard";
import Text from "src/components/text/Text";
import { ChewbaccaEmployee } from "src/types/employees";
import { fetchEmployeesByEmails } from "src/utils/employees";
import { ContactBoxSection } from "studio/lib/interfaces/pages";
import { EMPLOYEE_PAGE_SLUG_QUERY } from "studio/lib/queries/siteSettings";
import { loadStudioQuery } from "studio/lib/store";

import { fetchEmployeesWithTags, getEmployeesPageSlug } from "./api";
import styles from "./contact-box.module.css";
import ContactSelector, { EmployeeAndTag } from "./ContactSelector";
import ContactSelector from "./ContactSelector";

export interface ContactBoxProps {
section: ContactBoxSection;
Expand All @@ -20,21 +17,13 @@ export default async function ContactBox({
section,
language,
}: ContactBoxProps) {
const employeesPageRes = await loadStudioQuery<{ slug: string }>(
EMPLOYEE_PAGE_SLUG_QUERY,
{
language,
},
);
const employeesPageSlug = employeesPageRes.data.slug;
const employeesPageSlug = await getEmployeesPageSlug(language);

const contactPoints = fetchEmployeesByEmails(
section.contactPoints.map((contactPoint) => contactPoint.email),
).then((result) =>
result.ok
? result.value.map((e) => employeeAndTag(e, section.contactPoints))
: [],
);
if (!employeesPageSlug) {
return null;
}

const contactPoints = fetchEmployeesWithTags(section.contactPoints);

const backgroundClass =
section.background === "light" ? styles["contactBox__inner--light"] : "";
Expand Down Expand Up @@ -68,20 +57,3 @@ export default async function ContactBox({
</section>
);
}

function employeeAndTag(
employee: ChewbaccaEmployee,
contactPoints: ContactBoxSection["contactPoints"],
): EmployeeAndTag {
const tag =
contactPoints.find((contactPoint) => contactPoint.email === employee.email)
?.tag ?? "";
return {
employee,
tag,
tagSlug: slugify(tag),
};
}
function slugify(tag: string) {
return tag.toLowerCase().replace(/ /g, "-");
}
11 changes: 3 additions & 8 deletions src/components/sections/contact-box/ContactSelector.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,12 @@ import { use, useState } from "react";

import EmployeeCard from "src/components/employeeCard/EmployeeCard";
import { Tag } from "src/components/tag";
import { ChewbaccaEmployee } from "src/types/employees";

import styles from "./contact-box.module.css";

export type EmployeeAndTag = {
employee: ChewbaccaEmployee;
tag: string;
tagSlug: string;
};
import { EmployeeAndMetadata } from "./types";

export type ContactSelectorProps = {
contactPoints: Promise<EmployeeAndTag[]>;
contactPoints: Promise<EmployeeAndMetadata[]>;
employeesPageSlug: string;
language: string;
background?: "dark" | "light";
Expand Down Expand Up @@ -68,6 +62,7 @@ export default function ContactSelector({
employee={contactPoint.employee}
employeePageSlug={employeesPageSlug}
language={language}
overrideTitle={contactPoint.overrideTitle}
/>
</div>
))}
Expand Down
58 changes: 58 additions & 0 deletions src/components/sections/contact-box/api.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
import { ChewbaccaEmployee } from "src/types/employees";
import { fetchEmployeesByEmails } from "src/utils/employees";
import { ContactBoxSection } from "studio/lib/interfaces/pages";
import { EMPLOYEE_PAGE_SLUG_QUERY } from "studio/lib/queries/siteSettings";
import { loadStudioQuery } from "studio/lib/store";

import { EmployeeAndMetadata } from "./types";

export async function getEmployeesPageSlug(
language: string,
): Promise<string | undefined> {
const employeesPageRes = await loadStudioQuery<{ slug: string }>(
EMPLOYEE_PAGE_SLUG_QUERY,
{
language,
},
{
cache: "force-cache",
next: {
// Cache for 1 day.. Not likely to change (or is it???)
revalidate: 60 * 60 * 24,
},
},
);

return employeesPageRes.data?.slug;
}

export async function fetchEmployeesWithTags(
contactPoints: ContactBoxSection["contactPoints"],
) {
const contacts = fetchEmployeesByEmails(
contactPoints.map((contactPoint) => contactPoint.email),
).then((result) =>
result.ok
? result.value.map((e) => employeeAndMetadata(e, contactPoints))
: [],
);
return contacts;
}

function employeeAndMetadata(
employee: ChewbaccaEmployee,
contactPoints: ContactBoxSection["contactPoints"],
): EmployeeAndMetadata {
const metadata = contactPoints.find(
(contactPoint) => contactPoint.email === employee.email,
);
return {
employee,
tag: metadata?.tag ?? "",
tagSlug: slugify(metadata?.tag ?? ""),
overrideTitle: metadata?.overrideTitle ?? "",
};
}
function slugify(tag: string) {
return tag.toLowerCase().replace(/ /g, "-");
}
8 changes: 8 additions & 0 deletions src/components/sections/contact-box/types.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import { ChewbaccaEmployee } from "src/types/employees";

export type EmployeeAndMetadata = {
employee: ChewbaccaEmployee;
tag: string;
tagSlug: string;
overrideTitle: string;
};
8 changes: 0 additions & 8 deletions src/components/text/Text.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ const meta: Meta<typeof Text> = {
"h4",
"h5",
"h6",
"labelSmall",
"labelRegular",
"quoteItalic",
"quoteNormal",
Expand Down Expand Up @@ -90,13 +89,6 @@ export const H6: Story = {
},
};

export const LabelSmall: Story = {
args: {
type: "labelSmall",
children: "This is a Label Small text",
},
};

export const LabelRegular: Story = {
args: {
type: "labelRegular",
Expand Down
6 changes: 0 additions & 6 deletions src/components/text/Text.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,6 @@ export type TextType =
| "h5"
| "h6"
| "desktopLink"
| "desktopLinkBig"
| "labelSmall"
| "labelRegular"
| "labelLarge"
| "quoteItalic"
Expand All @@ -30,8 +28,6 @@ const elementMap: { [key in TextType]: keyof JSX.IntrinsicElements } = {
h5: "h5",
h6: "h6",
desktopLink: "p",
desktopLinkBig: "p",
labelSmall: "span",
labelRegular: "span",
labelLarge: "span",
quoteItalic: "p",
Expand All @@ -53,8 +49,6 @@ const classMap: { [key in TextType]?: string } = {
h5: styles.h5,
h6: styles.h6,
desktopLink: styles.desktopLink,
desktopLinkBig: styles.desktopLinkBig,
labelSmall: styles.labelSmall,
labelRegular: styles.labelRegular,
labelLarge: styles.labelLarge,
quoteItalic: styles.quoteItalic,
Expand Down
Loading

0 comments on commit 7f81382

Please sign in to comment.