import React, { useState, useEffect, useRef } from 'react'; import { initializeApp } from "firebase/app"; import { getAuth, onAuthStateChanged, createUserWithEmailAndPassword, signInWithEmailAndPassword, signOut } from "firebase/auth"; import { getFirestore, collection, doc, setDoc, getDoc, query, where, orderBy, onSnapshot, deleteDoc } from "firebase/firestore"; // --- Firebase Configuration --- // ကျေးဇူးပြု၍ ဤနေရာတွင် သင်၏ Firebase config ကို ထည့်သွင်းပါ const firebaseConfig = { apiKey: "YOUR_API_KEY", authDomain: "YOUR_AUTH_DOMAIN", projectId: "YOUR_PROJECT_ID", storageBucket: "YOUR_STORAGE_BUCKET", messagingSenderId: "YOUR_MESSAGING_SENDER_ID", appId: "YOUR_APP_ID" }; // --- Initialize Firebase --- const app = initializeApp(firebaseConfig); const auth = getAuth(app); const db = getFirestore(app); // --- Main App Component --- export default function App() { const [authState, setAuthState] = useState({ status: 'loading', user: null, isActive: false }); const [currentView, setCurrentView] = useState('home'); // 'home', 'add_edit', 'print' const [selectedJob, setSelectedJob] = useState(null); useEffect(() => { const unsubscribe = onAuthStateChanged(auth, async (user) => { if (user) { // User is logged in, check if their account is active const userDocRef = doc(db, 'users', user.uid); const userDocSnap = await getDoc(userDocRef); if (userDocSnap.exists() && userDocSnap.data().isActive) { setAuthState({ status: 'authenticated', user: user, isActive: true }); } else { setAuthState({ status: 'pending_activation', user: user, isActive: false }); } } else { setAuthState({ status: 'unauthenticated', user: null, isActive: false }); } }); return () => unsubscribe(); }, []); const navigateTo = (view, job = null) => { setSelectedJob(job); setCurrentView(view); }; const renderContent = () => { const { status } = authState; if (status === 'loading') return ; if (status === 'unauthenticated') return ; if (status === 'pending_activation') return ; if (status === 'authenticated') { switch (currentView) { case 'add_edit': return ; case 'print': return ; case 'home': default: return ; } } return ; // Fallback }; return
{renderContent()}
; } // --- Screens/Components --- const SplashScreen = () => (

KZT Mobile Service

Loading...

); const LoginScreen = ({ message }) => { const [email, setEmail] = useState(''); const [password, setPassword] = useState(''); const [error, setError] = useState(message || ''); const [isLoading, setIsLoading] = useState(false); const [isRegister, setIsRegister] = useState(false); const handleAuth = async (e) => { e.preventDefault(); if (!email || !password) { setError('Email နှင့် Password ထည့်သွင်းရန် လိုအပ်ပါသည်'); return; } setIsLoading(true); setError(''); try { if (isRegister) { // Registration Logic if (password !== e.target.confirmPassword.value) { setError('စကားဝှက်များ တူညီမှုမရှိပါ'); setIsLoading(false); return; } const userCredential = await createUserWithEmailAndPassword(auth, email, password); await setDoc(doc(db, "users", userCredential.user.uid), { uid: userCredential.user.uid, email: email, isActive: false, createdAt: new Date(), }); await signOut(auth); alert('Register အောင်မြင်ပါသည်။ Admin activate လုပ်သည်အထိ စောင့်ဆိုင်းပါ။'); setIsRegister(false); } else { // Login Logic await signInWithEmailAndPassword(auth, email, password); } } catch (err) { setError(err.message); } finally { setIsLoading(false); } }; return (

{isRegister ? 'Register ပြုလုပ်ရန်' : 'Login ဝင်ရောက်ရန်'}

setEmail(e.target.value)} placeholder="Email Address" required className="w-full px-4 py-2 text-gray-700 bg-gray-200 rounded-md focus:outline-none focus:ring-2 focus:ring-teal-500" /> setPassword(e.target.value)} placeholder="Password" required className="w-full px-4 py-2 text-gray-700 bg-gray-200 rounded-md focus:outline-none focus:ring-2 focus:ring-teal-500" /> {isRegister && } {error &&

{error}

}
); }; const PendingActivationScreen = () => (

Account Activation Pending

သင်၏ အကောင့်ကို Register ပြုလုပ်ပြီးပါပြီ။ Admin မှ Activate လုပ်ပေးသည်အထိ စောင့်ဆိုင်းပေးပါ။

); const HomePage = ({ navigateTo }) => { const [jobs, setJobs] = useState([]); const [isLoading, setIsLoading] = useState(true); const [searchQuery, setSearchQuery] = useState(''); const userId = auth.currentUser.uid; useEffect(() => { const q = query( collection(db, "service_jobs"), where("userId", "==", userId), orderBy("dateAdded", "desc") ); const unsubscribe = onSnapshot(q, (querySnapshot) => { const jobsData = []; querySnapshot.forEach((doc) => { jobsData.push(ServiceJob.fromMap(doc.data())); }); setJobs(jobsData); setIsLoading(false); }, (error) => { console.error("Error fetching jobs: ", error); setIsLoading(false); }); return () => unsubscribe(); }, [userId]); const filteredJobs = jobs.filter(job => job.customerName.toLowerCase().includes(searchQuery.toLowerCase()) || job.phoneModel.toLowerCase().includes(searchQuery.toLowerCase()) || job.voucherNumber.toLowerCase().includes(searchQuery.toLowerCase()) ); const getStatusColor = (status) => { switch (status) { case 'ပြင်ပြီး': return 'bg-green-500'; case 'ပြင်ဆင်နေဆဲ': return 'bg-orange-500'; case 'ပြင်မရ': return 'bg-red-500'; case 'ပြန်ပေးပြီး': return 'bg-gray-500'; default: return 'bg-gray-500'; } }; const deleteJob = (id) => { if (window.confirm('ဤစာရင်းကို ဖျက်ရန်သေချာလား?')) { deleteDoc(doc(db, "service_jobs", id)); } } return (

Service စာရင်းများ

setSearchQuery(e.target.value)} className="w-full p-2 border rounded-md" />
{isLoading ? (
Loading...
) : (
{filteredJobs.length > 0 ? filteredJobs.map(job => (

{job.customerName}

{job.phoneModel}

{job.problemDescription}

{job.status}

{job.estimatedCost} Ks

Voucher: {job.voucherNumber}

)) : (
စာရင်းများ မရှိသေးပါ။
)}
)}
); }; const AddEditJobPage = ({ job, navigateTo }) => { const [formData, setFormData] = useState({ voucherNumber: job?.voucherNumber || `S-${new Date().getTime().toString().slice(-6)}`, customerName: job?.customerName || '', phoneNumber: job?.phoneNumber || '', phoneModel: job?.phoneModel || '', problemDescription: job?.problemDescription || '', estimatedCost: job?.estimatedCost || 0, status: job?.status || 'ပြင်ဆင်နေဆဲ', }); const [isLoading, setIsLoading] = useState(false); const handleChange = (e) => { const { name, value } = e.target; setFormData(prev => ({ ...prev, [name]: name === 'estimatedCost' ? parseFloat(value) || 0 : value })); }; const handleSubmit = async (e) => { e.preventDefault(); setIsLoading(true); const userId = auth.currentUser.uid; const id = job?.id || new Uuid().v4(); const jobData = { ...formData, userId, id, dateAdded: job?.dateAdded || new Date() }; try { await setDoc(doc(db, "service_jobs", id), ServiceJob.fromMap(jobData).toMap()); navigateTo('home'); } catch (error) { console.error("Error saving job: ", error); alert("Error saving job."); } finally { setIsLoading(false); } }; return (

{job ? 'Service ပြင်ဆင်ရန်' : 'Service အသစ်ထည့်ရန်'}

{Object.keys(formData).map(key => { if (key === 'status') return null; // Handle dropdown separately const isNumber = key === 'estimatedCost'; const isTextarea = key === 'problemDescription'; return (
{isTextarea ? ( ) : ( )}
); })}
); }; const PrintableView = ({ job, navigateTo }) => { const printRef = useRef(); useEffect(() => { // A little hack to trigger print dialog once component is ready const timer = setTimeout(() => { window.print(); }, 500); return () => clearTimeout(timer); }, []); return (

KZT Mobile Service

Service ဘောင်ချာ

ဘောင်ချာနံပါတ်: {job.voucherNumber}
ရက်စွဲ: {new Intl.DateTimeFormat('en-CA').format(job.dateAdded)}
နာမည်: {job.customerName}
ဖုန်းနံပါတ်: {job.phoneNumber}
ဖုန်းမော်ဒယ်: {job.phoneModel}
ဖြစ်သော ပြဿနာ:

{job.problemDescription}

အခြေအနေ: {job.status}
ကုန်ကျစရိတ်: {job.estimatedCost} Ks

Contact: 09784568007

ကျေးဇူးတင်ပါသည်။

Developed by N.M.H

) }