@@ -22,6 +22,7 @@ const Contact = () => {
22
22
} ) ;
23
23
const [ loading , setLoading ] = useState ( false ) ;
24
24
const [ error , setError ] = useState ( "" ) ;
25
+ const [ success , setSuccess ] = useState ( "" ) ;
25
26
26
27
function handle ( e ) {
27
28
const newData = { ...data } ;
@@ -33,7 +34,7 @@ const Contact = () => {
33
34
e . preventDefault ( ) ;
34
35
setLoading ( true ) ;
35
36
setError ( "" ) ;
36
-
37
+ setSuccess ( "" ) ;
37
38
try {
38
39
await base ( "Table 1" ) . create ( [
39
40
{
@@ -44,9 +45,12 @@ const Contact = () => {
44
45
} ,
45
46
} ,
46
47
] ) ;
48
+ setSuccess ( "Your message has been sent successfully!" ) ;
49
+ setTimeout ( ( ) => setSuccess ( "" ) , 3000 ) ;
47
50
} catch ( err ) {
48
51
console . error ( "Error:" , err ) ;
49
52
setError ( "There was an error processing your request." ) ;
53
+ setTimeout ( ( ) => setError ( "" ) , 3000 ) ;
50
54
} finally {
51
55
setLoading ( false ) ;
52
56
setData ( {
@@ -60,7 +64,7 @@ const Contact = () => {
60
64
return (
61
65
< div >
62
66
< section className = "text-gray-400 bg-gray-1000 body-font" >
63
- < div className = "container px-5 py-24 mx-auto" >
67
+ < div className = "container px-5 py-10 mx-auto" >
64
68
< div className = "flex flex-col text-center w-full mb-12" >
65
69
< h1 className = "sm:text-3xl text-2xl font-medium title-font mb-4 text-white" >
66
70
Contact Us
@@ -152,8 +156,11 @@ const Contact = () => {
152
156
</ button >
153
157
</ div >
154
158
</ form >
155
- { loading && < p className = "text-white" > Loading...</ p > } { /* Optional loading message */ }
156
- { error && < p className = "text-red-500" > { error } </ p > } { /* Optional error message */ }
159
+ < div className = "py-6 text-center font-semibold" >
160
+ { loading && < p className = "text-white" > Loading...</ p > }
161
+ { error && < p className = "text-red-500" > { error } </ p > }
162
+ { success && < p className = "text-green-500" > { success } </ p > }
163
+ </ div >
157
164
</ div >
158
165
</ div >
159
166
</ section >
0 commit comments