Skip to content

Commit

Permalink
Contact.jsx working
Browse files Browse the repository at this point in the history
  • Loading branch information
rachOS committed Aug 10, 2020
1 parent fcae760 commit af9818f
Show file tree
Hide file tree
Showing 5 changed files with 93 additions and 71 deletions.
18 changes: 10 additions & 8 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@
"jquery": "^3.5.1",
"path": "^0.12.7",
"react": "^16.13.1",
"react-advanced-form": "^1.7.2",
"react-dom": "^16.13.1",
"react-final-form": "^6.5.1",
"react-redux": "^7.2.1",
"react-router": "^5.2.0",
"react-router-dom": "^5.2.0",
Expand Down
3 changes: 2 additions & 1 deletion src/App.css
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
"leftMenu footer footer footer footer";
row-gap: 5px;
column-gap: 5px;
background-color: #4ec044;
justify-items: stretch;
align-items: stretch;
padding: 5px;
Expand All @@ -32,7 +33,7 @@
grid-area: header;
}

.main{
.main {
grid-area: main;
}
.footer {
Expand Down
129 changes: 70 additions & 59 deletions src/components/Contact.jsx
Original file line number Diff line number Diff line change
@@ -1,31 +1,25 @@
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";
// import components

// import data
import { Form } from "react-advanced-form";
import { Card, InputLabel, Button, Typography, Input } from "@material-ui/core";

// import style
import "../App.css";
import "./style/contact.css";

function Contact() {
const [value, setValue] = useState({
user_email: "[email protected]",
subject: "coucou",
text: "lorem ipsum",
});
const initialUserState = {
user_email: "",
fullname: "",
text: "",
subject: "",
};
const [user, setUser] = useState(initialUserState);
const [input, setInput] = useState("");

useEffect(() => {
setUser(input);
}, [input]);

const sleep = (ms) => new Promise((resolve) => setTimeout(resolve, ms));
const onSubmit = async (values) => {
Expand All @@ -37,51 +31,68 @@ function Contact() {

const handleChange = (event) => {
event.preventDefault();
console.log("VALUE TARGET", event.target.value);
const { value, name } = event.target;
setInput({ ...input, [name]: value });
};
const handleReset = () => {
return setInput(initialUserState);
};

const handleSubmit = () => {
const sendURL = `${process.env.REACT_APP_HOST}/contact`;
const formDatas = value;
Axios.post(sendURL, formDatas);
// const sendURL = `${process.env.REACT_APP_HOST}/contact`;
// const formDatas = user;
// Axios.post(sendURL, formDatas);
onSubmit();
handleReset()
};

return (
<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>
)}
/>
// method="POST"
ref={(form) => (form = form)}
className="contact-container"
onReset={() => handleReset()}
>
<Typography variant="h2">Contactez moi!</Typography>
<InputLabel>Nom complet</InputLabel>
<input
name="fullname"
type="text"
value={user.fullname}
onChange={(event) => handleChange(event)}
placeholder="Mr John DOE / Miss Jane DOE"
/>
<InputLabel>Email</InputLabel>
<input
name="user_email"
type="email"
value={user.user_email}
onChange={(event) => handleChange(event)}
placeholder="[email protected]"
/>
<InputLabel>Sujet</InputLabel>
<input
name="subject"
type="text"
value={user.subject}
onChange={(event) => handleChange(event)}
/>
<InputLabel>Message</InputLabel>
<input
name="text"
type="textarea"
value={user.text}
onChange={(event) => handleChange(event)}
/>
<Button
component="submit"
onClick={(event) => handleSubmit(event)}
onSubmit={(event) => handleReset(event)}
>
Envoyer
</Button>
</Form>
</Card>
);
}
Expand Down
12 changes: 10 additions & 2 deletions src/components/Details.jsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import React from "react";
import React, { useState, useEffect } from "react";
import Axios from "axios";
import {
Paper,
Box,
Expand All @@ -17,13 +18,20 @@ import "../App.css";
import "./style/details.css";

function Details() {
const [cv, setCv] = useState();

const getCV = () => {
const cvURL = `${process.env.REACT_APP_HOST}/infos/download`;
Axios.get(cvURL).then((response) => console.log("RES", response));
};

return (
<Box className="main">
<Paper className="details-container">
<Card className="cv">
CV
<CardActions>
<Button>Télécharger</Button>
<Button onClick={() => getCV()}>Télécharger</Button>
</CardActions>
</Card>
<Card className="infos">Disponibilités et infos</Card>
Expand Down

0 comments on commit af9818f

Please sign in to comment.