-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
send mail form working but the handleChange() is wip
Installed React Final Form
- Loading branch information
Showing
4 changed files
with
85 additions
and
20 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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,10 +1,14 @@ | ||
import React from "react"; | ||
import React, { useState, useEffect } from "react"; | ||
import Axios from "axios"; | ||
import { Form, Field } from "react-final-form"; | ||
import { | ||
Paper, | ||
Box, | ||
Card, | ||
InputLabel, | ||
CardContent, | ||
Button, | ||
TextField, | ||
CardActions, | ||
Typography, | ||
} from "@material-ui/core"; | ||
|
@@ -17,23 +21,68 @@ import "../App.css"; | |
import "./style/contact.css"; | ||
|
||
function Contact() { | ||
const [value, setValue] = useState({ | ||
user_email: "[email protected]", | ||
subject: "coucou", | ||
text: "lorem ipsum", | ||
}); | ||
|
||
const sleep = (ms) => new Promise((resolve) => setTimeout(resolve, ms)); | ||
const onSubmit = async (values) => { | ||
await sleep(300); | ||
window.alert( | ||
"Je vous remercie pour votre message et j'y répondrai dès que possible" | ||
); | ||
}; | ||
|
||
const handleChange = (event) => { | ||
event.preventDefault(); | ||
console.log("VALUE TARGET", event.target.value); | ||
}; | ||
const handleSubmit = () => { | ||
const sendURL = `${process.env.REACT_APP_HOST}/contact`; | ||
const formDatas = value; | ||
Axios.post(sendURL, formDatas); | ||
}; | ||
return ( | ||
<Box className="main contact"> | ||
<Paper className="contact-container"> | ||
<Card className="title"> | ||
<Typography variant="h1">Contactez moi!</Typography> | ||
</Card> | ||
<Card className="email"> | ||
<Typography variant="">Email</Typography> | ||
</Card> | ||
<Card className="phone"> | ||
<Typography variant="">Tel</Typography> | ||
</Card> | ||
<Card className="text"> | ||
<Typography variant="">Texte</Typography> | ||
</Card> | ||
</Paper> | ||
</Box> | ||
<Card className="main contact"> | ||
<Form | ||
onSubmit={onSubmit} | ||
render={({ handleSubmit, handleChange }) => ( | ||
<form method="POST" className="contact-container"> | ||
<Typography variant="h1">Contactez moi!</Typography> | ||
<InputLabel>Email</InputLabel> | ||
<Field | ||
name="user_email" | ||
component="input" | ||
type="email" | ||
value={handleChange} | ||
placeholder="[email protected]" | ||
/> | ||
<InputLabel>Nom complet</InputLabel> | ||
<Field | ||
name="Nom complet" | ||
component="input" | ||
type="text" | ||
placeholder="Mr John DOE" | ||
/> | ||
<InputLabel>Message</InputLabel> | ||
<Field | ||
name="Message" | ||
component="input" | ||
type="textarea" | ||
placeholder="" | ||
/> | ||
<Button | ||
component="submit" | ||
onClick={() => handleSubmit()} | ||
> | ||
Envoyer | ||
</Button> | ||
</form> | ||
)} | ||
/> | ||
</Card> | ||
); | ||
} | ||
|
||
|