1
1
'use client' ;
2
- import React , { useState } from 'react' ;
2
+ import React , { useRef } from 'react' ;
3
3
import Link from 'next/link' ;
4
4
import Image from 'next/image' ;
5
5
import { sendContactMeEmail } from '../lib/client.js' ;
6
+ import { motion , useAnimationControls } from 'framer-motion' ;
6
7
7
8
const EmailSection = ( ) => {
8
- const [ emailSubmitted , setEmailSubmitted ] = useState ( false ) ;
9
+ const formRef = useRef ( null ) ;
10
+ const controls = useAnimationControls ( ) ;
9
11
const handleSubmit = async ( e ) => {
10
12
e . preventDefault ( ) ;
11
13
await sendContactMeEmail (
@@ -14,8 +16,7 @@ const EmailSection = () => {
14
16
e . target . message . value ,
15
17
) . then ( ( response ) => {
16
18
if ( response . status === 201 ) {
17
- console . log ( `Message sent` ) ;
18
- setEmailSubmitted ( true ) ;
19
+ formRef . current . reset ( ) ;
19
20
}
20
21
} ) ;
21
22
} ;
@@ -55,7 +56,7 @@ const EmailSection = () => {
55
56
</ div >
56
57
</ div >
57
58
< div >
58
- < form className = "flex flex-col" onSubmit = { handleSubmit } >
59
+ < form ref = { formRef } className = "flex flex-col" onSubmit = { handleSubmit } >
59
60
< div className = "mb-6" >
60
61
< label
61
62
htmlFor = "email"
@@ -107,14 +108,28 @@ const EmailSection = () => {
107
108
< button
108
109
type = "submit"
109
110
className = "rounded hover:bg-primary-400 bg-primary-600 text-primaryText w-full py-2.5 flex justify-center"
111
+ onClick = { ( ) => {
112
+ controls . set ( { opacity : 0 , scale : 1 } ) ;
113
+ controls . start ( {
114
+ opacity : 1 ,
115
+ scale : 1 ,
116
+ transition : {
117
+ repeat : 1 ,
118
+ repeatType : 'reverse' ,
119
+ duration : 2 ,
120
+ } ,
121
+ } ) ;
122
+ } }
110
123
>
111
124
Send Message
112
125
</ button >
113
- { emailSubmitted && (
114
- < p className = "text-primary-500 text-sm mt-2 block" >
115
- Email sent succesfully!
116
- </ p >
117
- ) }
126
+ < motion . p
127
+ className = "text-primary-500 text-sm mt-2 block"
128
+ initial = { { opacity : 0 , scale : 1 } }
129
+ animate = { controls }
130
+ >
131
+ Email sent succesfully!
132
+ </ motion . p >
118
133
</ form >
119
134
</ div >
120
135
</ section >
0 commit comments