From 2a7ee1edf66e4f28f1d56b96866f214f75ab5adc Mon Sep 17 00:00:00 2001 From: Norbert Maciaszek Date: Wed, 12 Nov 2025 11:17:38 +0100 Subject: [PATCH] Refactor YearOverview component to improve gift status tracking, update statistics display with detailed breakdowns for planned, decided, bought, and wrapped gifts, and adjust budget calculations for better financial overview. --- src/components/molecules/GiftCard/index.tsx | 2 - .../organisms/YearOverview/index.tsx | 40 +++++++++++++------ 2 files changed, 27 insertions(+), 15 deletions(-) diff --git a/src/components/molecules/GiftCard/index.tsx b/src/components/molecules/GiftCard/index.tsx index 0249100..1e69098 100644 --- a/src/components/molecules/GiftCard/index.tsx +++ b/src/components/molecules/GiftCard/index.tsx @@ -1,12 +1,10 @@ 'use client'; import { FC, useState } from 'react'; import { formatCurrency } from '@/helpers/formatCurrency'; -import { formatStatus } from '@/helpers/formatStatus'; import { GiftModal } from '../GiftModal'; import { useGlobalStore } from '@/app/store/global'; import { DB } from '@/lib/db'; import { useRouter } from 'next/navigation'; -import { Button } from '@/components/atoms/Button'; import { Badge } from '@/components/atoms/Badge'; import Link from 'next/link'; import { Heading } from '@/components/atoms/Heading'; diff --git a/src/components/organisms/YearOverview/index.tsx b/src/components/organisms/YearOverview/index.tsx index 61d61dd..7b00f3b 100644 --- a/src/components/organisms/YearOverview/index.tsx +++ b/src/components/organisms/YearOverview/index.tsx @@ -22,28 +22,42 @@ export const YearOverview: FC = async ({ year }) => { }), ); + const planned = gifts.filter((gift) => gift.status === 'planned'); + const decided = gifts.filter((gift) => gift.status === 'decided'); + const bought = gifts.filter((gift) => gift.status === 'bought'); + const wrapped = gifts.filter((gift) => gift.status === 'wrapped'); + const totalCost = gifts.reduce((acc, gift) => acc + gift.cost, 0); - const averageCost = totalCost / gifts.length; + const totalCostPlanned = + planned.reduce((acc, gift) => acc + gift.cost, 0) + decided.reduce((acc, gift) => acc + gift.cost, 0); + const totalCostBought = bought.reduce((acc, gift) => acc + gift.cost, 0); + + const remainingBudget = data.budgetLimit - totalCostBought; return (
Podsumowanie roku {data.year}
- + + + + + + + gift.status === 'decided').length} - description='Prezenty do kupienia' - /> - gift.status === 'bought').length} - description='Prezenty które zostały już kupione' + title='Bufor' + value={formatCurrency(remainingBudget - totalCostPlanned)} + description={`Pozostałe pieniądze (budżet - poniesione koszty - koszt prezentów)`} />