admin stuff

This commit is contained in:
Jake Kasper
2025-08-29 08:59:10 -04:00
parent 0cc5372e3d
commit 8c728d42d4
6 changed files with 485 additions and 14 deletions

View File

@@ -1,12 +1,15 @@
import React, { useState } from 'react';
import React, { useState, useEffect } from 'react';
import { Link, useNavigate, useLocation } from 'react-router-dom';
import { useForm } from 'react-hook-form';
import { EyeIcon, EyeSlashIcon } from '@heroicons/react/24/outline';
import { useAuth } from '../../hooks/useAuth';
import LoadingSpinner from '../../components/UI/LoadingSpinner';
import apiClient from '../../services/api';
const Login = () => {
const [showPassword, setShowPassword] = useState(false);
const [registrationEnabled, setRegistrationEnabled] = useState(true);
const [settingsLoading, setSettingsLoading] = useState(true);
const { login, loading } = useAuth();
const navigate = useNavigate();
const location = useLocation();
@@ -20,6 +23,24 @@ const Login = () => {
setError,
} = useForm();
// Fetch registration settings
useEffect(() => {
const fetchRegistrationSetting = async () => {
try {
const response = await apiClient.get('/auth/registration-status');
setRegistrationEnabled(response.data.data.enabled);
} catch (error) {
// If there's an error, default to allowing registration
console.error('Failed to fetch registration setting:', error);
setRegistrationEnabled(true);
} finally {
setSettingsLoading(false);
}
};
fetchRegistrationSetting();
}, []);
const onSubmit = async (data) => {
console.log('Login form submitted:', data.email);
const result = await login(data);
@@ -46,15 +67,17 @@ const Login = () => {
<div className="space-y-6">
<div>
<h2 className="text-2xl font-bold text-gray-900">Sign in to your account</h2>
<p className="mt-2 text-sm text-gray-600">
Or{' '}
<Link
to="/register"
className="font-medium text-primary-600 hover:text-primary-500"
>
create a new account
</Link>
</p>
{!settingsLoading && registrationEnabled && (
<p className="mt-2 text-sm text-gray-600">
Or{' '}
<Link
to="/register"
className="font-medium text-primary-600 hover:text-primary-500"
>
create a new account
</Link>
</p>
)}
</div>
<form className="space-y-6" onSubmit={handleSubmit(onSubmit)}>