diff --git a/app/upadaj/colors/page.tsx b/app/upadaj/colors/page.tsx index d129211..6dad72e 100644 --- a/app/upadaj/colors/page.tsx +++ b/app/upadaj/colors/page.tsx @@ -370,10 +370,24 @@ export default function ColorsManagement() { {/* Edit Modal */} {editingColor && ( -
-
+
setEditingColor(null)} + > +
e.stopPropagation()} + > +
+

Izmeni boju

+ +
-

Izmeni boju

{ @@ -477,7 +491,7 @@ function ColorForm({ readOnly={isBambuLabColor} pattern="^#[0-9A-Fa-f]{6}$" placeholder="#000000" - className={`flex-1 px-3 py-2 border border-gray-300 dark:border-gray-600 rounded-md bg-white dark:bg-gray-700 text-gray-900 dark:text-gray-100 focus:outline-none focus:ring-2 focus:ring-blue-500 ${isBambuLabColor ? 'bg-gray-100 dark:bg-gray-900 cursor-not-allowed' : ''}`} + className={`flex-1 px-3 py-2 border border-gray-300 dark:border-gray-600 rounded-md text-gray-900 dark:text-gray-100 focus:outline-none focus:ring-2 focus:ring-blue-500 ${isBambuLabColor ? 'bg-gray-100 dark:bg-gray-900 cursor-not-allowed' : 'bg-white dark:bg-gray-700'}`} />
{isBambuLabColor && ( diff --git a/app/upadaj/customers/page.tsx b/app/upadaj/customers/page.tsx index 7e34341..601f823 100644 --- a/app/upadaj/customers/page.tsx +++ b/app/upadaj/customers/page.tsx @@ -25,6 +25,10 @@ export default function CustomersManagement() { const [saving, setSaving] = useState(false); const [darkMode, setDarkMode] = useState(false); const [mounted, setMounted] = useState(false); + const [showAddModal, setShowAddModal] = useState(false); + const [addForm, setAddForm] = useState({ name: '', phone: '', city: '', notes: '' }); + const [addError, setAddError] = useState(''); + const [addSaving, setAddSaving] = useState(false); // Initialize dark mode useEffect(() => { @@ -139,6 +143,35 @@ export default function CustomersManagement() { } }; + const handleAddCustomer = async () => { + if (!addForm.name.trim()) { + setAddError('Ime je obavezno'); + return; + } + setAddSaving(true); + setAddError(''); + try { + await customerService.create({ + name: addForm.name.trim(), + phone: addForm.phone.trim() || undefined, + city: addForm.city.trim() || undefined, + notes: addForm.notes.trim() || undefined, + }); + setShowAddModal(false); + setAddForm({ name: '', phone: '', city: '', notes: '' }); + await fetchCustomers(); + } catch (err: unknown) { + const error = err as { response?: { data?: { code?: string } } }; + if (error.response?.data?.code === '23505') { + setAddError('Kupac sa ovim brojem telefona vec postoji'); + } else { + setAddError('Greska pri dodavanju kupca'); + } + } finally { + setAddSaving(false); + } + }; + const handleLogout = () => { localStorage.removeItem('authToken'); localStorage.removeItem('tokenExpiry'); @@ -230,8 +263,8 @@ export default function CustomersManagement() {
)} - {/* Search bar */} -
+ {/* Search bar + Add button */} +
setSearchTerm(e.target.value)} className="w-full max-w-md px-4 py-2 border border-gray-300 dark:border-gray-600 rounded-lg bg-white dark:bg-gray-700 text-gray-900 dark:text-white placeholder-gray-400 dark:placeholder-gray-500 focus:ring-2 focus:ring-blue-500 focus:border-transparent" /> +
{/* Customer count */} @@ -488,6 +527,108 @@ export default function CustomersManagement() {
+ + {/* Add Customer Modal */} + {showAddModal && ( +
setShowAddModal(false)} + > +
e.stopPropagation()} + > +
+

+ Dodaj kupca +

+ +
+ + {addError && ( +
+ {addError} +
+ )} + +
+
+ + setAddForm({ ...addForm, name: e.target.value })} + className="w-full px-3 py-2 border border-gray-300 dark:border-gray-600 rounded-lg bg-white dark:bg-gray-700 text-gray-900 dark:text-white focus:ring-2 focus:ring-green-500 focus:border-transparent" + placeholder="Ime i prezime" + autoFocus + /> +
+ +
+ + setAddForm({ ...addForm, phone: e.target.value })} + className="w-full px-3 py-2 border border-gray-300 dark:border-gray-600 rounded-lg bg-white dark:bg-gray-700 text-gray-900 dark:text-white focus:ring-2 focus:ring-green-500 focus:border-transparent" + placeholder="Broj telefona" + /> +
+ +
+ + setAddForm({ ...addForm, city: e.target.value })} + className="w-full px-3 py-2 border border-gray-300 dark:border-gray-600 rounded-lg bg-white dark:bg-gray-700 text-gray-900 dark:text-white focus:ring-2 focus:ring-green-500 focus:border-transparent" + placeholder="Grad" + /> +
+ +
+ +