Compare commits
5
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
eae1ae6844 | ||
|
|
5f212996e0 | ||
|
|
483c8aefe7 | ||
|
|
bfdc52a117 | ||
|
|
a46b4f61fe |
@@ -15,6 +15,8 @@ interface FormData {
|
|||||||
export function ContactForm() {
|
export function ContactForm() {
|
||||||
const t = useTranslations('pages.contact');
|
const t = useTranslations('pages.contact');
|
||||||
|
|
||||||
|
const MAX_MESSAGE_LENGTH = 1000;
|
||||||
|
|
||||||
const [isSubmitting, setIsSubmitting] = useState(false);
|
const [isSubmitting, setIsSubmitting] = useState(false);
|
||||||
const [submitStatus, setSubmitStatus] = useState<'idle' | 'success' | 'error'>('idle');
|
const [submitStatus, setSubmitStatus] = useState<'idle' | 'success' | 'error'>('idle');
|
||||||
const [errorMessage, setErrorMessage] = useState<string>('');
|
const [errorMessage, setErrorMessage] = useState<string>('');
|
||||||
@@ -26,6 +28,8 @@ export function ContactForm() {
|
|||||||
const [errors, setErrors] = useState<Partial<FormData>>({});
|
const [errors, setErrors] = useState<Partial<FormData>>({});
|
||||||
const [remainingAttempts, setRemainingAttempts] = useState<number | null>(null);
|
const [remainingAttempts, setRemainingAttempts] = useState<number | null>(null);
|
||||||
|
|
||||||
|
const messageLength = formData.message.length;
|
||||||
|
|
||||||
const validateForm = () => {
|
const validateForm = () => {
|
||||||
const newErrors: Partial<FormData> = {};
|
const newErrors: Partial<FormData> = {};
|
||||||
|
|
||||||
@@ -319,6 +323,7 @@ export function ContactForm() {
|
|||||||
onChange={handleChange}
|
onChange={handleChange}
|
||||||
placeholder={t('contactForm.message.placeholder')}
|
placeholder={t('contactForm.message.placeholder')}
|
||||||
rows={6}
|
rows={6}
|
||||||
|
maxLength={MAX_MESSAGE_LENGTH}
|
||||||
disabled={isSubmitting}
|
disabled={isSubmitting}
|
||||||
aria-required="true"
|
aria-required="true"
|
||||||
aria-invalid={!!errors.message}
|
aria-invalid={!!errors.message}
|
||||||
@@ -328,6 +333,19 @@ export function ContactForm() {
|
|||||||
{errors.message && (
|
{errors.message && (
|
||||||
<p id="message-error" role="alert" className="text-sm text-red-400">{errors.message}</p>
|
<p id="message-error" role="alert" className="text-sm text-red-400">{errors.message}</p>
|
||||||
)}
|
)}
|
||||||
|
<div className="flex justify-end">
|
||||||
|
<p
|
||||||
|
className={`text-xs transition-colors ${
|
||||||
|
messageLength > MAX_MESSAGE_LENGTH
|
||||||
|
? 'text-red-500'
|
||||||
|
: messageLength >= MAX_MESSAGE_LENGTH * 0.8
|
||||||
|
? 'text-yellow-500'
|
||||||
|
: 'text-zinc-500'
|
||||||
|
}`}
|
||||||
|
>
|
||||||
|
{t('contactForm.characterCounter', { current: messageLength, max: MAX_MESSAGE_LENGTH })}
|
||||||
|
</p>
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
|||||||
@@ -394,6 +394,7 @@
|
|||||||
"label": "Nachricht",
|
"label": "Nachricht",
|
||||||
"placeholder": "Ihre Nachricht an mich..."
|
"placeholder": "Ihre Nachricht an mich..."
|
||||||
},
|
},
|
||||||
|
"characterCounter": "{current}/{max} Zeichen",
|
||||||
"submit": "Nachricht senden",
|
"submit": "Nachricht senden",
|
||||||
"submitting": "Nachricht wird gesendet...",
|
"submitting": "Nachricht wird gesendet...",
|
||||||
"successMessage": "Vielen Dank für Ihre Nachricht! Ich werde mich so schnell wie möglich bei Ihnen melden.",
|
"successMessage": "Vielen Dank für Ihre Nachricht! Ich werde mich so schnell wie möglich bei Ihnen melden.",
|
||||||
|
|||||||
@@ -409,6 +409,7 @@
|
|||||||
"label": "Message",
|
"label": "Message",
|
||||||
"placeholder": "Your message to me..."
|
"placeholder": "Your message to me..."
|
||||||
},
|
},
|
||||||
|
"characterCounter": "{current}/{max} characters",
|
||||||
"submit": "Send Message",
|
"submit": "Send Message",
|
||||||
"submitting": "Sending message...",
|
"submitting": "Sending message...",
|
||||||
"successMessage": "Thank you for your message! I will get back to you as soon as possible.",
|
"successMessage": "Thank you for your message! I will get back to you as soon as possible.",
|
||||||
|
|||||||
@@ -416,6 +416,7 @@
|
|||||||
"label": "Poruka",
|
"label": "Poruka",
|
||||||
"placeholder": "Vasa poruka za mene..."
|
"placeholder": "Vasa poruka za mene..."
|
||||||
},
|
},
|
||||||
|
"characterCounter": "{current}/{max} karaktera",
|
||||||
"submit": "Posalji poruku",
|
"submit": "Posalji poruku",
|
||||||
"submitting": "Slanje poruke...",
|
"submitting": "Slanje poruke...",
|
||||||
"successMessage": "Hvala vam na poruci! Javicu vam se sto je pre moguce.",
|
"successMessage": "Hvala vam na poruci! Javicu vam se sto je pre moguce.",
|
||||||
|
|||||||
Reference in New Issue
Block a user