Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions src/app/globals.css
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,23 @@
@media print{.topbar,.demo-banner,.heading-actions,.filter-card,.toast,.button{display:none!important}.main-column{margin:0}.content{padding:0}.card{break-inside:avoid;box-shadow:none}.page-heading h1{font-size:20px}}
.donut-ring{position:absolute;width:182px;height:182px;border-radius:50%;left:50%;top:50%;transform:translate(-50%,-50%)}.donut-ring:after{content:'';position:absolute;inset:22px;border-radius:50%;background:var(--surface)}.donut-center{z-index:1}.dashboard-bottom-grid>.card,.report-bottom>.card,.dashboard-chart-grid>.card{min-width:0}@media(max-width:700px){.dashboard-bottom-grid,.dashboard-chart-grid,.report-bottom,.settings-grid{grid-template-columns:minmax(0,1fr)}.recent-row{min-width:0}.recent-row .amount{font-size:10px}}
.filter-extra{display:flex;flex-wrap:wrap;gap:10px;margin:-6px 0 16px}.filter-extra label{display:flex;align-items:center;gap:7px;color:var(--muted);font-size:10px;font-weight:700}.filter-extra input,.filter-extra select{border:1px solid var(--line);border-radius:7px;min-height:36px;padding:6px 8px;font-size:10px;max-width:170px}@media(max-width:700px){.filter-extra{display:grid;grid-template-columns:1fr 1fr}.filter-extra label{display:grid;gap:4px}.filter-extra label:first-child{grid-column:1/-1}.filter-extra input,.filter-extra select{width:100%;max-width:none}}

.filter-card{animation:filter-card-enter .24s cubic-bezier(.2,.8,.2,1) both}
.filter-extra{animation:filter-card-enter .28s cubic-bezier(.2,.8,.2,1) both}
.filter-controls{align-items:center}
.filter-select{position:relative}
.filter-select-trigger{width:100%;min-height:40px;justify-content:space-between;background:var(--surface);cursor:pointer}
.filter-select-trigger span{flex:1;overflow:hidden;text-overflow:ellipsis;white-space:nowrap;text-align:left;font-size:11px}
.filter-select-menu{position:absolute;z-index:30;top:calc(100% + 7px);left:0;min-width:100%;max-height:260px;overflow:auto;padding:5px;background:var(--surface);border:1px solid var(--line);border-radius:11px;box-shadow:0 14px 32px #0b2b2624;transform-origin:top left;animation:filter-menu-in .16s cubic-bezier(.2,.8,.2,1) both}
.filter-select-menu button{display:block;width:100%;padding:9px 11px;border:0;border-radius:7px;background:transparent;color:var(--ink);text-align:left;font-size:12px;white-space:nowrap}
.filter-select-menu button:hover,.filter-select-menu button[aria-selected=true]{background:var(--hover);color:var(--green)}
.filter-extra label{transition:transform .18s ease,opacity .18s ease}
.filter-extra label:focus-within{transform:translateY(-1px)}
.filter-extra select,.filter-extra input[type=date]{background:var(--surface);color:var(--ink);box-shadow:0 1px 2px #0b2b2608;cursor:pointer}
.filter-extra select:focus,.filter-extra input[type=date]:focus{border-color:var(--green);box-shadow:0 0 0 3px #23534718}
@keyframes filter-card-enter{from{opacity:0;translate:0 7px;scale:.99}to{opacity:1;translate:0 0;scale:1}}
@keyframes filter-menu-in{from{opacity:0;translate:0 -4px;scale:.98}to{opacity:1;translate:0 0;scale:1}}
@media(prefers-reduced-motion:reduce){.filter-card,.filter-extra,.filter-select-menu{animation:none}.filter-extra label{transition:none}}
@media(max-width:900px){.dashboard-bottom-grid{grid-template-columns:repeat(2,minmax(0,1fr))}.recent-row{min-width:0;overflow:hidden}}
@media(max-width:700px){.dashboard-bottom-grid{grid-template-columns:minmax(0,1fr)}}

Expand Down
24 changes: 23 additions & 1 deletion src/components/FinanceApp.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -647,6 +647,28 @@ function Dashboard({ data, current, categories, trend, period, open, go, goldPri
</section>;
}

function TransactionFilterPanel({ data, wallet, setWallet, type, setType, categoryFilter, setCategoryFilter, startDate, setStartDate, endDate, setEndDate, entries }: {
data: FinanceData; wallet: string; setWallet: (value: string) => void; type: string; setType: (value: string) => void;
categoryFilter: string; setCategoryFilter: (value: string) => void; startDate: string; setStartDate: (value: string) => void;
endDate: string; setEndDate: (value: string) => void; entries: Entry[];
}) {
const [open, setOpen] = useState<'wallet' | 'type' | null>(null);
const options = open === 'wallet' ? [{ value: 'all', label: 'Semua dompet' }, ...data.wallets.map(item => ({ value: item.id, label: item.name }))] : [
{ value: 'all', label: 'Semua tipe' }, { value: 'income', label: 'Pemasukan' }, { value: 'expense', label: 'Pengeluaran' }, { value: 'transfer', label: 'Transfer' },
];
const selected = open === 'wallet' ? wallet : type;
const change = open === 'wallet' ? setWallet : setType;
return <><div className="filter-controls">
{(['wallet', 'type'] as const).map(kind => <div className="filter-select" key={kind}>
<button type="button" className="select-wrap filter-select-trigger" aria-expanded={open === kind} onClick={() => setOpen(open === kind ? null : kind)}>
{kind === 'wallet' ? <WalletIcon size={16} /> : <Filter size={16} />}
<span>{kind === 'wallet' ? (wallet === 'all' ? 'Semua dompet' : data.wallets.find(item => item.id === wallet)?.name) : ({ all: 'Semua tipe', income: 'Pemasukan', expense: 'Pengeluaran', transfer: 'Transfer' } as Record<string, string>)[type]}</span><ChevronDown size={14} />
</button>
{open === kind && <div className="filter-select-menu" role="listbox">{options.map(option => <button type="button" role="option" aria-selected={selected === option.value} key={option.value} onClick={() => { change(option.value); setOpen(null); }}>{option.label}</button>)}</div>}
</div>)}
</div><div className="filter-extra"><label>Kategori<select aria-label="Filter kategori" value={categoryFilter} onChange={event => setCategoryFilter(event.target.value)}><option value="all">Semua kategori</option>{[...new Set(entries.map(entry => entry.category))].sort().map(item => <option key={item}>{item}</option>)}</select></label><label>Dari tanggal<input aria-label="Dari tanggal" type="date" value={startDate} max={endDate || undefined} onChange={event => setStartDate(event.target.value)} /></label><label>Sampai tanggal<input aria-label="Sampai tanggal" type="date" value={endDate} min={startDate || undefined} onChange={event => setEndDate(event.target.value)} /></label></div></>;
}

function Transactions({ data, entries, open, remove }: {
data: FinanceData;
entries: Entry[];
Expand All @@ -668,7 +690,7 @@ function Transactions({ data, entries, open, remove }: {
const filtered = useMemo(() => entries.filter(e => (type === 'all' || e.type === type) && (wallet === 'all' || e.walletId === wallet || (e.type === 'transfer' && e.targetWalletId === wallet)) && (categoryFilter === 'all' || e.category === categoryFilter) && (!startDate || e.date >= startDate) && (!endDate || e.date <= endDate) && `${e.title} ${e.category} ${e.note || ''} ${e.amount}`.toLowerCase().includes(searchTerm)).sort((a, b) => b.date.localeCompare(a.date)), [entries, type, wallet, categoryFilter, startDate, endDate, searchTerm]);
const pages = Math.max(1, Math.ceil(filtered.length / 10));
const visible = filtered.slice((Math.min(page, pages) - 1) * 10, Math.min(page, pages) * 10);
return <><PageHeading eyebrow="BUKU BESAR" title="Semua Transaksi" description="Cari, saring, dan kelola setiap pergerakan uang Anda." action={<MotionButton className="button button-dark transaction-action" onClick={() => open({ kind: 'transaction' })}><Plus size={18} /> Catat Transaksi</MotionButton>} /><div className="card filter-card"><div className="field-search"><Search size={18} /><input aria-label="Cari transaksi" placeholder="Cari transaksi, kategori, nominal..." value={query} onChange={e => { setQuery(e.target.value); setPage(1); }} /></div><div className="filter-controls"><label className="select-wrap"><WalletIcon size={16} /><select aria-label="Filter dompet" value={wallet} onChange={e => { setWallet(e.target.value); setPage(1); }}><option value="all">Semua dompet</option>{data.wallets.map(w => <option value={w.id} key={w.id}>{w.name}</option>)}</select><ChevronDown size={14} /></label><label className="select-wrap"><Filter size={16} /><select aria-label="Filter tipe" value={type} onChange={e => { setType(e.target.value); setPage(1); }}><option value="all">Semua tipe</option><option value="income">Pemasukan</option><option value="expense">Pengeluaran</option><option value="transfer">Transfer</option></select><ChevronDown size={14} /></label><MotionButton className="button button-outline" onClick={() => downloadCsv(data, filtered)}><Download size={16} /> CSV</MotionButton></div></div><div className="filter-extra"><label>Kategori<select aria-label="Filter kategori" value={categoryFilter} onChange={e => { setCategoryFilter(e.target.value); setPage(1); }}><option value="all">Semua kategori</option>{[...new Set(entries.map(e => e.category))].sort().map(c => <option key={c}>{c}</option>)}</select></label><label>Dari tanggal<input aria-label="Dari tanggal" type="date" value={startDate} max={endDate || undefined} onChange={e => { setStartDate(e.target.value); setPage(1); }} /></label><label>Sampai tanggal<input aria-label="Sampai tanggal" type="date" value={endDate} min={startDate || undefined} onChange={e => { setEndDate(e.target.value); setPage(1); }} /></label></div><div className="card table-card"><div className="table-top"><div><h2>Riwayat Transaksi</h2><p>{filtered.length} transaksi ditemukan</p></div><span className="subtle-badge">Terbaru dulu</span></div>{visible.length ? <><div className="table-scroll"><table><thead><tr><th>TANGGAL</th><th>TRANSAKSI</th><th>KATEGORI</th><th>DOMPET</th><th className="align-right">NOMINAL</th><th className="align-right">AKSI</th></tr></thead><tbody>{visible.map(entry => <tr key={entry.id}><td className="muted-cell">{dateLabel(entry.date)}</td><td><div className="table-title"><EntrySymbol type={entry.type} /><span><strong>{entry.title}</strong><small>{entry.note || (entry.type === 'transfer' ? `Ke ${data.wallets.find(w => w.id === entry.targetWalletId)?.name || 'dompet lain'}` : entry.type === 'income' ? 'Pemasukan' : 'Pengeluaran')}</small></span></div></td><td><span className="category-badge"><i style={{ background: categoryColors[entry.category] || '#94a3b8' }} />{entry.category}</span></td><td className="muted-cell">{data.wallets.find(w => w.id === entry.walletId)?.name || 'Dompet dihapus'}</td><td className={`align-right amount ${entry.type}`}>{entry.type === 'expense' ? '-' : entry.type === 'income' ? '+' : ''}{rupiah(entry.amount)}</td><td className="align-right"><MotionButton className="row-action" onClick={() => open({ kind: 'transaction', item: entry })} aria-label={`Ubah ${entry.title}`}>Ubah</MotionButton><MotionButton className="row-action delete" onClick={() => remove(entry)} aria-label={`Hapus ${entry.title}`}><Trash2 size={16} /></MotionButton></td></tr>)}</tbody></table></div><div className="table-bottom"><span>Menampilkan {visible.length} dari {filtered.length} transaksi</span><div><MotionButton disabled={page <= 1} onClick={() => setPage(page - 1)}>Sebelumnya</MotionButton><span>{Math.min(page, pages)} / {pages}</span><MotionButton disabled={page >= pages} onClick={() => setPage(page + 1)}>Berikutnya</MotionButton></div></div></> : <Empty title="Tidak ada transaksi" detail="Coba ubah filter atau catat transaksi baru." action={<MotionButton className="button button-dark transaction-action" onClick={() => open({ kind: 'transaction' })}>Catat transaksi</MotionButton>} />}</div></>;
return <><PageHeading eyebrow="BUKU BESAR" title="Semua Transaksi" description="Cari, saring, dan kelola setiap pergerakan uang Anda." action={<MotionButton className="button button-dark transaction-action" onClick={() => open({ kind: 'transaction' })}><Plus size={18} /> Catat Transaksi</MotionButton>} /><div className="card filter-card"><div className="field-search"><Search size={18} /><input aria-label="Cari transaksi" placeholder="Cari transaksi, kategori, nominal..." value={query} onChange={e => { setQuery(e.target.value); setPage(1); }} /></div><TransactionFilterPanel data={data} wallet={wallet} setWallet={value => { setWallet(value); setPage(1); }} type={type} setType={value => { setType(value); setPage(1); }} categoryFilter={categoryFilter} setCategoryFilter={value => { setCategoryFilter(value); setPage(1); }} startDate={startDate} setStartDate={value => { setStartDate(value); setPage(1); }} endDate={endDate} setEndDate={value => { setEndDate(value); setPage(1); }} entries={entries} /><div className="filter-controls"><MotionButton className="button button-outline" onClick={() => downloadCsv(data, filtered)}><Download size={16} /> CSV</MotionButton></div></div><div className="card table-card"><div className="table-top"><div><h2>Riwayat Transaksi</h2><p>{filtered.length} transaksi ditemukan</p></div><span className="subtle-badge">Terbaru dulu</span></div>{visible.length ? <><div className="table-scroll"><table><thead><tr><th>TANGGAL</th><th>TRANSAKSI</th><th>KATEGORI</th><th>DOMPET</th><th className="align-right">NOMINAL</th><th className="align-right">AKSI</th></tr></thead><tbody>{visible.map(entry => <tr key={entry.id}><td className="muted-cell">{dateLabel(entry.date)}</td><td><div className="table-title"><EntrySymbol type={entry.type} /><span><strong>{entry.title}</strong><small>{entry.note || (entry.type === 'transfer' ? `Ke ${data.wallets.find(w => w.id === entry.targetWalletId)?.name || 'dompet lain'}` : entry.type === 'income' ? 'Pemasukan' : 'Pengeluaran')}</small></span></div></td><td><span className="category-badge"><i style={{ background: categoryColors[entry.category] || '#94a3b8' }} />{entry.category}</span></td><td className="muted-cell">{data.wallets.find(w => w.id === entry.walletId)?.name || 'Dompet dihapus'}</td><td className={`align-right amount ${entry.type}`}>{entry.type === 'expense' ? '-' : entry.type === 'income' ? '+' : ''}{rupiah(entry.amount)}</td><td className="align-right"><MotionButton className="row-action" onClick={() => open({ kind: 'transaction', item: entry })} aria-label={`Ubah ${entry.title}`}>Ubah</MotionButton><MotionButton className="row-action delete" onClick={() => remove(entry)} aria-label={`Hapus ${entry.title}`}><Trash2 size={16} /></MotionButton></td></tr>)}</tbody></table></div><div className="table-bottom"><span>Menampilkan {visible.length} dari {filtered.length} transaksi</span><div><MotionButton disabled={page <= 1} onClick={() => setPage(page - 1)}>Sebelumnya</MotionButton><span>{Math.min(page, pages)} / {pages}</span><MotionButton disabled={page >= pages} onClick={() => setPage(page + 1)}>Berikutnya</MotionButton></div></div></> : <Empty title="Tidak ada transaksi" detail="Coba ubah filter atau catat transaksi baru." action={<MotionButton className="button button-dark transaction-action" onClick={() => open({ kind: 'transaction' })}>Catat transaksi</MotionButton>} />}</div></>;
}

function Wallets({ data, open, remove, commit }: { data: FinanceData; open: (editor: Editor) => void; remove: (wallet: Wallet) => void; commit: (next: FinanceData, message: string) => void }) {
Expand Down
3 changes: 2 additions & 1 deletion tests/ui/finance.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -391,7 +391,8 @@ test('simpanan dapat diisi dari bank dan ditarik ke e-wallet tanpa menghitungnya
expect(await page.evaluate(() => document.documentElement.scrollWidth <= innerWidth)).toBe(true);

await bottom.getByRole('button', { name: 'Transaksi', exact: true }).click();
await page.getByLabel('Filter dompet').selectOption({ label: 'Dana darurat' });
await page.getByRole('button', { name: 'Semua dompet' }).click();
await page.getByRole('option', { name: 'Dana darurat' }).click();
await expect(page.getByRole('row').filter({ hasText: 'Setoran simpanan' })).toBeVisible();
await expect(page.getByRole('row').filter({ hasText: 'Penarikan simpanan' })).toBeVisible();
await page.getByRole('button', { name: 'Hapus Setoran simpanan' }).click();
Expand Down
Loading