From cfe88ebc738128faf11b70ed2d70d05d5efc3cda Mon Sep 17 00:00:00 2001 From: eeshabarua Date: Tue, 16 Apr 2024 21:18:20 -0500 Subject: [PATCH] Add Action Network Widget --- src/components/display/ActionNetwork.tsx | 37 +++++++++++++++++++++ src/components/index.ts | 2 ++ src/components/navigation/PrimaryNavBar.tsx | 2 +- src/sections/take-action/momentum.tsx | 9 ++++- 4 files changed, 48 insertions(+), 2 deletions(-) create mode 100644 src/components/display/ActionNetwork.tsx diff --git a/src/components/display/ActionNetwork.tsx b/src/components/display/ActionNetwork.tsx new file mode 100644 index 00000000..0b7fcb0b --- /dev/null +++ b/src/components/display/ActionNetwork.tsx @@ -0,0 +1,37 @@ +import React, { useEffect } from 'react' + +const ActionNetworkWidget: React.FC = () => { + useEffect(() => { + // Create a link element for the CSS file + const link = document.createElement('link') + link.href = 'https://actionnetwork.org/css/style-embed-v3.css' + link.rel = 'stylesheet' + + // Create a script element for the widget + const script = document.createElement('script') + script.src = + 'https://actionnetwork.org/widgets/v5/event/red-ccn-4-21?format=js&source=widget' + script.async = true + + // Append both link and script elements to the document body + document.body.appendChild(link) + document.body.appendChild(script) + + // Cleanup function to remove the link and script when component unmounts + return () => { + document.body.removeChild(link) + document.body.removeChild(script) + } + }, []) // Empty dependency array ensures this effect runs only once + + return ( +
+ {/* This div is the target for our HTML insertion */} +
+ ) +} + +export default ActionNetworkWidget diff --git a/src/components/index.ts b/src/components/index.ts index 10c210ef..170eb668 100644 --- a/src/components/index.ts +++ b/src/components/index.ts @@ -25,6 +25,7 @@ import Tabs from './display/Tabs' import ClimateClock from './display/ClimateClock' import ImageWithCaption from './display/ImageWithCaption' import LinkBox from './display/LinkBox' +import ActionNetworkWidget from './display/ActionNetwork' // Accordions import RequestAccordion from './accordion/RequestAccordion' import CaseAccordion from './accordion/CaseAccordion' @@ -106,6 +107,7 @@ export { EnergyRadialChart, AdminNavBar, ClimateClock, + ActionNetworkWidget, AdminSelectCard, AdminListTable, InviteAdminBar, diff --git a/src/components/navigation/PrimaryNavBar.tsx b/src/components/navigation/PrimaryNavBar.tsx index 972ecb74..8ebe5b4f 100644 --- a/src/components/navigation/PrimaryNavBar.tsx +++ b/src/components/navigation/PrimaryNavBar.tsx @@ -48,7 +48,7 @@ const PrimaryNavBar: FC = () => { {/* Flowbite included styles has a w-full on mobile view that pushes whole page to the left, need to adjust for that */} - + diff --git a/src/sections/take-action/momentum.tsx b/src/sections/take-action/momentum.tsx index eb4ee26b..c966e88a 100644 --- a/src/sections/take-action/momentum.tsx +++ b/src/sections/take-action/momentum.tsx @@ -1,7 +1,11 @@ import type { FC } from 'react' import { documentToReactComponents } from '@contentful/rich-text-react-renderer' -import { HighlightedTitle, ListItem } from '../../components' +import { + HighlightedTitle, + ListItem, + ActionNetworkWidget, +} from '../../components' import type { ListEntryDocument } from '../../types' import { mainParagraphStyle } from '../../utils/renderer' @@ -27,6 +31,9 @@ const Momentum: FC<{ entries: ListEntryDocument[] }> = ({ entries }) => { ))} +
+ +
) }