Skip to content

Commit

Permalink
First deploy of our Momentum testing.
Browse files Browse the repository at this point in the history
  • Loading branch information
Spicer Matthews committed Jul 14, 2023
1 parent c927e75 commit bdca227
Show file tree
Hide file tree
Showing 2 changed files with 198 additions and 8 deletions.
188 changes: 188 additions & 0 deletions src/components/directDonateComponents/Momentum.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,188 @@
import React, { useState } from 'react'
import gtag from 'ga-gtag'
import PropTypes from 'prop-types'
import Button from '@material-ui/core/Button'
import Card from '@material-ui/core/Card'
import CardContent from '@material-ui/core/CardContent'
import Typography from '@material-ui/core/Typography'
import Modal from '@material-ui/core/Modal'
import IconButton from '@material-ui/core/IconButton'
import CloseIcon from '@material-ui/icons/Close'
import localStorageMgr from 'src/utils/localstorage-mgr'
import { NOTIF_DISMISS_PREFIX } from 'src/utils/constants'

const iframeUrl =
'https://tab-for-a-cause-360.givemomentum.com?background-color=red&show-container=false'

const contStyles = {
position: 'relative',
marginLeft: 'auto',
marginRight: 'auto',
width: 650,
marginTop: 0,
marginBottom: 60,
zIndex: 100000,
}

const Momentum = ({ user }) => {
const [show, setShow] = useState(true)
const [openWidget, setOpenWidget] = useState(false)

const getNotifDismissKey = (code) => `${NOTIF_DISMISS_PREFIX}.${code}`

const onOpen = () => {
setOpenWidget(true)
gtag('event', 'momentum_open')
}

const onClose = () => {
setOpenWidget(false)
gtag('event', 'momentum_close')
}

const onDismiss = (e) => {
e.stopPropagation()
e.nativeEvent.stopImmediatePropagation()
gtag('event', 'momentum_dismiss')
localStorageMgr.setItem(getNotifDismissKey('momentum'), true)
setShow(false)
return false
}

// useEffect(() => {
// const dissNotif =
// localStorageMgr.getItem(getNotifDismissKey('momentum')) || false

// if (!dissNotif) {
// setShow(true)
// } else {
// setShow(false)
// }
// }, [user])

return (
<>
{show && (
<div style={contStyles}>
<script src="https://donation-form-static.givemomentum.com/widget.js" />
<Card>
<CardContent
onClick={onOpen}
style={{
display: 'flex',
justifyContent: 'center',
flexDirection: 'column',
}}
>
<IconButton
onClick={onDismiss}
style={{
position: 'absolute',
right: 10,
top: 0,
}}
>
<CloseIcon sx={{ color: '#fff', width: 28, height: 28 }} />
</IconButton>
<Typography
variant="h4"
gutterBottom
align="center"
style={{ marginTop: 20 }}
>
Donate Directly to {user.cause.nameForShop || 'Charity'}
</Typography>
<Typography variant="body1" gutterBottom align="center">
By donating directly, 100% of your funds goes to supporting{' '}
{user.cause.nameForShop || 'Charity'}.
</Typography>
<Button
variant="contained"
color="primary"
style={{
marginTop: 10,
marginBottom: 10,
width: 250,
marginLeft: 'auto',
marginRight: 'auto',
}}
>
Donate Directly
</Button>
</CardContent>
</Card>
</div>
)}

{iframeUrl && (
<Modal
open={openWidget}
style={{
top: 100,
left: 100,
right: 100,
bottom: 100,
position: 'absolute',
backgroundColor: 'white',
zIndex: 100000000,
}}
>
<div style={{ height: '100%' }}>
<IconButton
onClick={onClose}
style={{ position: 'absolute', right: 25, top: 5 }}
>
<CloseIcon sx={{ color: '#fff', width: 28, height: 28 }} />
</IconButton>

<div
style={{
height: '100%',
width: '100%',
padding: 40,
backgroundColor: 'white',
display: 'flex',
flexFlow: 'column',
}}
>
<Typography
variant="h4"
gutterBottom
align="center"
style={{ marginTop: 20, flex: '0 1 auto' }}
>
Level Up Your Impact For {user.cause.nameForShop || 'Charity'}.
</Typography>
<Typography variant="body1" gutterBottom align="center">
By donating directly, 100% of your funds goes to supporting{' '}
{user.cause.nameForShop || 'Charity'}.
</Typography>
<iframe
style={{ border: 'none', flex: '1 1 auto' }}
id="momentum-donation-form"
title="Widget Content"
src={iframeUrl}
width="100%"
/>
</div>
</div>
</Modal>
)}
</>
)
}

Momentum.displayName = 'MomentumComponent'

Momentum.propTypes = {
user: PropTypes.shape({
userId: PropTypes.string,
cause: PropTypes.shape({
nameForShop: PropTypes.string,
}),
}).isRequired,
}

Momentum.defaultProps = {}

export default Momentum
18 changes: 10 additions & 8 deletions src/pages/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ import SquadCounter from 'src/components/SquadCounter'
import CustomThemeHOC from 'src/utils/pageWrappers/CustomThemeHOC'
import withGoogleAnalyticsProperties from 'src/utils/pageWrappers/withGoogleAnalyticsProperties'
import SfacActivityContainer from 'src/components/SfacActivityContainer'
import PrimeDay2023 from 'src/components/promos/PrimeDay2023'
import Momentum from 'src/components/directDonateComponents/Momentum'

// material components
import { makeStyles } from '@material-ui/core/styles'
Expand Down Expand Up @@ -655,10 +655,11 @@ const Index = ({ data: fallbackData, userAgent }) => {
// Determine if we should show any notifications. Currently, each
// notification is is configured on a one-off basis here (UI) and in the
// backend (enabling/disabling).
const [notificationsToShow, setNotifsToShow] = useState([])
const [, setNotifsToShow] = useState([])

useEffect(() => {
const getNotifDismissKey = (code) => `${NOTIF_DISMISS_PREFIX}.${code}`

const onNotificationClose = (code) => {
localStorageMgr.setItem(getNotifDismissKey(code), 'true')
setNotifsToShow((notifsToShow) =>
Expand All @@ -667,6 +668,7 @@ const Index = ({ data: fallbackData, userAgent }) => {

gtag('event', 'shop_full_page_2023_dismiss', { version: 'Version1' })
}

const hasDismissedNotif = (notif) =>
localStorageMgr.getItem(getNotifDismissKey(notif.code)) === 'true'

Expand All @@ -690,10 +692,10 @@ const Index = ({ data: fallbackData, userAgent }) => {
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [JSON.stringify(notifications), isDataFresh])

// Our notification
const notif = notificationsToShow.find(
(res) => res.code === 'shfac-notify-prime-day-2023'
)
// // Our notification
// const notif = notificationsToShow.find(
// (res) => res.code === 'shfac-notify-prime-day-2023'
// )

// let notif = notificationsToShow.find(
// (res) => res.code === 'shfac-notify-launch-fullpage'
Expand Down Expand Up @@ -1009,8 +1011,8 @@ const Index = ({ data: fallbackData, userAgent }) => {

<div className={classes.centerContainer}>
<div className={classes.searchBarContainer}>
{/* Prime day 2023 Promo */}
{user.userId && notif && <PrimeDay2023 user={user} />}
{/* Momentum Direct Donate */}
{user.userId && <Momentum user={user} />}

<Logo
includeText
Expand Down

0 comments on commit bdca227

Please sign in to comment.