fix(WEB-115): alter contact block to allow any version of multiple numbers and addresses

This commit is contained in:
Simon Emanuelsson
2024-03-15 07:56:25 +01:00
parent 70f9c22410
commit fd6c49ac7c
5 changed files with 164 additions and 80 deletions

View File

@@ -10,7 +10,7 @@ import Tracking from "@/components/Current/Tracking"
import type { PageArgs, LangParams, UriParams } from "@/types/params" import type { PageArgs, LangParams, UriParams } from "@/types/params"
import type { GetCurrentBlockPageData } from "@/types/requests/currentBlockPage" import type { GetCurrentBlockPageData } from "@/types/requests/currentBlockPage"
import { TrackingData } from "@/types/requests/trackingData" import type { TrackingData } from "@/types/requests/trackingData"
export default async function CurrentContentPage({ export default async function CurrentContentPage({
params, params,

View File

@@ -2,63 +2,71 @@ import styles from "./contact.module.css"
import { langEnum } from "@/types/lang" import { langEnum } from "@/types/lang"
import type { Lang } from "@/types/lang" import type { Lang } from "@/types/lang"
import type { ContactNode } from "@/types/requests/asides/contact" import { Section, type ContactNode } from "@/types/requests/asides/contact"
export default function Contact({ sections, system: { locale } }: ContactNode) {
if (!sections.length) {
return null
}
export default function Contact({
title,
mailing_address,
visiting_address,
phone,
system: { locale },
}: ContactNode) {
const visitingAddressMessage = getVisitingAddressMessage(locale) const visitingAddressMessage = getVisitingAddressMessage(locale)
return ( return (
<div> <section>
<div> {sections.map((section) => {
<div> switch (section.__typename) {
<div> case Section.ContactBlockSectionsExtraInfo:
<h2 className={styles.heading}>{title}</h2> return <p>{section.extra_info.text}</p>
<p> case Section.ContactBlockSectionsMailingAddress:
{mailing_address.name} return (
<br /> <p>
{mailing_address.street} {section.mailing_address.name}
<br /> <br />
{mailing_address.zip} {mailing_address.city} {section.mailing_address.street}
<br /> <br />
{mailing_address.country} {section.mailing_address.zip} {section.mailing_address.city}
</p> <br />
<p> {section.mailing_address.country}
{visitingAddressMessage}: {visiting_address.street}{" "} </p>
</p> )
</div> case Section.ContactBlockSectionsPhone:
</div> return (
<div> <div className={styles.highlightBlock}>
<div className={styles.highlightBlock}> <h3>{section.phone.title}</h3>
<h3>{phone.title}</h3> <div className={styles.phoneContainer}>
<div className={styles.phoneContainer}> <svg
<svg focusable="false"
focusable="false" className={styles.phoneIcon}
className={styles.phoneIcon} viewBox="0 0 32 32"
viewBox="0 0 32 32" >
> <use
<use xmlnsXlink="http://www.w3.org/1999/xlink"
xmlnsXlink="http://www.w3.org/1999/xlink" xlinkHref="/_static/img/icons/sprites.svg#icon-phone"
xlinkHref="/_static/img/icons/sprites.svg#icon-phone" ></use>
></use> </svg>
</svg>
<a <a
href={phone.number} href={`tel:+${section.phone.number}`}
itemProp="telephone" itemProp="telephone"
className={styles.phoneNumberLink} className={styles.phoneNumberLink}
> >
{phone.number} +{section.phone.number}
</a> </a>
</div> </div>
</div> </div>
</div> )
</div> case Section.ContactBlockSectionsTitle:
</div> return <h2 className={styles.heading}>{section.title.text}</h2>
case Section.ContactBlockSectionsVisitingAddress:
return (
<p>
{visitingAddressMessage}: {section.visiting_address.street}{" "}
</p>
)
default:
return null
}
})}
</section>
) )
} }

View File

@@ -1,6 +1,7 @@
import type { ContactsProps } from "@/types/components/current/asides/contact"
import Contact from "./Contact" import Contact from "./Contact"
import type { ContactsProps } from "@/types/components/current/asides/contact"
export default function Contacts({ contacts }: ContactsProps) { export default function Contacts({ contacts }: ContactsProps) {
return contacts.map((contact) => ( return contacts.map((contact) => (
<Contact key={contact.node.system.uid} {...contact.node} /> <Contact key={contact.node.system.uid} {...contact.node} />

View File

@@ -1,4 +1,10 @@
fragment Contact on ContactBlock { fragment ContactExtraInfo on ContactBlockSectionsExtraInfo {
extra_info {
text
}
}
fragment ContactMailingAddress on ContactBlockSectionsMailingAddress {
mailing_address { mailing_address {
city city
country country
@@ -6,15 +12,22 @@ fragment Contact on ContactBlock {
street street
zip zip
} }
system { }
uid
locale fragment ContactPhone on ContactBlockSectionsPhone {
}
phone { phone {
number number
title title
} }
title }
fragment ContactTitle on ContactBlockSectionsTitle {
title {
text
}
}
fragment ContactVisitingAddress on ContactBlockSectionsVisitingAddress {
visiting_address { visiting_address {
city city
country country
@@ -22,3 +35,18 @@ fragment Contact on ContactBlock {
zip zip
} }
} }
fragment Contact on ContactBlock {
sections {
__typename
...ContactExtraInfo
...ContactMailingAddress
...ContactPhone
...ContactTitle
...ContactVisitingAddress
}
system {
locale
uid
}
}

View File

@@ -1,28 +1,75 @@
import type { Edges } from "../utils/edges" import type { Edges } from "../utils/edges"
import type { Lang } from "@/types/lang" import type { Lang } from "@/types/lang"
import type { Typename } from "../utils/typename"
export enum Section {
ContactBlockSectionsExtraInfo = "ContactBlockSectionsExtraInfo",
ContactBlockSectionsMailingAddress = "ContactBlockSectionsMailingAddress",
ContactBlockSectionsPhone = "ContactBlockSectionsPhone",
ContactBlockSectionsTitle = "ContactBlockSectionsTitle",
ContactBlockSectionsVisitingAddress = "ContactBlockSectionsVisitingAddress",
}
type ExtraInfo = Typename<
{
extra_info: {
text: string
}
},
Section.ContactBlockSectionsExtraInfo
>
type MailingAddress = Typename<
{
mailing_address: {
city: string
country: string
name: string
street: string
zip: string
}
},
Section.ContactBlockSectionsMailingAddress
>
type Phone = Typename<
{
phone: {
number: number
title: string
}
},
Section.ContactBlockSectionsPhone
>
type Title = Typename<
{
title: {
text: string
}
},
Section.ContactBlockSectionsTitle
>
type VisitingAddress = Typename<
{
visiting_address: {
city: string
country: string
street: string
zip: string
}
},
Section.ContactBlockSectionsVisitingAddress
>
type Sections = ExtraInfo | MailingAddress | Phone | Title | VisitingAddress
export type ContactNode = { export type ContactNode = {
mailing_address: { sections: Sections[]
city: string
country: string
name: string
street: string
zip: string
}
system: { system: {
uid: string
locale: Lang locale: Lang
} uid: string
phone: {
number: string
title: string
}
title: string
visiting_address: {
city: string
country: string
street: string
zip: string
} }
} }