Skip to content
Open
Show file tree
Hide file tree
Changes from 3 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
6 changes: 6 additions & 0 deletions config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
// URL for Contact Form submission
const hooksUrl = 'https://hooks.zapier.com/hooks/catch/1041785/21ewe5/'

module.exports = {
hooksUrl
}
Comment thread
Kameshwaran marked this conversation as resolved.
Outdated
41 changes: 27 additions & 14 deletions src/pages/contact.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -26,18 +26,31 @@ San Francisco

#### Or leave us a msg :)

<form
action="https://formspree.io/anand@codebrahma.com"
method="post" target='/thanks'>
<Flex flexWrap='wrap' flexDirection='column'>
<Box width={[1,1/3]}>
<InputText size='25' rows="5" style={{width:'100%'}} required as='textarea' name='msg' placeholder='Tell us about your idea'/>
</Box>
<Box width={[1,1/3]} mt={1}>
<InputText style={{width:'100%'}} name='email' type='email' required placeholder='Email address'/>
</Box>
<Box width={[1,1/3]} mt={1}>
<InputButton/>
</Box>
</Flex>
<form id="contact-form">
<Flex flexWrap='wrap' flexDirection='column'>
Comment thread
Kameshwaran marked this conversation as resolved.
<Box width={[1,1/3]}>
<InputText
id="idea"
size='25'
rows="5"
style={{width:'100%'}}
Comment thread
Kameshwaran marked this conversation as resolved.
required as='textarea'
name='msg'
placeholder='Tell us about your idea'
/>
</Box>
<Box width={[1,1/3]} mt={1}>
<InputText
id="email"
style={{width:'100%'}}
name='email'
type='email'
required
placeholder='Email address'
/>
</Box>
<Box width={[1,1/3]} mt={1} id="contact-submit">
<InputButton/>
</Box>
</Flex>
</form>
34 changes: 34 additions & 0 deletions src/pages/thank-you.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
import React from 'react'
import styled from '@emotion/styled'
import { Link } from 'gatsby'
import { Flex, Box, P, H1, css } from 'bricks'

const ThankYou = () => {

const CenteredDiv = styled(Flex)(
Comment thread
Kameshwaran marked this conversation as resolved.
Outdated
css({
width: "100vw",
height: "100vh",
Comment thread
Kameshwaran marked this conversation as resolved.
Outdated
alignItems: "center",
justifyContent: "center",
})
)

return (
<CenteredDiv>
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

https://theme-ui.com/guides/layouts , can we use main component from https://theme-ui.com/guides/layouts instead of centered div

<Box textAlign="center">
<H1 fontSize="6" mb="4">Thank You!</H1>
Comment thread
Kameshwaran marked this conversation as resolved.
Outdated
<P fontSize="3" mb="4">
We will get back to you within 24 hours. Our typical response time is 5 minutes.
</P>
<P fontSize="3">
<Link to="/">
Back to Homepage
</Link>
</P>
</Box>
</CenteredDiv>
)
}

export default ThankYou
100 changes: 86 additions & 14 deletions src/templates/header.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
import React, { Component } from "react"
import PropTypes from "prop-types"
import React from "react"
import { Nav } from 'bricks'
import { Logo } from '../components/logo'
import { Link } from 'gatsby'
import { Link, navigate } from 'gatsby'
import hooksUrl from '../../config'

const links = [
{title: 'Work', link: '/work'},
Expand All @@ -11,20 +12,91 @@ const links = [
{title: 'Contact', link: '/contact'},
]

const Header = ({ siteTitle }) => {
return (
<header>
<div>
<Nav
logo={Logo({title: siteTitle})}
links={links}
GatsbyLink={Link}
/>
</div>
</header>
)
class Header extends Component {

componentDidMount() {
if(typeof window !== 'undefined') {
Comment thread
Kameshwaran marked this conversation as resolved.
let userDetails = {}
let SITE_NAME = window.location.origin
document.getElementById('contact-form') &&
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Kameshwaran should we put this in JS only in the contact page. in header.js means it will come in every page right?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's keep it in the header.
This JS not only contains form handling logic, but also tracks the list of pages browsed by the visitor. That info also sent in the form when a visitor submits it.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

document
.getElementById('contact-form')
.addEventListener('submit', (e => {
Comment thread
Kameshwaran marked this conversation as resolved.
e.preventDefault()
const idea = document.getElementById('idea').value
const email = document.getElementById('email').value
document.getElementById('contact-submit').disabled = true
document.getElementById('idea').value = ""
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Kameshwaran why reset values even when there is an error?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good catch. Thanks.

document.getElementById('email').value = ""

const formSubmitData = {
email,
idea,
userDetails,
}

const http = new XMLHttpRequest()
http.open('POST', hooksUrl)
http.onreadystatechange = function() {
if(http.readyState === XMLHttpRequest.DONE && http.status === 200) {
localStorage.setItem('userDetails', JSON.stringify({}))
document.getElementById('contact-submit').disabled = false
navigate('/thank-you')
}
}
Comment thread
Kameshwaran marked this conversation as resolved.
Comment thread
Kameshwaran marked this conversation as resolved.
http.send(JSON.stringify(formSubmitData))
}))

const isObjectEmpty = (obj = {}) => {
return Object.keys(obj).length === 0 && obj.constructor === Object
}

const distinct = (value, index, self) => {
return self.indexOf(value) === index
}

const updateUserDetailsWithCurrentUrl = (userDetails, currentUrl) => {
userDetails.browsedLinks = [...userDetails.browsedLinks, currentUrl]
userDetails.browsedLinks = userDetails.browsedLinks.filter(distinct)
localStorage.setItem('userDetails', JSON.stringify(userDetails))
}

userDetails = JSON.parse(localStorage.getItem('userDetails')) || {}
// User already entered site atleast once
if (!isObjectEmpty(userDetails)) {
// Extract userDetails from localStorage
userDetails = JSON.parse(localStorage.getItem('userDetails'))
updateUserDetailsWithCurrentUrl(userDetails, document.URL)
} else {
// If entering first time
// Set referrer
userDetails.referrer = (!document.referrer.includes(SITE_NAME) && document.referrer) || ''
// Clear past links or set it empty
userDetails.browsedLinks = []
const currentTimeZone = `${parseInt(new Date().getTimezoneOffset() / -60)}:${Math.abs(new Date().getTimezoneOffset() % 60)}`
userDetails.timeZone = `UTC${currentTimeZone.startsWith('-') ? '' : '+'}${currentTimeZone}`
updateUserDetailsWithCurrentUrl(userDetails, document.URL)
}
}
}

render() {
const { siteTitle } = this.props
return (
<header>
<div>
<Nav
logo={Logo({title: siteTitle})}
links={links}
GatsbyLink={Link}
/>
</div>
</header>
)
}
}


Header.propTypes = {
siteTitle: PropTypes.string,
}
Expand Down