diff --git a/src/components/NewsletterForm.jsx b/src/components/NewsletterForm.jsx
index be78b344..2fca83b1 100644
--- a/src/components/NewsletterForm.jsx
+++ b/src/components/NewsletterForm.jsx
@@ -1,7 +1,27 @@
import React from 'react'
-import styled from 'styled-components'
-
+import styled, { keyframes } from 'styled-components'
import useNewsletter from 'hooks/useNewsletter'
+import ArrowPathIcon from './icons/heroicons/ArrowPathicon'
+import CheckIcon from './icons/heroicons/CheckIcon'
+
+const spin = keyframes`
+ from {
+ transform: rotate(0deg);
+ }
+ to {
+ transform: rotate(360deg);
+ }
+`
+
+const SpinningIcon = styled.div`
+ display: inline-flex;
+ animation: ${spin} 1s linear infinite;
+
+ svg {
+ width: 1.25rem;
+ height: 1.25rem;
+ }
+`
const Input = styled.input`
width: 100%;
@@ -34,23 +54,74 @@ const Button = styled.button`
font-weight: 600;
cursor: pointer;
transition: background-color 0.2s;
+ display: flex;
+ align-items: center;
+ justify-content: center;
+ gap: 0.5rem;
&:hover {
background: ${(p) => p.theme.colors.main.dark};
}
+
+ &:disabled {
+ opacity: 0.7;
+ cursor: not-allowed;
+ }
+`
+
+const ErrorMessage = styled.p`
+ color: #dc2626;
+ font-size: 0.875rem;
+ margin-top: 0.5rem;
+`
+
+const SuccessMessage = styled.div`
+ display: flex;
+ text-align: center;
+ align-items: center;
+ justify-content: center;
+ gap: 0.5rem;
+ background-color: #f0fdf4;
+ border: 1px solid #86efac;
+ border-radius: 8px;
+ padding: 0rem;
+ color: #166534;
+
+ svg {
+ width: 1.25rem;
+ height: 1.25rem;
+ }
+
+ p {
+ font-size: 0.875rem;
+ color: #15803d;
+ }
`
const NewsletterForm = () => {
const [email, setEmail] = React.useState('')
const { subscribe } = useNewsletter()
const [status, setStatus] = React.useState('idle')
+ const [error, setError] = React.useState(null)
const handleSubmit = (e) => {
e.preventDefault()
setStatus('loading')
subscribe(email)
.then(() => setStatus('success'))
- .catch(() => setStatus('error'))
+ .catch((err) => {
+ setStatus('error')
+ setError(err.message)
+ })
+ }
+
+ if (status === 'success') {
+ return (
+ Thanks for subscribing!
Loading...
} - {status === 'success' &&Success!
} - {status === 'error' &&Error
} + + {status === 'error' &&