-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: adds contact box section (#928)
* feat: adds section schema for contact box * adds contact box * makes titles translateable * feat: adds component and basic functionality for contact box * feat: adds option for light/dark mode for contact box * initial unfinished design * fix: ambiguous syntax * fix: set contact selector as proper tablist * feat: adds background dark/light mode to Tag * fix: sizing for employee card * fix: skeleton loading with container queries * fix: responsiveness contact box * refactor: renames design mode to background to align with sketches * fix: employee skeleton dark/light background * fix: simplify email type * fix: adds description to tag field in contact box
- Loading branch information
Showing
14 changed files
with
571 additions
and
89 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,87 @@ | ||
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 styles from "./contact-box.module.css"; | ||
import ContactSelector, { EmployeeAndTag } from "./ContactSelector"; | ||
|
||
export interface ContactBoxProps { | ||
section: ContactBoxSection; | ||
language: string; | ||
} | ||
|
||
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 contactPoints = fetchEmployeesByEmails( | ||
section.contactPoints.map((contactPoint) => contactPoint.email), | ||
).then((result) => | ||
result.ok | ||
? result.value.map((e) => employeeAndTag(e, section.contactPoints)) | ||
: [], | ||
); | ||
|
||
const backgroundClass = | ||
section.background === "light" ? styles["contactBox__inner--light"] : ""; | ||
|
||
return ( | ||
<section className={styles.contactBox}> | ||
<div className={`${styles.contactBox__inner} ${backgroundClass}`}> | ||
<div className={styles.textContent}> | ||
<Text type="h3" as="h2"> | ||
{section.basicTitle} | ||
</Text> | ||
|
||
{section.optionalSubtitle && ( | ||
<Text type="bodyBig">{section.optionalSubtitle}</Text> | ||
)} | ||
</div> | ||
|
||
<div className={styles.contactSelectorWrapper}> | ||
<Suspense | ||
fallback={<EmployeeCardSkeleton background={section.background} />} | ||
> | ||
<ContactSelector | ||
employeesPageSlug={employeesPageSlug} | ||
contactPoints={contactPoints} | ||
language={language} | ||
background={section.background} | ||
/> | ||
</Suspense> | ||
</div> | ||
</div> | ||
</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, "-"); | ||
} |
Oops, something went wrong.