Implemented notification strategy

This commit is contained in:
2026-10-22 22:59:33 +02:00
parent 7071c404f0
commit 46c6ddcc80
11 changed files with 784 additions and 71 deletions
@@ -60,6 +60,7 @@ import {
assignUserRole,
getSystemRoles,
getCurrentUserTenantId,
notifyNewUserCreated,
} from '../services/api';
import { Modal } from '../components/ui/Modal';
import { HelpTooltip } from '../components/ui/HelpTooltip';
@@ -251,7 +252,7 @@ export const GovernancePage: React.FC = () => {
const assignableRolesForOrg = React.useMemo(() => {
return systemRoles.filter(
(r) => r.name.toLowerCase() !== 'admin' && r.id !== '1'
(r) => (r.name || r.Name || '').toLowerCase() !== 'admin' && (r.id || r.Id) !== '1'
);
}, [systemRoles]);
@@ -274,9 +275,9 @@ export const GovernancePage: React.FC = () => {
React.useEffect(() => {
if (!quickUserRoleId && assignableRolesForOrg.length > 0) {
const execRole = assignableRolesForOrg.find((r) => r.name.toLowerCase() === 'executive');
if (execRole) setQuickUserRoleId(execRole.id);
else setQuickUserRoleId(assignableRolesForOrg[0].id);
const execRole = assignableRolesForOrg.find((r) => (r.name || r.Name || '').toLowerCase() === 'executive');
if (execRole) setQuickUserRoleId(execRole.id || execRole.Id || '');
else setQuickUserRoleId(assignableRolesForOrg[0].id || assignableRolesForOrg[0].Id || '');
}
}, [assignableRolesForOrg, quickUserRoleId]);
@@ -334,6 +335,19 @@ export const GovernancePage: React.FC = () => {
orgForm.setValue('organisationUser', createdUser.id, { shouldValidate: true });
}
// RULE 3: Notify created Executive/Manager user via InApp and Email (directs to Console)
if (createdUser) {
await notifyNewUserCreated({
userId: createdUser.id,
email: quickUserEmail,
isPartner: false,
roleName: 'Executive',
tenantId,
}).catch(console.warn);
queryClient.invalidateQueries({ queryKey: ['inapp-notifications'] });
queryClient.invalidateQueries({ queryKey: ['notifications'] });
}
success('Executive User Created', `User ${quickUserEmail} successfully created and linked.`);
setQuickUserEmail('');
setQuickUserName('');
@@ -644,7 +658,7 @@ export const GovernancePage: React.FC = () => {
programmeId: editingProgramme.id,
name: data.name,
portfolioId: Number(data.portfolioId),
status: data.status !== undefined ? Number(data.status) : undefined,
status: (data.status !== undefined ? Number(data.status) : 1) as ApprovalStatus,
ownerId: resolvedOwnerId,
});
}
@@ -861,7 +875,7 @@ export const GovernancePage: React.FC = () => {
key: 'portfolioId',
format: (val) => {
const port = portfolios.find((p) => String(p.id) === String(val));
return port ? port.name : `Portfolio #${val}`;
return port && port.name ? port.name : `Portfolio #${val}`;
},
},
{ header: 'Governance Status', key: 'status', format: (val) => getApprovalStatusBadge(val).label },
@@ -1253,8 +1267,8 @@ export const GovernancePage: React.FC = () => {
<div className="mt-4 pt-3 border-t border-slate-800/80 space-y-2.5">
<div className="flex items-center justify-between text-xs text-slate-400">
<span className="truncate max-w-[200px] font-medium text-slate-300" title={org ? org.name : `Org #${p.organisationId}`}>
{org ? org.name : `Org #${p.organisationId}`}
<span className="truncate max-w-[200px] font-medium text-slate-300" title={org && org.name ? org.name : `Org #${p.organisationId}`}>
{org && org.name ? org.name : `Org #${p.organisationId}`}
</span>
<span className="font-mono text-[11px] text-slate-500 shrink-0">{formatDate(p.createdAt)}</span>
</div>