Skip to content

Commit

Permalink
Merge pull request #21 from prezly/feature/dev-10834-implement-change…
Browse files Browse the repository at this point in the history
…s-to-contact-cards-in-new-themes

[DEV-10834] Update ContactNode type, use it in email content format
  • Loading branch information
kudlajz authored May 23, 2023
2 parents 4825f36 + a81db63 commit 1ad13b5
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 12 deletions.
20 changes: 10 additions & 10 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

16 changes: 14 additions & 2 deletions packages/content-format/src/nodes/ContactNode.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Element } from '../Element';
import { isObject, isUuid } from '../validation';
import { isBoolean, isEnum, isObject, isUuid } from '../validation';

interface NewsroomContact {
uuid: string;
Expand All @@ -9,6 +9,8 @@ export interface ContactNode extends Element<typeof ContactNode.TYPE> {
uuid: string;
reference: NewsroomContact['uuid'] | null;
contact: ContactNode.ContactInfo;
layout: ContactNode.Layout;
show_avatar: boolean;
}

export namespace ContactNode {
Expand All @@ -28,12 +30,22 @@ export namespace ContactNode {
address: string;
}

export enum Layout {
CARD = 'card',
SIGNATURE = 'signature',
}

export function isContactNode(value: any): value is ContactNode {
return Element.isElement(value, TYPE);
}

export function validateContactNode(value: any): ContactNode | null {
const isValid = isContactNode(value) && isUuid(value.uuid) && isObject(value.contact);
const isValid =
isContactNode(value) &&
isUuid(value.uuid) &&
isObject(value.contact) &&
isEnum(value.layout, ContactNode.Layout) &&
isBoolean(value.show_avatar);

return isValid ? value : null;
}
Expand Down
4 changes: 4 additions & 0 deletions packages/email-content-format/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ export namespace InlineNode {
export type BlockNode =
| AttachmentNode
| BookmarkNode
| ContactNode
| CoverageNode
| DividerNode
| EmbedNode
Expand All @@ -59,6 +60,7 @@ export namespace BlockNode {
export function isBlockNode(value: any): value is BlockNode {
return (
AttachmentNode.isAttachmentNode(value) ||
ContactNode.isContactNode(value) ||
CoverageNode.isCoverageNode(value) ||
DividerNode.isDividerNode(value) ||
EmbedNode.isEmbedNode(value) ||
Expand All @@ -80,6 +82,7 @@ export namespace BlockNode {
export function validateBlockNode(value: any): BlockNode | null {
return (
AttachmentNode.validateAttachmentNode(value) ??
ContactNode.validateContactNode(value) ??
CoverageNode.validateCoverageNode(value) ??
DividerNode.validateDividerNode(value) ??
EmbedNode.validateEmbedNode(value) ??
Expand Down Expand Up @@ -219,6 +222,7 @@ export namespace AttachmentNode {
}

export import BookmarkNode = Core.BookmarkNode;
export import ContactNode = Core.ContactNode;
export import CoverageNode = Core.CoverageNode;
export import DividerNode = Core.DividerNode;
export import EmbedNode = Core.EmbedNode;
Expand Down

0 comments on commit 1ad13b5

Please sign in to comment.