From 3bd907eaf2a4dd4d4f3f7a3b6a365a61b5a8c11f Mon Sep 17 00:00:00 2001 From: DaX Date: Mon, 30 Jun 2025 23:29:25 +0200 Subject: [PATCH] Add admin sorting options and prevent zero quantity filament creation MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - Add sorting dropdown with Serbian labels (alphabetical, date-based, quantity) - Fix Safari dropdown styling with custom-select class - Add validation to prevent adding filaments with 0 quantity - Improve sort dropdown layout and error handling 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: DaX --- app/upadaj/dashboard/page.tsx | 81 +++++++++++++++++++++++++++++------ 1 file changed, 68 insertions(+), 13 deletions(-) diff --git a/app/upadaj/dashboard/page.tsx b/app/upadaj/dashboard/page.tsx index d697a90..5cacfa7 100644 --- a/app/upadaj/dashboard/page.tsx +++ b/app/upadaj/dashboard/page.tsx @@ -158,7 +158,21 @@ export default function AdminDashboard() { if (aVal === null || aVal === undefined) aVal = ''; if (bVal === null || bVal === undefined) bVal = ''; - // Convert to strings for comparison + // Handle date fields + if (sortField === 'created_at' || sortField === 'updated_at') { + const aDate = new Date(String(aVal)); + const bDate = new Date(String(bVal)); + return sortOrder === 'asc' ? aDate.getTime() - bDate.getTime() : bDate.getTime() - aDate.getTime(); + } + + // Handle numeric fields + if (sortField === 'kolicina' || sortField === 'refill' || sortField === 'spulna') { + const aNum = Number(aVal) || 0; + const bNum = Number(bVal) || 0; + return sortOrder === 'asc' ? aNum - bNum : bNum - aNum; + } + + // String comparison for other fields aVal = String(aVal).toLowerCase(); bVal = String(bVal).toLowerCase(); @@ -355,19 +369,54 @@ export default function AdminDashboard() { )} - {/* Search Bar */} + {/* Search Bar and Sorting */}
-
- setSearchTerm(e.target.value)} - className="w-full px-4 py-2 pl-10 pr-4 text-gray-700 dark:text-gray-300 bg-white dark:bg-gray-800 border border-gray-300 dark:border-gray-600 rounded-lg focus:outline-none focus:border-blue-500" - /> - - - +
+ {/* Search Input */} +
+ setSearchTerm(e.target.value)} + className="w-full px-4 py-2 pl-10 pr-4 text-gray-700 dark:text-gray-300 bg-white dark:bg-gray-800 border border-gray-300 dark:border-gray-600 rounded-lg focus:outline-none focus:border-blue-500" + /> + + + +
+ + {/* Sort Dropdown */} +
+ +
@@ -637,6 +686,12 @@ function FilamentForm({ // Calculate total quantity const totalQuantity = formData.refill + formData.spulna; + // Prevent adding filaments with 0 quantity + if (totalQuantity === 0) { + alert('Količina mora biti veća od 0. Dodajte refill ili spulna.'); + return; + } + // Use the prices from the form (which can be edited) const refillPrice = formData.cena_refill; const spoolPrice = formData.cena_spulna;