diff --git a/src/components/FinanceApp.tsx b/src/components/FinanceApp.tsx index f714383..59d1b97 100644 --- a/src/components/FinanceApp.tsx +++ b/src/components/FinanceApp.tsx @@ -3,7 +3,7 @@ import { useCallback, useEffect, useMemo, useRef, useState, type CSSProperties } from 'react'; import { Activity, ArrowDownLeft, ArrowDownRight, ArrowLeftRight, ArrowRight, ArrowUpRight, Banknote, BarChart3, Bell, CalendarDays, Check, ChevronDown, ChevronLeft, ChevronRight, CircleHelp, CreditCard, Download, FileText, Filter, LayoutDashboard, Moon, Plus, Power, PiggyBank, Repeat2, Search, Settings, ShieldCheck, Smartphone, Sun, Target, Trash2, TrendingUp, Wallet as WalletIcon, X, type LucideIcon } from 'lucide-react'; import { Area, AreaChart, Bar, BarChart, CartesianGrid, ResponsiveContainer, Tooltip, XAxis, YAxis } from 'recharts'; -import { Budget, BUDGET_MONTH_MIN, BUDGET_MONTH_MAX, MONTHLY_BUDGET_REPEAT_MARKER, budgetsOverlap, categoryColors, digitalWalletBalances, Entry, EntryType, expenseCategories, FinanceData, goldHoldingGrams, incomeCategories, investmentMovement, InvestmentMovement, monthKey, budgetsForMonth, addDays, budgetRange, budgetSpent, countDays, monthRange, newFinanceData, Recurring, seedData, Wallet, walletBalance, walletMarketValue, isBudgetMonth, isDigitalWallet } from '@/lib/finance'; +import { Budget, BUDGET_MONTH_MIN, BUDGET_MONTH_MAX, MONTHLY_BUDGET_REPEAT_MARKER, budgetsOverlap, categoryColors, digitalWalletBalances, Entry, EntryType, expenseCategories, FinanceData, goldHoldingGrams, incomeCategories, investmentMovement, InvestmentMovement, monthKey, budgetsForMonth, addDays, budgetRange, budgetSpent, countDays, monthRange, newFinanceData, Recurring, seedData, Wallet, walletBalance, walletMarketValue, isBudgetMonth } from '@/lib/finance'; import { fetchGoldQuote, GoldQuoteError, type GoldQuote } from '@/lib/gold'; import { byCategory, cashflow, byCategoryForDateRange, cashflowForDateRange, dateRangeDayCount, dateRangeMonthCount, entriesForDateRange, metrics, previousDateRange, type ReportDateRange, budgetTotals } from '@/lib/metrics'; import { compact, dateLabel, goldGrams, monthLabel, rupiah, rupiahAxisTick } from '@/lib/format'; @@ -1067,9 +1067,7 @@ function EditorDialog({ editor, data, period, saving, opener, onClose, onSave }: const [color, setColor] = useState(editor.kind === 'wallet' ? editor.item?.color || '#10b981' : '#10b981'); const [hasGoal, setHasGoal] = useState(editor.kind === 'wallet' ? Boolean(editor.item?.goal) : false); const [goalAmount, setGoalAmount] = useState(editor.kind === 'wallet' && editor.item?.goal ? String(editor.item.goal) : ''); - const digitalWallets = data.wallets.filter(wallet => isDigitalWallet(wallet) && (!wallet.archived || wallet.id === currentWallet?.preferredWalletId)); const [investmentAsset, setInvestmentAsset] = useState>(editor.kind === 'wallet' ? editor.item?.investmentAsset ?? 'money' : 'money'); - const [preferredWalletId, setPreferredWalletId] = useState(editor.kind === 'wallet' ? editor.item?.preferredWalletId ?? digitalWallets.find(wallet => !wallet.archived)?.id ?? '' : ''); const [frequency, setFrequency] = useState(editor.kind === 'recurring' ? editor.item?.frequency || 'monthly' : 'monthly'); const editedBudget = editor.kind === 'budget' ? editor.item : undefined; const [budgetTitle, setBudgetTitle] = useState(editedBudget?.title || ''); @@ -1096,7 +1094,7 @@ function EditorDialog({ editor, data, period, saving, opener, onClose, onSave }: if (investment && hasGoal && goalValue <= 0) { setError('Isi target dana goal.'); return; } const newWalletId = editor.item?.id || id(); const initialEntry = !current && !investment && value > 0 ? { type: 'income' as const, amount: value, walletId: newWalletId, category: 'Lainnya', title: 'Saldo Awal', note: '', date: today() } : undefined; - onSave({ id: newWalletId, name: title.trim(), type: investment ? 'investment' : walletType, openingBalance: 0, color, archived: editor.item?.archived || false, goal: investment && hasGoal ? goalValue : undefined, investmentAsset: investment ? investmentAsset : undefined, preferredWalletId: investment ? (investmentAsset === 'gold' ? currentWallet?.preferredWalletId : preferredWalletId || undefined) : undefined }, initialEntry); + onSave({ id: newWalletId, name: title.trim(), type: investment ? 'investment' : walletType, openingBalance: 0, color, archived: editor.item?.archived || false, goal: investment && hasGoal ? goalValue : undefined, investmentAsset: investment ? investmentAsset : undefined, preferredWalletId: investment ? currentWallet?.preferredWalletId : undefined }, initialEntry); } else if (editor.kind === 'budget') { if (budgetMode === 'cycle' && !isBudgetMonth(startMonth)) { setError('Pilih bulan mulai antara Januari 1900 dan Desember 2199, misalnya 2026-12.'); @@ -1131,7 +1129,6 @@ function EditorDialog({ editor, data, period, saving, opener, onClose, onSave }: } {investment && !current && } - {investment && investmentAsset !== 'gold' && } {investment && hasGoal && } {editor.kind === 'wallet' && !investment && !current && } {!investment && editor.kind !== 'wallet' && } diff --git a/src/components/Investments.tsx b/src/components/Investments.tsx index b4066fc..ba328de 100644 --- a/src/components/Investments.tsx +++ b/src/components/Investments.tsx @@ -118,7 +118,6 @@ export function SavingsCards({ data, onCreate, onRename, onRemove, onTransfer, o )} } - {!gold && wallet.preferredWalletId &&

Dompet pilihan: {names.get(wallet.preferredWalletId) ?? 'Tidak tersedia'}

} {wallet.goal ? (gold && !goldQuote ?

Target {rupiah(wallet.goal)} · menunggu harga emas

: ) :

Belum ada goal. Ubah simpanan untuk mengatur target.

}
onTransfer({ investmentId: wallet.id, direction: 'deposit' })}> @@ -244,9 +243,7 @@ function LegacyInvestmentTransferDialog({ movement, entry, data, initialDate, sa const previousWalletId = deposit ? entry?.walletId : entry?.targetWalletId; const wallets = data.wallets.filter(wallet => isDigitalWallet(wallet) && (!wallet.archived || wallet.id === previousWalletId)); const preferredWalletId = investment?.preferredWalletId && wallets.some(wallet => wallet.id === investment.preferredWalletId) ? investment.preferredWalletId : undefined; - const [walletId, setWalletId] = useState(() => previousWalletId ?? preferredWalletId ?? ( - deposit ? wallets.find(wallet => walletBalance(data, wallet.id) > 0)?.id : wallets[0]?.id - ) ?? ''); + const [walletId, setWalletId] = useState(() => previousWalletId ?? (deposit ? '' : preferredWalletId ?? wallets[0]?.id ?? '')); const [amount, setAmount] = useState(entry ? String(entry.amount) : ''); const [grams, setGrams] = useState(entry?.investmentGrams ? formatGramInput(entry.investmentGrams) : ''); const [date, setDate] = useState(entry?.date ?? initialDate); @@ -356,7 +353,7 @@ function LegacyInvestmentTransferDialog({ movement, entry, data, initialDate, sa {gold ? deposit ? `Saldo dompet tersedia ${rupiah(Math.max(available, 0))}` : `Emas tersedia ${goldHoldingGrams(data, movement.investmentId, entry?.id).toLocaleString('id-ID', { maximumFractionDigits: 6 })} gram · nilai spot ${rupiah(goldHoldingGrams(data, movement.investmentId, entry?.id) * (spot ?? 0))}` - : `Saldo tersedia ${rupiah(Math.max(available, 0))}`} + : deposit && !walletId ? 'Pilih dompet untuk melihat saldo tersedia.' : `Saldo tersedia ${rupiah(Math.max(available, 0))}`}

Untuk rekening bank dan e-wallet, lakukan transfer di aplikasi penyedia lalu catat di FinTrack.

; diff --git a/tests/ui/finance.spec.ts b/tests/ui/finance.spec.ts index c4980e4..d12754c 100644 --- a/tests/ui/finance.spec.ts +++ b/tests/ui/finance.spec.ts @@ -508,11 +508,14 @@ test('simpanan dapat diisi dari bank dan ditarik ke e-wallet tanpa menghitungnya await expect(page).toHaveURL(/\/investments$/); await page.getByRole('button', { name: 'Buat simpanan pertama' }).click(); await page.getByLabel('Nama simpanan').fill('Dana darurat'); + await expect(page.getByRole('dialog').getByLabel(/dompet/i)).toHaveCount(0); await page.getByRole('button', { name: 'Simpan Simpanan' }).click(); const savings = page.getByRole('article').filter({ hasText: 'Dana darurat' }); await expect(savings.getByRole('button', { name: 'Tarik', exact: true })).toBeDisabled(); await savings.getByRole('button', { name: 'Setor', exact: true }).click(); let dialog = page.getByRole('dialog'); + await expect(dialog.getByLabel('Dompet sumber')).toHaveValue(''); + await expect(dialog.getByText('Pilih dompet untuk melihat saldo tersedia.')).toBeVisible(); await dialog.getByLabel('Dompet sumber').selectOption('bca'); await dialog.getByLabel(/Nominal rupiah/).fill('1000000000'); await dialog.getByRole('button', { name: 'Setor dana' }).click(); @@ -520,6 +523,9 @@ test('simpanan dapat diisi dari bank dan ditarik ke e-wallet tanpa menghitungnya await dialog.getByLabel(/Nominal rupiah/).fill('500000'); await dialog.getByRole('button', { name: 'Setor dana' }).click(); await expect(savings).toContainText(/Rp\s*500\.000/); + await savings.getByRole('button', { name: 'Setor', exact: true }).click(); + await expect(dialog.getByLabel('Dompet sumber')).toHaveValue(''); + await dialog.getByRole('button', { name: 'Batal' }).click(); await savings.getByRole('button', { name: 'Tarik', exact: true }).click(); dialog = page.getByRole('dialog'); await dialog.getByLabel('Dompet tujuan').selectOption('gopay');