-
-
Notifications
You must be signed in to change notification settings - Fork 27.1k
Lokal hat #17126
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Lokal hat #17126
Conversation
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 ( <div className="max-w-4xl mx-auto p-4 space-y-6"> <h1 className="text-3xl font-bold text-center">📍 লোকাল হাট - দর্শনা, চুয়াডাঙ্গা</h1> {!user && ( <Card className="p-4"> <CardContent className="space-y-2"> <h2 className="text-xl font-semibold">📱 লগইন করুন</h2> <Input placeholder="আপনার ফোন নম্বর (+880...)" value={phoneNumber} onChange={(e) => setPhoneNumber(e.target.value)} /> <Button onClick={handleSendOtp}>OTP পাঠান</Button> <Input placeholder="OTP" value={otp} onChange={(e) => setOtp(e.target.value)} /> <Button onClick={handleVerifyOtp}>OTP যাচাই করুন</Button> <div id="recaptcha-container" /> </CardContent> </Card> )} {user && ( <> <p className="text-center font-medium">👤 {user.phoneNumber} | 💰 Wallet: {wallet}৳</p> {/* নতুন পণ্য পোস্ট */} <Card className="p-4"> <CardContent className="space-y-2"> <h2 className="text-xl font-semibold">🛍️ নতুন পণ্য পোস্ট করুন</h2> <Input placeholder="পণ্যের নাম" value={form.title} onChange={(e) => setForm({ ...form, title: e.target.value })} /> <Input placeholder="দাম (৳)" value={form.price} onChange={(e) => setForm({ ...form, price: e.target.value })} /> <Textarea placeholder="পণ্যের বিস্তারিত" value={form.description} onChange={(e) => setForm({ ...form, description: e.target.value })} /> <Input placeholder="পণ্যের ছবি (লিংক)" value={form.image} onChange={(e) => setForm({ ...form, image: e.target.value })} /> <Input placeholder="মোবাইল নম্বর" value={form.phone} onChange={(e) => setForm({ ...form, phone: e.target.value })} /> <Button onClick={handlePost}>✅ পোস্ট করুন</Button> </CardContent> </Card> {/* বিকাশ টাকা তোলার ফর্ম */} <Card className="p-4"> <CardContent className="space-y-2"> <h2 className="text-xl font-semibold">📤 বিকাশে টাকা তুলুন</h2> <Input placeholder="বিকাশ নম্বর" value={withdraw.number} onChange={(e) => setWithdraw({ ...withdraw, number: e.target.value })} /> <Input placeholder="পরিমাণ (৳)" value={withdraw.amount} onChange={(e) => setWithdraw({ ...withdraw, amount: e.target.value })} /> <Button onClick={handleWithdraw}>📤 রিকোয়েস্ট পাঠান</Button> </CardContent> </Card> </> )} {/* পণ্য তালিকা */} <div className="grid grid-cols-1 md:grid-cols-2 gap-4"> {products.map((product, idx) => ( <Card key={idx} className="overflow-hidden"> {product.image && <img src={product.image} alt={product.title} className="w-full h-48 object-cover" />} <CardContent className="p-4 space-y-1"> <h3 className="text-lg font-semibold">{product.title}</h3> <p className="text-green-700 font-bold">৳ {product.price}</p> <p className="text-sm text-gray-600">{product.description}</p> <Badge>📞 {product.phone}</Badge> </CardContent> </Card> ))} </div> </div> ); }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 ( <div className="max-w-4xl mx-auto p-4 space-y-6"> <h1 className="text-3xl font-bold text-center">📍 লোকাল হাট - দর্শনা, চুয়াডাঙ্গা</h1> {!user && ( <Card className="p-4"> <CardContent className="space-y-2"> <h2 className="text-xl font-semibold">📱 লগইন করুন</h2> <Input placeholder="আপনার ফোন নম্বর (+880...)" value={phoneNumber} onChange={(e) => setPhoneNumber(e.target.value)} /> <Button onClick={handleSendOtp}>OTP পাঠান</Button> <Input placeholder="OTP" value={otp} onChange={(e) => setOtp(e.target.value)} /> <Button onClick={handleVerifyOtp}>OTP যাচাই করুন</Button> <div id="recaptcha-container" /> </CardContent> </Card> )} {user && ( <> <p className="text-center font-medium">👤 {user.phoneNumber} | 💰 Wallet: {wallet}৳</p> {/* নতুন পণ্য পোস্ট */} <Card className="p-4"> <CardContent className="space-y-2"> <h2 className="text-xl font-semibold">🛍️ নতুন পণ্য পোস্ট করুন</h2> <Input placeholder="পণ্যের নাম" value={form.title} onChange={(e) => setForm({ ...form, title: e.target.value })} /> <Input placeholder="দাম (৳)" value={form.price} onChange={(e) => setForm({ ...form, price: e.target.value })} /> <Textarea placeholder="পণ্যের বিস্তারিত" value={form.description} onChange={(e) => setForm({ ...form, description: e.target.value })} /> <Input placeholder="পণ্যের ছবি (লিংক)" value={form.image} onChange={(e) => setForm({ ...form, image: e.target.value })} /> <Input placeholder="মোবাইল নম্বর" value={form.phone} onChange={(e) => setForm({ ...form, phone: e.target.value })} /> <Button onClick={handlePost}>✅ পোস্ট করুন</Button> </CardContent> </Card> {/* বিকাশ টাকা তোলার ফর্ম */} <Card className="p-4"> <CardContent className="space-y-2"> <h2 className="text-xl font-semibold">📤 বিকাশে টাকা তুলুন</h2> <Input placeholder="বিকাশ নম্বর" value={withdraw.number} onChange={(e) => setWithdraw({ ...withdraw, number: e.target.value })} /> <Input placeholder="পরিমাণ (৳)" value={withdraw.amount} onChange={(e) => setWithdraw({ ...withdraw, amount: e.target.value })} /> <Button onClick={handleWithdraw}>📤 রিকোয়েস্ট পাঠান</Button> </CardContent> </Card> </> )} {/* পণ্য তালিকা */} <div className="grid grid-cols-1 md:grid-cols-2 gap-4"> {products.map((product, idx) => ( <Card key={idx} className="overflow-hidden"> {product.image && <img src={product.image} alt={product.title} className="w-full h-48 object-cover" />} <CardContent className="p-4 space-y-1"> <h3 className="text-lg font-semibold">{product.title}</h3> <p className="text-green-700 font-bold">৳ {product.price}</p> <p className="text-sm text-gray-600">{product.description}</p> <Badge>📞 {product.phone}</Badge> </CardContent> </Card> ))} </div> </div> ); }
Thank you for your pull request and welcome to our community. Action RequiredIn order to merge any pull request (code, docs, etc.), we require contributors to sign our Contributor License Agreement, and we don't seem to have one on file for you. ProcessIn order for us to review and merge your suggested changes, please sign at https://code.facebook.com/cla. If you are contributing on behalf of someone else (eg your employer), the individual CLA may not be sufficient and your employer may need to sign the corporate CLA. Once the CLA is signed, our tooling will perform checks and validations. Afterwards, the pull request will be tagged with If you have received this in error or have any questions, please contact us at cla@meta.com. Thanks! |
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 (
📍 লোকাল হাট - দর্শনা, চুয়াডাঙ্গা
);
}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 (
📍 লোকাল হাট - দর্শনা, চুয়াডাঙ্গা
);
}