feat: Introduce multi-condo management and notices

This commit refactors the application to support managing multiple condominiums.

Key changes include:
- Introduction of `Condo` and `Notice` data types.
- Implementation of multi-condo selection and management, including active condo context.
- Addition of a notice system to inform users about important updates or events within a condo.
- Styling adjustments to ensure better visibility of form elements.
- Mock database updates to accommodate new entities and features.
This commit is contained in:
2025-12-07 01:37:19 +01:00
parent fdd912a932
commit 3f954c65b1
11 changed files with 1169 additions and 1283 deletions

View File

@@ -1,7 +1,8 @@
import React, { useEffect, useState, useMemo } from 'react';
import { useParams, useNavigate } from 'react-router-dom';
import { CondoService } from '../services/mockDb';
import { Family, Payment, AppSettings, MonthStatus, PaymentStatus } from '../types';
import { Family, Payment, AppSettings, MonthStatus, PaymentStatus, Condo } from '../types';
import { ArrowLeft, CheckCircle2, AlertCircle, Plus, Calendar, CreditCard, TrendingUp } from 'lucide-react';
const MONTH_NAMES = [
@@ -16,6 +17,7 @@ export const FamilyDetail: React.FC = () => {
const [family, setFamily] = useState<Family | null>(null);
const [payments, setPayments] = useState<Payment[]>([]);
const [settings, setSettings] = useState<AppSettings | null>(null);
const [condo, setCondo] = useState<Condo | undefined>(undefined);
const [loading, setLoading] = useState(true);
const [selectedYear, setSelectedYear] = useState<number>(new Date().getFullYear());
const [availableYears, setAvailableYears] = useState<number[]>([]);
@@ -31,11 +33,12 @@ export const FamilyDetail: React.FC = () => {
const loadData = async () => {
setLoading(true);
try {
const [famList, famPayments, appSettings, years] = await Promise.all([
const [famList, famPayments, appSettings, years, activeCondo] = await Promise.all([
CondoService.getFamilies(),
CondoService.getPaymentsByFamily(id),
CondoService.getSettings(),
CondoService.getAvailableYears()
CondoService.getAvailableYears(),
CondoService.getActiveCondo()
]);
const foundFamily = famList.find(f => f.id === id);
@@ -43,7 +46,12 @@ export const FamilyDetail: React.FC = () => {
setFamily(foundFamily);
setPayments(famPayments);
setSettings(appSettings);
setNewPaymentAmount(appSettings.defaultMonthlyQuota);
setCondo(activeCondo);
// Use Family Custom Quota OR Condo Default
const defaultAmount = foundFamily.customMonthlyQuota ?? activeCondo?.defaultMonthlyQuota ?? 100;
setNewPaymentAmount(defaultAmount);
setAvailableYears(years);
setSelectedYear(appSettings.currentYear);
} else {
@@ -104,9 +112,10 @@ export const FamilyDetail: React.FC = () => {
const maxChartValue = useMemo(() => {
const max = Math.max(...chartData.map(d => d.amount));
const baseline = settings?.defaultMonthlyQuota || 100;
// Check family specific quota first
const baseline = family?.customMonthlyQuota ?? condo?.defaultMonthlyQuota ?? 100;
return max > 0 ? Math.max(max * 1.2, baseline) : baseline;
}, [chartData, settings]);
}, [chartData, condo, family]);
const handleAddPayment = async (e: React.FormEvent) => {
e.preventDefault();
@@ -154,6 +163,11 @@ export const FamilyDetail: React.FC = () => {
<div className="flex items-center gap-2 text-slate-500 mt-1 text-sm md:text-base">
<BuildingIcon className="w-4 h-4 flex-shrink-0" />
<span>Interno: {family.unitNumber}</span>
{family.customMonthlyQuota && (
<span className="ml-2 text-xs bg-blue-100 text-blue-700 px-2 py-0.5 rounded-full font-bold">
Quota Personalizzata: {family.customMonthlyQuota}
</span>
)}
</div>
</div>
</div>