1
1
import { useForm } from "react-hook-form" ;
2
- import clickSound from "../../assets/mixkit-mouse-click-close-1113.wav" ; // Importing the sound file
2
+ import clickSound from "../../assets/mixkit-mouse-click-close-1113.wav" ;
3
3
4
4
const ContactForm = ( ) => {
5
5
const {
@@ -11,89 +11,85 @@ const ContactForm = () => {
11
11
12
12
const playSound = ( ) => {
13
13
const audio = new Audio ( clickSound ) ;
14
- audio . play ( ) ; // Play the sound
14
+ audio . play ( ) ;
15
15
} ;
16
16
17
17
const onSubmit = ( data ) => {
18
- playSound ( ) ; // Play sound on submit
18
+ playSound ( ) ;
19
19
alert ( "Message sent successfully" ) ;
20
20
console . log ( data ) ;
21
- reset ( ) ; // reset form fields after submission
21
+ reset ( ) ;
22
22
} ;
23
23
24
24
return (
25
- < >
26
- < section className = "flex flex-col my-20 md:flex-row gap-y-10" >
27
- < article className = "flex justify-center flex-1 p-5 md:p-0 md:mr-24" >
28
- < form onSubmit = { handleSubmit ( onSubmit ) } className = "w-full gap-x-5" >
29
- < div className = "flex flex-col justify-between mb-6 md:flex-row" >
30
- < div className = "flex flex-col md:w-6/12" >
31
- < input
32
- { ...register ( "firstName" , {
33
- required : "First name is required" ,
34
- } ) }
35
- className = "h-16 p-2 mb-6 border-2 rounded-lg border-green text-green-dark md:mb-0 placeholder-textBlack"
36
- placeholder = "First name"
37
- style = { { marginRight : "5px" } }
38
- />
39
- < span className = "pl-4 text-[#ff0000] text-sm" >
40
- { errors . firstName && errors . firstName . message }
41
- </ span >
42
- </ div >
43
- < div className = "flex flex-col md:w-6/12" >
44
- < input
45
- { ...register ( "lastName" , {
46
- required : "Last name is required" ,
47
- } ) }
48
- className = "h-16 p-2 border-2 rounded-lg border-green text-green-dark placeholder-textBlack"
49
- placeholder = "Last name"
50
- />
51
- < span className = "pl-4 text-[#ff0000] text-sm" >
52
- { errors . lastName && errors . lastName . message }
53
- </ span >
54
- </ div >
55
- </ div >
56
- < div className = "flex flex-col justify-between mb-6 md:flex-row" >
57
- < div className = "flex flex-col w-full" >
58
- < input
59
- { ...register ( "email" , {
60
- required : "Email is required" ,
61
- pattern : {
62
- value : / \S + @ \S + \. \S + / ,
63
- message : "Email is not valid" ,
64
- } ,
65
- } ) }
66
- className = "h-16 p-2 border-2 rounded-lg border-green text-green-dark placeholder-textBlack"
67
- placeholder = "Email"
68
- />
69
- < span className = "pl-4 text-[#ff0000] text-sm" >
70
- { errors . email && errors . email . message }
71
- </ span >
72
- </ div >
25
+ < section className = "bg-light-blue shadow-lg rounded-lg p-8" >
26
+ < form onSubmit = { handleSubmit ( onSubmit ) } className = "space-y-6" >
27
+ < div className = "flex flex-col md:flex-row gap-6" >
28
+ < div className = "flex-1" >
29
+ < input
30
+ { ...register ( "firstName" , { required : "First name is required" } ) }
31
+ className = "w-full h-12 p-3 border border-gray-300 rounded-md focus:outline-none focus:ring-2 focus:ring-primaryGreen transition duration-200 ease-in-out"
32
+ placeholder = "First Name"
33
+ />
34
+ < div className = "min-h-[1.5rem]" >
35
+ { errors . firstName && (
36
+ < span className = "text-customRed text-sm" > { errors . firstName . message } </ span >
37
+ ) }
73
38
</ div >
74
-
75
- < textarea
76
- { ...register ( "message" , {
77
- required : "Message is required" ,
78
- } ) }
79
- className = "w-full h-40 p-2 border-2 rounded-lg border-green text-green-dark placeholder-textBlack"
80
- placeholder = "Your message here"
39
+ </ div >
40
+ < div className = "flex-1" >
41
+ < input
42
+ { ...register ( "lastName" , { required : "Last name is required" } ) }
43
+ className = "w-full h-12 p-3 border border-gray-300 rounded-md focus:outline-none focus:ring-2 focus:ring-primaryGreen transition duration-200 ease-in-out"
44
+ placeholder = "Last Name"
81
45
/>
82
- < span className = "pl-4 text-[#ff0000] text-sm" >
83
- { errors . message && errors . message . message }
84
- </ span >
85
- < div className = "flex justify-center md:justify-start" >
86
- < button
87
- className = "relative flex cursor-pointer items-center justify-center mt-5 bg-green rounded-lg w-40 lg:w-60 p-3 text-textWhite text-2xl md:text-xl font-bold font-monsterrat ease-in-out duration-300 hover:bg-[transparent] hover:text-green hover:border-green hover:border-[2px]"
88
- type = "submit"
89
- >
90
- Submit
91
- </ button >
46
+ < div className = "min-h-[1.5rem]" >
47
+ { errors . lastName && (
48
+ < span className = "text-customRed text-sm" > { errors . lastName . message } </ span >
49
+ ) }
92
50
</ div >
93
- </ form >
94
- </ article >
95
- </ section >
96
- </ >
51
+ </ div >
52
+ </ div >
53
+ < div >
54
+ < input
55
+ { ...register ( "email" , {
56
+ required : "Email is required" ,
57
+ pattern : {
58
+ value : / \S + @ \S + \. \S + / ,
59
+ message : "Email is not valid" ,
60
+ } ,
61
+ } ) }
62
+ className = "w-full h-12 p-3 border border-gray-300 rounded-md focus:outline-none focus:ring-2 focus:ring-primaryGreen transition duration-200 ease-in-out"
63
+ placeholder = "Email"
64
+ />
65
+ < div className = "min-h-[1.5rem]" >
66
+ { errors . email && (
67
+ < span className = "text-customRed text-sm" > { errors . email . message } </ span >
68
+ ) }
69
+ </ div >
70
+ </ div >
71
+ < div >
72
+ < textarea
73
+ { ...register ( "message" , { required : "Message is required" } ) }
74
+ className = "w-full h-32 p-3 border border-gray-300 rounded-md focus:outline-none focus:ring-2 focus:ring-primaryGreen transition duration-200 ease-in-out"
75
+ placeholder = "Your Message"
76
+ />
77
+ < div className = "min-h-[1.5rem]" >
78
+ { errors . message && (
79
+ < span className = "text-customRed text-sm" > { errors . message . message } </ span >
80
+ ) }
81
+ </ div >
82
+ </ div >
83
+ < div className = "flex justify-center" >
84
+ < button
85
+ type = "submit"
86
+ className = "w-40 py-3 bg-primaryGreen text-textWhite rounded-full transition-all duration-300 hover:bg-customRed focus:outline-none focus:ring-2 focus:ring-black"
87
+ >
88
+ Submit
89
+ </ button >
90
+ </ div >
91
+ </ form >
92
+ </ section >
97
93
) ;
98
94
} ;
99
95
0 commit comments