add contact pages and blocks

This commit is contained in:
2024-06-24 05:11:55 +02:00
parent 944506cc2f
commit 15e4e70806
30 changed files with 1448 additions and 51 deletions

View File

@ -37,6 +37,31 @@ export function unique<T>(array: any[]): any[] {
return Array.from(array.reduce((set, item) => set.add(item), new Set()));
}
export function stripWhitespace(s: string): string {
return s.replace(/\s/g, "");
}
export function formatPhoneE164(phone: string): string {
phone = stripWhitespace(phone);
if (phone.startsWith("+") || phone.length != 8) {
return phone;
}
return "+47" + phone;
}
export function formatNorwegianPhoneNumber(phone: string): string {
if (phone.startsWith("+47")) {
const local = phone.substring(3);
if (local.length === 8) {
return `${local.substring(0, 3)} ${local.substring(
3,
5
)} ${local.substring(5)}`;
}
}
return phone;
}
const OneLevelOfBlocksFragmentDefinition = graphql(`
fragment OneLevelOfBlocks on StreamFieldInterface {
id
@ -90,6 +115,16 @@ const OneLevelOfBlocksFragmentDefinition = graphql(`
...Image
}
}
... on ContactListBlock {
items {
blockType
... on ContactEntityBlock {
contactEntity {
...ContactEntity
}
}
}
}
}
`);
@ -102,6 +137,20 @@ const BlockFragmentDefinition = graphql(`
...OneLevelOfBlocks
}
}
... on ContactSectionBlock {
title
text
blocks {
... on ContactSubsectionBlock {
title
text
blocks {
...OneLevelOfBlocks
}
}
...OneLevelOfBlocks
}
}
...OneLevelOfBlocks
}
`);
@ -116,3 +165,17 @@ const ImageFragmentDefinition = graphql(`
attribution
}
`);
const ContactEntityFragmentDefinition = graphql(`
fragment ContactEntity on ContactEntity {
id
name
contactType
title
email
phoneNumber
image {
...Image
}
}
`);