mirror of
https://github.com/clucraft/PriceGhost.git
synced 2026-05-04 21:32:40 +02:00
Hide sign up link when registration is disabled
- Check registration status on login page load - Only show sign up link if registration is enabled Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
parent
afda0b3f01
commit
0a762eba76
1 changed files with 19 additions and 11 deletions
|
|
@ -1,5 +1,6 @@
|
|||
import { useState, useEffect, FormEvent } from 'react';
|
||||
import { Link } from 'react-router-dom';
|
||||
import { authApi } from '../api/client';
|
||||
|
||||
interface AuthFormProps {
|
||||
mode: 'login' | 'register';
|
||||
|
|
@ -12,6 +13,7 @@ export default function AuthForm({ mode, onSubmit }: AuthFormProps) {
|
|||
const [confirmPassword, setConfirmPassword] = useState('');
|
||||
const [error, setError] = useState('');
|
||||
const [isLoading, setIsLoading] = useState(false);
|
||||
const [registrationEnabled, setRegistrationEnabled] = useState<boolean | null>(null);
|
||||
const [theme, setTheme] = useState<'light' | 'dark'>(() => {
|
||||
const saved = localStorage.getItem('theme');
|
||||
return (saved as 'light' | 'dark') || 'light';
|
||||
|
|
@ -22,6 +24,13 @@ export default function AuthForm({ mode, onSubmit }: AuthFormProps) {
|
|||
localStorage.setItem('theme', theme);
|
||||
}, [theme]);
|
||||
|
||||
useEffect(() => {
|
||||
// Check if registration is enabled
|
||||
authApi.getRegistrationStatus()
|
||||
.then(res => setRegistrationEnabled(res.data.registration_enabled))
|
||||
.catch(() => setRegistrationEnabled(true)); // Default to true on error
|
||||
}, []);
|
||||
|
||||
const toggleTheme = () => {
|
||||
setTheme((prev) => (prev === 'light' ? 'dark' : 'light'));
|
||||
};
|
||||
|
|
@ -206,17 +215,16 @@ export default function AuthForm({ mode, onSubmit }: AuthFormProps) {
|
|||
</button>
|
||||
</form>
|
||||
|
||||
<div className="auth-form-footer">
|
||||
{mode === 'login' ? (
|
||||
<>
|
||||
Don't have an account? <Link to="/register">Sign up</Link>
|
||||
</>
|
||||
) : (
|
||||
<>
|
||||
Already have an account? <Link to="/login">Sign in</Link>
|
||||
</>
|
||||
)}
|
||||
</div>
|
||||
{mode === 'login' && registrationEnabled && (
|
||||
<div className="auth-form-footer">
|
||||
Don't have an account? <Link to="/register">Sign up</Link>
|
||||
</div>
|
||||
)}
|
||||
{mode === 'register' && (
|
||||
<div className="auth-form-footer">
|
||||
Already have an account? <Link to="/login">Sign in</Link>
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue