This repository has been archived by the owner on Mar 30, 2022. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 4
feature/mantine form with validation for host signup #9
Merged
Merged
Changes from 1 commit
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,24 +1,125 @@ | ||
import { useState } from 'react'; | ||
import { useForm } from 'react-hook-form'; | ||
import { Space } from '@mantine/core'; | ||
import { useForm } from '@mantine/hooks'; | ||
|
||
import { | ||
Space, | ||
Paper, | ||
Title, | ||
TextInput, | ||
Textarea, | ||
Button, | ||
NumberInput, | ||
MultiSelect, | ||
Checkbox, | ||
} from '@mantine/core'; | ||
import { MdOutlineMailOutline, MdMap, MdPhone } from 'react-icons/md'; | ||
import axios from 'axios'; | ||
|
||
const languagesOptions = [ | ||
{ value: 'English', label: 'English' }, | ||
{ value: 'Ukrainian', label: 'Ukrainian' }, | ||
{ value: 'Russian', label: 'Russian' }, | ||
{ value: 'Polish', label: 'Polish' }, | ||
{ value: 'Romanian', label: 'Romanian' }, | ||
{ value: 'German', label: 'German' }, | ||
{ value: 'Hungarian', label: 'Hungarian' }, | ||
]; | ||
|
||
export const HostSignup = () => { | ||
const { register, handleSubmit } = useForm(); | ||
const [data, setData] = useState(''); | ||
const form = useForm({ | ||
initialValues: { | ||
firstName: '', | ||
lastName: '', | ||
phoneNumber: '', | ||
email: '', | ||
cityRegion: '', | ||
accomodationDetails: '', | ||
hostCapacity: 0, | ||
languages: '', | ||
termsOfService: false, | ||
}, | ||
|
||
validationRules: { | ||
email: (value) => /^\S+@\S+$/.test(value), | ||
}, | ||
}); | ||
|
||
const onSubmitHandler = (values: typeof form['values']) => { | ||
console.log(values); | ||
axios({ method: 'POST', url: '/api/host', data: values }); | ||
}; | ||
|
||
return ( | ||
<> | ||
<Space h="sm" /> | ||
<iframe | ||
className="airtable-embed" | ||
src="https://airtable.com/embed/shrGJ9QFefvxi47xL?backgroundColor=yellow" | ||
frameBorder="0" | ||
style={{ | ||
width: '100%', | ||
height: '100%', | ||
background: 'transparent', | ||
display: 'block', | ||
}} | ||
></iframe> | ||
<Paper padding="lg" shadow="sm" radius="md" withBorder> | ||
<Title order={3}>Find a host</Title> | ||
<Space h="lg" /> | ||
|
||
<form onSubmit={form.onSubmit(onSubmitHandler)}> | ||
<TextInput | ||
{...form.getInputProps('firstName')} | ||
placeholder="First Name" | ||
label="First Name" | ||
required | ||
/> | ||
<TextInput | ||
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. Should we just use the session.user.name from NextAuth for this instead of having them fill it out? |
||
{...form.getInputProps('lastName')} | ||
placeholder="Last Name" | ||
label="Last Name" | ||
required | ||
/> | ||
<TextInput | ||
{...form.getInputProps('phoneNumber')} | ||
icon={<MdPhone />} | ||
placeholder="+03 123 456 789" | ||
label="Phone Number" | ||
required | ||
/> | ||
<TextInput | ||
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. Should we just use the session.user.email from NextAuth for this instead of having them fill it out? |
||
{...form.getInputProps('email')} | ||
icon={<MdOutlineMailOutline />} | ||
placeholder="Email" | ||
label="Email address" | ||
required | ||
/> | ||
<TextInput | ||
{...form.getInputProps('cityRegion')} | ||
icon={<MdMap />} | ||
placeholder="City" | ||
label="City / Region Name" | ||
required | ||
/> | ||
<Textarea | ||
{...form.getInputProps('accomodationDetails')} | ||
placeholder="About the accomodation and Rules" | ||
label="Accomodation details" | ||
/> | ||
<NumberInput | ||
defaultValue={1} | ||
{...form.getInputProps('hostCapacity')} | ||
placeholder="Number of people" | ||
label="Host capacity" | ||
required | ||
/> | ||
<MultiSelect | ||
{...form.getInputProps('languages')} | ||
data={languagesOptions} | ||
label="Spoken languages" | ||
placeholder="Pick all that you like" | ||
/> | ||
<Space h="lg" /> | ||
<Checkbox | ||
{...form.getInputProps('termsOfService')} | ||
label="I agree to sell my privacy" | ||
required | ||
/> | ||
<Space h="xl" /> | ||
|
||
<Button type="submit" color="teal"> | ||
Submit | ||
</Button> | ||
</form> | ||
</Paper> | ||
</> | ||
); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,2 @@ | ||
export const AIRTABLE_URL = `https://api.airtable.com/v0/${process.env.AIRTABLE_APP_ID}/Hosts?maxRecords=50&view=Grid%20view`; | ||
export const AIRTABLE_API_KEY = process.env.AIRTABLE_API_KEY; | ||
export const AIRTABLE_URL = `https://api.airtable.com/v0/${process.env.AIRTABLE_APP_ID}/Hosts`; | ||
export const AIRTABLE_API_KEY = process.env.AIRTABLE_API_KEY; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
import axios from 'axios'; | ||
import { AIRTABLE_API_KEY, AIRTABLE_URL } from '../../config'; | ||
import type { NextApiRequest, NextApiResponse } from 'next'; | ||
|
||
const handler = async (req: NextApiRequest, res: NextApiResponse) => { | ||
if (req.method === 'POST') { | ||
console.log('Called with', req.body); | ||
const { | ||
firstName, | ||
lastName, | ||
phoneNumber, | ||
email, | ||
cityRegion, | ||
accomodationDetails, | ||
hostCapacity, | ||
languages, | ||
} = req.body; | ||
try { | ||
const response = await axios({ | ||
method: 'POST', | ||
url: AIRTABLE_URL, | ||
data: { | ||
records: [ | ||
{ | ||
fields: { | ||
firstName, | ||
lastName, | ||
phoneNumber, | ||
email, | ||
cityRegion, | ||
accomodationDetails, | ||
hostCapacity, | ||
languages, | ||
}, | ||
}, | ||
], | ||
typecast: true, | ||
}, | ||
headers: { Authorization: `Bearer ${AIRTABLE_API_KEY}` }, | ||
}); | ||
res.status(200).json({ created: response.data }); | ||
} catch (err) { | ||
res.status(500).json({ error: err }); | ||
} | ||
} else { | ||
res.status(404).json({ info: 'method not implemented' }); | ||
} | ||
}; | ||
|
||
export default handler; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Should we just use the session.user.name from NextAuth for this instead of having them fill it out?