mirror of
https://github.com/felipegcoutinho/openmonetis.git
synced 2026-07-09 03:16:01 +00:00
feat(dashboard): vincula tendências às categorias
This commit is contained in:
@@ -6,6 +6,7 @@ import {
|
|||||||
RiHistoryLine,
|
RiHistoryLine,
|
||||||
RiLineChartLine,
|
RiLineChartLine,
|
||||||
} from "@remixicon/react";
|
} from "@remixicon/react";
|
||||||
|
import Link from "next/link";
|
||||||
import type { DashboardCategoryBreakdownItem } from "@/features/dashboard/categories/category-breakdown-helpers";
|
import type { DashboardCategoryBreakdownItem } from "@/features/dashboard/categories/category-breakdown-helpers";
|
||||||
import { dashboardWidgetListStyles as styles } from "@/features/dashboard/components/dashboard-widget-list-styles";
|
import { dashboardWidgetListStyles as styles } from "@/features/dashboard/components/dashboard-widget-list-styles";
|
||||||
import { PercentageChangeIndicator } from "@/features/dashboard/components/percentage-change-indicator";
|
import { PercentageChangeIndicator } from "@/features/dashboard/components/percentage-change-indicator";
|
||||||
@@ -13,14 +14,18 @@ import { CategoryIconBadge } from "@/shared/components/entity-avatar";
|
|||||||
import MoneyValues from "@/shared/components/money-values";
|
import MoneyValues from "@/shared/components/money-values";
|
||||||
import { WidgetEmptyState } from "@/shared/components/widgets/widget-empty-state";
|
import { WidgetEmptyState } from "@/shared/components/widgets/widget-empty-state";
|
||||||
import { formatPercentage } from "@/shared/utils/percentage";
|
import { formatPercentage } from "@/shared/utils/percentage";
|
||||||
|
import { formatPeriodForUrl } from "@/shared/utils/period";
|
||||||
|
|
||||||
type CategoryTrendsWidgetProps = {
|
type CategoryTrendsWidgetProps = {
|
||||||
categories: DashboardCategoryBreakdownItem[];
|
categories: DashboardCategoryBreakdownItem[];
|
||||||
|
period: string;
|
||||||
};
|
};
|
||||||
|
|
||||||
export function CategoryTrendsWidget({
|
export function CategoryTrendsWidget({
|
||||||
categories,
|
categories,
|
||||||
|
period,
|
||||||
}: CategoryTrendsWidgetProps) {
|
}: CategoryTrendsWidgetProps) {
|
||||||
|
const periodParam = formatPeriodForUrl(period);
|
||||||
const trending = categories
|
const trending = categories
|
||||||
.filter((c) => c.percentageChange !== null && c.previousAmount > 0)
|
.filter((c) => c.percentageChange !== null && c.previousAmount > 0)
|
||||||
.sort(
|
.sort(
|
||||||
@@ -53,7 +58,12 @@ export function CategoryTrendsWidget({
|
|||||||
size="md"
|
size="md"
|
||||||
/>
|
/>
|
||||||
<div className={styles.textStack}>
|
<div className={styles.textStack}>
|
||||||
<p className={styles.title}>{category.categoryName}</p>
|
<Link
|
||||||
|
href={`/categories/${category.categoryId}?periodo=${periodParam}`}
|
||||||
|
className={styles.titleLink}
|
||||||
|
>
|
||||||
|
<span className="truncate">{category.categoryName}</span>
|
||||||
|
</Link>
|
||||||
<p className={styles.meta}>
|
<p className={styles.meta}>
|
||||||
<span
|
<span
|
||||||
className="inline-flex items-center gap-1"
|
className="inline-flex items-center gap-1"
|
||||||
|
|||||||
@@ -174,9 +174,10 @@ export const widgetsConfig: WidgetConfig[] = [
|
|||||||
title: "Tendências de categorias",
|
title: "Tendências de categorias",
|
||||||
subtitle: "Top 10 maiores variações vs. mês anterior",
|
subtitle: "Top 10 maiores variações vs. mês anterior",
|
||||||
icon: <RiLineChartLine className="size-4" />,
|
icon: <RiLineChartLine className="size-4" />,
|
||||||
component: ({ data }) => (
|
component: ({ data, period }) => (
|
||||||
<CategoryTrendsWidget
|
<CategoryTrendsWidget
|
||||||
categories={data.expensesByCategoryData.categories}
|
categories={data.expensesByCategoryData.categories}
|
||||||
|
period={period}
|
||||||
/>
|
/>
|
||||||
),
|
),
|
||||||
},
|
},
|
||||||
|
|||||||
Reference in New Issue
Block a user