Skip to content

Commit 763072e

Browse files
committed
Added contect us page
1 parent d571eb0 commit 763072e

File tree

4 files changed

+140
-7
lines changed

4 files changed

+140
-7
lines changed

package-lock.json

+2-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

+2-1
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,8 @@
2222
"react-hot-toast": "^2.4.1",
2323
"react-icons": "^5.0.1",
2424
"react-redux": "^9.1.0",
25-
"react-router-dom": "^6.22.3"
25+
"react-router-dom": "^6.22.3",
26+
"redux": "^5.0.1"
2627
},
2728
"devDependencies": {
2829
"@types/react": "^18.2.66",

src/App.jsx

+7-5
Original file line numberDiff line numberDiff line change
@@ -8,16 +8,18 @@ import NotFound from "./Pages/NotFound";
88
import Signup from "./Pages/Signup";
99
import Login from "./Pages/Login";
1010
import CourseList from "./Pages/Course/CourseList";
11+
import Contect from "./Pages/Contect";
1112

1213
function App() {
1314
return (
1415
<>
1516
<Routes>
16-
<Route path="/" element={<HomePage />}></Route>
17-
<Route path="/about" element={<AboutUs />}></Route>
18-
<Route path="/signup" element={<Signup />}></Route>
19-
<Route path="/login" element={<Login />}></Route>
20-
<Route path="/courses" element={<CourseList />}></Route>
17+
<Route path="/" element={<HomePage />} />
18+
<Route path="/about" element={<AboutUs />} />
19+
<Route path="/signup" element={<Signup />} />
20+
<Route path="/login" element={<Login />} />
21+
<Route path="/courses" element={<CourseList />} />
22+
<Route path="/contect" element={<Contect />} />
2123

2224
<Route path="*" element={<NotFound />}></Route>
2325
</Routes>

src/Pages/Contect.jsx

+129
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,129 @@
1+
import React, { useState } from "react";
2+
import HomeLayout from "../Layouts/HomeLayout";
3+
import toast from "react-hot-toast";
4+
import axiosInstance from "../Helpers/axiosinstance";
5+
6+
const Contect = () => {
7+
const [contectFrom, setContectForm] = useState({
8+
name: "",
9+
email: "",
10+
message: "",
11+
});
12+
13+
const handleInputs = (event) => {
14+
event.preventDefault();
15+
const { name, value } = event.target;
16+
17+
setContectForm({
18+
...contectFrom,
19+
[name]: value,
20+
});
21+
};
22+
23+
const onSubmitForm = async (e) => {
24+
e.preventDefault();
25+
26+
if (!contectFrom.name || !contectFrom.email || !contectFrom.message) {
27+
toast.error("All fields are required");
28+
return;
29+
}
30+
31+
if (
32+
!contectFrom.email.match(
33+
/^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}$/
34+
)
35+
) {
36+
toast.error("Invalid email address");
37+
return;
38+
}
39+
try {
40+
const responce = axiosInstance.post("/contact", contectFrom);
41+
toast.promise(responce, {
42+
loading: "Submitting your message...",
43+
success: "Form submitted successfully",
44+
error: "Failed to submit the form",
45+
});
46+
const contectresponce = await responce;
47+
console.log(contectresponce);
48+
if (contectresponce?.data?.success) {
49+
setContectForm({
50+
...contectFrom,
51+
name: "",
52+
email: "",
53+
message: "",
54+
});
55+
}
56+
} catch (error) {
57+
toast.error(error.message);
58+
}
59+
};
60+
61+
return (
62+
<div>
63+
<HomeLayout>
64+
<div className="flex items-center justify-center h-[100vh]">
65+
<form
66+
onSubmit={onSubmitForm}
67+
className="flex flex-col items-center justify-center gap-2 p-5 rounded-md text-white shadow-[0_0_10px_black] w-[22rem]"
68+
>
69+
<h1 className="text-3xl font-semibold">Contact Form</h1>
70+
71+
<div className="flex flex-col w-full gap-1">
72+
<label htmlFor="name" className="text-xl font-semibold">
73+
Name
74+
</label>
75+
<input
76+
onChange={handleInputs}
77+
className="bg-transparent border px-2 py-1 rounded-sm"
78+
id="name"
79+
type="text"
80+
name="name"
81+
value={contectFrom.name}
82+
placeholder="Enter your name"
83+
/>
84+
</div>
85+
86+
<div className="flex flex-col w-full gap-1">
87+
<label htmlFor="email" className="text-xl font-semibold">
88+
Email
89+
</label>
90+
<input
91+
onChange={handleInputs}
92+
className="bg-transparent border px-2 py-1 rounded-sm"
93+
id="email"
94+
type="email"
95+
name="email"
96+
value={contectFrom.email}
97+
placeholder="Enter your email"
98+
/>
99+
</div>
100+
101+
<div className="flex flex-col w-full gap-1">
102+
<label htmlFor="message" className="text-xl font-semibold">
103+
Message
104+
</label>
105+
<textarea
106+
onChange={handleInputs}
107+
className="bg-transparent border px-2 py-1 rounded-sm resize-none h-40"
108+
id="message"
109+
type="message"
110+
name="message"
111+
value={contectFrom.message}
112+
placeholder="Enter your message"
113+
/>
114+
</div>
115+
<button
116+
type="submit"
117+
className="w-full
118+
py-2 bg-yellow-600 hover:bg-yellow-500 transition-all ease-in-out duration-300 rounded-sm font-semibold text-xl"
119+
>
120+
Submit
121+
</button>
122+
</form>
123+
</div>
124+
</HomeLayout>
125+
</div>
126+
);
127+
};
128+
129+
export default Contect;

0 commit comments

Comments
 (0)