From 06025623ffe6ffd3506928c55ae8e2d6ac881792 Mon Sep 17 00:00:00 2001 From: DaX Date: Fri, 27 Jun 2025 01:42:11 +0200 Subject: [PATCH] Update quantity field to show sum of all inventory types MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - Remove "količina" from Refill, Vakuum, and Otvoreno labels - Move Količina field to end of form as "Ukupna količina" (Total quantity) - Make Količina field read-only and calculate sum of all inventory types - Update form submission to calculate total quantity automatically - Update tests to reflect new label changes 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: DaX --- __tests__/ui-features.test.ts | 7 ++--- app/upadaj/dashboard/page.tsx | 51 ++++++++++++++++++++++------------- 2 files changed, 37 insertions(+), 21 deletions(-) diff --git a/__tests__/ui-features.test.ts b/__tests__/ui-features.test.ts index 274d80e..4cb91b8 100644 --- a/__tests__/ui-features.test.ts +++ b/__tests__/ui-features.test.ts @@ -29,9 +29,10 @@ describe('UI Features Tests', () => { expect(adminContent).toMatch(/type="number"[\s\S]*?name="refill"/); expect(adminContent).toMatch(/type="number"[\s\S]*?name="vakum"/); expect(adminContent).toMatch(/type="number"[\s\S]*?name="otvoreno"/); - expect(adminContent).toContain('Refill količina'); - expect(adminContent).toContain('Vakuum količina'); - expect(adminContent).toContain('Otvoreno količina'); + expect(adminContent).toContain('Refill'); + expect(adminContent).toContain('Vakuum'); + expect(adminContent).toContain('Otvoreno'); + expect(adminContent).toContain('Ukupna količina'); }); it('should have number input for quantity', () => { diff --git a/app/upadaj/dashboard/page.tsx b/app/upadaj/dashboard/page.tsx index 12059a4..eccba26 100644 --- a/app/upadaj/dashboard/page.tsx +++ b/app/upadaj/dashboard/page.tsx @@ -421,9 +421,19 @@ function FilamentForm({ const handleSubmit = (e: React.FormEvent) => { e.preventDefault(); + + // Calculate total quantity + const refillCount = parseInt(formData.refill) || (formData.refill?.toLowerCase() === 'da' ? 1 : 0); + const vakuumMatch = formData.vakum?.match(/^(\d+)\s*vakuum/); + const vakuumCount = vakuumMatch ? parseInt(vakuumMatch[1]) : (formData.vakum?.toLowerCase().includes('vakuum') ? 1 : 0); + const otvorenMatch = formData.otvoreno?.match(/^(\d+)\s*otvorena/); + const otvorenCount = otvorenMatch ? parseInt(otvorenMatch[1]) : (formData.otvoreno?.toLowerCase().includes('otvorena') ? 1 : 0); + const totalQuantity = refillCount + vakuumCount + otvorenCount; + onSave({ ...filament, - ...formData + ...formData, + kolicina: totalQuantity.toString() }); }; @@ -564,20 +574,6 @@ function FilamentForm({ -
- - -
-
- +
- +
- +
+ {/* Total quantity display */} +
+ + { + const refillCount = parseInt(formData.refill) || (formData.refill?.toLowerCase() === 'da' ? 1 : 0); + const vakuumMatch = formData.vakum?.match(/^(\d+)\s*vakuum/); + const vakuumCount = vakuumMatch ? parseInt(vakuumMatch[1]) : (formData.vakum?.toLowerCase().includes('vakuum') ? 1 : 0); + const otvorenMatch = formData.otvoreno?.match(/^(\d+)\s*otvorena/); + const otvorenCount = otvorenMatch ? parseInt(otvorenMatch[1]) : (formData.otvoreno?.toLowerCase().includes('otvorena') ? 1 : 0); + return refillCount + vakuumCount + otvorenCount; + })()} + readOnly + className="w-full px-3 py-2 border border-gray-300 dark:border-gray-600 rounded-md bg-gray-100 dark:bg-gray-600 text-gray-900 dark:text-gray-100 cursor-not-allowed" + /> +
+