Skip to content
This repository has been archived by the owner on Sep 10, 2019. It is now read-only.

Commit

Permalink
pages: add contact page
Browse files Browse the repository at this point in the history
  • Loading branch information
Vitor Dino committed Sep 18, 2018
1 parent ddab7e8 commit fdd7d88
Show file tree
Hide file tree
Showing 3 changed files with 304 additions and 0 deletions.
201 changes: 201 additions & 0 deletions packages/campus-online-frontend/src/pages/contato/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,201 @@
import React from 'react'
import styled from 'styled-components'
import {navigateTo} from 'gatsby-link'
import {compose} from 'recompose'
import {Form, withFormik} from 'formik'
import {colors} from '../../constants'
import {above} from '../../utils/responsive'
import {withLayout} from '../../components/Layout'
import Navbar from '../../components/Navbar'
import AboutHero from '../../components/AboutHero'
import MetaTags from '../../components/MetaTags'
import Hero from '../../components/Hero'
import Container from '../../components/Container'
import Text from '../../components/Text'
import {Row, Cell} from '../../components/Grid'
import {FormikField as Input} from '../../components/Input'
import {FormikField as TextArea} from '../../components/TextArea'
import Button from '../../components/Button'
import Link from '../../components/StylableLink'
import UnstyledMap from '../../components/Map'
import meta from './index.json'

const StyledLink = styled(Link)`
display: block;
color: currentColor;
text-decoration: none;
line-height: 1.5rem;
padding: 0.5rem 0;
color: ${colors.base66};
font-weight: 500;
&:hover,
&:focus,
&:active {
color: ${colors.base88};
}
`

const MapWrapper = styled.div`
position: relative;
margin-top: 2rem;
${above.md`
margin-top: 6rem;
`};
`

const MapLabel = styled(Link)`
text-decoration: none;
color: currentColor;
display: inline-block;
display: inline-flex;
flex-direction: column;
padding: 1rem 0;
color: ${colors.white};
${above.md`
margin-top: 3rem;
padding: 2rem;
background: ${colors.base};
z-index: 1;
position: absolute;
`};
`

const Address = styled.div`
font-size: 1rem;
line-height: 1.5rem;
font-weight: 600;
color: ${colors.base22};
`

const City = styled(Address)`
font-weight: 300;
`

const MapZIP = styled.div`
font-size: 0.875rem;
font-weight: 400;
color: ${colors.base44};
line-height: 1.5rem;
`

const Map = styled(UnstyledMap)`
width: 100%;
height: 16rem;
${above.md`
height: 25rem;
`};
`

const validation = ({values}) => {
const errors = {}
if (!values.name) {
errors.name = 'Nome é obrigatório'
}
if (!values.message) {
errors.message = 'Mensagem é obrigatório'
}
if (!values.email) {
errors.email = 'Email é obrigatório'
} else if (!/^[A-Z0-9._%+-]+@[A-Z0-9.-]+\.[A-Z]{2,4}$/i.test(values.email)) {
errors.email = 'Email inválido'
}
return errors
}

function encode(data) {
return Object.keys(data)
.map(key => encodeURIComponent(key) + '=' + encodeURIComponent(data[key]))
.join('&')
}

const Wrapper = styled.div`
`

const ContactPage = () => (
<div style={{background: colors.base, colors: colors.white}}>
<MetaTags title="Contato" />
<Navbar style={{position: 'fixed', top: 0, zIndex: 3}} dark={true} />
<AboutHero contact background={colors.base} color='rgba(255,255,255, 0.2)' style={{marginTop: '7rem'}} />
<Container>
<Row>
<Cell xs={12} md={8}>
<Form
name="contact"
data-netlify="true"
data-netlify-honeypot="honey"
style={{width: '100%'}}
>
<Input type="hidden" name="form-name" value="contact" />
<p hidden>
<Input name="honey" />
</p>
<Row>
<Cell xs={12} sm={6} md={12} lg={6}>
<Input color='white' name="name" label="Nome" required />
</Cell>
<Cell xs={12} sm={6} md={12} lg={6}>
<Input
color='white'
name="email"
label="Email"
type="text"
autoComplete="email"
autoCapitalize="off"
required
/>
</Cell>
</Row>
<TextArea color='white' name="message" label="Mensagem" />
<Button stretch style={{margin: '2rem 0'}}>
Enviar
</Button>
</Form>
</Cell>

</Row>
</Container>
<MapWrapper>
<Container>
{meta.firstLine &&
meta.secondLine &&
meta.zip && (
<MapLabel to="https://www.google.com.br/maps/place/Av.+Jos%C3%A9+de+Souza+Campos,+1073+-+Cambu%C3%AD,+Campinas+-+SP,+13025-320">
<Address>{meta.firstLine}</Address>
<City>{meta.secondLine}</City>
<MapZIP>{meta.zip}</MapZIP>
</MapLabel>
)}
</Container>
{meta.lat &&
meta.long && (
<Map coordinates={[meta.lat, meta.long]} zoom={[12, 16]} />
)}
</MapWrapper>
</div>
)

/* eslint-disable no-unused-vars */
const enhance = compose(
withFormik({
isInitialValid: false,
mapPropsToValues: props => ({name: '', email: '', message: ''}),
validate: (values, props) => validation({values, props}),
handleSubmit: async (values, {setSubmitting}) => {
try {
await fetch('/', {
method: 'POST',
headers: {'Content-Type': 'application/x-www-form-urlencoded'},
body: encode({...values, 'form-name': 'contact'}),
})
setSubmitting(false)
navigateTo('./sucesso')
} catch (error) {
alert(error)
}
},
}),
)
/* eslint-enable no-unused-vars */

export default enhance(withLayout(ContactPage))
9 changes: 9 additions & 0 deletions packages/campus-online-frontend/src/pages/contato/index.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"zip": "70910-900",
"secondLine": "Universidade de Brasília",
"firstLine": "Faculdade de Comunicação",
"long": "-15.760837",
"sidebar": "Outros meios de contato",
"description": "Para agendar uma consulta, solicitar uma proposta, enviar o seu currículo ou dúvidas em geral, preencha o formulário abaixo. Você também poderá utilizar este canal para apresentar sugestões, críticas e feedbacks sobre os nossos serviços.",
"lat": "-47.8702936"
}
94 changes: 94 additions & 0 deletions packages/campus-online-frontend/src/pages/contato/sucesso.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
import React from 'react'
import styled from 'styled-components'
import {colors} from '../../constants'
import {above} from '../../utils/responsive'
import {withLayout} from '../../components/Layout'
import Navbar from '../../components/Navbar'
import Container from '../../components/Container'
import Text from '../../components/Text'
import UnstyledMap from '../../components/Map'
import UnstyledLink from '../../components/StylableLink'
import meta from './index.json'

const Wrapper = styled.div`
background: ${colors.base03};
position: relative;
display: flex;
flex: 1;
flex-direction: column;
overflow: hidden;
min-height: 100vh;
`

const MapWrapper = styled.div`
position: absolute;
top: 0;
flex: 1;
`

const Map = styled(UnstyledMap)`
margin-top: 0;
width: 100vw;
height: 100vh;
opacity: 0.44;
`

const Main = styled.div`
display: inline-block;
display: inline-flex;
flex-direction: column;
margin: 4rem 0;
padding: 1rem 2rem 1rem 0;
z-index: 3;
position: relative;
background: ${colors.base};
color: ${colors.base03};
${above.md`
padding: 2rem 4rem 2rem 0;
`} :before {
content: '';
position: absolute;
background: ${colors.base};
top: 0;
width: 100%;
width: 50vw;
right: 100%;
height: 100%;
}
`

const Link = styled(UnstyledLink)`
display: block;
color: ${colors.base44};
text-decoration: none;
line-height: 1;
padding: 0.25em 0;
${above.md`
font-size: 1.25rem;
`} :hover {
color: ${colors.white};
}
`

const SuccessPage = () => (
<Wrapper>
<Navbar style={{position: 'fixed', top: 0, zIndex: 3}} dark={true} />
<MapWrapper>
{meta.lat &&
meta.long && (
<Map coordinates={[meta.lat, meta.long]} zoom={[12, 16]} />
)}
</MapWrapper>
<Container>
<Main>
<div>
{/* <Icon icon="message-square" size={48} strokeWidth={0.875} /> */}
</div>
<Text style={{margin: '0'}}><h1>Mensagem enviada com sucesso!</h1></Text>
<Link to="/">Voltar para Home</Link>
</Main>
</Container>
</Wrapper>
)

export default withLayout(SuccessPage)

0 comments on commit fdd7d88

Please sign in to comment.