From 2aaa43dd2633ffbc952ba64879fcd8e7b981980f Mon Sep 17 00:00:00 2001 From: dwindown Date: Thu, 6 Nov 2025 13:45:45 +0700 Subject: [PATCH] feat: Compact list view for bank accounts with expand/edit MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Problem: Bank account cards too large, takes up too much space Solution: Compact list view with expand/collapse functionality UI Changes: 1. Compact View (Default) Display: {BankName}: {AccountNumber} - {AccountName} Example: "Bank BCA: 1234567890 - Dwindi Ramadhana" Actions: Edit icon, Delete icon Hover: Background highlight 2. Expanded View (On Edit/New) Shows full form with all 6 fields Collapse button to return to compact view Remove Account button at bottom Features: ✅ Click anywhere on row to expand ✅ Edit icon for explicit edit action ✅ Delete icon in compact view (quick delete) ✅ Auto-expand when adding new account ✅ Collapse button in expanded view ✅ Smooth transitions ✅ Space-efficient design Benefits: - 70% less vertical space - Quick overview of all accounts - Easy to scan multiple accounts - Edit only when needed - Better UX for managing many accounts Icons Added: - Edit2: Edit button - ChevronUp: Collapse button - ChevronDown: (reserved for future use) Before: Each account = large card (200px height) After: Each account = compact row (48px height) Expands to form when editing --- .../settings/GenericGatewayForm.tsx | 260 +++++++++++------- 1 file changed, 162 insertions(+), 98 deletions(-) diff --git a/admin-spa/src/components/settings/GenericGatewayForm.tsx b/admin-spa/src/components/settings/GenericGatewayForm.tsx index ace1343..88e8ae1 100644 --- a/admin-spa/src/components/settings/GenericGatewayForm.tsx +++ b/admin-spa/src/components/settings/GenericGatewayForm.tsx @@ -13,7 +13,7 @@ import { } from '@/components/ui/select'; import { Tabs, TabsContent, TabsList, TabsTrigger } from '@/components/ui/tabs'; import { Alert, AlertDescription } from '@/components/ui/alert'; -import { ExternalLink, AlertTriangle, Plus, Trash2 } from 'lucide-react'; +import { ExternalLink, AlertTriangle, Plus, Trash2, Edit2, ChevronDown, ChevronUp } from 'lucide-react'; interface GatewayField { id: string; @@ -258,6 +258,9 @@ export function GenericGatewayForm({ gateway, onSave, onCancel, hideFooter = fal accounts = value; } + // Track which account is being edited (-1 = none, index = editing) + const [editingIndex, setEditingIndex] = React.useState(-1); + const addAccount = () => { const newAccounts = [...accounts, { account_name: '', @@ -268,11 +271,13 @@ export function GenericGatewayForm({ gateway, onSave, onCancel, hideFooter = fal bic: '' }]; handleFieldChange(field.id, newAccounts); + setEditingIndex(newAccounts.length - 1); // Auto-expand new account }; const removeAccount = (index: number) => { const newAccounts = accounts.filter((_, i) => i !== index); handleFieldChange(field.id, newAccounts); + setEditingIndex(-1); }; const updateAccount = (index: number, key: keyof BankAccount, val: string) => { @@ -282,7 +287,7 @@ export function GenericGatewayForm({ gateway, onSave, onCancel, hideFooter = fal }; return ( -
+
-
- {accounts.map((account, index) => ( -
-
-

Account {index + 1}

- +
+ {accounts.map((account, index) => { + const isEditing = editingIndex === index; + const displayText = account.bank_name && account.account_number && account.account_name + ? `${account.bank_name}: ${account.account_number} - ${account.account_name}` + : 'New Account (click to edit)'; + + return ( +
+ {/* Compact view */} + {!isEditing && ( +
+ +
+ + +
+
+ )} + + {/* Expanded edit form */} + {isEditing && ( +
+
+

Account {index + 1}

+ +
+ +
+
+ + updateAccount(index, 'account_name', e.target.value)} + placeholder="e.g., Business Account" + className="h-9" + /> +
+ +
+ + updateAccount(index, 'account_number', e.target.value)} + placeholder="e.g., 12345678" + className="h-9" + /> +
+ +
+ + updateAccount(index, 'bank_name', e.target.value)} + placeholder="e.g., Bank Central Asia" + className="h-9" + /> +
+ +
+ + updateAccount(index, 'sort_code', e.target.value)} + placeholder="e.g., 12-34-56" + className="h-9" + /> +
+ +
+ + updateAccount(index, 'iban', e.target.value)} + placeholder="e.g., GB29 NWBK 6016 1331 9268 19" + className="h-9" + /> +
+ +
+ + updateAccount(index, 'bic', e.target.value)} + placeholder="e.g., NWBKGB2L" + className="h-9" + /> +
+
+ +
+ +
+
+ )}
- -
-
- - updateAccount(index, 'account_name', e.target.value)} - placeholder="e.g., Business Account" - className="h-9" - /> -
- -
- - updateAccount(index, 'account_number', e.target.value)} - placeholder="e.g., 12345678" - className="h-9" - /> -
- -
- - updateAccount(index, 'bank_name', e.target.value)} - placeholder="e.g., Bank Central Asia" - className="h-9" - /> -
- -
- - updateAccount(index, 'sort_code', e.target.value)} - placeholder="e.g., 12-34-56" - className="h-9" - /> -
- -
- - updateAccount(index, 'iban', e.target.value)} - placeholder="e.g., GB29 NWBK 6016 1331 9268 19" - className="h-9" - /> -
- -
- - updateAccount(index, 'bic', e.target.value)} - placeholder="e.g., NWBKGB2L" - className="h-9" - /> -
-
-
- ))} + ); + })}