Fixed external email receivers
This commit is contained in:
@@ -3,7 +3,7 @@
|
||||
'use client';
|
||||
|
||||
import { Turnstile, TurnstileInstance } from '@marsidev/react-turnstile';
|
||||
import React, { useRef, useActionState, useEffect } from 'react';
|
||||
import React, { useRef, useActionState, useEffect, useState } from 'react';
|
||||
import { FaUser, FaEnvelope, FaPhone, FaUsers, FaTrophy, FaCheckCircle, FaExclamationTriangle } from "react-icons/fa";
|
||||
import { submitRegistration } from './actions';
|
||||
import { SiteConfig } from '../lib/config';
|
||||
@@ -12,6 +12,7 @@ export default function BeachRegistrationForm({ config, turnstileSiteKey }: { co
|
||||
const [state, formAction, isPending] = useActionState(submitRegistration, null);
|
||||
const formRef = useRef<HTMLFormElement>(null);
|
||||
const turnstileRef = useRef<TurnstileInstance>(null);
|
||||
const [token, setToken] = useState<string | null>(null);
|
||||
|
||||
const classesData = Array.isArray(config.beachPage?.classes)
|
||||
? config.beachPage.classes
|
||||
@@ -22,13 +23,13 @@ export default function BeachRegistrationForm({ config, turnstileSiteKey }: { co
|
||||
];
|
||||
|
||||
useEffect(() => {
|
||||
// Rensa endast vid lyckad inskickning
|
||||
if (state?.success) {
|
||||
formRef.current?.reset();
|
||||
turnstileRef.current?.reset();
|
||||
setToken(null);
|
||||
} else if (state?.success === false) {
|
||||
// Återställ Turnstile så de kan försöka igen vid fel
|
||||
turnstileRef.current?.reset();
|
||||
setToken(null);
|
||||
}
|
||||
}, [state]);
|
||||
|
||||
@@ -131,7 +132,15 @@ export default function BeachRegistrationForm({ config, turnstileSiteKey }: { co
|
||||
|
||||
<input type="text" name="website" className="hidden" tabIndex={-1} />
|
||||
|
||||
<div className="flex justify-center py-2"><Turnstile ref={turnstileRef} siteKey={turnstileSiteKey} options={{ theme: 'light' }} /></div>
|
||||
<div className="flex justify-center py-2">
|
||||
<Turnstile
|
||||
ref={turnstileRef}
|
||||
siteKey={turnstileSiteKey}
|
||||
onSuccess={(token) => setToken(token)}
|
||||
onExpire={() => setToken(null)}
|
||||
options={{ theme: 'light' }}
|
||||
/>
|
||||
</div>
|
||||
|
||||
{state && (
|
||||
<div className={`flex items-center gap-3 p-5 rounded-2xl font-bold transition-all ${state.success ? 'bg-green-100 text-green-700' : 'bg-red-100 text-red-700'}`}>
|
||||
@@ -142,7 +151,7 @@ export default function BeachRegistrationForm({ config, turnstileSiteKey }: { co
|
||||
|
||||
<button
|
||||
type="submit"
|
||||
disabled={isPending}
|
||||
disabled={isPending || !token}
|
||||
className="w-full py-5 bg-[#39979f] text-white rounded-2xl font-bold text-xl uppercase tracking-wide shadow-xl hover:bg-[#fdb84b] hover:text-[#39979f] transition-all active:scale-[0.98] disabled:bg-gray-300 disabled:text-gray-500"
|
||||
>
|
||||
{isPending ? 'Skickar...' : 'Skicka anmälan'}
|
||||
|
||||
Reference in New Issue
Block a user