From 1cc9d1acce8c64eb8d8ad3ac0975be2423fa5d6d Mon Sep 17 00:00:00 2001 From: shawonmia254-blip Date: Fri, 25 Jul 2025 15:19:56 +0600 Subject: [PATCH] Lokal hat MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit import { useState, useEffect } from "react"; import { auth, db } from "../firebase"; import { doc, setDoc, getDoc, collection, addDoc } from "firebase/firestore"; import { RecaptchaVerifier, signInWithPhoneNumber, onAuthStateChanged, } from "firebase/auth"; import { Card, CardContent } from "@/components/ui/card"; import { Button } from "@/components/ui/button"; import { Input } from "@/components/ui/input"; import { Textarea } from "@/components/ui/textarea"; import { Badge } from "@/components/ui/badge"; export default function LocalHaatApp() { const [form, setForm] = useState({ title: "", price: "", description: "", image: "", phone: "" }); const [products, setProducts] = useState([]); const [user, setUser] = useState(null); const [wallet, setWallet] = useState(0); const [phoneNumber, setPhoneNumber] = useState(""); const [otp, setOtp] = useState(""); const [confirmationResult, setConfirmationResult] = useState(null); const [withdraw, setWithdraw] = useState({ number: "", amount: "" }); useEffect(() => { onAuthStateChanged(auth, async (usr) => { if (usr) { setUser(usr); const userRef = doc(db, "users", usr.phoneNumber); const snap = await getDoc(userRef); if (snap.exists()) { setWallet(snap.data().wallet); } else { await setDoc(userRef, { wallet: 20 }); // 🎉 নতুন ইউজার: ২০ টাকা বোনাস setWallet(20); } } }); }, []); const setupRecaptcha = () => { window.recaptchaVerifier = new RecaptchaVerifier(auth, "recaptcha-container", { size: "invisible", }); }; const handleSendOtp = async () => { setupRecaptcha(); const appVerifier = window.recaptchaVerifier; const result = await signInWithPhoneNumber(auth, phoneNumber, appVerifier); setConfirmationResult(result); alert("📨 OTP পাঠানো হয়েছে!"); }; const handleVerifyOtp = async () => { const result = await confirmationResult.confirm(otp); if (result.user) alert("✅ লগইন সফল!"); }; const handlePost = () => { if (form.title && form.price && form.phone && user) { setProducts([...products, form]); setForm({ title: "", price: "", description: "", image: "", phone: "" }); } }; const handleWithdraw = async () => { if (withdraw.amount <= wallet) { await addDoc(collection(db, "withdraws"), { phone: user.phoneNumber, to: withdraw.number, amount: parseInt(withdraw.amount), status: "pending", createdAt: new Date() }); setWallet(wallet - parseInt(withdraw.amount)); await setDoc(doc(db, "users", user.phoneNumber), { wallet: wallet - parseInt(withdraw.amount) }); alert("✅ রিকোয়েস্ট পাঠানো হয়েছে"); } else { alert("❌ আপনার পর্যাপ্ত টাকা নেই"); } }; return (

📍 লোকাল হাট - দর্শনা, চুয়াডাঙ্গা

{!user && (

📱 লগইন করুন

setPhoneNumber(e.target.value)} /> setOtp(e.target.value)} />
)} {user && ( <>

👤 {user.phoneNumber} | 💰 Wallet: {wallet}৳

{/* নতুন পণ্য পোস্ট */}

🛍️ নতুন পণ্য পোস্ট করুন

setForm({ ...form, title: e.target.value })} /> setForm({ ...form, price: e.target.value })} />