'use client'; import { useState, useEffect } from 'react'; import { useRouter } from 'next/navigation'; import DashboardSidebar from '@/components/DashboardSidebar'; import { useSession } from 'next-auth/react'; import { FiPackage, FiArrowLeft, FiSave } from 'react-icons/fi'; import Link from 'next/link'; export default function NewEquipmentPage() { const router = useRouter(); const { data: session } = useSession(); const [locations, setLocations] = useState([]); const [projects, setProjects] = useState([]); const [loading, setLoading] = useState(false); const [error, setError] = useState(''); const [formData, setFormData] = useState({ name: '', type: 'PRINTER', brand: '', model: '', serialNumber: '', quantity: 1, status: 'AVAILABLE', locationId: '', projectId: '', notes: '', purchaseDate: '', purchasePrice: '', minStockLevel: '', currentStock: '', }); useEffect(() => { fetchLocationsAndProjects(); }, []); const fetchLocationsAndProjects = async () => { try { const [locRes, projRes] = await Promise.all([ fetch('/api/locations'), fetch('/api/projects'), ]); if (locRes.ok) { const locData = await locRes.json(); setLocations(locData.locations || []); } if (projRes.ok) { const projData = await projRes.json(); setProjects(projData.projects || []); } } catch (err) { console.error('Error fetching data:', err); } }; const handleSubmit = async (e: React.FormEvent) => { e.preventDefault(); setLoading(true); setError(''); try { const res = await fetch('/api/inventory', { method: 'POST', headers: { 'Content-Type': 'application/json' }, body: JSON.stringify({ ...formData, quantity: parseInt(formData.quantity.toString()), purchasePrice: formData.purchasePrice ? parseFloat(formData.purchasePrice) : null, minStockLevel: formData.minStockLevel ? parseInt(formData.minStockLevel.toString()) : null, currentStock: formData.currentStock ? parseInt(formData.currentStock.toString()) : null, locationId: formData.locationId || null, projectId: formData.projectId || null, }), }); const data = await res.json(); if (!res.ok) { throw new Error(data.error || 'Fehler beim Erstellen'); } alert('Equipment erfolgreich erstellt!'); router.push('/dashboard/inventory'); } catch (err: any) { setError(err.message); setLoading(false); } }; if (!session) { return null; } return (
Zurück zum Inventar

Neues Equipment anlegen

Equipment zum Inventar hinzufügen

Grunddaten

setFormData({ ...formData, name: e.target.value })} required placeholder="z.B. Citizen CX-02 #1" className="w-full px-4 py-2 bg-gray-700 border border-gray-600 text-white rounded-lg focus:ring-2 focus:ring-red-500 focus:border-transparent placeholder-gray-500" />
setFormData({ ...formData, brand: e.target.value })} placeholder="z.B. Citizen" className="w-full px-4 py-2 bg-gray-700 border border-gray-600 text-white rounded-lg focus:ring-2 focus:ring-red-500 focus:border-transparent placeholder-gray-500" />
setFormData({ ...formData, model: e.target.value })} placeholder="z.B. CX-02" className="w-full px-4 py-2 bg-gray-700 border border-gray-600 text-white rounded-lg focus:ring-2 focus:ring-red-500 focus:border-transparent placeholder-gray-500" />
setFormData({ ...formData, serialNumber: e.target.value })} className="w-full px-4 py-2 bg-gray-700 border border-gray-600 text-white rounded-lg focus:ring-2 focus:ring-red-500 focus:border-transparent" />
setFormData({ ...formData, quantity: parseInt(e.target.value) })} required min="1" className="w-full px-4 py-2 bg-gray-700 border border-gray-600 text-white rounded-lg focus:ring-2 focus:ring-red-500 focus:border-transparent" />

Zuordnung

Bestandsverwaltung (für Verbrauchsmaterial)

setFormData({ ...formData, currentStock: e.target.value })} placeholder="Nur für Verbrauchsmaterial" className="w-full px-4 py-2 bg-gray-700 border border-gray-600 text-white rounded-lg focus:ring-2 focus:ring-red-500 focus:border-transparent placeholder-gray-500" />
setFormData({ ...formData, minStockLevel: e.target.value })} placeholder="Warnung bei Unterschreitung" className="w-full px-4 py-2 bg-gray-700 border border-gray-600 text-white rounded-lg focus:ring-2 focus:ring-red-500 focus:border-transparent placeholder-gray-500" />

Kaufinformationen (optional)

setFormData({ ...formData, purchaseDate: e.target.value })} className="w-full px-4 py-2 bg-gray-700 border border-gray-600 text-white rounded-lg focus:ring-2 focus:ring-red-500 focus:border-transparent" />
setFormData({ ...formData, purchasePrice: e.target.value })} className="w-full px-4 py-2 bg-gray-700 border border-gray-600 text-white rounded-lg focus:ring-2 focus:ring-red-500 focus:border-transparent" />