diff --git a/src/data/mockStore.jsx b/src/data/mockStore.jsx index 4e45ba1..ea010f4 100644 --- a/src/data/mockStore.jsx +++ b/src/data/mockStore.jsx @@ -1,4 +1,4 @@ -import React, { createContext, useContext, useState, useEffect } from 'react'; +import React, { createContext, useContext, useState, useEffect, useMemo } from 'react'; import { toast } from 'sonner'; import { logger } from '../utils/logger'; @@ -6034,6 +6034,21 @@ export const MockStoreProvider = ({ children }) => { const [subcontractorTasks, setSubcontractorTasks] = useState(MOCK_SUBCONTRACTOR_TASKS); const [notifications, setNotifications] = useState(MOCK_NOTIFICATIONS); + // One lookup for any person across users/personnel/owners/subcontractors. + const peopleIndex = useMemo(() => { + const idx = {}; + const add = (p) => { if (p?.id && !idx[p.id]) idx[p.id] = p; }; + [...(users || []), ...(personnel || []), ...(owners || []), + ...(subcontractors || [])].forEach(add); + return idx; + }, [users, personnel, owners, subcontractors]); + + const resolvePerson = (id) => { + const p = peopleIndex[id]; + if (!p) return { id, name: 'Unknown', email: '', role: '' }; + return { id: p.id, name: p.name || p.fullName || 'Unknown', email: p.email || p.emailAddress || '', role: p.role || '' }; + }; + // Initialize properties once useEffect(() => { const data = generateProperties(); @@ -6752,6 +6767,7 @@ export const MockStoreProvider = ({ children }) => { notifications, addNotification, markNotificationRead, + resolvePerson, }}> {children}