From 8f2f561c713b02536b0d99c763fc8906447a3833 Mon Sep 17 00:00:00 2001 From: michael Date: Fri, 27 Feb 2026 14:44:55 -0600 Subject: [PATCH] Fix stale UserContext after agency/role changes and remove hardcoded values in CreateProjectModal UserManagement now calls refresh() on the global UserContext when the current user's agency or role is changed, so downstream consumers (e.g. CreateCampaignModal) immediately reflect the update. CreateProjectModal now reads the Agency and Agency Lead fields from the current user's profile instead of hardcoding "OLIVER Agency" and "Steve O'Donoghue". Co-Authored-By: Claude Opus 4.6 --- frontend/components/CreateProjectModal.tsx | 6 ++++-- frontend/components/UserManagement.tsx | 5 ++++- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/frontend/components/CreateProjectModal.tsx b/frontend/components/CreateProjectModal.tsx index 9593fbd..471bfe0 100755 --- a/frontend/components/CreateProjectModal.tsx +++ b/frontend/components/CreateProjectModal.tsx @@ -1,5 +1,6 @@ import React, { useState, useEffect } from 'react'; import { XIcon } from './icons/XIcon'; +import { useUser } from '../contexts/UserContext'; interface CreateProjectModalProps { isOpen: boolean; @@ -12,6 +13,7 @@ interface CreateProjectModalProps { } export const CreateProjectModal: React.FC = ({ isOpen, onClose, onAddProject }) => { + const { user } = useUser(); const [name, setName] = useState(''); const [workfrontId, setWorkfrontId] = useState(''); const [clientLead, setClientLead] = useState(''); @@ -125,7 +127,7 @@ export const CreateProjectModal: React.FC = ({ isOpen, @@ -134,7 +136,7 @@ export const CreateProjectModal: React.FC = ({ isOpen, diff --git a/frontend/components/UserManagement.tsx b/frontend/components/UserManagement.tsx index 1ea9777..54e816e 100644 --- a/frontend/components/UserManagement.tsx +++ b/frontend/components/UserManagement.tsx @@ -20,7 +20,7 @@ const formatDate = (iso: string) => { }; export const UserManagement: React.FC = () => { - const { isSuperAdmin } = useUser(); + const { user: currentUser, isSuperAdmin, refresh } = useUser(); const [users, setUsers] = useState([]); const [agencies, setAgencies] = useState([]); const [isLoading, setIsLoading] = useState(true); @@ -81,6 +81,7 @@ export const UserManagement: React.FC = () => { const updated = await apiService.updateUser(userId, { role: newRole }); setUsers(prev => prev.map(u => u.id === userId ? updated : u)); showSavedIndicator(userId); + if (userId === currentUser?.id) await refresh(); } catch (err) { console.error('Failed to update user role:', err); setError('Failed to update user role.'); @@ -101,6 +102,7 @@ export const UserManagement: React.FC = () => { const updated = await apiService.updateUser(userId, { role: 'super_admin' }); setUsers(prev => prev.map(u => u.id === userId ? updated : u)); showSavedIndicator(userId); + if (userId === currentUser?.id) await refresh(); } catch (err) { console.error('Failed to update user role:', err); setError('Failed to update user role.'); @@ -118,6 +120,7 @@ export const UserManagement: React.FC = () => { const updated = await apiService.updateUser(userId, { agency_id: agencyId }); setUsers(prev => prev.map(u => u.id === userId ? updated : u)); showSavedIndicator(userId); + if (userId === currentUser?.id) await refresh(); } catch (err) { console.error('Failed to update user agency:', err); setError('Failed to update user agency.');