diff --git a/.dockerignore b/.dockerignore index 21edd64..276bbec 100644 Binary files a/.dockerignore and b/.dockerignore differ diff --git a/pages/Settings.tsx b/pages/Settings.tsx index 52eecb5..992b006 100644 --- a/pages/Settings.tsx +++ b/pages/Settings.tsx @@ -2,7 +2,7 @@ import React, { useEffect, useState } from 'react'; import { CondoService } from '../services/mockDb'; import { AppSettings, Family, User, AlertDefinition, Condo, Notice, NoticeIconType, NoticeRead } from '../types'; -import { Save, Building, Coins, Plus, Pencil, Trash2, X, CalendarCheck, AlertTriangle, User as UserIcon, Server, Bell, Clock, FileText, Lock, Megaphone, CheckCircle2, Info, Hammer, Link as LinkIcon, Eye, Calendar, List, UserCog, Mail, Power, MapPin, CreditCard, ToggleLeft, ToggleRight, LayoutGrid, PieChart } from 'lucide-react'; +import { Save, Building, Coins, Plus, Pencil, Trash2, X, CalendarCheck, AlertTriangle, User as UserIcon, Server, Bell, Clock, FileText, Lock, Megaphone, CheckCircle2, Info, Hammer, Link as LinkIcon, Eye, Calendar, List, UserCog, Mail, Power, MapPin, CreditCard, ToggleLeft, ToggleRight, LayoutGrid, PieChart, Users } from 'lucide-react'; export const SettingsPage: React.FC = () => { const currentUser = CondoService.getCurrentUser(); @@ -96,6 +96,7 @@ export const SettingsPage: React.FC = () => { const [notices, setNotices] = useState([]); const [showNoticeModal, setShowNoticeModal] = useState(false); const [editingNotice, setEditingNotice] = useState(null); + const [noticeTargetMode, setNoticeTargetMode] = useState<'all' | 'specific'>('all'); const [noticeForm, setNoticeForm] = useState<{ title: string; content: string; @@ -103,13 +104,15 @@ export const SettingsPage: React.FC = () => { link: string; condoId: string; active: boolean; + targetFamilyIds: string[]; }>({ title: '', content: '', type: 'info', link: '', condoId: '', - active: true + active: true, + targetFamilyIds: [] }); const [noticeReadStats, setNoticeReadStats] = useState>({}); @@ -421,12 +424,23 @@ export const SettingsPage: React.FC = () => { // --- Notice Handlers --- const openAddNoticeModal = () => { setEditingNotice(null); - setNoticeForm({ title: '', content: '', type: 'info', link: '', condoId: activeCondo?.id || '', active: true }); + setNoticeTargetMode('all'); + setNoticeForm({ title: '', content: '', type: 'info', link: '', condoId: activeCondo?.id || '', active: true, targetFamilyIds: [] }); setShowNoticeModal(true); }; const openEditNoticeModal = (n: Notice) => { setEditingNotice(n); - setNoticeForm({ title: n.title, content: n.content, type: n.type, link: n.link || '', condoId: n.condoId, active: n.active }); + const isTargeted = n.targetFamilyIds && n.targetFamilyIds.length > 0; + setNoticeTargetMode(isTargeted ? 'specific' : 'all'); + setNoticeForm({ + title: n.title, + content: n.content, + type: n.type, + link: n.link || '', + condoId: n.condoId, + active: n.active, + targetFamilyIds: n.targetFamilyIds || [] + }); setShowNoticeModal(true); }; const handleNoticeSubmit = async (e: React.FormEvent) => { @@ -435,6 +449,7 @@ export const SettingsPage: React.FC = () => { const payload: Notice = { id: editingNotice ? editingNotice.id : '', ...noticeForm, + targetFamilyIds: noticeTargetMode === 'all' ? [] : noticeForm.targetFamilyIds, date: editingNotice ? editingNotice.date : new Date().toISOString() }; await CondoService.saveNotice(payload); @@ -456,6 +471,17 @@ export const SettingsPage: React.FC = () => { setNotices(notices.map(n => n.id === notice.id ? updated : n)); } catch(e) { console.error(e); } }; + + const toggleNoticeFamilyTarget = (familyId: string) => { + setNoticeForm(prev => { + const current = prev.targetFamilyIds; + if (current.includes(familyId)) { + return { ...prev, targetFamilyIds: current.filter(id => id !== familyId) }; + } else { + return { ...prev, targetFamilyIds: [...current, familyId] }; + } + }); + }; const openReadDetails = (noticeId: string) => { setSelectedNoticeId(noticeId); @@ -841,18 +867,32 @@ export const SettingsPage: React.FC = () => {
- {notices.map(notice => ( -
+ {notices.map(notice => { + const isTargeted = notice.targetFamilyIds && notice.targetFamilyIds.length > 0; + return ( +
{notice.type === 'warning' ? : notice.type === 'maintenance' ? : notice.type === 'event' ? : }
-

{notice.title}

+

+ {notice.title} + {isTargeted && ( + + Privato + + )} +

{getCondoName(notice.condoId)} • {new Date(notice.date).toLocaleDateString()}

{notice.content}

{notice.link && Allegato} + {isTargeted && ( +

+ Visibile a: {notice.targetFamilyIds!.length} famiglie +

+ )}
@@ -881,7 +921,8 @@ export const SettingsPage: React.FC = () => {
- ))} + ); + })} {notices.length === 0 &&
Nessun avviso pubblicato.
}
@@ -1017,44 +1058,96 @@ export const SettingsPage: React.FC = () => {
)} - {/* NOTICE MODAL (Existing) */} + {/* NOTICE MODAL (Updated with Target Selector) */} {showNoticeModal && (
-
-

{editingNotice ? 'Modifica Avviso' : 'Nuovo Avviso'}

-
- setNoticeForm({...noticeForm, title: e.target.value})} required /> -