From e6e1386dab296a0a8fcf724922e56d3c9467675d Mon Sep 17 00:00:00 2001 From: Hazem Krimi Date: Mon, 22 Mar 2021 01:59:12 +0100 Subject: [PATCH] Fix contact form behavior bug --- pages/about.tsx | 41 ++++++++++++++++++++++------------------- 1 file changed, 22 insertions(+), 19 deletions(-) diff --git a/pages/about.tsx b/pages/about.tsx index 3ae2930..66c30fd 100644 --- a/pages/about.tsx +++ b/pages/about.tsx @@ -46,6 +46,12 @@ const Wrapper = styled.div<{ dark: boolean }>` } } + .success { + color: #73d26b; + align-self: center; + font-weight: normal; + } + .contact { display: grid; grid-template-columns: auto; @@ -55,15 +61,6 @@ const Wrapper = styled.div<{ dark: boolean }>` color: #d75050; } - .success { - color: #73d26b; - } - - .success-button { - cursor: default; - background: #73d26b; - } - @media (max-width: 768px) { row-gap: 0.5rem; } @@ -84,8 +81,11 @@ const About: FC = () => { }; const handleSubmit = async (event: React.FormEvent) => { - await Submit(event); - setForm({ name: '', email: '', message: '' }); + try { + await Submit(event); + } finally { + setForm({ name: '', email: '', message: '' }); + } }; return ( @@ -126,13 +126,19 @@ const About: FC = () => {
-

Contact Me

+

+ Contact Me{' '} + {state.succeeded && state.submitting && ( + Message sent ✔️ + )} +

@@ -142,6 +148,7 @@ const About: FC = () => { placeholder='Email' variant='small' name='email' + required value={form.email} onChange={handleChange} /> @@ -156,6 +163,7 @@ const About: FC = () => { placeholder='Message' variant='big' name='message' + required value={form.message} onChange={handleChange} /> @@ -165,13 +173,8 @@ const About: FC = () => { field='message' errors={state.errors} /> - - {state.submitting && state.succeeded ? 'Message sent' : 'Submit'} + + Submit