mirror of
https://github.com/felipegcoutinho/openmonetis.git
synced 2026-05-09 11:01:45 +00:00
refactor(dashboard): reorganiza widgets e remove magnet-lines
This commit is contained in:
45
lib/dashboard/goals-progress-helpers.ts
Normal file
45
lib/dashboard/goals-progress-helpers.ts
Normal file
@@ -0,0 +1,45 @@
|
||||
import type { Budget, BudgetCategory } from "@/components/orcamentos/types";
|
||||
import type {
|
||||
GoalProgressCategory,
|
||||
GoalProgressItem,
|
||||
GoalProgressStatus,
|
||||
} from "@/lib/dashboard/goals-progress";
|
||||
import { formatPercentage } from "@/lib/utils/percentage";
|
||||
|
||||
export const clampGoalProgress = (value: number, min: number, max: number) =>
|
||||
Math.min(max, Math.max(min, value));
|
||||
|
||||
export const formatGoalProgressPercentage = (value: number, withSign = false) =>
|
||||
formatPercentage(value, {
|
||||
maximumFractionDigits: 1,
|
||||
signDisplay: withSign ? "always" : "auto",
|
||||
});
|
||||
|
||||
export const getGoalProgressStatusColorClass = (status: GoalProgressStatus) =>
|
||||
status === "exceeded" ? "text-destructive" : "";
|
||||
|
||||
export const mapGoalProgressCategoriesToBudgetCategories = (
|
||||
categories: GoalProgressCategory[],
|
||||
): BudgetCategory[] =>
|
||||
categories.map((category) => ({
|
||||
id: category.id,
|
||||
name: category.name,
|
||||
icon: category.icon,
|
||||
}));
|
||||
|
||||
export const mapGoalProgressItemToBudget = (
|
||||
item: GoalProgressItem,
|
||||
): Budget => ({
|
||||
id: item.id,
|
||||
amount: item.budgetAmount,
|
||||
spent: item.spentAmount,
|
||||
period: item.period,
|
||||
createdAt: item.createdAt,
|
||||
category: item.categoryId
|
||||
? {
|
||||
id: item.categoryId,
|
||||
name: item.categoryName,
|
||||
icon: item.categoryIcon,
|
||||
}
|
||||
: null,
|
||||
});
|
||||
Reference in New Issue
Block a user