mirror of
https://github.com/hazemKrimi/personal-website.git
synced 2026-05-01 18:00:26 +00:00
Fix contact form behavior bug
This commit is contained in:
+22
-19
@@ -46,6 +46,12 @@ const Wrapper = styled.div<{ dark: boolean }>`
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.success {
|
||||||
|
color: #73d26b;
|
||||||
|
align-self: center;
|
||||||
|
font-weight: normal;
|
||||||
|
}
|
||||||
|
|
||||||
.contact {
|
.contact {
|
||||||
display: grid;
|
display: grid;
|
||||||
grid-template-columns: auto;
|
grid-template-columns: auto;
|
||||||
@@ -55,15 +61,6 @@ const Wrapper = styled.div<{ dark: boolean }>`
|
|||||||
color: #d75050;
|
color: #d75050;
|
||||||
}
|
}
|
||||||
|
|
||||||
.success {
|
|
||||||
color: #73d26b;
|
|
||||||
}
|
|
||||||
|
|
||||||
.success-button {
|
|
||||||
cursor: default;
|
|
||||||
background: #73d26b;
|
|
||||||
}
|
|
||||||
|
|
||||||
@media (max-width: 768px) {
|
@media (max-width: 768px) {
|
||||||
row-gap: 0.5rem;
|
row-gap: 0.5rem;
|
||||||
}
|
}
|
||||||
@@ -84,8 +81,11 @@ const About: FC = () => {
|
|||||||
};
|
};
|
||||||
|
|
||||||
const handleSubmit = async (event: React.FormEvent<HTMLFormElement>) => {
|
const handleSubmit = async (event: React.FormEvent<HTMLFormElement>) => {
|
||||||
await Submit(event);
|
try {
|
||||||
setForm({ name: '', email: '', message: '' });
|
await Submit(event);
|
||||||
|
} finally {
|
||||||
|
setForm({ name: '', email: '', message: '' });
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
return (
|
return (
|
||||||
@@ -126,13 +126,19 @@ const About: FC = () => {
|
|||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div>
|
<div>
|
||||||
<h1>Contact Me</h1>
|
<h1>
|
||||||
|
Contact Me{' '}
|
||||||
|
{state.succeeded && state.submitting && (
|
||||||
|
<span className='success'>Message sent ✔️</span>
|
||||||
|
)}
|
||||||
|
</h1>
|
||||||
<form className='contact' onSubmit={handleSubmit}>
|
<form className='contact' onSubmit={handleSubmit}>
|
||||||
<Input
|
<Input
|
||||||
type='text'
|
type='text'
|
||||||
placeholder='Name'
|
placeholder='Name'
|
||||||
variant='small'
|
variant='small'
|
||||||
name='name'
|
name='name'
|
||||||
|
required
|
||||||
value={form.name}
|
value={form.name}
|
||||||
onChange={handleChange}
|
onChange={handleChange}
|
||||||
/>
|
/>
|
||||||
@@ -142,6 +148,7 @@ const About: FC = () => {
|
|||||||
placeholder='Email'
|
placeholder='Email'
|
||||||
variant='small'
|
variant='small'
|
||||||
name='email'
|
name='email'
|
||||||
|
required
|
||||||
value={form.email}
|
value={form.email}
|
||||||
onChange={handleChange}
|
onChange={handleChange}
|
||||||
/>
|
/>
|
||||||
@@ -156,6 +163,7 @@ const About: FC = () => {
|
|||||||
placeholder='Message'
|
placeholder='Message'
|
||||||
variant='big'
|
variant='big'
|
||||||
name='message'
|
name='message'
|
||||||
|
required
|
||||||
value={form.message}
|
value={form.message}
|
||||||
onChange={handleChange}
|
onChange={handleChange}
|
||||||
/>
|
/>
|
||||||
@@ -165,13 +173,8 @@ const About: FC = () => {
|
|||||||
field='message'
|
field='message'
|
||||||
errors={state.errors}
|
errors={state.errors}
|
||||||
/>
|
/>
|
||||||
<MDXButton
|
<MDXButton type='submit' variant='action' disabled={state.submitting}>
|
||||||
type='submit'
|
Submit
|
||||||
variant='action'
|
|
||||||
disabled={state.submitting}
|
|
||||||
className={state.submitting && state.succeeded ? 'success-button' : ''}
|
|
||||||
>
|
|
||||||
{state.submitting && state.succeeded ? 'Message sent' : 'Submit'}
|
|
||||||
</MDXButton>
|
</MDXButton>
|
||||||
</form>
|
</form>
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
Reference in New Issue
Block a user