| import { useState, useEffect } from "react"; | |
| import { X } from "lucide-react"; | |
| interface ChemicalFormData { | |
| name: string; | |
| casNumber?: string; | |
| formula?: string; | |
| location: string; | |
| quantity: number; | |
| unit: string; | |
| minStock: number; | |
| expiryDate?: string; | |
| description?: string; | |
| supplier?: string; | |
| lotNumber?: string; | |
| nfpa?: { | |
| health?: number; | |
| flammability?: number; | |
| instability?: number; | |
| special?: string; | |
| }; | |
| } | |
| interface ChemicalFormModalProps { | |
| isOpen: boolean; | |
| onClose: () => void; | |
| onSave: (data: ChemicalFormData) => void; | |
| saving?: boolean; | |
| initialData?: Partial<ChemicalFormData>; | |
| scannedBarcode?: string; | |
| } | |
| export function ChemicalFormModal({ | |
| isOpen, | |
| onClose, | |
| onSave, | |
| saving = false, | |
| initialData, | |
| scannedBarcode, | |
| }: ChemicalFormModalProps) { | |
| const [form, setForm] = useState<ChemicalFormData>({ | |
| name: "", | |
| casNumber: "", | |
| formula: "", | |
| location: "", | |
| quantity: 0, | |
| unit: "g", | |
| minStock: 0, | |
| expiryDate: "", | |
| description: "", | |
| supplier: "", | |
| lotNumber: "", | |
| nfpa: { health: 0, flammability: 0, instability: 0, special: "" }, | |
| }); | |
| useEffect(() => { | |
| if (initialData) { | |
| setForm((prev) => ({ ...prev, ...initialData })); | |
| } else if (scannedBarcode) { | |
| setForm((prev) => ({ ...prev, casNumber: scannedBarcode })); | |
| } | |
| }, [initialData, scannedBarcode]); | |
| if (!isOpen) return null; | |
| const handleSubmit = () => { | |
| onSave(form); | |
| }; | |
| return ( | |
| <div className="fixed inset-0 bg-black/50 flex items-center justify-center z-50 p-4"> | |
| <div className="bg-white dark:bg-gray-800 rounded-xl p-6 max-w-2xl w-full max-h-[90vh] overflow-y-auto"> | |
| <div className="flex justify-between items-center mb-4"> | |
| <h2 className="text-xl font-bold">{initialData ? "Edit Chemical" : "Add Chemical"}</h2> | |
| <button onClick={onClose} className="text-gray-500 hover:text-gray-700"> | |
| <X className="w-6 h-6" /> | |
| </button> | |
| </div> | |
| <div className="space-y-4"> | |
| <div> | |
| <label className="block text-sm font-medium mb-1">Name *</label> | |
| <input | |
| type="text" | |
| className="input w-full" | |
| value={form.name} | |
| onChange={(e) => setForm({ ...form, name: e.target.value })} | |
| required | |
| /> | |
| </div> | |
| <div className="grid grid-cols-2 gap-4"> | |
| <div> | |
| <label className="block text-sm font-medium mb-1">CAS Number</label> | |
| <input | |
| type="text" | |
| className="input w-full" | |
| value={form.casNumber} | |
| onChange={(e) => setForm({ ...form, casNumber: e.target.value })} | |
| /> | |
| </div> | |
| <div> | |
| <label className="block text-sm font-medium mb-1">Formula</label> | |
| <input | |
| type="text" | |
| className="input w-full" | |
| value={form.formula} | |
| onChange={(e) => setForm({ ...form, formula: e.target.value })} | |
| /> | |
| </div> | |
| </div> | |
| <div> | |
| <label className="block text-sm font-medium mb-1">Location *</label> | |
| <input | |
| type="text" | |
| className="input w-full" | |
| value={form.location} | |
| onChange={(e) => setForm({ ...form, location: e.target.value })} | |
| required | |
| /> | |
| </div> | |
| <div className="grid grid-cols-3 gap-4"> | |
| <div> | |
| <label className="block text-sm font-medium mb-1">Quantity *</label> | |
| <input | |
| type="number" | |
| step="any" | |
| className="input w-full" | |
| value={form.quantity} | |
| onChange={(e) => setForm({ ...form, quantity: parseFloat(e.target.value) || 0 })} | |
| required | |
| /> | |
| </div> | |
| <div> | |
| <label className="block text-sm font-medium mb-1">Unit</label> | |
| <select | |
| className="input w-full" | |
| value={form.unit} | |
| onChange={(e) => setForm({ ...form, unit: e.target.value })} | |
| > | |
| <option>g</option> | |
| <option>mg</option> | |
| <option>kg</option> | |
| <option>L</option> | |
| <option>mL</option> | |
| <option>pcs</option> | |
| </select> | |
| </div> | |
| <div> | |
| <label className="block text-sm font-medium mb-1">Min Stock</label> | |
| <input | |
| type="number" | |
| step="any" | |
| className="input w-full" | |
| value={form.minStock} | |
| onChange={(e) => setForm({ ...form, minStock: parseFloat(e.target.value) || 0 })} | |
| /> | |
| </div> | |
| </div> | |
| <div className="grid grid-cols-2 gap-4"> | |
| <div> | |
| <label className="block text-sm font-medium mb-1">Expiry Date</label> | |
| <input | |
| type="date" | |
| className="input w-full" | |
| value={form.expiryDate} | |
| onChange={(e) => setForm({ ...form, expiryDate: e.target.value })} | |
| /> | |
| </div> | |
| <div> | |
| <label className="block text-sm font-medium mb-1">Lot Number</label> | |
| <input | |
| type="text" | |
| className="input w-full" | |
| value={form.lotNumber} | |
| onChange={(e) => setForm({ ...form, lotNumber: e.target.value })} | |
| /> | |
| </div> | |
| </div> | |
| <div> | |
| <label className="block text-sm font-medium mb-1">Supplier</label> | |
| <input | |
| type="text" | |
| className="input w-full" | |
| value={form.supplier} | |
| onChange={(e) => setForm({ ...form, supplier: e.target.value })} | |
| /> | |
| </div> | |
| <div> | |
| <label className="block text-sm font-medium mb-1">Description</label> | |
| <textarea | |
| className="input w-full" | |
| rows={3} | |
| value={form.description} | |
| onChange={(e) => setForm({ ...form, description: e.target.value })} | |
| /> | |
| </div> | |
| <fieldset className="border border-gray-200 dark:border-gray-700 rounded-lg p-4"> | |
| <legend className="text-sm font-semibold px-2">NFPA 704 Hazards</legend> | |
| <div className="grid grid-cols-2 gap-4"> | |
| <div> | |
| <label className="block text-sm">Health (0-4)</label> | |
| <input | |
| type="number" | |
| min={0} | |
| max={4} | |
| className="input w-full" | |
| value={form.nfpa?.health ?? 0} | |
| onChange={(e) => | |
| setForm({ | |
| ...form, | |
| nfpa: { ...form.nfpa, health: parseInt(e.target.value) || 0 }, | |
| }) | |
| } | |
| /> | |
| </div> | |
| <div> | |
| <label className="block text-sm">Flammability (0-4)</label> | |
| <input | |
| type="number" | |
| min={0} | |
| max={4} | |
| className="input w-full" | |
| value={form.nfpa?.flammability ?? 0} | |
| onChange={(e) => | |
| setForm({ | |
| ...form, | |
| nfpa: { ...form.nfpa, flammability: parseInt(e.target.value) || 0 }, | |
| }) | |
| } | |
| /> | |
| </div> | |
| <div> | |
| <label className="block text-sm">Instability (0-4)</label> | |
| <input | |
| type="number" | |
| min={0} | |
| max={4} | |
| className="input w-full" | |
| value={form.nfpa?.instability ?? 0} | |
| onChange={(e) => | |
| setForm({ | |
| ...form, | |
| nfpa: { ...form.nfpa, instability: parseInt(e.target.value) || 0 }, | |
| }) | |
| } | |
| /> | |
| </div> | |
| <div> | |
| <label className="block text-sm">Special (W, OX, SA)</label> | |
| <input | |
| type="text" | |
| className="input w-full" | |
| value={form.nfpa?.special ?? ""} | |
| onChange={(e) => | |
| setForm({ | |
| ...form, | |
| nfpa: { ...form.nfpa, special: e.target.value }, | |
| }) | |
| } | |
| /> | |
| </div> | |
| </div> | |
| </fieldset> | |
| </div> | |
| <div className="flex justify-end gap-2 mt-6"> | |
| <button onClick={onClose} className="btn btn-secondary"> | |
| Cancel | |
| </button> | |
| <button onClick={handleSubmit} disabled={saving} className="btn btn-primary"> | |
| {saving ? "Saving..." : "Save"} | |
| </button> | |
| </div> | |
| </div> | |
| </div> | |
| ); | |
| } | |
Xet Storage Details
- Size:
- 9.16 kB
- Xet hash:
- 999d49c6844af2e94a8583187b9ea66224738c1fd54093b55212e7d0f03cc085
·
Xet efficiently stores files, intelligently splitting them into unique chunks and accelerating uploads and downloads. More info.