feat: call odoo api and update styles

This commit is contained in:
jongomez 2023-10-26 14:40:46 +01:00 committed by Jon
parent 2461659b5d
commit 17f716c6ce
3 changed files with 111 additions and 65 deletions

View File

@ -113,7 +113,7 @@ export default function NavBar({ defaultState }: NavBarProps) {
) )
} }
export const PressLogoType = styled(Typography)<{ display: boolean }>` const PressLogoType = styled(Typography)<{ display: boolean }>`
text-transform: uppercase; text-transform: uppercase;
${(props) => ${(props) =>
!props.display && !props.display &&

View File

@ -3,15 +3,6 @@ import styled from '@emotion/styled'
import { useState } from 'react' import { useState } from 'react'
import { SubscribeDialogue } from '../SubscribeDialogue' import { SubscribeDialogue } from '../SubscribeDialogue'
const mockOnSubmit = (data: any) => {
return new Promise((resolve, reject) => {
setTimeout(() => {
console.log('Form data submitted:', data)
resolve(true)
}, 3000)
})
}
export default function SubscribeButton() { export default function SubscribeButton() {
const [showDialogue, setShowDialogue] = useState(false) const [showDialogue, setShowDialogue] = useState(false)
@ -27,7 +18,6 @@ export default function SubscribeButton() {
</Typography> </Typography>
</CustomTag> </CustomTag>
<SubscribeDialogue <SubscribeDialogue
onSubmit={mockOnSubmit}
isOpen={showDialogue} isOpen={showDialogue}
onClose={() => setShowDialogue(false)} onClose={() => setShowDialogue(false)}
/> />

View File

@ -1,44 +1,60 @@
import { copyConfigs } from '@/configs/copy.configs' import { copyConfigs } from '@/configs/copy.configs'
import { Button, CloseIcon, IconButton, Typography } from '@acid-info/lsd-react' import { api } from '@/services/api.service'
import { lsdUtils } from '@/utils/lsd.utils'
import {
Button,
CheckIcon,
CloseIcon,
ErrorIcon,
IconButton,
Typography,
} from '@acid-info/lsd-react'
import styled from '@emotion/styled' import styled from '@emotion/styled'
import Link from 'next/link'
import { useEffect, useState } from 'react' import { useEffect, useState } from 'react'
import { LogosIcon } from '../Icons/LogosIcon' import { LogosIcon } from '../Icons/LogosIcon'
import { PressLogoType } from '../NavBar/NavBar'
const mockOnSubmit = (data: any) => {
return new Promise((resolve, reject) => {
setTimeout(() => {
console.log('Form data submitted:', data)
resolve(true)
}, 3000)
})
}
type EmailSubscribeProps = React.HTMLAttributes<HTMLDivElement> & { type EmailSubscribeProps = React.HTMLAttributes<HTMLDivElement> & {
onSubmit: (formData: SubscribeFormData) => void
isOpen: boolean isOpen: boolean
onClose: () => void onClose: () => void
} }
type SubscribeFormData = { export type SubscribeFormData = {
email: string email: string
firstName: string firstName: string
lastName: string lastName: string
} }
export default function SubscribeDialogue({ export default function SubscribeDialogue({
onSubmit,
isOpen, isOpen,
onClose, onClose,
...props ...props
}: EmailSubscribeProps) { }: EmailSubscribeProps) {
const [isSubmitting, setIsSubmitting] = useState(false) const [isSubmitting, setIsSubmitting] = useState(false)
const [isSuccess, setIsSuccess] = useState(false) const [successMessage, setSuccessMessage] = useState('')
const [errorMessage, setErrorMessage] = useState('') const [errorMessage, setErrorMessage] = useState('')
// Reset states when the dialog is closed. // Reset states when the dialog is closed.
useEffect(() => { useEffect(() => {
if (!isOpen) { if (!isOpen) {
if (isSuccess) { if (successMessage) {
setIsSuccess(false) setSuccessMessage('')
} }
if (errorMessage) { if (errorMessage) {
setErrorMessage('') setErrorMessage('')
} }
} }
}, [isOpen, isSuccess, errorMessage]) }, [isOpen, successMessage, errorMessage])
if (!isOpen) { if (!isOpen) {
return null return null
@ -47,18 +63,20 @@ export default function SubscribeDialogue({
const handleFormSubmit = async (e: React.FormEvent<HTMLFormElement>) => { const handleFormSubmit = async (e: React.FormEvent<HTMLFormElement>) => {
e.preventDefault() e.preventDefault()
setIsSubmitting(true) setIsSubmitting(true)
setErrorMessage('')
setSuccessMessage('')
try { try {
await onSubmit({ const firstName = e.currentTarget.firstName.value || ''
email: e.currentTarget.email.value, const lastName = e.currentTarget.lastName.value || ''
firstName: e.currentTarget.firstName.value,
lastName: e.currentTarget.lastName.value,
})
setErrorMessage('') const apiResponse = await api.subscribeToMailingList(
setIsSuccess(true) e.currentTarget.email.value,
e.currentTarget.firstName.value + ' ' + e.currentTarget.lastName.value,
)
setSuccessMessage(apiResponse.message)
} catch (error) { } catch (error) {
setIsSuccess(false)
setErrorMessage( setErrorMessage(
'There was an error submitting the form. Please try again.', 'There was an error submitting the form. Please try again.',
) )
@ -79,27 +97,46 @@ export default function SubscribeDialogue({
</IconButton> </IconButton>
<LogosIconAndTitleContainer> <LogosIconAndTitleContainer>
<LogosIcon color="primary" width="44px" height="44px" /> <LogosIcon color="primary" width="36px" height="36px" />
<PressLogoType variant={'h2'} genericFontFamily={'serif'} display> <PressLogoType variant={'h1'} genericFontFamily={'serif'}>
{copyConfigs.navbar.title} {copyConfigs.navbar.title}
</PressLogoType> </PressLogoType>
</LogosIconAndTitleContainer> </LogosIconAndTitleContainer>
<Typography <Typography variant="body2">Subscribe for updates</Typography>
variant="body1"
style={{ {errorMessage && (
marginBottom: '24px', <MessageContainer>
}} <ErrorIcon color="primary" />
<SubmitionInfoMessage variant="body2">
{errorMessage}
</SubmitionInfoMessage>
</MessageContainer>
)}
{successMessage && (
<>
<MessageContainer>
<CheckIcon color="primary" />
<SubmitionInfoMessage variant="body2">
{successMessage}
</SubmitionInfoMessage>
</MessageContainer>
<Link href="/">
<ToHomePageButton variant="filled">To home page</ToHomePageButton>
</Link>
</>
)}
<EmailSubscribeForm
onSubmit={handleFormSubmit}
hideForm={!!successMessage}
> >
Subscribe for updates
</Typography>
<EmailSubscribeForm onSubmit={handleFormSubmit}>
<StyledInput <StyledInput
type="text" type="text"
id="firstName" id="firstName"
name="firstName" name="firstName"
placeholder="First Name" placeholder="First Name"
disabled={isSubmitting} disabled={isSubmitting}
required
/> />
<StyledInput <StyledInput
@ -108,14 +145,13 @@ export default function SubscribeDialogue({
name="lastName" name="lastName"
placeholder="Last Name" placeholder="Last Name"
disabled={isSubmitting} disabled={isSubmitting}
required
/> />
<StyledInput <StyledInput
type="email" type="email"
id="email" id="email"
name="email" name="email"
placeholder="Email address" placeholder="Email address (required)"
disabled={isSubmitting} disabled={isSubmitting}
required required
/> />
@ -123,34 +159,51 @@ export default function SubscribeDialogue({
<SubscribeButton <SubscribeButton
variant="filled" variant="filled"
type="submit" type="submit"
size="medium"
disabled={isSubmitting} disabled={isSubmitting}
> >
Subscribe {isSubmitting ? 'Subscribing...' : 'Subscribe'}
</SubscribeButton> </SubscribeButton>
</EmailSubscribeForm> </EmailSubscribeForm>
{isSubmitting && (
<SubmitionInfoMessage variant="body1">
Submitting...
</SubmitionInfoMessage>
)}
{isSuccess && (
<SubmitionInfoMessage variant="body1">
Submitted successfully!
</SubmitionInfoMessage>
)}
{errorMessage && (
<SubmitionInfoMessage variant="body1">
{errorMessage}
</SubmitionInfoMessage>
)}
</MainContentContainer> </MainContentContainer>
</SubscribeDialogueContainer> </SubscribeDialogueContainer>
) )
} }
const PressLogoType = styled(Typography)`
text-transform: uppercase;
font-size: 30px;
line-height: 36px;
${(props) => lsdUtils.breakpoint(props.theme, 'xs', 'down')} {
font-size: 20px;
line-height: 26px;
}
`
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)` const SubmitionInfoMessage = styled(Typography)`
margin: 16px 0px; padding-left: 14px;
` `
const LogosIconAndTitleContainer = styled.div` const LogosIconAndTitleContainer = styled.div`
@ -166,13 +219,13 @@ const MainContentContainer = styled.div`
align-items: center; align-items: center;
padding: 24px 0; padding: 24px 0;
width: 518px; width: 430px;
max-width: 90%; max-width: 90%;
.subscribe-dialogue__close-button { .subscribe-dialogue__close-button {
position: absolute; position: absolute;
top: 16px; top: 8px;
right: 32px; right: 30px;
} }
` `
@ -190,8 +243,10 @@ const SubscribeDialogueContainer = styled.div`
justify-content: center; justify-content: center;
` `
const EmailSubscribeForm = styled.form` const EmailSubscribeForm = styled.form<{
display: flex; hideForm: boolean
}>`
display: ${({ hideForm }) => (hideForm ? 'none' : 'flex')};
justify-content: center; justify-content: center;
align-items: center; align-items: center;
flex-direction: column; flex-direction: column;
@ -215,11 +270,12 @@ const StyledInput = styled.input`
&:focus { &:focus {
outline: none; outline: none;
} }
background-color: rgb(var(--lsd-surface-primary));
` `
const SubscribeButton = styled(Button)` const SubscribeButton = styled(Button)`
margin-top: 30px; margin-top: 30px;
height: 40px; height: 40px;
width: 162px; width: 162px;
flex-shrink: 0;
` `