add dark mode to signup
This commit is contained in:
parent
d3e4882d9e
commit
abded046a1
@ -9,7 +9,7 @@ import { getSession } from 'next-auth/react';
|
||||
type SignUpPageProps = object // Keine spezifischen Props vom Server benötigt
|
||||
|
||||
const SignUpPage: NextPage<SignUpPageProps> = () => {
|
||||
const { status } = useSession();
|
||||
const {status } = useSession();
|
||||
const router = useRouter();
|
||||
|
||||
const [name, setName] = useState('');
|
||||
@ -67,23 +67,20 @@ const SignUpPage: NextPage<SignUpPageProps> = () => {
|
||||
}
|
||||
|
||||
setSuccessMessage(data.message + ' Du wirst in Kürze zur Anmeldung weitergeleitet.');
|
||||
// Kurze Verzögerung vor der Weiterleitung, damit der Benutzer die Nachricht lesen kann
|
||||
setTimeout(() => {
|
||||
router.push('/auth/signin');
|
||||
}, 3000);
|
||||
|
||||
} catch (err: unknown) {
|
||||
console.error('Registrierungsfehler (Client):', err);
|
||||
// Der Fehler wird bereits im if (!response.ok) Block gesetzt,
|
||||
// außer es ist ein Netzwerkfehler o.ä.
|
||||
|
||||
if (typeof err === 'string') {
|
||||
setError(err);
|
||||
} else if (err instanceof Error) {
|
||||
setError(err.message);
|
||||
} catch (err: unknown) { // Fehlerbehandlung mit unknown
|
||||
if (err instanceof Error) {
|
||||
// Fehler wurde bereits im if(!response.ok) Block gesetzt, falls es ein API Fehler war
|
||||
if (!error && fieldErrors.length === 0) {
|
||||
setError(err.message);
|
||||
}
|
||||
} else {
|
||||
setError('Ein unerwarteter Fehler ist aufgetreten.');
|
||||
}
|
||||
console.error('Registrierungsfehler (Client):', err);
|
||||
} finally {
|
||||
setIsLoading(false);
|
||||
}
|
||||
@ -91,35 +88,35 @@ const SignUpPage: NextPage<SignUpPageProps> = () => {
|
||||
|
||||
if (status === 'loading' || status === 'authenticated') {
|
||||
return (
|
||||
<div className="min-h-screen flex items-center justify-center bg-gray-100">
|
||||
<p className="text-lg text-gray-600">Laden...</p>
|
||||
<div className="min-h-screen flex items-center justify-center bg-gray-100 dark:bg-gray-900">
|
||||
<p className="text-lg text-gray-600 dark:text-gray-300">Laden...</p>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
return (
|
||||
<div className="min-h-screen bg-gray-100 flex flex-col justify-center py-12 sm:px-6 lg:px-8">
|
||||
<div className="min-h-screen bg-gray-100 dark:bg-gray-900 flex flex-col justify-center py-12 sm:px-6 lg:px-8 transition-colors duration-300">
|
||||
<div className="sm:mx-auto sm:w-full sm:max-w-md">
|
||||
<h2 className="mt-6 text-center text-3xl font-extrabold text-gray-900">
|
||||
<h2 className="mt-6 text-center text-3xl font-extrabold text-gray-900 dark:text-gray-100">
|
||||
Neues Konto erstellen
|
||||
</h2>
|
||||
</div>
|
||||
|
||||
<div className="mt-8 sm:mx-auto sm:w-full sm:max-w-md">
|
||||
<div className="bg-white py-8 px-4 shadow-xl ring-1 ring-gray-900/10 sm:rounded-lg sm:px-10">
|
||||
<div className="bg-white dark:bg-slate-800 py-8 px-4 shadow-xl ring-1 ring-gray-900/10 dark:ring-gray-700 sm:rounded-lg sm:px-10">
|
||||
{error && (
|
||||
<div className="mb-4 p-3 bg-red-100 text-red-700 border border-red-300 rounded-md text-sm">
|
||||
<div className="mb-4 p-3 bg-red-100 text-red-700 border border-red-300 rounded-md text-sm dark:bg-red-900 dark:text-red-200 dark:border-red-700">
|
||||
{error}
|
||||
</div>
|
||||
)}
|
||||
{successMessage && (
|
||||
<div className="mb-4 p-3 bg-green-100 text-green-700 border border-green-300 rounded-md text-sm">
|
||||
<div className="mb-4 p-3 bg-green-100 text-green-700 border border-green-300 rounded-md text-sm dark:bg-green-900 dark:text-green-200 dark:border-green-700">
|
||||
{successMessage}
|
||||
</div>
|
||||
)}
|
||||
<form onSubmit={handleSubmit} className="space-y-6">
|
||||
<div>
|
||||
<label htmlFor="name" className="block text-sm font-medium text-gray-700">
|
||||
<label htmlFor="name" className="block text-sm font-medium text-gray-700 dark:text-gray-300">
|
||||
Name
|
||||
</label>
|
||||
<div className="mt-1">
|
||||
@ -131,14 +128,14 @@ const SignUpPage: NextPage<SignUpPageProps> = () => {
|
||||
required
|
||||
value={name}
|
||||
onChange={(e) => setName(e.target.value)}
|
||||
className={`appearance-none text-black block w-full px-3 py-2 border rounded-md shadow-sm placeholder-gray-400 focus:outline-none sm:text-sm ${getFieldError('name') ? 'border-red-500 focus:ring-red-500 focus:border-red-500' : 'border-gray-300 focus:ring-indigo-500 focus:border-indigo-500'}`}
|
||||
className={`appearance-none block w-full px-3 py-2 border rounded-md shadow-sm placeholder-gray-400 dark:placeholder-gray-500 focus:outline-none sm:text-sm bg-white dark:bg-slate-700 text-gray-900 dark:text-gray-100 ${getFieldError('name') ? 'border-red-500 focus:ring-red-500 focus:border-red-500 dark:border-red-500' : 'border-gray-300 dark:border-gray-600 focus:ring-indigo-500 focus:border-indigo-500'}`}
|
||||
/>
|
||||
{getFieldError('name') && <p className="mt-1 text-xs text-red-600">{getFieldError('name')}</p>}
|
||||
{getFieldError('name') && <p className="mt-1 text-xs text-red-600 dark:text-red-400">{getFieldError('name')}</p>}
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div>
|
||||
<label htmlFor="email" className="block text-sm font-medium text-gray-700">
|
||||
<label htmlFor="email" className="block text-sm font-medium text-gray-700 dark:text-gray-300">
|
||||
E-Mail-Adresse
|
||||
</label>
|
||||
<div className="mt-1">
|
||||
@ -150,14 +147,14 @@ const SignUpPage: NextPage<SignUpPageProps> = () => {
|
||||
required
|
||||
value={email}
|
||||
onChange={(e) => setEmail(e.target.value)}
|
||||
className={`appearance-none text-black block w-full px-3 py-2 border rounded-md shadow-sm placeholder-gray-400 focus:outline-none sm:text-sm ${getFieldError('email') ? 'border-red-500 focus:ring-red-500 focus:border-red-500' : 'border-gray-300 focus:ring-indigo-500 focus:border-indigo-500'}`}
|
||||
className={`appearance-none block w-full px-3 py-2 border rounded-md shadow-sm placeholder-gray-400 dark:placeholder-gray-500 focus:outline-none sm:text-sm bg-white dark:bg-slate-700 text-gray-900 dark:text-gray-100 ${getFieldError('email') ? 'border-red-500 focus:ring-red-500 focus:border-red-500 dark:border-red-500' : 'border-gray-300 dark:border-gray-600 focus:ring-indigo-500 focus:border-indigo-500'}`}
|
||||
/>
|
||||
{getFieldError('email') && <p className="mt-1 text-xs text-red-600">{getFieldError('email')}</p>}
|
||||
{getFieldError('email') && <p className="mt-1 text-xs text-red-600 dark:text-red-400">{getFieldError('email')}</p>}
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div>
|
||||
<label htmlFor="password" className="block text-sm font-medium text-gray-700">
|
||||
<label htmlFor="password" className="block text-sm font-medium text-gray-700 dark:text-gray-300">
|
||||
Passwort (min. 6 Zeichen)
|
||||
</label>
|
||||
<div className="mt-1">
|
||||
@ -169,14 +166,14 @@ const SignUpPage: NextPage<SignUpPageProps> = () => {
|
||||
required
|
||||
value={password}
|
||||
onChange={(e) => setPassword(e.target.value)}
|
||||
className={`appearance-none text-black block w-full px-3 py-2 border rounded-md shadow-sm placeholder-gray-400 focus:outline-none sm:text-sm ${getFieldError('password') ? 'border-red-500 focus:ring-red-500 focus:border-red-500' : 'border-gray-300 focus:ring-indigo-500 focus:border-indigo-500'}`}
|
||||
className={`appearance-none block w-full px-3 py-2 border rounded-md shadow-sm placeholder-gray-400 dark:placeholder-gray-500 focus:outline-none sm:text-sm bg-white dark:bg-slate-700 text-gray-900 dark:text-gray-100 ${getFieldError('password') ? 'border-red-500 focus:ring-red-500 focus:border-red-500 dark:border-red-500' : 'border-gray-300 dark:border-gray-600 focus:ring-indigo-500 focus:border-indigo-500'}`}
|
||||
/>
|
||||
{getFieldError('password') && <p className="mt-1 text-xs text-red-600">{getFieldError('password')}</p>}
|
||||
{getFieldError('password') && <p className="mt-1 text-xs text-red-600 dark:text-red-400">{getFieldError('password')}</p>}
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div>
|
||||
<label htmlFor="confirmPassword" className="block text-sm font-medium text-gray-700">
|
||||
<label htmlFor="confirmPassword" className="block text-sm font-medium text-gray-700 dark:text-gray-300">
|
||||
Passwort bestätigen
|
||||
</label>
|
||||
<div className="mt-1">
|
||||
@ -188,7 +185,7 @@ const SignUpPage: NextPage<SignUpPageProps> = () => {
|
||||
required
|
||||
value={confirmPassword}
|
||||
onChange={(e) => setConfirmPassword(e.target.value)}
|
||||
className="appearance-none text-black block w-full px-3 py-2 border border-gray-300 rounded-md shadow-sm placeholder-gray-400 focus:outline-none focus:ring-indigo-500 focus:border-indigo-500 sm:text-sm"
|
||||
className="appearance-none block w-full px-3 py-2 border border-gray-300 dark:border-gray-600 rounded-md shadow-sm placeholder-gray-400 dark:placeholder-gray-500 focus:outline-none focus:ring-indigo-500 focus:border-indigo-500 sm:text-sm bg-white dark:bg-slate-700 text-gray-900 dark:text-gray-100"
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
@ -197,7 +194,7 @@ const SignUpPage: NextPage<SignUpPageProps> = () => {
|
||||
<button
|
||||
type="submit"
|
||||
disabled={isLoading}
|
||||
className="w-full flex justify-center py-2 px-4 border border-transparent rounded-md shadow-sm text-sm font-medium text-white bg-indigo-600 hover:bg-indigo-700 focus:outline-none focus:ring-2 focus:ring-offset-2 focus:ring-indigo-500 disabled:opacity-50"
|
||||
className="w-full flex justify-center py-2 px-4 border border-transparent rounded-md shadow-sm text-sm font-medium text-white bg-indigo-600 hover:bg-indigo-700 focus:outline-none focus:ring-2 focus:ring-offset-2 focus:ring-indigo-500 disabled:opacity-50 dark:bg-indigo-500 dark:hover:bg-indigo-600"
|
||||
>
|
||||
{isLoading ? 'Registrieren...' : 'Konto erstellen'}
|
||||
</button>
|
||||
@ -207,17 +204,17 @@ const SignUpPage: NextPage<SignUpPageProps> = () => {
|
||||
<div className="mt-6">
|
||||
<div className="relative">
|
||||
<div className="absolute inset-0 flex items-center">
|
||||
<div className="w-full border-t border-gray-300" />
|
||||
<div className="w-full border-t border-gray-300 dark:border-gray-600" />
|
||||
</div>
|
||||
<div className="relative flex justify-center text-sm">
|
||||
<span className="px-2 bg-white text-gray-500">Oder</span>
|
||||
<span className="px-2 bg-white dark:bg-slate-800 text-gray-500 dark:text-gray-400">Oder</span>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div className="mt-6 text-center">
|
||||
<p className="text-sm text-gray-600">
|
||||
<p className="text-sm text-gray-600 dark:text-gray-400">
|
||||
Bereits ein Konto?{' '}
|
||||
<Link href="/auth/signin" className="font-medium text-indigo-600 hover:text-indigo-500">
|
||||
<Link href="/auth/signin" className="font-medium text-indigo-600 hover:text-indigo-500 dark:text-indigo-400 dark:hover:text-indigo-300">
|
||||
Hier anmelden
|
||||
</Link>
|
||||
</p>
|
||||
@ -229,8 +226,6 @@ const SignUpPage: NextPage<SignUpPageProps> = () => {
|
||||
);
|
||||
};
|
||||
|
||||
// Serverseitige Prüfung, ob der Benutzer bereits angemeldet ist.
|
||||
// Wenn ja, direkt zum Dashboard weiterleiten.
|
||||
export const getServerSideProps: GetServerSideProps<SignUpPageProps> = async (context) => {
|
||||
const session = await getSession(context);
|
||||
if (session) {
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user