@@ -3,6 +3,7 @@ import { rem } from 'polished'
33import { useEffect , useState } from 'react'
44import styled from 'styled-components'
55import Button from '../button'
6+ import { FadeIn , FadeOut } from '../fade'
67import Input from '../input'
78import { Loader , LoaderContainer } from '../loader'
89import Text from '../text'
@@ -22,7 +23,7 @@ const SuccessHeader = styled.h2`
2223`
2324
2425const Form = ( ) => {
25- const [ isFormSubmitted , setIsFormSubmitted ] = useState ( false )
26+ const [ isSubmitted , setIsSubmitted ] = useState ( true )
2627 const [ isSubmitting , setIsSubmitting ] = useState ( false )
2728 const [ hasErrors , setHasErrors ] = useState ( false )
2829 const [ state , setState ] = useState ( {
@@ -49,7 +50,7 @@ const Form = () => {
4950 body : JSON . stringify ( state ) ,
5051 } )
5152 if ( res . status === 200 ) {
52- setIsFormSubmitted ( true )
53+ setIsSubmitted ( true )
5354 } else {
5455 setHasErrors ( true )
5556 }
@@ -61,16 +62,16 @@ const Form = () => {
6162 }
6263
6364 useEffect ( ( ) => {
64- setIsFormSubmitted ( localStorage . getItem ( 'formSubmitted' ) )
65+ setIsSubmitted ( localStorage . getItem ( 'formSubmitted' ) === 'true' )
6566 } , [ ] )
6667
6768 useEffect ( ( ) => {
68- localStorage . setItem ( 'formSubmitted' , isFormSubmitted )
69- } , [ isFormSubmitted ] )
69+ localStorage . setItem ( 'formSubmitted' , isSubmitted )
70+ } , [ isSubmitted ] )
7071
71- const renderForm = ( ) =>
72- isFormSubmitted === true ? (
73- < div >
72+ const renderForm = ( ) => (
73+ < div >
74+ < FadeIn show = { isSubmitted } >
7475 < CheckCircle
7576 { ...{
7677 color : '#FF68BA' ,
@@ -87,56 +88,61 @@ const Form = () => {
8788 In the meantime take a look at some{ ' ' }
8889 < a href = "https://blog.commit.dev/" > blog posts</ a > from our engineers.
8990 </ Text >
90- </ div >
91- ) : (
91+ </ FadeIn >
9292 < >
93- { hasErrors && (
93+ < FadeIn show = { hasErrors } >
9494 < Text errorText >
9595 Woops, the application failed to send. Please try again.
9696 </ Text >
97- ) }
97+ </ FadeIn >
98+
9899 < LoaderContainer >
99- { isSubmitting && < Loader /> }
100- < form >
101- < Input
102- { ...{
103- name : 'name' ,
104- onChange,
105- placeholder : 'Name' ,
106- value : state . name ,
107- } }
108- />
109- < Input
110- { ...{
111- name : 'email' ,
112- onChange,
113- placeholder : 'E-mail' ,
114- type : 'email' ,
115- value : state . email ,
116- } }
117- />
118- < TextArea
119- { ...{
120- name : 'info' ,
121- onChange,
122- placeholder :
123- 'Let us know where to learn more about you\n(Ex. Website, blog, youtube, etc)' ,
124- value : state . info ,
125- } }
126- />
127- < Button
128- { ...{
129- 'data-test-id' : 'button' ,
130- disabled : isSubmitting ,
131- onClick,
132- } }
133- >
134- Apply To Join
135- </ Button >
136- </ form >
100+ < Loader show = { isSubmitting } />
101+ { ! isSubmitted && (
102+ < FadeOut show = { ! isSubmitting } >
103+ < form >
104+ < Input
105+ { ...{
106+ name : 'name' ,
107+ onChange,
108+ placeholder : 'Name' ,
109+ value : state . name ,
110+ } }
111+ />
112+ < Input
113+ { ...{
114+ name : 'email' ,
115+ onChange,
116+ placeholder : 'E-mail' ,
117+ type : 'email' ,
118+ value : state . email ,
119+ } }
120+ />
121+ < TextArea
122+ { ...{
123+ name : 'info' ,
124+ onChange,
125+ placeholder :
126+ 'Let us know where to learn more about you\n(Ex. Website, blog, youtube, etc)' ,
127+ value : state . info ,
128+ } }
129+ />
130+ < Button
131+ { ...{
132+ 'data-test-id' : 'button' ,
133+ disabled : isSubmitting ,
134+ onClick,
135+ } }
136+ >
137+ Apply To Join
138+ </ Button >
139+ </ form >
140+ </ FadeOut >
141+ ) }
137142 </ LoaderContainer >
138143 </ >
139- )
144+ </ div >
145+ )
140146
141147 return renderForm ( )
142148}
0 commit comments