From fd6c49ac7c4f2c1c5b6dd71bb90b60e62b437443 Mon Sep 17 00:00:00 2001 From: Simon Emanuelsson Date: Fri, 15 Mar 2024 07:56:25 +0100 Subject: [PATCH] fix(WEB-115): alter contact block to allow any version of multiple numbers and addresses --- .../current-content-page/page.tsx | 2 +- components/Current/Aside/Contacts/Contact.tsx | 114 ++++++++++-------- components/Current/Aside/Contacts/index.tsx | 3 +- lib/graphql/Fragments/Contact.graphql | 40 +++++- types/requests/asides/contact.ts | 85 ++++++++++--- 5 files changed, 164 insertions(+), 80 deletions(-) diff --git a/app/[lang]/(live-current)/current-content-page/page.tsx b/app/[lang]/(live-current)/current-content-page/page.tsx index aed056925..5e6ec11a8 100644 --- a/app/[lang]/(live-current)/current-content-page/page.tsx +++ b/app/[lang]/(live-current)/current-content-page/page.tsx @@ -10,7 +10,7 @@ import Tracking from "@/components/Current/Tracking" import type { PageArgs, LangParams, UriParams } from "@/types/params" 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({ params, diff --git a/components/Current/Aside/Contacts/Contact.tsx b/components/Current/Aside/Contacts/Contact.tsx index 32279d445..cb2055d19 100644 --- a/components/Current/Aside/Contacts/Contact.tsx +++ b/components/Current/Aside/Contacts/Contact.tsx @@ -2,63 +2,71 @@ import styles from "./contact.module.css" import { langEnum } 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) return ( -
-
-
-
-

{title}

-

- {mailing_address.name} -
- {mailing_address.street} -
- {mailing_address.zip} {mailing_address.city} -
- {mailing_address.country} -

-

- {visitingAddressMessage}: {visiting_address.street}{" "} -

-
-
-
-
-

{phone.title}

-
- - - +
+ {sections.map((section) => { + switch (section.__typename) { + case Section.ContactBlockSectionsExtraInfo: + return

{section.extra_info.text}

+ case Section.ContactBlockSectionsMailingAddress: + return ( +

+ {section.mailing_address.name} +
+ {section.mailing_address.street} +
+ {section.mailing_address.zip} {section.mailing_address.city} +
+ {section.mailing_address.country} +

+ ) + case Section.ContactBlockSectionsPhone: + return ( +
+

{section.phone.title}

+ -
-
-
-
+ + +{section.phone.number} + +
+
+ ) + case Section.ContactBlockSectionsTitle: + return

{section.title.text}

+ case Section.ContactBlockSectionsVisitingAddress: + return ( +

+ {visitingAddressMessage}: {section.visiting_address.street}{" "} +

+ ) + default: + return null + } + })} + ) } diff --git a/components/Current/Aside/Contacts/index.tsx b/components/Current/Aside/Contacts/index.tsx index 76abe48b3..1198b3f30 100644 --- a/components/Current/Aside/Contacts/index.tsx +++ b/components/Current/Aside/Contacts/index.tsx @@ -1,6 +1,7 @@ -import type { ContactsProps } from "@/types/components/current/asides/contact" import Contact from "./Contact" +import type { ContactsProps } from "@/types/components/current/asides/contact" + export default function Contacts({ contacts }: ContactsProps) { return contacts.map((contact) => ( diff --git a/lib/graphql/Fragments/Contact.graphql b/lib/graphql/Fragments/Contact.graphql index a38910e6e..bd2068829 100644 --- a/lib/graphql/Fragments/Contact.graphql +++ b/lib/graphql/Fragments/Contact.graphql @@ -1,4 +1,10 @@ -fragment Contact on ContactBlock { +fragment ContactExtraInfo on ContactBlockSectionsExtraInfo { + extra_info { + text + } +} + +fragment ContactMailingAddress on ContactBlockSectionsMailingAddress { mailing_address { city country @@ -6,15 +12,22 @@ fragment Contact on ContactBlock { street zip } - system { - uid - locale - } +} + +fragment ContactPhone on ContactBlockSectionsPhone { phone { number title } - title +} + +fragment ContactTitle on ContactBlockSectionsTitle { + title { + text + } +} + +fragment ContactVisitingAddress on ContactBlockSectionsVisitingAddress { visiting_address { city country @@ -22,3 +35,18 @@ fragment Contact on ContactBlock { zip } } + +fragment Contact on ContactBlock { + sections { + __typename + ...ContactExtraInfo + ...ContactMailingAddress + ...ContactPhone + ...ContactTitle + ...ContactVisitingAddress + } + system { + locale + uid + } +} diff --git a/types/requests/asides/contact.ts b/types/requests/asides/contact.ts index af9e1ada0..6c466b067 100644 --- a/types/requests/asides/contact.ts +++ b/types/requests/asides/contact.ts @@ -1,28 +1,75 @@ import type { Edges } from "../utils/edges" 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 = { - mailing_address: { - city: string - country: string - name: string - street: string - zip: string - } + sections: Sections[] system: { - uid: string locale: Lang - } - phone: { - number: string - title: string - } - title: string - visiting_address: { - city: string - country: string - street: string - zip: string + uid: string } }