linguagem
This commit is contained in:
374
diff.txt
Normal file
374
diff.txt
Normal file
@@ -0,0 +1,374 @@
|
||||
--- index.html 2026-05-07 09:17:34
|
||||
+++ temp_script.jsx 2026-05-08 09:01:25
|
||||
@@ -40,7 +40,6 @@
|
||||
</script>
|
||||
|
||||
<script src="https://unpkg.com/@babel/standalone/babel.min.js"></script>
|
||||
-
|
||||
<style>
|
||||
@keyframes fadeIn {
|
||||
from {
|
||||
@@ -100,41 +99,10 @@
|
||||
Dumbbell, PartyPopper, Trophy, Map, Calendar, MapPin, Info,
|
||||
MessageCircle, Paperclip, Send
|
||||
} from 'lucide-react';
|
||||
-
|
||||
import { app } from './firebase.js';
|
||||
import { getAuth, signInWithEmailAndPassword, createUserWithEmailAndPassword } from 'https://www.gstatic.com/firebasejs/12.1.0/firebase-auth.js';
|
||||
import { getDatabase, ref, push, set, onValue, remove, update } from 'https://www.gstatic.com/firebasejs/12.1.0/firebase-database.js';
|
||||
|
||||
- class ErrorBoundary extends React.Component {
|
||||
- constructor(props) {
|
||||
- super(props);
|
||||
- this.state = { hasError: false, error: null, errorInfo: null };
|
||||
- }
|
||||
- static getDerivedStateFromError(error) {
|
||||
- return { hasError: true };
|
||||
- }
|
||||
- componentDidCatch(error, errorInfo) {
|
||||
- this.setState({ error, errorInfo });
|
||||
- console.error("ErrorBoundary caught an error:", error, errorInfo);
|
||||
- }
|
||||
- render() {
|
||||
- if (this.state.hasError) {
|
||||
- return (
|
||||
- <div style={{ padding: '20px', backgroundColor: '#fee2e2', color: '#991b1b', fontFamily: 'sans-serif', height: '100vh' }}>
|
||||
- <h1 style={{ fontSize: '24px', fontWeight: 'bold' }}>Algo correu mal (Erro na Aplicação)</h1>
|
||||
- <pre style={{ marginTop: '20px', whiteSpace: 'pre-wrap', backgroundColor: '#fef2f2', padding: '15px', border: '1px solid #f87171' }}>
|
||||
- {this.state.error && this.state.error.toString()}
|
||||
- <br />
|
||||
- {this.state.errorInfo && this.state.errorInfo.componentStack}
|
||||
- </pre>
|
||||
- <button onClick={() => window.location.reload()} style={{ marginTop: '20px', padding: '10px 20px', backgroundColor: '#dc2626', color: 'white', border: 'none', borderRadius: '5px', cursor: 'pointer' }}>Recarregar Página</button>
|
||||
- </div>
|
||||
- );
|
||||
- }
|
||||
- return this.props.children;
|
||||
- }
|
||||
- }
|
||||
-
|
||||
const auth = getAuth(app);
|
||||
const db = getDatabase(app);
|
||||
|
||||
@@ -341,23 +309,12 @@
|
||||
const [email, setEmail] = useState('');
|
||||
const [password, setPassword] = useState('');
|
||||
const [error, setError] = useState('');
|
||||
- const [isLoading, setIsLoading] = useState(false);
|
||||
|
||||
const handleSubmit = async (e) => {
|
||||
e.preventDefault();
|
||||
- if (isLoading) return;
|
||||
-
|
||||
- setError('');
|
||||
- setIsLoading(true);
|
||||
-
|
||||
const success = await onLogin(email, password);
|
||||
-
|
||||
- setIsLoading(false);
|
||||
if (!success) {
|
||||
setError('Email ou Palavra-passe incorreta');
|
||||
- setTimeout(() => {
|
||||
- setError('');
|
||||
- }, 5000);
|
||||
}
|
||||
};
|
||||
|
||||
@@ -403,15 +360,8 @@
|
||||
</div>
|
||||
)}
|
||||
<div className="space-y-4">
|
||||
- <button type="submit" disabled={isLoading} className={`w-full ${isLoading ? 'bg-blue-400 dark:bg-blue-600/50 cursor-not-allowed' : 'bg-blue-600 hover:bg-blue-700 shadow-lg shadow-blue-500/30'} text-white font-bold py-3 rounded-lg transition-colors flex justify-center items-center gap-2`}>
|
||||
- {isLoading ? (
|
||||
- <>
|
||||
- <div className="w-5 h-5 border-2 border-white/30 border-t-white rounded-full animate-spin"></div>
|
||||
- A entrar...
|
||||
- </>
|
||||
- ) : (
|
||||
- 'Entrar'
|
||||
- )}
|
||||
+ <button type="submit" className="w-full bg-blue-600 hover:bg-blue-700 text-white font-bold py-3 rounded-lg transition-colors shadow-lg shadow-blue-500/30">
|
||||
+ Entrar
|
||||
</button>
|
||||
</div>
|
||||
</form>
|
||||
@@ -490,7 +440,7 @@
|
||||
userId = 'admin_001';
|
||||
} else {
|
||||
const residentUser = residents.find(r => r.email && r.email.toLowerCase() === email.toLowerCase());
|
||||
- if (residentUser && (password === residentUser.password || password === '1234')) {
|
||||
+ if (residentUser && (password === residentUser.contact || password === '1234')) {
|
||||
role = residentUser.role || 'morador';
|
||||
userName = residentUser.name + (residentUser.unit && residentUser.unit !== 'Pendente' ? ` (${residentUser.unit})` : '');
|
||||
userId = residentUser.id || userId;
|
||||
@@ -550,17 +500,7 @@
|
||||
return onValue(ref(db, path), (snapshot) => {
|
||||
const data = snapshot.val();
|
||||
if (data) {
|
||||
- let parsed = Object.entries(data).map(([id, val]) => {
|
||||
- if (path === 'faturas' && val.status === 'Em Validação') {
|
||||
- return { id, ...val, status: 'Pago' };
|
||||
- }
|
||||
- return { id, ...val };
|
||||
- });
|
||||
-
|
||||
- if (userRole !== 'admin' && (path === 'manutencao' || path === 'reservas')) {
|
||||
- parsed = parsed.filter(item => item.moradorId === currentUserId);
|
||||
- }
|
||||
-
|
||||
+ let parsed = Object.entries(data).map(([id, val]) => ({ id, ...val }));
|
||||
if (sortFunc) parsed = parsed.sort(sortFunc);
|
||||
setter(parsed);
|
||||
} else {
|
||||
@@ -781,8 +721,7 @@
|
||||
try {
|
||||
if (editingItem) {
|
||||
const residentRef = ref(db, `condominos/${editingItem.id}`);
|
||||
- const updatedData = {
|
||||
- ...editingItem,
|
||||
+ await set(residentRef, {
|
||||
unit: formData.unit || '',
|
||||
name: formData.name || '',
|
||||
contact: formData.contact || '',
|
||||
@@ -790,11 +729,7 @@
|
||||
status: formData.status || 'Pago',
|
||||
pending: Number(formData.pending) || 0,
|
||||
role: formData.role || 'morador'
|
||||
- };
|
||||
- if (formData.password) {
|
||||
- updatedData.password = formData.password;
|
||||
- }
|
||||
- await set(residentRef, updatedData);
|
||||
+ });
|
||||
showNotification(`Condómino ${formData.name} atualizado`);
|
||||
} else {
|
||||
const residentsListRef = ref(db, 'condominos');
|
||||
@@ -804,7 +739,6 @@
|
||||
name: formData.name || '',
|
||||
contact: formData.contact || '',
|
||||
email: formData.email || '',
|
||||
- password: formData.password || '1234',
|
||||
status: formData.status || 'Pago',
|
||||
pending: Number(formData.pending) || 0,
|
||||
role: formData.role || 'morador'
|
||||
@@ -864,7 +798,7 @@
|
||||
}
|
||||
try {
|
||||
const newIssueRef = push(ref(db, 'manutencao'));
|
||||
- await set(newIssueRef, { ...formData, moradorId: currentUserId });
|
||||
+ await set(newIssueRef, { ...formData });
|
||||
|
||||
sendSystemNotification(`Nova ocorrência reportada: ${formData.title} (${formData.location})`, 'warning', 'admin');
|
||||
if (userRole !== 'admin') {
|
||||
@@ -918,17 +852,10 @@
|
||||
|
||||
const handlePayFatura = async (fatura) => {
|
||||
try {
|
||||
- await set(ref(db, `faturas/${fatura.id}/status`), 'Pago');
|
||||
-
|
||||
- const morador = residents.find(r => r.id === fatura.moradorId);
|
||||
- if (morador) {
|
||||
- let newPending = (Number(morador.pending) || 0) - Number(fatura.valor);
|
||||
- if (newPending < 0) newPending = 0;
|
||||
- await set(ref(db, `condominos/${morador.id}/pending`), newPending);
|
||||
- }
|
||||
- sendSystemNotification(`O pagamento da sua fatura de ${fatura.categoria} foi concluído!`, 'success', fatura.moradorId);
|
||||
- sendSystemNotification(`Pagamento registado para a fatura de ${fatura.categoria} da fração ${morador?.unit || fatura.fracao}.`, 'success', 'admin');
|
||||
- showNotification("Pagamento efetuado com sucesso!", "success");
|
||||
+ await set(ref(db, `faturas/${fatura.id}/status`), 'Em Validação');
|
||||
+ sendSystemNotification(`O pagamento da sua fatura de ${fatura.categoria} foi submetido. Aguarda validação.`, 'info', fatura.moradorId);
|
||||
+ sendSystemNotification(`Comprovativo recebido da fração ${fatura.fracao}.`, 'info', 'admin');
|
||||
+ showNotification("Comprovativo enviado! A aguardar validação do administrador.", "success");
|
||||
} catch (error) {
|
||||
console.error("Erro ao pagar fatura:", error);
|
||||
showNotification("Erro ao processar pagamento.", "error");
|
||||
@@ -979,8 +906,7 @@
|
||||
const bookingData = {
|
||||
...formData,
|
||||
facilityName: facilityNames[formData.facility],
|
||||
- status: 'Confirmado',
|
||||
- moradorId: currentUserId
|
||||
+ status: 'Confirmado'
|
||||
};
|
||||
|
||||
const newBookingRef = push(ref(db, 'reservas'));
|
||||
@@ -1289,74 +1215,7 @@
|
||||
|
||||
const ProfileView = ({ theme, setTheme }) => {
|
||||
const [activeSection, setActiveSection] = useState('personal');
|
||||
-
|
||||
- const isMorador = userRole !== 'admin';
|
||||
- const [formData, setFormData] = useState({
|
||||
- name: 'A carregar...',
|
||||
- role: '...',
|
||||
- email: '',
|
||||
- contact: '',
|
||||
- address: ''
|
||||
- });
|
||||
|
||||
- useEffect(() => {
|
||||
- if (isMorador) {
|
||||
- const currentUserData = residents.find(r => r.id === currentUserId) || {};
|
||||
- setFormData({
|
||||
- name: currentUserData.name || currentUserName || '',
|
||||
- role: `Fração ${currentUserData.unit || 'N/A'}`,
|
||||
- email: currentUserData.email || '',
|
||||
- contact: currentUserData.contact || '',
|
||||
- address: 'Morada do Condomínio'
|
||||
- });
|
||||
- } else {
|
||||
- const adminRef = ref(db, 'configuracoes/admin_profile');
|
||||
- const unsub = onValue(adminRef, (snapshot) => {
|
||||
- if (snapshot.exists()) {
|
||||
- setFormData(snapshot.val());
|
||||
- } else {
|
||||
- setFormData({
|
||||
- name: 'Administrador do Condomínio',
|
||||
- role: 'Síndico / Gestor',
|
||||
- email: 'admin@mycondominium.pt',
|
||||
- contact: '+351 912 345 678',
|
||||
- address: 'Rua das Flores, nº 123, Escritório 2B'
|
||||
- });
|
||||
- }
|
||||
- });
|
||||
- return () => unsub();
|
||||
- }
|
||||
- }, [residents, currentUserId, userRole, currentUserName, isMorador]);
|
||||
-
|
||||
- const handleChange = (field, value) => {
|
||||
- setFormData(prev => ({ ...prev, [field]: value }));
|
||||
- };
|
||||
-
|
||||
- const handleSave = async () => {
|
||||
- if (isMorador) {
|
||||
- const currentUserData = residents.find(r => r.id === currentUserId);
|
||||
- if (currentUserData && currentUserData.id) {
|
||||
- try {
|
||||
- await set(ref(db, `condominos/${currentUserData.id}/email`), formData.email);
|
||||
- await set(ref(db, `condominos/${currentUserData.id}/contact`), formData.contact);
|
||||
- showNotification('Dados atualizados com sucesso!', 'success');
|
||||
- sendSystemNotification('Um utilizador atualizou os seus dados pessoais.', 'info', 'admin');
|
||||
- } catch (error) {
|
||||
- console.error("Erro ao guardar os dados:", error);
|
||||
- showNotification('Erro ao guardar os dados.', 'error');
|
||||
- }
|
||||
- }
|
||||
- } else {
|
||||
- try {
|
||||
- await set(ref(db, 'configuracoes/admin_profile'), formData);
|
||||
- showNotification('Alterações guardadas com sucesso!', 'success');
|
||||
- } catch (error) {
|
||||
- console.error("Erro ao guardar perfil admin:", error);
|
||||
- showNotification('Erro ao guardar as alterações.', 'error');
|
||||
- }
|
||||
- }
|
||||
- };
|
||||
-
|
||||
return (
|
||||
<div className="bg-white dark:bg-dark-surface rounded-xl shadow-sm border border-slate-100 dark:border-dark-border overflow-hidden animate-fade-in flex flex-col h-full transition-colors">
|
||||
<div className="flex flex-col md:flex-row h-full">
|
||||
@@ -1405,16 +1264,19 @@
|
||||
<h3 className="text-lg font-bold text-slate-800 dark:text-white mb-6 pb-2 border-b border-slate-100 dark:border-dark-border">Dados Pessoais</h3>
|
||||
<div className="space-y-4">
|
||||
<div className="grid grid-cols-1 md:grid-cols-2 gap-4">
|
||||
- <InputGroup label="Nome Completo" value={formData.name} onChange={(e) => handleChange('name', e.target.value)} disabled={isMorador} />
|
||||
- <InputGroup label={isMorador ? "Fração" : "Cargo"} value={formData.role} onChange={(e) => handleChange('role', e.target.value)} disabled={isMorador} />
|
||||
+ <InputGroup label="Nome Completo" value="Administrador do Condomínio" disabled />
|
||||
+ <InputGroup label="Cargo" value="Síndico / Gestor" disabled />
|
||||
</div>
|
||||
<div className="grid grid-cols-1 md:grid-cols-2 gap-4">
|
||||
- <InputGroup label="Email" value={formData.email} onChange={(e) => handleChange('email', e.target.value)} type="email" />
|
||||
- <InputGroup label="Telefone" value={formData.contact} onChange={(e) => handleChange('contact', e.target.value)} />
|
||||
+ <InputGroup label="Email" value="admin@mycondominium.pt" type="email" />
|
||||
+ <InputGroup label="Telefone" value="+351 912 345 678" />
|
||||
</div>
|
||||
- <InputGroup label={isMorador ? "Morada" : "Morada (Sede)"} value={formData.address} onChange={(e) => handleChange('address', e.target.value)} disabled={isMorador} />
|
||||
+ <InputGroup label="Morada (Sede)" value="Rua das Flores, nº 123, Escritório 2B" />
|
||||
<div className="flex justify-end mt-6">
|
||||
- <button onClick={handleSave} className="bg-blue-600 text-white px-6 py-2 rounded-lg font-medium hover:bg-blue-700 shadow-sm transition-colors">
|
||||
+ <button onClick={() => {
|
||||
+ showNotification('Alterações guardadas com sucesso!', 'success');
|
||||
+ sendSystemNotification('Um utilizador atualizou os seus dados pessoais.', 'info', 'admin');
|
||||
+ }} className="bg-blue-600 text-white px-6 py-2 rounded-lg font-medium hover:bg-blue-700 shadow-sm transition-colors">
|
||||
Guardar Alterações
|
||||
</button>
|
||||
</div>
|
||||
@@ -2038,6 +1900,10 @@
|
||||
>
|
||||
Pagar
|
||||
</button>
|
||||
+ ) : fatura.status === 'Em Validação' ? (
|
||||
+ <span className="text-orange-500 text-xs font-bold flex items-center justify-center gap-1">
|
||||
+ <Clock size={14} /> Em Validação
|
||||
+ </span>
|
||||
) : (
|
||||
<span className="text-slate-400 text-xs font-bold flex items-center justify-center gap-1">
|
||||
<CheckCircle size={14} /> Pago
|
||||
@@ -2090,32 +1956,12 @@
|
||||
<h3 className="font-bold text-lg text-slate-800 dark:text-white">Diário Financeiro</h3>
|
||||
<span className="text-xs bg-slate-100 dark:bg-dark-bg text-slate-600 dark:text-slate-400 px-2 py-1 rounded-full">{finances.length} movimentos</span>
|
||||
</div>
|
||||
- <div className="flex items-center gap-3">
|
||||
- {finances.length === 0 && (
|
||||
- <button
|
||||
- onClick={async () => {
|
||||
- try {
|
||||
- for (const item of INITIAL_FINANCES) {
|
||||
- await set(push(ref(db, 'financas')), item);
|
||||
- }
|
||||
- showNotification("Dados de exemplo restaurados com sucesso!", "success");
|
||||
- } catch (error) {
|
||||
- console.error("Erro ao restaurar:", error);
|
||||
- showNotification("Erro ao restaurar.", "error");
|
||||
- }
|
||||
- }}
|
||||
- className="bg-orange-500 text-white px-4 py-2 rounded-lg text-sm font-medium hover:bg-orange-600 transition-colors shadow-sm flex items-center gap-2"
|
||||
- >
|
||||
- <Wrench size={16} /> Restaurar Base de Dados
|
||||
- </button>
|
||||
- )}
|
||||
- <button
|
||||
- onClick={() => handleOpenModal('finance')}
|
||||
- className="bg-slate-900 dark:bg-slate-700 text-white px-4 py-2 rounded-lg text-sm font-medium hover:bg-slate-800 dark:hover:bg-slate-600 flex items-center gap-2 shadow-lg hover:shadow-xl transition-all"
|
||||
- >
|
||||
- <Plus size={18} /> Novo Registo
|
||||
- </button>
|
||||
- </div>
|
||||
+ <button
|
||||
+ onClick={() => handleOpenModal('finance')}
|
||||
+ className="bg-slate-900 dark:bg-slate-700 text-white px-4 py-2 rounded-lg text-sm font-medium hover:bg-slate-800 dark:hover:bg-slate-600 flex items-center gap-2 shadow-lg hover:shadow-xl transition-all"
|
||||
+ >
|
||||
+ <Plus size={18} /> Novo Registo
|
||||
+ </button>
|
||||
</div>
|
||||
<div className="overflow-auto flex-1">
|
||||
<table className="w-full text-sm text-left">
|
||||
@@ -2344,11 +2190,8 @@
|
||||
<InputGroup label="Fração" name="unit" value={formData.unit || ''} onChange={handleInputChange} placeholder="Ex: 1º Esq" required />
|
||||
<InputGroup label="Nome Completo" name="name" value={formData.name || ''} onChange={handleInputChange} placeholder="Nome do proprietário" required />
|
||||
<InputGroup label="Email" type="email" name="email" value={formData.email || ''} onChange={handleInputChange} placeholder="email@exemplo.com" />
|
||||
+ <InputGroup label="Contacto" name="contact" value={formData.contact || ''} onChange={handleInputChange} placeholder="912 345 678" />
|
||||
<div className="grid grid-cols-2 gap-4">
|
||||
- <InputGroup label="Telemóvel" name="contact" value={formData.contact || ''} onChange={handleInputChange} placeholder="912 345 678" required />
|
||||
- <InputGroup label="Palavra-passe" type="text" name="password" value={formData.password || ''} onChange={handleInputChange} placeholder={editingItem ? "Deixar em branco para manter" : "1234"} required={!editingItem} />
|
||||
- </div>
|
||||
- <div className="grid grid-cols-2 gap-4">
|
||||
<InputGroup label="Estado" name="status" value={formData.status || 'Pago'} onChange={handleInputChange} options={[{ value: 'Pago', label: 'Pago' }, { value: 'Pendente', label: 'Pendente' }, { value: 'Atrasado', label: 'Atrasado' }]} />
|
||||
<InputGroup label="Valor Pendente (€)" type="number" name="pending" value={formData.pending || 0} onChange={handleInputChange} />
|
||||
</div>
|
||||
@@ -2492,12 +2335,8 @@
|
||||
}
|
||||
|
||||
const root = createRoot(document.getElementById('root'));
|
||||
- root.render(
|
||||
- <ErrorBoundary>
|
||||
- <App />
|
||||
- </ErrorBoundary>
|
||||
- );
|
||||
+ root.render(<App />);
|
||||
</script>
|
||||
<!-- Firebase configs moved to top in React Module -->
|
||||
</body>
|
||||
-</html>
|
||||
\ No newline at end of file
|
||||
+</html>
|
||||
Reference in New Issue
Block a user