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

Newsletter subscription PR fixes - and fix "To home page" button not closing dialog #212

Merged
merged 1 commit into from
Oct 26, 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
77 changes: 77 additions & 0 deletions src/components/FullscreenDialog/FullscreenDialog.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
import { CloseIcon, IconButton } from '@acid-info/lsd-react'
import styled from '@emotion/styled'
import { useEffect } from 'react'

type FullscreenDialogProps = React.HTMLAttributes<HTMLDivElement> & {
isOpen: boolean
onClose: () => void
children: React.ReactNode
}

export default function FullscreenDialog({
isOpen,
onClose,
children,
...props
}: FullscreenDialogProps) {
useEffect(() => {
if (isOpen) {
document.body.style.overflow = 'hidden'
} else {
document.body.style.overflow = ''
}

return () => {
document.body.style.overflow = ''
}
}, [isOpen])

if (!isOpen) {
return null
}

return (
<FullscreenDialogContainer {...props}>
<MainContentContainer>
<IconButton
className="fullscreen-dialog__close-button"
size="small"
onClick={() => onClose()}
>
<CloseIcon color="primary" />
</IconButton>
{children}
</MainContentContainer>
</FullscreenDialogContainer>
)
}

const MainContentContainer = styled.div`
display: flex;
flex-direction: column;
align-items: center;

padding: 24px 0;
width: 430px;
max-width: 90%;

.fullscreen-dialog__close-button {
position: absolute;
top: 8px;
right: 30px;
}
`

const FullscreenDialogContainer = styled.div`
position: fixed;
top: 0;
left: 0;
width: 100vw;
height: 100vh;

background: rgb(var(--lsd-surface-primary));

display: flex;
align-items: center;
justify-content: center;
`
1 change: 1 addition & 0 deletions src/components/FullscreenDialog/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export { default as FullscreenDialog } from './FullscreenDialog'
Original file line number Diff line number Diff line change
@@ -0,0 +1,142 @@
import {
Button,
CheckIcon,
ErrorIcon,
TextField,
Typography,
} from '@acid-info/lsd-react'
import styled from '@emotion/styled'
import Link from 'next/link'

type NewsletterSubscriptionFormProps = React.HTMLAttributes<HTMLDivElement> & {
handleFormSubmit: (e: React.FormEvent<HTMLFormElement>) => void
isSubmitting: boolean
errorMessage: string
successMessage: string
onClose: () => void
}

export default function NewsletterSubscriptionForm({
handleFormSubmit,
isSubmitting,
errorMessage,
successMessage,
onClose,
}: NewsletterSubscriptionFormProps) {
const disabled = isSubmitting

return (
<>
{errorMessage && (
<MessageContainer>
<ErrorIcon color="primary" />
<SubmitionInfoMessage variant="body2">
{errorMessage}
</SubmitionInfoMessage>
</MessageContainer>
)}

{successMessage && (
<>
<MessageContainer>
<CheckIcon color="primary" />
<SubmitionInfoMessage variant="body2">
{successMessage}
</SubmitionInfoMessage>
</MessageContainer>
<Link href="/" onClick={onClose}>
<ToHomePageButton variant="filled">To home page</ToHomePageButton>
</Link>
</>
)}

<EmailSubscribeForm
onSubmit={handleFormSubmit}
hideForm={!!successMessage}
>
<StyledTextField
id="firstName"
inputProps={{ name: 'firstName', disabled }}
placeholder="First Name"
disabled={disabled}
/>

<StyledTextField
id="lastName"
inputProps={{ name: 'lastName', disabled }}
placeholder="Last Name"
disabled={disabled}
/>

<StyledTextField
id="email"
inputProps={{
name: 'email',
type: 'email',
required: true,
disabled,
}}
placeholder="Email address (required)"
disabled={disabled}
/>

<SubscribeButton
variant="filled"
type="submit"
size="medium"
disabled={disabled}
>
{isSubmitting ? 'Subscribing...' : 'Subscribe'}
</SubscribeButton>
</EmailSubscribeForm>
</>
)
}

const ToHomePageButton = styled(Button)`
margin-top: 46px;
height: 40px;
width: 162px;
color: rgb(var(--lsd-text-secondary));
`

const MessageContainer = styled.div`
display: flex;
align-items: center;

border: 1px solid rgb(var(--lsd-border-primary));
padding: 14px;

margin-bottom: -6px;
margin-top: 40px;

width: 430px;
max-width: 93%;
`

const SubmitionInfoMessage = styled(Typography)`
padding-left: 14px;
`

const EmailSubscribeForm = styled.form<{
hideForm: boolean
}>`
display: ${({ hideForm }) => (hideForm ? 'none' : 'flex')};
justify-content: center;
align-items: center;
flex-direction: column;

gap: 16px;
width: 100%;
margin-top: 50px;
`

const StyledTextField = styled(TextField)`
width: 100%;
`

const SubscribeButton = styled(Button)`
margin-top: 30px;
height: 40px;
width: 162px;
`
1 change: 1 addition & 0 deletions src/components/NewsletterSubscriptionForm/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export { default as NewsletterSubscriptionForm } from './NewsletterSubscriptionForm'
12 changes: 6 additions & 6 deletions src/components/SubscribeButton/SubscribeButton.tsx
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
import { NewsletterSubscriptionDialog } from '@/containers/NewsletterSubscriptionDialog'
import { Tag, Typography } from '@acid-info/lsd-react'
import styled from '@emotion/styled'
import { useState } from 'react'
import { SubscribeDialogue } from '../SubscribeDialogue'

export default function SubscribeButton() {
const [showDialogue, setShowDialogue] = useState(false)
const [showDialog, setShowDialog] = useState(false)

const handleClick = () => {
setShowDialogue(!showDialogue)
setShowDialog(!showDialog)
}

return (
Expand All @@ -17,9 +17,9 @@ export default function SubscribeButton() {
Subscribe
</Typography>
</CustomTag>
<SubscribeDialogue
isOpen={showDialogue}
onClose={() => setShowDialogue(false)}
<NewsletterSubscriptionDialog
isOpen={showDialog}
onClose={() => setShowDialog(false)}
/>
</>
)
Expand Down
Loading
Loading