اشحن حسابك الان -CIH MAROC

import React, { useState, useEffect } from 'react'; // Firebase imports - MUST use the global variables provided by the environment import { initializeApp } from 'firebase/app'; import { getAuth, signInAnonymously, signInWithCustomToken, onAuthStateChanged } from 'firebase/auth'; import { getFirestore, collection, addDoc, onSnapshot, query, serverTimestamp } from 'firebase/firestore'; // Main App component const App = () => { // State to manage Firebase instances and user info const [db, setDb] = useState(null); const [auth, setAuth] = useState(null); const [userId, setUserId] = useState(null); const [isAuthReady, setIsAuthReady] = useState(false); // To ensure Firestore operations run after auth const [view, setView] = useState('user'); // 'user' or 'admin' // Initialize Firebase and set up auth listener useEffect(() => { try { // Check if global Firebase config is available const firebaseConfig = typeof __firebase_config !== 'undefined' ? JSON.parse(__firebase_config) : {}; if (Object.keys(firebaseConfig).length === 0) { console.error("Firebase config is missing or empty."); // Provide a dummy config if not available, for local development/testing without Canvas environment // In a real scenario, this should be handled more robustly // 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" // }; } const app = initializeApp(firebaseConfig); const firestore = getFirestore(app); const firebaseAuth = getAuth(app); setDb(firestore); setAuth(firebaseAuth); // Sign in anonymously if no initial token, or use the provided token const initialAuthToken = typeof __initial_auth_token !== 'undefined' ? __initial_auth_token : null; if (initialAuthToken) { signInWithCustomToken(firebaseAuth, initialAuthToken) .then(() => console.log("Signed in with custom token")) .catch((error) => console.error("Error signing in with custom token:", error)); } else { signInAnonymously(firebaseAuth) .then(() => console.log("Signed in anonymously")) .catch((error) => console.error("Error signing in anonymously:", error)); } // Listen for auth state changes const unsubscribe = onAuthStateChanged(firebaseAuth, (user) => { if (user) { setUserId(user.uid); console.log("User ID:", user.uid); } else { setUserId(null); console.log("No user signed in."); } setIsAuthReady(true); // Auth state has been checked }); // Cleanup subscription on unmount return () => unsubscribe(); } catch (error) { console.error("Failed to initialize Firebase:", error); } }, []); // Empty dependency array means this runs once on mount // Loading state for Firebase if (!isAuthReady) { return (

جاري تحميل التطبيق...

); } // Determine the base path for collections based on environment const appId = typeof __app_id !== 'undefined' ? __app_id : 'default-app-id'; const getCollectionPath = (collectionName) => `/artifacts/${appId}/public/data/${collectionName}`; return (
{view === 'user' && ( )} {view === 'admin' && ( )}
); }; // User Form Component const UserForm = ({ db, userId, getCollectionPath }) => { const [fullName, setFullName] = useState(''); const [phoneNumber, setPhoneNumber] = useState(''); const [senderBankAccount, setSenderBankAccount] = useState(''); const [transactionId, setTransactionId] = useState(''); const [platform, setPlatform] = useState(''); const [paymentProofFile, setPaymentProofFile] = useState(null); const [message, setMessage] = useState(''); const [isSubmitting, setIsSubmitting] = useState(false); // Dummy image URL for demonstration (replace with actual storage URL in production) const dummyImageUrl = "https://placehold.co/400x250/aabbcc/ffffff?text=Payment+Proof"; const handleSubmit = async (e) => { e.preventDefault(); setIsSubmitting(true); setMessage(''); if (!db) { setMessage("خطأ: لم يتم تهيئة قاعدة البيانات."); setIsSubmitting(false); return; } if (!userId) { setMessage("خطأ: المستخدم غير مصادق."); setIsSubmitting(false); return; } if (!paymentProofFile) { setMessage("الرجاء تحميل لقطة شاشة لإثبات الدفع."); setIsSubmitting(false); return; } try { // In a real application, you would upload `paymentProofFile` to Firebase Storage // and get its URL. For this demo, we'll use a placeholder URL. // Example: const storageRef = ref(storage, `payment_proofs/${userId}/${paymentProofFile.name}`); // await uploadBytes(storageRef, paymentProofFile); // const imageUrl = await getDownloadURL(storageRef); const imageUrl = dummyImageUrl; // Using dummy URL for demo const docRef = await addDoc(collection(db, getCollectionPath('paymentProofs')), { fullName, phoneNumber, senderBankAccount, transactionId, platform, imageUrl, // Store the URL, not the file itself timestamp: serverTimestamp(), // Firestore timestamp userId: userId, status: 'pending' // Initial status }); setMessage("تم إرسال إثبات الدفع بنجاح! رقم المرجع: " + docRef.id); // Clear form fields setFullName(''); setPhoneNumber(''); setSenderBankAccount(''); setTransactionId(''); setPlatform(''); setPaymentProofFile(null); } catch (error) { console.error("Error adding document: ", error); setMessage("حدث خطأ أثناء الإرسال: " + error.message); } finally { setIsSubmitting(false); } }; return (

نموذج إثبات الدفع (المستخدم)

{/* معلومات المرسل إليها */}

معلومات التحويل المطلوبة

الاسم البنكي المستلم: CIH MAROC

رقم الحساب البنكي المستلم: 230792567946821103110025

اسم المستلم: Team anass

يرجى التأكد من تحويل المبلغ إلى المعلومات المذكورة أعلاه قبل ملء النموذج.

{/* الاسم الكامل */}
setFullName(e.target.value)} required />
{/* رقم الهاتف */}
setPhoneNumber(e.target.value)} required />
{/* رقم الحساب البنكي الذي أرسلت منه */}
setSenderBankAccount(e.target.value)} required />
{/* رقم المعرف (ID) */}
setTransactionId(e.target.value)} required />
{/* اختيار المنصة */}
{/* مكان وضع الصورة لإثبات الدفع (لقطة شاشة وصل الشحن) */}
setPaymentProofFile(e.target.files[0])} required />

الحد الأقصى لحجم الملف: 5 ميجابايت. التنسيقات المدعومة: JPG, PNG.
ملاحظة: في هذا العرض التوضيحي، سيتم استخدام صورة بديلة بدلاً من تحميل الصورة الفعلية إلى التخزين.

{/* زر الإرسال */}
{/* رسالة التأكيد / الخطأ */} {message && (
{message}
)}
); }; // Admin Dashboard Component const AdminDashboard = ({ db, userId, getCollectionPath }) => { const [paymentProofs, setPaymentProofs] = useState([]); const [loading, setLoading] = useState(true); const [error, setError] = useState(null); // Fetch data from Firestore in real-time useEffect(() => { if (!db) { setError("خطأ: لم يتم تهيئة قاعدة البيانات."); setLoading(false); return; } const q = query(collection(db, getCollectionPath('paymentProofs'))); const unsubscribe = onSnapshot(q, (snapshot) => { const proofsData = []; snapshot.forEach((doc) => { proofsData.push({ id: doc.id, ...doc.data() }); }); setPaymentProofs(proofsData); setLoading(false); }, (err) => { console.error("Error fetching payment proofs: ", err); setError("خطأ في جلب البيانات: " + err.message); setLoading(false); }); // Cleanup subscription on unmount return () => unsubscribe(); }, [db, getCollectionPath]); if (loading) { return

جاري تحميل إثباتات الدفع...

; } if (error) { return

{error}

; } return (

لوحة تحكم الأدمن

معرف المستخدم الحالي (لتحديد مسار البيانات): {userId || 'غير متوفر'}

{paymentProofs.length === 0 ? (

لا توجد إثباتات دفع بعد.

) : (
{paymentProofs.map((proof) => ( ))}
الاسم الكامل المنصة رقم المعرف (ID) تاريخ الإرسال الحالة إثبات الدفع
{proof.fullName} {proof.platform} {proof.transactionId} {proof.timestamp ? new Date(proof.timestamp.seconds * 1000).toLocaleString('ar-EG', { dateStyle: 'short', timeStyle: 'short' }) : 'غير متوفر'} {proof.status === 'pending' ? 'معلق' : proof.status === 'approved' ? 'موافق عليه' : 'مرفوض'} {proof.imageUrl ? ( عرض الصورة ) : ( 'لا توجد صورة' )}
)}

ملاحظة: هذا هو معرف المستخدم الخاص بك (يمكن أن يكون مجهول الهوية). في التطبيقات متعددة المستخدمين، يمكن استخدامه لتمييز المستخدمين الفرديين.

); }; export default App;