Skip to content

Commit 4d8bbe5

Browse files
committedNov 13, 2023
Readme, screenshot and comments
1 parent ff5a638 commit 4d8bbe5

File tree

4 files changed

+15
-8
lines changed

4 files changed

+15
-8
lines changed
 

‎README.md

+10-2
Original file line numberDiff line numberDiff line change
@@ -8,17 +8,25 @@ Project currently in development.
88

99
## Features
1010

11-
To fullfill
11+
- A responsive form using useform hook
12+
- Inform user : if there is errors in inputs fulfillment, if submission is successful, if submission is not successful
13+
- All inputs data from an array
14+
15+
To test it, set VITE_IS_TEST as true in .env
16+
17+
For production, change api url to yours in .env VITE_API_URL='your-api-url' and in utils/index.jsx → usePostForm hook → customFetch.post('/your-api-route', mailBody)
1218

1319
## Project
1420

1521
React powered by [Vite](https://vitejs.dev/)
1622

1723
With :
1824

19-
- [TailwindCss](https://tailwindcss.com/) & [DaisyUI](https://daisyui.com/) for styling
2025
- [@tanstack/react-query](https://tanstack.com/query/v3/)
2126
- [react-hook-form - useForm](https://react-hook-form.com/)
27+
- [react-toastify](react-toastify) for beautiful toaster
28+
- [miragejs](https://miragejs.com) to mockup server response
29+
- [TailwindCss](https://tailwindcss.com/) & [DaisyUI](https://daisyui.com/) for styling
2230

2331
## Use it !
2432

‎images/screenshot.png

352 Bytes
Loading

‎index.html

-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
<html lang="en">
33
<head>
44
<meta charset="UTF-8" />
5-
<link rel="icon" type="image/svg+xml" href="/vite.svg" />
65
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
76
<title>React form</title>
87
</head>

‎src/App.jsx

+5-5
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ function App() {
3737
postForm(formAnswers);
3838
};
3939

40-
// toggle form
40+
// === Fold form === //
4141

4242
const [foldForm, setFoldForm] = useState(false);
4343

@@ -50,15 +50,13 @@ function App() {
5050
const [errorTypesArray, setErrorTypesArray] = useState([]);
5151

5252
const validateForm = () => {
53+
// if no error, return
5354
if (Object.entries(errors).length === 0) return;
54-
console.log('error presence');
55-
console.log(errors);
5655

5756
// transform error object to array
5857
const errorsAsArray = Object.entries(errors);
5958

60-
// loop thru errorsAsArray and test error types
61-
59+
// loop thru errorsAsArray and store error types in errorTypesArray state
6260
let tempErrorArray = [];
6361
if (errorsAsArray.length > 0) {
6462
errorsAsArray.map((singleError) => {
@@ -68,6 +66,8 @@ function App() {
6866
}
6967
};
7068

69+
// check errors types in errorTypesArray state
70+
// for each type, trigger a toast
7171
useEffect(() => {
7272
// if error type required or pattern → trigger toastify with info
7373
errorTypesArray.includes('required') &&

0 commit comments

Comments
 (0)
Please sign in to comment.