Add Spanish/English languaje
This commit is contained in:
@@ -2,11 +2,14 @@ import { useState, useEffect } from 'react';
|
||||
import axios from 'axios';
|
||||
import { Car, Clock, CheckCircle, AlertCircle, Users, Trash2, PlusCircle, UserPlus, AlertTriangle } from 'lucide-react';
|
||||
import io from 'socket.io-client';
|
||||
import { useTranslation } from 'react-i18next';
|
||||
import LanguageSelector from '../components/LanguageSelector';
|
||||
|
||||
const API_URL = import.meta.env.VITE_API_URL || 'http://localhost:3000';
|
||||
const socket = io(API_URL);
|
||||
|
||||
function UserDashboard({ token, username }) {
|
||||
const { t } = useTranslation();
|
||||
const [plates, setPlates] = useState([]);
|
||||
const [newPlate, setNewPlate] = useState({ number: '', owner: '' });
|
||||
const [detections, setDetections] = useState([]);
|
||||
@@ -91,7 +94,7 @@ function UserDashboard({ token, username }) {
|
||||
};
|
||||
|
||||
const handleDeletePlate = async (id) => {
|
||||
if (!confirm('Are you sure you want to delete this plate?')) return;
|
||||
if (!confirm(t('confirm_delete_plate'))) return;
|
||||
try {
|
||||
await axios.delete(`${API_URL}/api/plates/${id}`, {
|
||||
headers: { Authorization: `Bearer ${token}` }
|
||||
@@ -103,7 +106,7 @@ function UserDashboard({ token, username }) {
|
||||
};
|
||||
|
||||
const handleDeletePerson = async (id) => {
|
||||
if (!confirm('Are you sure you want to delete this visitor?')) return;
|
||||
if (!confirm(t('confirm_delete_visitor'))) return;
|
||||
try {
|
||||
await axios.delete(`${API_URL}/api/people/${id}`, {
|
||||
headers: { Authorization: `Bearer ${token}` }
|
||||
@@ -118,48 +121,51 @@ function UserDashboard({ token, username }) {
|
||||
<div className="min-h-screen bg-slate-900 text-slate-100 p-8">
|
||||
<div className="max-w-6xl mx-auto space-y-8">
|
||||
|
||||
<header>
|
||||
<h1 className="text-3xl font-bold bg-gradient-to-r from-blue-400 to-cyan-300 bg-clip-text text-transparent mb-2">
|
||||
Welcome, {username}
|
||||
</h1>
|
||||
<p className="text-slate-400">Manage your vehicles and visitors.</p>
|
||||
<header className="flex justify-between items-center">
|
||||
<div>
|
||||
<h1 className="text-3xl font-bold bg-gradient-to-r from-blue-400 to-cyan-300 bg-clip-text text-transparent mb-2">
|
||||
{t('welcome')}, {username}
|
||||
</h1>
|
||||
<p className="text-slate-400">Manage your vehicles and visitors.</p>
|
||||
</div>
|
||||
<LanguageSelector />
|
||||
</header>
|
||||
|
||||
<div className="grid grid-cols-1 lg:grid-cols-2 gap-8">
|
||||
{/* Plate Registration Form (Existing) */}
|
||||
<div className="bg-slate-800 rounded-2xl p-6 border border-slate-700">
|
||||
<h2 className="text-xl font-bold mb-4 flex items-center gap-2">
|
||||
<PlusCircle className="text-blue-500" /> Register New Plate
|
||||
<PlusCircle className="text-blue-500" /> {t('register_plate')}
|
||||
</h2>
|
||||
<form onSubmit={handleRegister} className="space-y-4">
|
||||
<input
|
||||
className="w-full bg-slate-900 border border-slate-700 rounded-lg p-3 font-mono text-lg"
|
||||
placeholder="Plate Number (e.g. AA-BB-11)"
|
||||
placeholder={t('plate_number')}
|
||||
value={newPlate.number}
|
||||
onChange={e => setNewPlate({ ...newPlate, number: e.target.value.toUpperCase() })}
|
||||
required
|
||||
/>
|
||||
<input
|
||||
className="w-full bg-slate-900 border border-slate-700 rounded-lg p-3"
|
||||
placeholder="Owner / Description"
|
||||
placeholder={t('owner_desc')}
|
||||
value={newPlate.owner}
|
||||
onChange={e => setNewPlate({ ...newPlate, owner: e.target.value })}
|
||||
required
|
||||
/>
|
||||
<button className="w-full py-3 bg-blue-600 hover:bg-blue-500 rounded-lg font-bold">Register Plate</button>
|
||||
<button className="w-full py-3 bg-blue-600 hover:bg-blue-500 rounded-lg font-bold">{t('submit_plate')}</button>
|
||||
</form>
|
||||
</div>
|
||||
|
||||
{/* Visitor Registration Form (Existing) */}
|
||||
<div className="bg-slate-800 rounded-2xl p-6 border border-slate-700">
|
||||
<h2 className="text-xl font-bold mb-4 flex items-center gap-2">
|
||||
<UserPlus className="text-purple-500" /> Register Visitor
|
||||
<UserPlus className="text-purple-500" /> {t('register_visitor')}
|
||||
</h2>
|
||||
<form onSubmit={handleAddPerson} className="space-y-4">
|
||||
<div className="grid grid-cols-2 gap-4">
|
||||
<input
|
||||
className="bg-slate-900 border border-slate-700 rounded-lg p-3"
|
||||
placeholder="RUT (12345678-9)"
|
||||
placeholder={t('visitor_rut')}
|
||||
value={newPerson.rut}
|
||||
onChange={e => setNewPerson({ ...newPerson, rut: e.target.value })}
|
||||
required
|
||||
@@ -170,26 +176,26 @@ function UserDashboard({ token, username }) {
|
||||
onChange={e => setNewPerson({ ...newPerson, durationDays: parseInt(e.target.value) })}
|
||||
required
|
||||
>
|
||||
<option value="1">1 Day Access</option>
|
||||
<option value="2">2 Days Access</option>
|
||||
<option value="7">1 Week Access</option>
|
||||
<option value="1">{t('1_day')}</option>
|
||||
<option value="2">{t('2_days')}</option>
|
||||
<option value="7">{t('1_week')}</option>
|
||||
</select>
|
||||
</div>
|
||||
<input
|
||||
className="w-full bg-slate-900 border border-slate-700 rounded-lg p-3"
|
||||
placeholder="Full Name"
|
||||
placeholder={t('full_name')}
|
||||
value={newPerson.name}
|
||||
onChange={e => setNewPerson({ ...newPerson, name: e.target.value })}
|
||||
required
|
||||
/>
|
||||
<button className="w-full py-3 bg-purple-600 hover:bg-purple-500 rounded-lg font-bold">Register Visitor</button>
|
||||
<button className="w-full py-3 bg-purple-600 hover:bg-purple-500 rounded-lg font-bold">{t('submit_visitor')}</button>
|
||||
</form>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{/* My Plates List */}
|
||||
<div>
|
||||
<h2 className="text-2xl font-bold mb-4">My Registered Plates</h2>
|
||||
<h2 className="text-2xl font-bold mb-4">{t('my_plates_title')}</h2>
|
||||
<div className="grid grid-cols-1 md:grid-cols-2 lg:grid-cols-3 gap-4">
|
||||
{plates.length === 0 && <p className="text-slate-500 col-span-3">No plates registered.</p>}
|
||||
{plates.map(plate => (
|
||||
@@ -201,23 +207,23 @@ function UserDashboard({ token, username }) {
|
||||
<div className="flex items-center gap-3">
|
||||
{plate.status === 'ALLOWED' && (
|
||||
<span className="flex items-center gap-1 text-green-400 bg-green-900/30 px-3 py-1 rounded-full text-xs font-bold">
|
||||
<CheckCircle size={14} /> ACTIVE
|
||||
<CheckCircle size={14} /> {t('active')}
|
||||
</span>
|
||||
)}
|
||||
{plate.status === 'PENDING' && (
|
||||
<span className="flex items-center gap-1 text-yellow-400 bg-yellow-900/30 px-3 py-1 rounded-full text-xs font-bold">
|
||||
<Clock size={14} /> PENDING
|
||||
<Clock size={14} /> {t('pending')}
|
||||
</span>
|
||||
)}
|
||||
{plate.status === 'DENIED' && (
|
||||
<span className="flex items-center gap-1 text-red-400 bg-red-900/30 px-3 py-1 rounded-full text-xs font-bold">
|
||||
<AlertTriangle size={14} /> DENIED
|
||||
<AlertTriangle size={14} /> {t('denied')}
|
||||
</span>
|
||||
)}
|
||||
<button
|
||||
onClick={() => handleDeletePlate(plate.id)}
|
||||
className="text-slate-600 hover:text-red-500 transition-colors p-1"
|
||||
title="Delete Plate"
|
||||
title={t('delete')}
|
||||
>
|
||||
<Trash2 size={18} />
|
||||
</button>
|
||||
@@ -229,7 +235,7 @@ function UserDashboard({ token, username }) {
|
||||
|
||||
{/* My Visitors List */}
|
||||
<div>
|
||||
<h2 className="text-2xl font-bold mb-4">My Visitors</h2>
|
||||
<h2 className="text-2xl font-bold mb-4">{t('my_visitors_title')}</h2>
|
||||
<div className="grid grid-cols-1 md:grid-cols-2 lg:grid-cols-3 gap-4">
|
||||
{people.length === 0 && <p className="text-slate-500 col-span-3">No visitors registered.</p>}
|
||||
{people.map(p => (
|
||||
@@ -241,14 +247,14 @@ function UserDashboard({ token, username }) {
|
||||
</div>
|
||||
<div className="flex items-center gap-3">
|
||||
<span className={`px-2 py-1 rounded text-xs font-bold ${p.status === 'APPROVED' ? 'bg-green-900 text-green-300' :
|
||||
p.status === 'DENIED' ? 'bg-red-900 text-red-300' : 'bg-yellow-900 text-yellow-300'
|
||||
p.status === 'DENIED' ? 'bg-red-900 text-red-300' : 'bg-yellow-900 text-yellow-300'
|
||||
}`}>
|
||||
{p.status}
|
||||
{p.status === 'APPROVED' ? t('approved') : p.status === 'DENIED' ? t('denied') : t('pending')}
|
||||
</span>
|
||||
<button
|
||||
onClick={() => handleDeletePerson(p.id)}
|
||||
className="text-slate-600 hover:text-red-500 transition-colors p-1"
|
||||
title="Delete Visitor"
|
||||
title={t('delete')}
|
||||
>
|
||||
<Trash2 size={18} />
|
||||
</button>
|
||||
|
||||
Reference in New Issue
Block a user