import React, { useState, useEffect, useRef } from 'react';
import {
Printer,
FileText,
CreditCard,
ShieldCheck,
User,
Phone,
MapPin,
Mail,
Upload,
CheckCircle,
Clock,
AlertCircle,
Lock,
LogOut,
ShoppingBag,
Settings,
Plus,
Trash2,
Edit3,
QrCode,
Download,
Volume2,
ChevronRight,
Eye,
FileCheck,
Search,
RefreshCw,
TrendingUp,
FileSpreadsheet
} from 'lucide-react';
// Main Web Application Component
export default function App() {
// Navigation & User State
const [activeTab, setActiveTab] = useState('services'); // services, orders, profile, admin
const [user, setUser] = useState(() => {
const saved = localStorage.getItem('narayan_user');
return saved ? JSON.parse(saved) : null;
});
// Auth Modals & Form State
const [authModal, setAuthModal] = useState({ open: false, mode: 'login' }); // 'login', 'register', 'forgot'
const [adminPin, setAdminPin] = useState('');
const [isAdminAuthenticated, setIsAdminAuthenticated] = useState(() => {
return localStorage.getItem('narayan_admin_auth') === 'true';
});
// Services Catalog State (Dukandaar can update rates dynamically)
const [services, setServices] = useState(() => {
const saved = localStorage.getItem('narayan_services');
return saved ? JSON.parse(saved) : [
{ id: 'pdf', title: 'PDF Document Print', icon: 'FileText', badge: 'Tiered Pricing', requiresUpload: true, fields: ['pdfFile'] },
{ id: 'photo', title: 'Passport Photo Print (6 Pcs)', price: 40, icon: 'Printer', requiresUpload: true, fields: ['photo'] },
{ id: 'aadhar', title: 'Aadhar Card Print', price: 50, icon: 'ShieldCheck', requiresUpload: true, fields: ['aadhar'] },
{ id: 'voter', title: 'Voter Card Print', price: 50, icon: 'CreditCard', requiresUpload: true, fields: ['voter'] },
{ id: 'new_pan', title: 'New PAN Card Apply', price: 200, icon: 'FileCheck', requiresUpload: true, fields: ['aadhar', 'birthCert'] },
{ id: 'pan_corr', title: 'PAN Card Correction', price: 300, icon: 'Edit3', requiresUpload: true, fields: ['aadhar', 'birthCert'] },
{ id: 'new_gst', title: 'New GST Registration', price: 1500, icon: 'TrendingUp', requiresUpload: true, fields: ['aadhar', 'pan', 'photo', 'electricity'] },
{ id: 'itr', title: 'ITR Filing', price: 1200, icon: 'FileSpreadsheet', requiresUpload: true, fields: ['aadhar', 'pan', 'bankStatement'] }
];
});
// Orders State
const [orders, setOrders] = useState(() => {
const saved = localStorage.getItem('narayan_orders');
return saved ? JSON.parse(saved) : [
{
id: 'NC-98421',
customerName: 'Rahul Kumar',
mobile: '9876543210',
address: 'Main Road, Near Hanuman Mandir, Patna',
serviceName: 'Aadhar Card Print',
amount: 50,
status: 'Completed',
date: new Date(Date.now() - 86400000).toLocaleString(),
paymentStatus: 'Paid (UPI)',
files: [{ name: 'Aadhar_Doc.pdf', type: 'aadhar' }]
}
];
});
// Selected Service for Ordering
const [selectedService, setSelectedService] = useState(null);
const [pdfPageCount, setPdfPageCount] = useState(1);
const [uploadedFiles, setUploadedFiles] = useState({});
const [activePaymentOrder, setActivePaymentOrder] = useState(null);
const [receiptOrder, setReceiptOrder] = useState(null);
// Audio simulation for New Order alert in Dukandaar portal
const playAlertSound = () => {
try {
const ctx = new (window.AudioContext || window.webkitAudioContext)();
const osc = ctx.createOscillator();
const gain = ctx.createGain();
osc.type = 'sine';
osc.frequency.setValueAtTime(587.33, ctx.currentTime); // D5
osc.frequency.setValueAtTime(880, ctx.currentTime + 0.15); // A5
gain.gain.setValueAtTime(0.3, ctx.currentTime);
osc.connect(gain);
gain.connect(ctx.destination);
osc.start();
osc.stop(ctx.currentTime + 0.4);
} catch (e) {
console.log('Audio alert allowed after interaction');
}
};
// Save changes to localStorage
useEffect(() => {
localStorage.setItem('narayan_orders', JSON.stringify(orders));
}, [orders]);
useEffect(() => {
localStorage.setItem('narayan_services', JSON.stringify(services));
}, [services]);
// Handle PDF Price Calculation Tier
const calculatePdfPrice = (pages) => {
const count = parseInt(pages) || 1;
if (count === 1) return 10;
if (count >= 10 && count <= 50) return count * 5;
if (count > 50) return count * 3;
return count * 10; // Default for 2-9 pages
};
// Auth Submit Handlers
const handleAuthSubmit = (e) => {
e.preventDefault();
const formData = new FormData(e.target);
const data = Object.fromEntries(formData.entries());
if (authModal.mode === 'register') {
const newUser = {
name: data.name,
address: data.address,
mobile: data.mobile,
email: data.email,
password: data.password
};
localStorage.setItem('narayan_user_' + data.mobile, JSON.stringify(newUser));
setUser(newUser);
localStorage.setItem('narayan_user', JSON.stringify(newUser));
setAuthModal({ open: false, mode: 'login' });
} else if (authModal.mode === 'login') {
const saved = localStorage.getItem('narayan_user_' + data.mobile);
if (saved) {
const parsed = JSON.parse(saved);
if (parsed.password === data.password) {
setUser(parsed);
localStorage.setItem('narayan_user', JSON.stringify(parsed));
setAuthModal({ open: false, mode: 'login' });
} else {
alert('Incorrect Password! Please try again.');
}
} else {
// Fallback quick simulation login
const tempUser = { name: 'Customer', mobile: data.mobile, address: 'Patna, Bihar' };
setUser(tempUser);
localStorage.setItem('narayan_user', JSON.stringify(tempUser));
setAuthModal({ open: false, mode: 'login' });
}
} else if (authModal.mode === 'forgot') {
alert('Password reset link sent to your mobile via SMS simulation.');
setAuthModal({ open: false, mode: 'login' });
}
};
const handleLogout = () => {
setUser(null);
localStorage.removeItem('narayan_user');
setIsAdminAuthenticated(false);
localStorage.removeItem('narayan_admin_auth');
};
const handleAdminLogin = (e) => {
e.preventDefault();
if (adminPin === '703388') { // Dukandaar PIN
setIsAdminAuthenticated(true);
localStorage.setItem('narayan_admin_auth', 'true');
setActiveTab('admin');
} else {
alert('Invalid Admin PIN! Default PIN is 703388');
}
};
// Handle File Input Simulation
const handleFileUpload = (fieldName, e) => {
const file = e.target.files[0];
if (file) {
setUploadedFiles(prev => ({
...prev,
[fieldName]: { name: file.name, size: (file.size / 1024).toFixed(1) + ' KB' }
}));
}
};
// Create Order and Prompt Payment Modal
const initiateOrder = (service) => {
if (!user) {
setAuthModal({ open: true, mode: 'login' });
return;
}
let calculatedAmount = service.price || 0;
if (service.id === 'pdf') {
calculatedAmount = calculatePdfPrice(pdfPageCount);
}
// Check required uploads
const required = service.fields || [];
const missing = required.filter(f => !uploadedFiles[f]);
if (missing.length > 0) {
alert(`Please upload all required documents (${missing.join(', ')}) before proceeding to payment.`);
return;
}
const orderId = 'NC-' + Math.floor(10000 + Math.random() * 90000);
const newOrder = {
id: orderId,
customerName: user.name,
mobile: user.mobile,
address: user.address || 'Self Pick-up / Local Address',
serviceName: service.title + (service.id === 'pdf' ? ` (${pdfPageCount} Pages)` : ''),
amount: calculatedAmount,
status: 'Pending',
date: new Date().toLocaleString(),
paymentStatus: 'Payment Pending',
files: Object.keys(uploadedFiles).map(k => ({ type: k, name: uploadedFiles[k].name }))
};
setActivePaymentOrder(newOrder);
};
// Confirm Payment & Trigger Store Alert
const confirmPayment = () => {
if (!activePaymentOrder) return;
const finalizedOrder = {
...activePaymentOrder,
paymentStatus: 'Paid (UPI)',
status: 'Received'
};
setOrders(prev => [finalizedOrder, ...prev]);
playAlertSound();
setReceiptOrder(finalizedOrder);
setActivePaymentOrder(null);
setSelectedService(null);
setUploadedFiles({});
};
// Dukandaar update order status
const updateOrderStatus = (orderId, newStatus) => {
setOrders(prev => prev.map(o => o.id === orderId ? { ...o, status: newStatus } : o));
};
return (
{/* HEADER SECTION */}
{/* HERO / NOTICE BANNER */}
Ghar Baith Kar Document Print & Apply Karein! 🖨️
Upload files, pay instantly via UPI/Scanner, and get printing & online service delivery right at your door or instant shop pickup.
Official Shop Scanner UPI ID:
7033886620@okbizaxis
{/* MAIN CONTENT CONTAINERS */}
{/* TAB 1: CUSTOMER SERVICES VIEW */}
{activeTab === 'services' && (
Select Service & Upload Documents
Fast document printing, PAN, GST, and ITR services
{/* SERVICES GRID */}
{/* SPECIAL TIERS PDF PRINT CARD */}
Popular Service
PDF Document Print
Tiered discount pricing based on document page count.
{/* Dynamic Rate Info Chart */}
• 1 Page: ₹10 / Page
• 10 to 50 Pages: ₹5 / Page
• 50 to 500 Pages: ₹3 / Page
{/* PDF Calculator Input */}
{/* File Upload Box */}
handleFileUpload('pdfFile', e)}
className="hidden"
id="pdf-file-input"
/>
{uploadedFiles['pdfFile'] ? uploadedFiles['pdfFile'].name : 'Upload PDF File Here'}
PDF, DOC up to 50MB
initiateOrder(services.find(s => s.id === 'pdf'))}
className="w-full bg-blue-600 hover:bg-blue-700 text-white font-semibold py-2.5 rounded-xl shadow transition text-sm flex items-center justify-center gap-2"
>
Order & Pay ₹{calculatePdfPrice(pdfPageCount)}
{/* OTHER DYNAMIC SERVICES CARDS */}
{services.filter(s => s.id !== 'pdf').map((service) => (
{service.title}
Upload required documents to submit online request.
{/* Required Documents Upload list */}
Required Document Uploads:
{service.fields && service.fields.map((field) => (
{field.replace(/([A-Z])/g, ' $1')} File
{uploadedFiles[field] ? '✓ Selected' : 'Choose File'}
handleFileUpload(field, e)}
/>
))}
initiateOrder(service)}
className="w-full bg-emerald-600 hover:bg-emerald-700 text-white font-semibold py-2.5 rounded-xl shadow transition text-sm flex items-center justify-center gap-2"
>
Pay ₹{service.price} & Order
))}
)}
{/* TAB 2: MY ORDERS & STATUS TRACKING */}
{activeTab === 'orders' && user && (
My Print & Service Orders
{orders.filter(o => o.mobile === user.mobile).length === 0 ? (
No active or past orders found.
setActiveTab('services')} className="mt-4 text-blue-600 hover:underline font-semibold text-sm">
Browse Services & Order Now
) : (
{orders.filter(o => o.mobile === user.mobile).map((order) => (
{order.id}
{order.date}
{order.serviceName}
Delivery Address: {order.address}
₹{order.amount}
{order.paymentStatus}
{/* Status Indicator Badge */}
{order.status}
{/* Download Receipt Button */}
setReceiptOrder(order)}
className="bg-slate-100 hover:bg-slate-200 text-slate-700 p-2 rounded-lg text-xs font-semibold flex items-center gap-1"
title="View Bill Receipt"
>
Bill
))}
)}
)}
{/* TAB 3: DUKANDAAR / ADMIN DASHBOARD */}
{activeTab === 'admin' && (
{!isAdminAuthenticated ? (
/* Admin PIN Login Form */
Dukandaar Access Portal
Enter shop owner pin to control customer orders and services
) : (
/* Authenticated Admin Dashboard */
{/* Top Control Bar */}
DUKANDAAR CONTROL CENTER
Manage orders, update rates, and view customer uploads
playAlertSound()}
className="bg-slate-800 hover:bg-slate-700 text-yellow-400 text-xs px-3 py-1.5 rounded-lg border border-yellow-500/30 flex items-center gap-1.5"
>
Test Sound Alert
setIsAdminAuthenticated(false)}
className="bg-red-600 hover:bg-red-700 text-white text-xs px-3 py-1.5 rounded-lg font-semibold"
>
Exit Admin
{/* ORDERS MANAGEMENT TABLE */}
Incoming Customer Orders ({orders.length})
Order ID & Date
Customer Details
Service & Amount
Uploaded Documents
Status Control
{orders.map((o) => (
{o.id}
{o.date}
{o.customerName}
📞 {o.mobile}
🏠 {o.address}
{o.serviceName}
₹{o.amount} ({o.paymentStatus})
{o.files && o.files.length > 0 ? (
{o.files.map((f, i) => (
{f.name}
))}
) : (
No files
)}
updateOrderStatus(o.id, e.target.value)}
className="border rounded px-2 py-1 text-xs font-semibold bg-white text-slate-800 focus:ring-2 focus:ring-emerald-500"
>
Pending
Processing / Printing
Completed
Out for Delivery
))}
{/* SERVICE CATALOG EDITOR (DUKANDAAR DYNAMIC ADD/EDIT) */}
Manage Shop Services & Rates
{services.map((s) => (
{s.title}
{s.id === 'pdf' ? 'Tiered Rates (10/5/3)' : `Rate: ₹${s.price}`}
{s.id !== 'pdf' && (
{
const newPrice = parseInt(e.target.value) || 0;
setServices(prev => prev.map(serv => serv.id === s.id ? { ...serv, price: newPrice } : serv));
}}
className="w-20 border rounded px-2 py-1 text-xs text-right font-bold"
/>
)}
))}
)}
)}
{/* MODAL 1: AUTHENTICATION (LOGIN / REGISTER / FORGOT) */}
{authModal.open && (
setAuthModal({ open: false, mode: 'login' })}
className="absolute top-4 right-4 text-slate-400 hover:text-slate-600"
>
✕
{authModal.mode === 'login' && 'Customer Login'}
{authModal.mode === 'register' && 'New Account Registration'}
{authModal.mode === 'forgot' && 'Reset Password'}
{authModal.mode === 'login' ? (
<>
Don't have an account? setAuthModal({ open: true, mode: 'register' })} className="text-blue-600 font-bold hover:underline">Register Here
setAuthModal({ open: true, mode: 'forgot' })} className="text-slate-400 hover:underline">Forgot Password?
>
) : (
Already have an account? setAuthModal({ open: true, mode: 'login' })} className="text-blue-600 font-bold hover:underline">Login Here
)}
)}
{/* MODAL 2: DYNAMIC UPI PAYMENT GATEWAY & SCANNER */}
{activePaymentOrder && (
{/* Header */}
UPI / SCANNER PAYMENT GATEWAY
NARAYAN COMPUTER AND CYBER CAFE
Total Payable Amount
₹{activePaymentOrder.amount}
{activePaymentOrder.serviceName}
{/* DYNAMIC QR CODE DISPLAY */}
Scan & Pay using GPay, PhonePe, Paytm
UPI ID: 7033886620@okbizaxis
📌 Payment Alert Note: After paying via Google Pay or PhonePe scanner, click below to confirm. The store owner will automatically receive an order alert.
setActivePaymentOrder(null)}
className="w-1/2 bg-slate-100 hover:bg-slate-200 text-slate-700 font-semibold py-2.5 rounded-xl text-xs"
>
Cancel Order
I Have Paid ₹{activePaymentOrder.amount}
)}
{/* MODAL 3: DIGITAL BILL RECEIPT */}
{receiptOrder && (
setReceiptOrder(null)}
className="absolute top-3 right-3 text-slate-400 hover:text-slate-600"
>
✕
NARAYAN COMPUTER
Cyber Cafe & Online Digital Services
Mobile: +91 70338 86620
Bill Order ID:
{receiptOrder.id}
Date & Time:
{receiptOrder.date}
Customer Name:
{receiptOrder.customerName}
Mobile Number:
{receiptOrder.mobile}
Service Chosen:
{receiptOrder.serviceName}
Total Amount Paid:
₹{receiptOrder.amount}
Payment Status:
{receiptOrder.paymentStatus}
{
window.print();
}}
className="w-full bg-blue-600 hover:bg-blue-700 text-white font-bold py-2.5 rounded-xl shadow transition text-xs flex items-center justify-center gap-2"
>
Download / Print Digital Bill
)}
{/* FOOTER */}
);
}