-
Notifications
You must be signed in to change notification settings - Fork 17
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add generic title/content notice type
- Loading branch information
Showing
7 changed files
with
155 additions
and
53 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
111 changes: 63 additions & 48 deletions
111
src/containers/AdminDashboard/components/NotificationCard.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,64 +1,79 @@ | ||
// import Card from "@material-ui/core/Card"; | ||
// import CardContent from "@material-ui/core/CardContent"; | ||
// import Divider from "@material-ui/core/Divider"; | ||
// import { useGetOrganizationNotificationsQuery } from "@spoke/spoke-codegen"; | ||
import Card from "@material-ui/core/Card"; | ||
import CardContent from "@material-ui/core/CardContent"; | ||
import Divider from "@material-ui/core/Divider"; | ||
import { useGetOrganizationNotificationsQuery } from "@spoke/spoke-codegen"; | ||
import React from "react"; | ||
|
||
// import { | ||
// isPending10DlcCampaignNotice, | ||
// isPricing10DlcNotice, | ||
// isPricingTollFreeNotice, | ||
// isRegister10DlcBrandNotice, | ||
// isRegister10DlcCampaignNotice | ||
// } from "../../../api/notice"; | ||
// import Pending10DlcCampaignNoticeCard from "./Pending10DlcCampaignNoticeCard"; | ||
// import PricingNoticeCard from "./PricingNoticeCard"; | ||
// import Register10DlcNoticeCard from "./Register10DlcNoticeCard"; | ||
import { | ||
isPending10DlcCampaignNotice, | ||
isPricing10DlcNotice, | ||
isPricingTollFreeNotice, | ||
isRegister10DlcBrandNotice, | ||
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; | ||
} | ||
|
||
export const NotificationCard: React.FC<NotificationCardProps> = () => { | ||
export const NotificationCard: React.FC<NotificationCardProps> = ({ | ||
organizationId | ||
}) => { | ||
return <ShutdownNoticeCard />; | ||
|
||
// const { data, loading, error } = useGetOrganizationNotificationsQuery({ | ||
// variables: { organizationId } | ||
// }); | ||
const { data, loading, error } = useGetOrganizationNotificationsQuery({ | ||
variables: { organizationId } | ||
}); | ||
|
||
// if (loading) return null; | ||
if (loading) return null; | ||
|
||
// if (error || !data?.notices) { | ||
// return ( | ||
// <Card style={{ marginBottom: "2em" }}> | ||
// <CardContent>There was an error fetching notifications.</CardContent> | ||
// </Card> | ||
// ); | ||
// } | ||
if (error || !data?.notices) { | ||
return ( | ||
<Card style={{ marginBottom: "2em" }}> | ||
<CardContent>There was an error fetching notifications.</CardContent> | ||
</Card> | ||
); | ||
} | ||
|
||
// return ( | ||
// <div> | ||
// {data?.notices.edges.map(({ node }) => { | ||
// if (window.SHOW_10DLC_REGISTRATION_NOTICES) { | ||
// if ( | ||
// isRegister10DlcBrandNotice(node) || | ||
// isRegister10DlcCampaignNotice(node) | ||
// ) { | ||
// return <Register10DlcNoticeCard key={node.id} {...node} />; | ||
// } | ||
// if (isPending10DlcCampaignNotice(node)) { | ||
// return <Pending10DlcCampaignNoticeCard key={node.id} {...node} />; | ||
// } | ||
// if (isPricing10DlcNotice(node) || isPricingTollFreeNotice(node)) { | ||
// return <PricingNoticeCard key={node.id} {...node} />; | ||
// } | ||
// } | ||
// return null; | ||
// })} | ||
// {data?.notices.pageInfo.totalCount > 0 && <Divider />} | ||
// </div> | ||
// ); | ||
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) || | ||
isRegister10DlcCampaignNotice(node) | ||
) { | ||
return <Register10DlcNoticeCard key={node.id} {...node} />; | ||
} | ||
if (isPending10DlcCampaignNotice(node)) { | ||
return <Pending10DlcCampaignNoticeCard key={node.id} {...node} />; | ||
} | ||
if (isPricing10DlcNotice(node) || isPricingTollFreeNotice(node)) { | ||
return <PricingNoticeCard key={node.id} {...node} />; | ||
} | ||
} | ||
return null; | ||
})} | ||
{data?.notices.pageInfo.totalCount > 0 && <Divider />} | ||
</div> | ||
); | ||
}; | ||
|
||
export default NotificationCard; |
52 changes: 52 additions & 0 deletions
52
src/containers/AdminDashboard/components/TitleContentNoticeCard.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters