refactor(js): use shared formatMonthFromYearMonth in dashboard (#482)

## What

`use-dashboard-data.ts` had a private `formatMonth()` duplicating
`utils/date.ts` `formatMonthFromYearMonth()`.

Removed the local copy; dashboard now uses the shared util.

**Tiny visual change:** non-current-year labels on dashboard net-worth
chart render `Jan '26` instead of `Jan 26` — now consistent with
cashflow-trend and account-balance charts which already use the shared
util.

## Stats

- **-14 / +2 lines**

## Checks

- `bun run test` — 154 passed
- `bun run lint` — clean (1 pre-existing warning)

Part of duplication-removal series (#475–#481).
This commit is contained in:
Víctor Falcón 2026-06-03 19:00:46 +02:00 committed by GitHub
parent 7784f0d4fb
commit 4028e5dfa3
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
1 changed files with 2 additions and 15 deletions

View File

@ -2,6 +2,7 @@ import { useLocale } from '@/hooks/use-locale';
import { getAccountSign } from '@/lib/chart-calculations';
import { Account, AccountType, Bank } from '@/types/account';
import { Category } from '@/types/category';
import { formatMonthFromYearMonth } from '@/utils/date';
import { format, subDays, subMonths } from 'date-fns';
import { useCallback, useEffect, useState } from 'react';
@ -66,7 +67,7 @@ export function deriveAccountMetrics(
return Object.values(accounts).map((account) => {
const investedKey = account.id + '_invested';
const history = data.map((point) => ({
date: formatMonth(point.month as string, locale),
date: formatMonthFromYearMonth(point.month as string, locale),
value:
typeof point[account.id] === 'number'
? getAccountSign(account.type) *
@ -100,20 +101,6 @@ export function deriveAccountMetrics(
});
}
function formatMonth(yearMonth: string, locale = 'en-US'): string {
const [year, month] = yearMonth.split('-');
const date = new Date(parseInt(year), parseInt(month) - 1);
const isCurrentYear = date.getFullYear() === new Date().getFullYear();
return date.toLocaleDateString(
locale,
isCurrentYear
? { month: 'short' }
: { year: '2-digit', month: 'short' },
);
}
export function useDashboardData(): DashboardData & { refetch: () => void } {
const locale = useLocale();
const [data, setData] = useState<Omit<DashboardData, 'isLoading'>>({