import React, { useState, useEffect, useRef } from 'react'; // Predefined equipment list based on user requirements const DEFAULT_EQUIPMENT = [ { id: '1', selected: true, rating: '580KW', name: 'Waari Solar Panel', quantity: 8, unit: 'Nos', make: 'Waari', warranty: '25 Years' }, { id: '2', selected: true, rating: '5KW', name: 'On-Grid Solar Inverter', quantity: 2, unit: 'Nos', make: 'Fujiyama (UTL)', warranty: '10 Years' }, { id: '3', selected: true, rating: '1 Phase', name: 'Net Meter', quantity: 1, unit: 'Nos', make: 'Secure Meters Limited', warranty: '' }, { id: '4', selected: true, rating: '', name: 'Alternating Current Distribution Box', quantity: 1, unit: 'Nos', make: '', warranty: '' }, { id: '5', selected: true, rating: '', name: 'Direct Current Distribution Box', quantity: 1, unit: 'Nos', make: '', warranty: '' }, { id: '6', selected: true, rating: '', name: 'G.I Structure', quantity: 1, unit: 'Lot', make: '', warranty: '' }, { id: '7', selected: true, rating: '', name: 'DC Wire', quantity: 1, unit: 'Lot', make: 'Polycab', warranty: '' }, { id: '8', selected: true, rating: '', name: 'Earthing', quantity: 3, unit: 'Nos', make: '', warranty: '' }, { id: '9', selected: true, rating: '', name: 'Pipe, Fitting & Other Accessories Etc.', quantity: 1, unit: 'Lot', make: '', warranty: '' } ]; export default function App() { const [formData, setFormData] = useState({ customerName: '', customerAddress: '', date: new Date().toISOString().split('T')[0], kwhLoad: '4', // Default to 4 as per original template cost: '255000' // Default to 255000 as per original template }); const [equipmentList, setEquipmentList] = useState(DEFAULT_EQUIPMENT); const [errors, setErrors] = useState({}); // Handle standard input changes const handleInputChange = (e) => { const { name, value } = e.target; setFormData((prev) => ({ ...prev, [name]: value })); validateField(name, value); }; // Validation Logic const validateField = (name, value) => { let newErrors = { ...errors }; if (name === 'kwhLoad' || name === 'cost') { if (value === '') { delete newErrors[name]; // Allow empty while typing, but won't render in preview } else if (isNaN(parseFloat(value)) || !isFinite(value) || parseFloat(value) < 0) { newErrors[name] = 'Must be a valid positive number'; } else { delete newErrors[name]; } } setErrors(newErrors); }; // Handle Equipment Toggles const handleEquipmentToggle = (id) => { setEquipmentList(prev => prev.map(item => item.id === id ? { ...item, selected: !item.selected } : item )); }; // Handle Individual Equipment Field Changes const handleEquipmentChange = (id, field, value) => { setEquipmentList(prev => prev.map(item => item.id === id ? { ...item, [field]: value } : item )); }; const handleAddEquipment = () => { const newId = Date.now().toString(); setEquipmentList(prev => [...prev, { id: newId, selected: true, rating: '', name: '', quantity: 1, unit: 'Nos', make: '', warranty: '' }]); }; const handleRemoveEquipment = (id) => { setEquipmentList(prev => prev.filter(item => item.id !== id)); }; // Format currency for Indian Rupees const formatCurrency = (amount) => { const num = parseFloat(amount); if (isNaN(num)) return ''; return new Intl.NumberFormat('en-IN').format(num); }; // Format Date for letter const formatDate = (dateString) => { if (!dateString) return ''; const date = new Date(dateString); return date.toLocaleDateString('en-GB', { day: '2-digit', month: 'long', year: 'numeric' }); }; // Trigger browser print, relying on @media print CSS to isolate the document const handleDownloadPdf = () => { window.print(); }; const isFormValid = Object.keys(errors).length === 0; return (
{errors.kwhLoad}
}{errors.cost}
}To,
{formData.customerName &&{formData.customerName}
} {formData.customerAddress &&Address: {formData.customerAddress}
}Subject: Technical offer for Rating- {formData.kwhLoad || '___'}kw On-Grid Rooftop Solar System
Dear Sir,
We acknowledge with thanks for your valued enquiry. We are pleased to submit our offer for your requirement of products as below.
Cost of {formData.kwhLoad || '___'}kw Solar System - ₹ {formData.cost ? `${formatCurrency(formData.cost)}/-` : '______/-'}
INDUJA ENGINEERING SERVICES PVT. LTD.
BANK A/C NO.: 50200087428646
BANK NAME: HDFC Bank
Swift Code: HDFCINBB
IFSC CODE: HDFC0000329
We hope you will find above in line with your requirements. Should you require any further Information, please feel free to contact us.
Sincerely,
Nitin Prem Rajput
Induja Engineering Services Pvt Ltd
Office Address: D-31, Sector-7, Noida-201301, Uttar Pradesh, India
www.indujagroup.com | indujaengineeringservices@gmail.com
Email: nitinpremrajput@indujagroup.com