Skip to content

Commit

Permalink
feat: add generic title/content notice type (#1677)
Browse files Browse the repository at this point in the history
  • Loading branch information
bchrobot authored Dec 10, 2023
1 parent 1e00140 commit adb168d
Show file tree
Hide file tree
Showing 7 changed files with 106 additions and 6 deletions.
10 changes: 9 additions & 1 deletion libs/gql-schema/notice.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,15 @@ export const schema = `
id: ID!
}
union Notice = Register10DlcBrandNotice | Register10DlcCampaignNotice | Pending10DlcCampaignNotice | Pricing10DlcNotice | PricingTollFreeNotice
type TitleContentNotice {
id: ID!
title: String!
avatarIcon: String!
avatarColor: String!
markdownContent: String!
}
union Notice = Register10DlcBrandNotice | Register10DlcCampaignNotice | Pending10DlcCampaignNotice | Pricing10DlcNotice | PricingTollFreeNotice | TitleContentNotice
type NoticeEdge {
cursor: Cursor!
Expand Down
9 changes: 8 additions & 1 deletion libs/spoke-codegen/src/graphql/notifications.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,13 @@ query getOrganizationNotifications($organizationId: String!) {
}
edges {
node {
... on TitleContentNotice {
id
title
avatarIcon
avatarColor
markdownContent
}
... on Register10DlcBrandNotice {
id
tcrRegistrationUrl
Expand All @@ -25,4 +32,4 @@ query getOrganizationNotifications($organizationId: String!) {
}
}
}
}
}
10 changes: 9 additions & 1 deletion src/api/notice.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,18 @@ import type {
Pricing10DlcNotice,
PricingTollFreeNotice,
Register10DlcBrandNotice,
Register10DlcCampaignNotice
Register10DlcCampaignNotice,
TitleContentNotice
} from "@spoke/spoke-codegen";
import type { GraphQLType } from "graphql";

export function isTitleContentNotice(obj: Notice): obj is TitleContentNotice {
return (
(obj as TitleContentNotice & GraphQLType).__typename ===
"TitleContentNotice"
);
}

export function isRegister10DlcBrandNotice(
obj: Notice
): obj is Register10DlcBrandNotice {
Expand Down
15 changes: 14 additions & 1 deletion src/containers/AdminDashboard/components/NotificationCard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,14 @@ import {
isPricing10DlcNotice,
isPricingTollFreeNotice,
isRegister10DlcBrandNotice,
isRegister10DlcCampaignNotice
isRegister10DlcCampaignNotice,
isTitleContentNotice
} from "../../../api/notice";
import Pending10DlcCampaignNoticeCard from "./Pending10DlcCampaignNoticeCard";
import PricingNoticeCard from "./PricingNoticeCard";
import Register10DlcNoticeCard from "./Register10DlcNoticeCard";
import ShutdownNoticeCard from "./ShutdownNoticeCard";
import TitleContentNoticeCard from "./TitleContentNoticeCard";

interface NotificationCardProps {
organizationId: string;
Expand Down Expand Up @@ -42,6 +44,17 @@ export const NotificationCard: React.FC<NotificationCardProps> = ({
return (
<div>
{data?.notices.edges.map(({ node }) => {
if (isTitleContentNotice(node)) {
return (
<TitleContentNoticeCard
key={node.id}
title={node.title}
avatarIcon={node.avatarIcon}
avatarColor={node.avatarColor as any}
markdownContent={node.markdownContent}
/>
);
}
if (window.SHOW_10DLC_REGISTRATION_NOTICES) {
if (
isRegister10DlcBrandNotice(node) ||
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
import Card from "@material-ui/core/Card";
import CardContent from "@material-ui/core/CardContent";
import CardHeader from "@material-ui/core/CardHeader";
import Announcement from "@material-ui/icons/Announcement";
import React from "react";
import type { Components } from "react-markdown";
import ReactMarkdown from "react-markdown";

type TitleContentNoticeCardProps = {
title: string;
avatarIcon: string;
avatarColor:
| "error"
| "inherit"
| "disabled"
| "action"
| "primary"
| "secondary"
| undefined;
markdownContent: string;
};

// Force links to open in a new window/tab
const components: Components = {
a: ({ node: _node, children, href, title, ...props }) => (
<a href={href} title={title} rel="noreferrer" target="_blank" {...props}>
{children}
</a>
)
};

const TitleContentNoticeCard: React.FC<TitleContentNoticeCardProps> = (
props
) => {
const avatar =
props.avatarIcon === "announcement" ? (
<Announcement color={props.avatarColor} />
) : null;

return (
<Card variant="outlined" style={{ marginBottom: "2em" }}>
<CardHeader title={props.title} avatar={avatar} />
<CardContent>
<ReactMarkdown components={components}>
{props.markdownContent}
</ReactMarkdown>
</CardContent>
</Card>
);
};

export default TitleContentNoticeCard;
10 changes: 9 additions & 1 deletion src/schema.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -889,7 +889,15 @@ type PricingTollFreeNotice implements PricingNotice {
id: ID!
}

union Notice = Register10DlcBrandNotice | Register10DlcCampaignNotice | Pending10DlcCampaignNotice | Pricing10DlcNotice | PricingTollFreeNotice
type TitleContentNotice {
id: ID!
title: String!
avatarIcon: String!
avatarColor: String!
markdownContent: String!
}

union Notice = Register10DlcBrandNotice | Register10DlcCampaignNotice | Pending10DlcCampaignNotice | Pricing10DlcNotice | PricingTollFreeNotice | TitleContentNotice

type NoticeEdge {
cursor: Cursor!
Expand Down
6 changes: 5 additions & 1 deletion src/server/api/notice.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,17 @@ import {
isPricing10DlcNotice,
isPricingTollFreeNotice,
isRegister10DlcBrandNotice,
isRegister10DlcCampaignNotice
isRegister10DlcCampaignNotice,
isTitleContentNotice
} from "../../api/notice";

// explicitly setting typename
export const resolvers = {
Notice: {
__resolveType(obj: Notice) {
if (isTitleContentNotice(obj)) {
return "TitleContentNotice";
}
if (isRegister10DlcBrandNotice(obj)) {
return "Register10DlcBrandNotice";
}
Expand Down

0 comments on commit adb168d

Please sign in to comment.