From ffebddaf3301387e9fae92599650753056825f3f Mon Sep 17 00:00:00 2001 From: frakarr Date: Thu, 11 Dec 2025 22:27:46 +0100 Subject: [PATCH] Update Layout.tsx --- components/Layout.tsx | 44 +++++++++++++++++++++---------------------- 1 file changed, 21 insertions(+), 23 deletions(-) diff --git a/components/Layout.tsx b/components/Layout.tsx index 83817c3..dce09a7 100644 --- a/components/Layout.tsx +++ b/components/Layout.tsx @@ -8,7 +8,10 @@ import { Condo, Notice, AppSettings } from '../types'; export const Layout: React.FC = () => { const [isMobileMenuOpen, setIsMobileMenuOpen] = useState(false); const user = CondoService.getCurrentUser(); - const isAdmin = user?.role === 'admin' || user?.role === 'poweruser'; + + // Logic: "isPrivileged" includes Admin AND PowerUser. + // This allows PowerUsers to see Reports and other admin-like features. + const isPrivileged = user?.role === 'admin' || user?.role === 'poweruser'; const [condos, setCondos] = useState([]); const [activeCondo, setActiveCondo] = useState(undefined); @@ -28,10 +31,10 @@ export const Layout: React.FC = () => { const globalSettings = await CondoService.getSettings(); setSettings(globalSettings); - if (isAdmin && globalSettings.features.multiCondo) { + if (isPrivileged && globalSettings.features.multiCondo) { const list = await CondoService.getCondos(); setCondos(list); - } else if (isAdmin) { + } else if (isPrivileged) { const list = await CondoService.getCondos(); setCondos(list); } @@ -55,18 +58,13 @@ export const Layout: React.FC = () => { const isTicketNew = ticketDate > lastViewedTickets; const isArchived = t.status === 'RESOLVED' || t.status === 'CLOSED'; - if (isAdmin) { - // Admin: Count new unarchived tickets OR tickets with new comments from users + if (isPrivileged) { + // Admin/PowerUser: Count new unarchived tickets OR tickets with new comments from users if (isTicketNew && !isArchived) { count++; } else { - // Check for new comments from users - // Optimization: In a real app we'd need a lighter query. - // Here we iterate because we have the data or fetch lightly. - // Assuming getTickets includes basic info or we need to check updatedAt const updatedDate = new Date(t.updatedAt).getTime(); if (updatedDate > lastViewedTickets) { - // Deep check: fetch comments only if recently updated const comments = await CondoService.getTicketComments(t.id); const hasNewUserReply = comments.some(c => new Date(c.createdAt).getTime() > lastViewedTickets && c.userId !== user?.id); if (hasNewUserReply) count++; @@ -87,8 +85,8 @@ export const Layout: React.FC = () => { } catch(e) { console.error("Error calc ticket badges", e); } - // Check for notices & expenses for User - if (!isAdmin && active && user) { + // Check for notices & expenses for User (non-privileged mostly, but logic works for all if needed) + if (!isPrivileged && active && user) { try { // 2. Check Notices const unread = await CondoService.getUnreadNoticesForUser(user.id, active.id); @@ -122,7 +120,7 @@ export const Layout: React.FC = () => { window.removeEventListener('expenses-viewed', handleUpdate); window.removeEventListener('tickets-viewed', handleUpdate); }; - }, [isAdmin]); + }, [isPrivileged]); const handleCondoSwitch = (condoId: string) => { CondoService.setActiveCondo(condoId); @@ -229,8 +227,8 @@ export const Layout: React.FC = () => {

CondoPay

- {/* Condo Switcher (Admin Only & MultiCondo Enabled) */} - {isAdmin && settings?.features.multiCondo && ( + {/* Condo Switcher (Privileged Only & MultiCondo Enabled) */} + {isPrivileged && settings?.features.multiCondo && (
@@ -260,8 +258,8 @@ export const Layout: React.FC = () => { )}
)} - {/* Static info if not multi-condo or not admin */} - {(!isAdmin || (isAdmin && !settings?.features.multiCondo)) && activeCondo && ( + {/* Static info if not multi-condo or not privileged */} + {(!isPrivileged || (isPrivileged && !settings?.features.multiCondo)) && activeCondo && (
{activeCondo.name}
@@ -275,7 +273,7 @@ export const Layout: React.FC = () => {
{/* Mobile Condo Switcher */} - {isAdmin && settings?.features.multiCondo && ( + {isPrivileged && settings?.features.multiCondo && (

@@ -301,8 +299,8 @@ export const Layout: React.FC = () => { Famiglie - {/* Condo Financials - Admin or Enabled User */} - {(isAdmin || settings?.features.condoFinancialsView) && ( + {/* Condo Financials - Admin/PowerUser or Enabled User */} + {(isPrivileged || settings?.features.condoFinancialsView) && ( Spese Condominio @@ -315,7 +313,7 @@ export const Layout: React.FC = () => {

- {isAdmin ? 'Spese Straordinarie' : 'Le Mie Spese Extra'} + {isPrivileged ? 'Spese Straordinarie' : 'Le Mie Spese Extra'}
{newExpensesCount > 0 && ( @@ -326,8 +324,8 @@ export const Layout: React.FC = () => { )} - {/* Privileged Links */} - {isAdmin && settings?.features.reports && ( + {/* Privileged Links (Admin & PowerUser) */} + {isPrivileged && settings?.features.reports && ( Reportistica