Files
openmonetis/src/features/dashboard/page-data-queries.ts
Felipe Coutinho ba05985725 refactor(dashboard): reorganizar módulos em subdiretórios e nova arquitetura de widgets
Arquivos de queries, helpers e controllers dispersos na raiz de dashboard/
foram movidos para subdiretórios temáticos (bills/, invoices/, notes/,
notifications/, overview/, payments/, goals-progress/, categories/).
~25 widgets monolíticos obsoletos removidos em favor de nova arquitetura
baseada em widget-registry com components/widgets/. Novos componentes:
category-breakdown-chart/list, goals-progress-item, percentage-change-indicator.
Imports atualizados em fetch-dashboard-data e transaction-filters limpos.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-04-20 17:51:56 +00:00

75 lines
2.1 KiB
TypeScript

import { cacheLife, cacheTag } from "next/cache";
import { fetchDashboardData } from "@/features/dashboard/fetch-dashboard-data";
import { fetchUserDashboardPreferences } from "@/features/dashboard/preferences-queries";
import {
buildOptionSets,
buildSluggedFilters,
} from "@/features/transactions/page-helpers";
import {
fetchRecentEstablishments,
fetchTransactionFilterSources,
} from "@/features/transactions/queries";
type DashboardQuickActionOptions = {
payerOptions: ReturnType<typeof buildOptionSets>["payerOptions"];
splitPayerOptions: ReturnType<typeof buildOptionSets>["splitPayerOptions"];
defaultPayerId: string | null;
accountOptions: ReturnType<typeof buildOptionSets>["accountOptions"];
cardOptions: ReturnType<typeof buildOptionSets>["cardOptions"];
categoryOptions: ReturnType<typeof buildOptionSets>["categoryOptions"];
estabelecimentos: string[];
};
async function fetchDashboardQuickActionOptionsInternal(
userId: string,
): Promise<DashboardQuickActionOptions> {
const [filterSources, estabelecimentos] = await Promise.all([
fetchTransactionFilterSources(userId),
fetchRecentEstablishments(userId),
]);
const sluggedFilters = buildSluggedFilters(filterSources);
const {
payerOptions,
splitPayerOptions,
defaultPayerId,
accountOptions,
cardOptions,
categoryOptions,
} = buildOptionSets({
...sluggedFilters,
payerRows: filterSources.payerRows,
});
return {
payerOptions,
splitPayerOptions,
defaultPayerId,
accountOptions,
cardOptions,
categoryOptions,
estabelecimentos,
};
}
export async function fetchDashboardQuickActionOptions(userId: string) {
"use cache";
cacheTag(`dashboard-${userId}`);
cacheLife({ revalidate: 3 });
return fetchDashboardQuickActionOptionsInternal(userId);
}
export async function fetchDashboardPageData(userId: string, period: string) {
const [dashboardData, preferences, quickActionOptions] = await Promise.all([
fetchDashboardData(userId, period),
fetchUserDashboardPreferences(userId),
fetchDashboardQuickActionOptions(userId),
]);
return {
dashboardData,
preferences,
quickActionOptions,
};
}