-
Notifications
You must be signed in to change notification settings - Fork 47
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
doctom: Add contact page #113
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,145 @@ | ||
import { Container, Grid, Box, TextField, RadioGroup, FormControlLabel, Radio, FormLabel, Divider, withStyles, createStyles, Theme, styled, Button, Snackbar } from '@material-ui/core'; | ||
import React, { useState } from 'react'; | ||
import { Helmet } from 'react-helmet'; | ||
import Hero from '../../components/Hero'; | ||
import { ReactComponent as ContactSvg } from './contact.svg'; | ||
import Alert from '@material-ui/lab/Alert'; | ||
import { submitFormData } from './functions'; | ||
|
||
const StyledDivider = styled(Divider)({ | ||
margin: '20px' | ||
}); | ||
|
||
const StyledButton = styled(Button)({ | ||
float: 'right', | ||
borderRadius: '10px', | ||
color: 'white', | ||
padding: '10px 20px', | ||
background: "linear-gradient(127deg, rgba(12,0,213,1) 0%, rgba(248,0,255,1) 100%)" | ||
}); | ||
|
||
const Contact: React.FC = () => { | ||
|
||
interface ContactData { | ||
firstName: string; | ||
lastName: string; | ||
email: string; | ||
year: string; | ||
major: string; | ||
// TODO: ask if we still want to do user-submitted questions | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ❓ Did we ever ask about this? If so, was this implemented or not? |
||
questions: any[]; | ||
role: string; | ||
} | ||
|
||
const [data, setData] = useState({ firstName: '', lastName: '', email: '', year: '', major: '', questions: [], role: '' } as ContactData); | ||
const [showAlert, setShowAlert] = useState<boolean>(false) | ||
|
||
return ( | ||
<div> | ||
<Container maxWidth="md"> | ||
<Helmet> | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ❓ What does |
||
<title>Projects</title> | ||
<meta | ||
name="description" | ||
content="C4C delivers web applications to Boston-based nonprofits." | ||
/> | ||
</Helmet> | ||
<Hero | ||
subtitle="Want to stay in touch? Fill out your contact info below!" | ||
title="Contact Us" | ||
SvgNode={ContactSvg} | ||
/> | ||
</Container> | ||
<Container maxWidth="md"> | ||
<Box marginTop={5}> | ||
<Grid container> | ||
<TextField | ||
label="First Name" | ||
value={data.firstName} | ||
onChange={(event) => setData({...data, firstName: event.target.value})} | ||
/> | ||
<TextField | ||
label="Last Name" | ||
value={data.lastName} | ||
onChange={(event) => setData({...data, lastName: event.target.value})} | ||
/> | ||
<TextField | ||
label="Email" | ||
value={data.email} | ||
onChange={(event) => setData({...data, email: event.target.value})} | ||
/> | ||
<TextField | ||
label="Graduation Year" | ||
value={data.year} | ||
onChange={(event) => setData({...data, year: event.target.value})} | ||
/> | ||
<TextField | ||
label="Major" | ||
value={data.major} | ||
onChange={(event) => setData({...data, major: event.target.value})} | ||
/> | ||
Comment on lines
+56
to
+80
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ⛏️ It looks like there's a lot being repeated here - could we possibly abstract this out into something? |
||
</Grid> | ||
<StyledDivider /> | ||
<FormLabel component="legend">Which positions are you interested in?</FormLabel> | ||
<RadioGroup value={data.role} row> | ||
<FormControlLabel value="developer" control={<Radio />} label="Developer" | ||
onChange={(event: any) => setData({...data, role: "developer"})} | ||
/> | ||
<FormControlLabel value="designer" control={<Radio />} label="Designer" | ||
onChange={(event: any) => setData({...data, role: "designer"})} | ||
/> | ||
<FormControlLabel value="productmanager" control={<Radio />} label="Product Manager" | ||
onChange={(event: any) => setData({...data, role: "productmanager"})} | ||
/> | ||
</RadioGroup> | ||
<StyledButton onClick={(event) => { | ||
console.log('submitting form', data); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is a pretty big function - could we possibly break it up into a few smaller functions? |
||
|
||
if (data.email.indexOf('@') === -1) { | ||
setShowAlert(true); | ||
return; | ||
} | ||
|
||
if (data.email.indexOf('.') === -1) { | ||
setShowAlert(true); | ||
return; | ||
} | ||
|
||
const gradYear = parseInt(data.year); | ||
if (isNaN(gradYear)) { | ||
setShowAlert(true); | ||
return; | ||
} | ||
const submitData = {...data, gradYear}; | ||
|
||
submitFormData({ | ||
url: 'https://<some api url>', | ||
data: submitData, | ||
accessToken: 'some API token', | ||
secretToken: 'some secret API token', | ||
}).then((data: any) => { | ||
const { success, errorMessage } = data; | ||
|
||
if (success) { | ||
console.info("API submit successful") | ||
} else { | ||
console.info(`warning: ${errorMessage}`); | ||
setShowAlert(true); | ||
setData({ firstName: '', lastName: '', email: '', year: '', major: '', questions: [], role: '' }) | ||
} | ||
}).catch((error) => { | ||
setShowAlert(true); | ||
}) | ||
}}> | ||
Submit | ||
</StyledButton> | ||
</Box> | ||
</Container> | ||
<Snackbar open={showAlert} autoHideDuration={3000} onClose={() => setShowAlert(false)} anchorOrigin={{vertical: 'top', horizontal: 'center'}}> | ||
<Alert severity="info">Error submiting data</Alert> | ||
</Snackbar> | ||
</div> | ||
); | ||
}; | ||
|
||
export default Contact; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
❓ Did we ever ask about this? If so, was this implemented or not?