feat(data): add resolvePerson selector over a merged people index
This commit is contained in:
+17
-1
@@ -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}
|
||||
</MockStoreContext.Provider>
|
||||
|
||||
Reference in New Issue
Block a user