Ligação inicial ao Firebase e criação do formulário de condomínios

This commit is contained in:
2026-04-14 17:15:05 +01:00
parent aa64354c06
commit 58a5649851
4 changed files with 57 additions and 36 deletions

View File

@@ -1,3 +1,3 @@
{
"liveServer.settings.port": 5502
"liveServer.settings.port": 5503
}

16
firebase.js Normal file
View File

@@ -0,0 +1,16 @@
import { initializeApp } from "https://www.gstatic.com/firebasejs/12.1.0/firebase-app.js";
import { getFirestore } from "https://www.gstatic.com/firebasejs/12.1.0/firebase-firestore.js";
const firebaseConfig = {
apiKey: "SUA_API_KEY",
authDomain: "SEU_PROJETO.firebaseapp.com",
projectId: "SEU_PROJECT_ID",
storageBucket: "SEU_PROJETO.appspot.com",
messagingSenderId: "SEU_ID",
appId: "SEU_APP_ID"
};
const app = initializeApp(firebaseConfig);
const db = getFirestore(app);
export { db };

View File

@@ -95,10 +95,10 @@
Building2, Users, Wallet, Wrench, Bell, Search, Plus, Menu, X,
TrendingUp, TrendingDown, CheckCircle, AlertCircle, Clock, LogOut,
Edit2, Trash2, Save, Filter, MoreVertical, FileText,
Dumbbell, PartyPopper, Trophy, Map, Calendar, MapPin, Info
Dumbbell, PartyPopper, Trophy, Map, Calendar, MapPin, Info,
MessageCircle, Paperclip, Send
} from 'lucide-react';
const INITIAL_RESIDENTS = [
{ id: 1, unit: '1º Esq', name: 'Ana Silva', contact: '912 345 678', email: 'ana.silva@email.com', status: 'Pago', pending: 0, role: 'morador' },
{ id: 2, unit: '1º Dto', name: 'Carlos Santos', contact: '965 432 109', email: 'carlos.s@email.com', status: 'Pendente', pending: 45.00, role: 'morador' },
@@ -256,9 +256,9 @@
const [password, setPassword] = useState('');
const [error, setError] = useState('');
const handleSubmit = (e) => {
const handleSubmit = async (e) => {
e.preventDefault();
const success = onLogin(email, password);
const success = await onLogin(email, password);
if (!success) {
setError('Email ou Palavra-passe incorreta');
}
@@ -327,27 +327,46 @@
return sessionStorage.getItem('condo_role') || 'morador';
});
const handleLogin = (email, password) => {
let role = null;
if (email === 'administradores@gmail.com' && password === 'admin123') {
role = 'admin';
} else if (email === 'moradores@gmail.com' && password === 'moradores123') {
role = 'morador';
} else {
const residentUser = residents.find(r => r.email && r.email.toLowerCase() === email.toLowerCase());
if (residentUser && (password === residentUser.contact || password === '1234')) {
role = residentUser.role || 'morador';
const handleLogin = async (email, password) => {
try {
const userCredential = await signInWithEmailAndPassword(auth, email, password);
let role = 'morador';
if (email.toLowerCase().includes('admin')) {
role = 'admin';
} else {
const residentUser = residents.find(r => r.email && r.email.toLowerCase() === email.toLowerCase());
if (residentUser) {
role = residentUser.role || 'morador';
}
}
}
if (role) {
sessionStorage.setItem('condo_auth', 'true');
sessionStorage.setItem('condo_role', role);
setIsAuthenticated(true);
setUserRole(role);
return true;
} catch (error) {
console.log("Firebase Auth falhou, a tentar conta local...", error);
let role = null;
if (email === 'administradores@gmail.com' && password === 'admin123') {
role = 'admin';
} else if (email === 'moradores@gmail.com' && password === 'moradores123') {
role = 'morador';
} else {
const residentUser = residents.find(r => r.email && r.email.toLowerCase() === email.toLowerCase());
if (residentUser && (password === residentUser.contact || password === '1234')) {
role = residentUser.role || 'morador';
}
}
if (role) {
sessionStorage.setItem('condo_auth', 'true');
sessionStorage.setItem('condo_role', role);
setIsAuthenticated(true);
setUserRole(role);
return true;
}
return false;
}
return false;
};
const handleLogout = () => {
@@ -1629,23 +1648,7 @@
const root = createRoot(document.getElementById('root'));
root.render(<App />);
</script>
<script type="module">
import { initializeApp } from "https://www.gstatic.com/firebasejs/12.10.0/firebase-app.js";
import { getAnalytics } from "https://www.gstatic.com/firebasejs/12.10.0/firebase-analytics.js";
const firebaseConfig = {
apiKey: "AIzaSyAQHgVDJWM42HfRzvKTxdVW78Qq48vBb2A",
authDomain: "condomaster-pro-ed9af.firebaseapp.com",
projectId: "condomaster-pro-ed9af",
storageBucket: "condomaster-pro-ed9af.firebasestorage.app",
messagingSenderId: "169472241616",
appId: "1:169472241616:web:8e6074dc4b8a6dce9013d5",
measurementId: "G-2BH2VTW6D5"
};
const app = initializeApp(firebaseConfig);
const analytics = getAnalytics(app);
</script>
<!-- Firebase configs moved to top in React Module -->
</body>
</html>

View File

@@ -490,3 +490,5 @@ function exportPDF(tableId, filename) {
doc.save(filename + '.pdf');
showToast("PDF gerado com sucesso!", "success");
}
import { db } from "./firebase.js";
import { collection, addDoc } from "https://www.gstatic.com/firebasejs/12.1.0/firebase-firestore.js";