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 <noreply@anthropic.com>
This commit is contained in:
parent
b6078cf534
commit
8f2f561c71
2 changed files with 8 additions and 3 deletions
|
|
@ -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<CreateProjectModalProps> = ({ 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<CreateProjectModalProps> = ({ isOpen,
|
|||
<label className="block text-sm font-medium text-black-title">Agency</label>
|
||||
<input
|
||||
type="text"
|
||||
value="OLIVER Agency"
|
||||
value={user?.agencyName ?? ''}
|
||||
className="mt-1 block w-full p-2 border-2 border-grey-300 rounded-[10px] shadow-sm bg-grey-100 text-grey-900 cursor-not-allowed"
|
||||
disabled
|
||||
/>
|
||||
|
|
@ -134,7 +136,7 @@ export const CreateProjectModal: React.FC<CreateProjectModalProps> = ({ isOpen,
|
|||
<label className="block text-sm font-medium text-black-title">Agency Lead</label>
|
||||
<input
|
||||
type="text"
|
||||
value="Steve O'Donoghue"
|
||||
value={user?.name ?? ''}
|
||||
className="mt-1 block w-full p-2 border-2 border-grey-300 rounded-[10px] shadow-sm bg-grey-100 text-grey-900 cursor-not-allowed"
|
||||
disabled
|
||||
/>
|
||||
|
|
|
|||
|
|
@ -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<UserManagementResponse[]>([]);
|
||||
const [agencies, setAgencies] = useState<AgencyResponse[]>([]);
|
||||
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.');
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue