Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Lottie #671

Merged
merged 2 commits into from
Oct 31, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,6 @@
"react-dom": "18.2.0",
"react-in-viewport": "^1.0.0-alpha.29",
"react-keyed-flatten-children": "^1.3.0",
"react-mailchimp-subscribe": "^2.1.3",
"react-markdown": "^8.0.4",
"react-phone-number-input": "^3.2.12",
"react-slidedown": "^2.4.7",
Expand Down
158 changes: 14 additions & 144 deletions src/components/Newsletter.tsx
Original file line number Diff line number Diff line change
@@ -1,64 +1,21 @@
import { useState, useEffect } from 'react'
import styled from 'styled-components'
import MailchimpSubscribe, { FormHooks, NameFormFields } from 'react-mailchimp-subscribe'
import { rgba, assert, useFormLocalStorage } from '@lib'
import { Form, Button, PagePadding, Icon } from '@components'
import { rgba } from '@lib'
import { Button, PagePadding, Icon } from '@components'
import { breakpoint, palette, typography } from '@theme'
import { schema, uischema, initialState, FormState } from '@forms/newsletter'
import { newsletter } from '@copy/common'

const Newsletter = ({ subscribe, status, message }: FormHooks<NameFormFields>) => {
const LOCALSTORAGE_KEY = 'newsletter'
const [data, setData] = useFormLocalStorage<FormState>(LOCALSTORAGE_KEY, initialState)

const [submitted, setSubmitted] = useState(false)
const [error, setError] = useState<string>()
const [readonly, setReadonly] = useState(false)

const [buttonLabel, setButtonLabel] = useState<string | undefined>(newsletter.buttonLabel)

useEffect(() => {
switch (status) {
case 'sending':
setButtonLabel(newsletter.buttonSending)
setReadonly(true)
setError(undefined)
break
case 'success':
setButtonLabel(undefined)
setSubmitted(true)
break
case 'error':
setButtonLabel('try again')
setError(error)
default:
setButtonLabel(newsletter.buttonLabel)
setReadonly(false)
}
}, [status, error])

const Newsletter = () => {
return (
<StyledPagePadding black>
<Wrapper className={submitted ? 'submitted' : ''}>
<Wrapper>
<Copy>
<Header>{newsletter.headline}</Header>
<Subhead>{newsletter.subhead}</Subhead>
</Copy>
<Form localStorageKey={LOCALSTORAGE_KEY} {...{ schema, uischema, initialState, data, setData, readonly }}>
<StyledButton
onClick={() => subscribe(data as NameFormFields)}
inverted
level={0}
disabled={!data.EMAIL || !data.OPTIN}
>
{buttonLabel}
</StyledButton>
<Confirmation>
<Icon glyph="tick" level={1} outline color="uiSuccess" />
<div>{newsletter.responseHeadline}</div>
<p>{newsletter.responseSubhead}</p>
</Confirmation>
</Form>

<StyledButton href="https://artizenfund.substack.com/" inverted level={0}>
{newsletter.buttonLabel}
</StyledButton>
</Wrapper>
</StyledPagePadding>
)
Expand All @@ -68,95 +25,24 @@ const StyledPagePadding = styled(props => <PagePadding {...props} />)``

const StyledButton = styled(props => <Button {...props} />)`
grid-area: submit;
margin-top: 14px;
@media only screen and (min-width: ${breakpoint.laptop}px) {
margin-top: 25px;
}
@media only screen and (min-width: ${breakpoint.desktop}px) {
margin-top: 29px;
}
`

const Confirmation = styled.div`
display: none;
grid-area: confirmation;
flex-direction: column;
justify-content: center;
align-items: center;
gap: 15px;
> div {
${typography.title.l4}
color: ${rgba(palette.moon)};
margin-bottom: 0.25em;
}
p {
max-width: 300px;
${typography.label.l1}
color: ${rgba(palette.barracuda)};
}
text-align: center;
height: 24px;
`

const Wrapper = styled.div`
display: grid;
align-items: center;
gap: 10px;
grid-template-areas:
'copy copy'
'email email'
'submit submit'
'optIn optIn';
&.submitted {
grid-template-areas:
'copy'
'optIn'
'confirmation';
}
'submit submit';

@media only screen and (min-width: ${breakpoint.laptop}px) {
gap: 12px;
grid-template-areas:
'copy copy email email'
'optIn optIn submit submit';
&.submitted {
grid-template-areas:
'copy copy confirmation confirmation'
'optIn optIn confirmation confirmation';
}
grid-template-areas: 'copy copy submit submit';
}
@media only screen and (min-width: ${breakpoint.desktop}px) {
gap: 16px;
}

.vertical-layout,
.vertical-layout-item {
display: contents;
}

*[id='#/properties/EMAIL'] {
grid-area: email;
}

*[id='#/properties/OPTIN'] {
grid-area: optIn;
text-align: center;
margin: 1em auto 0 auto;
@media only screen and (min-width: ${breakpoint.laptop}px) {
margin: 0;
padding-top: 28px;
}
@media only screen and (min-width: ${breakpoint.laptop}px) {
padding-top: 32px;
}
}

&.submitted {
*[id='#/properties/EMAIL'],
${StyledButton} {
display: none;
}
${Confirmation} {
display: flex;
}
}
`

const Copy = styled.div`
Expand All @@ -174,20 +60,4 @@ const Subhead = styled.div`
color: ${rgba(palette.barracuda)};
`

const MailChimpForm = () => {
const NEXT_PUBLIC_MAILCHIMP_SUBCRIPTION_URL = assert(
process.env.NEXT_PUBLIC_MAILCHIMP_SUBCRIPTION_URL,
'NEXT_PUBLIC_MAILCHIMP_SUBCRIPTION_URL',
)
// return <MailchimpSubscribe url={NEXT_PUBLIC_MAILCHIMP_SUBCRIPTION_URL} render={props => <Newsletter {...props} />} />
return (
<iframe
src="https://artizenfund.substack.com/embed"
width="100%"
height="320"
// Style="border:1px solid #EEE; background:white;"
></iframe>
)
}

export default MailChimpForm
export default Newsletter