Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 17 additions & 1 deletion Clients/src/application/constants/roles.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,20 @@ export const ROLES = {
3 : "Editor",
4 : "Auditor",
5 : "Super Admin"
}
}

/** Assignable role options (excludes Super Admin) for dropdowns */
export const ROLE_OPTIONS = [
{ value: 1, label: "Admin" },
{ value: 2, label: "Reviewer" },
{ value: 3, label: "Editor" },
{ value: 4, label: "Auditor" },
] as const;

/** Role badge colors for table display */
export const ROLE_COLORS: Record<string, { bg: string; text: string }> = {
Admin: { bg: "#eff6ff", text: "#2563eb" },
Reviewer: { bg: "#faf5ff", text: "#9333ea" },
Editor: { bg: "#f0fdf4", text: "#16a34a" },
Auditor: { bg: "#fefce8", text: "#ca8a04" },
};
8 changes: 8 additions & 0 deletions Clients/src/application/repository/superAdmin.repository.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,10 @@ export async function updateOrganization(id: number, data: { name?: string; logo
return apiServices.patch(`/super-admin/organizations/${id}`, data);
}

export async function getUserCount() {
return apiServices.get<ServerResponse<{ count: number }>>("/super-admin/users/count");
}

export async function getAllUsers() {
return apiServices.get<ServerResponse<GlobalUser[]>>("/super-admin/users");
}
Expand All @@ -59,6 +63,10 @@ export async function inviteUserToOrg(orgId: number, data: { email: string; name
return apiServices.post(`/super-admin/organizations/${orgId}/invite`, data);
}

export async function updateUser(userId: number, data: { name?: string; surname?: string; email?: string; roleId?: number }) {
return apiServices.patch(`/super-admin/users/${userId}`, data);
}

export async function removeUser(userId: number) {
return apiServices.delete(`/super-admin/users/${userId}`);
}
19 changes: 18 additions & 1 deletion Clients/src/presentation/components/SuperAdminSidebar/index.tsx
Original file line number Diff line number Diff line change
@@ -1,11 +1,27 @@
import React from "react";
import React, { useState, useEffect, useCallback } from "react";
import { useLocation, useNavigate } from "react-router";
import { Building, Users } from "lucide-react";
import SidebarShell, { SidebarMenuItem } from "../Sidebar/SidebarShell";
import { getUserCount } from "../../../application/repository/superAdmin.repository";

const SuperAdminSidebar: React.FC = () => {
const navigate = useNavigate();
const location = useLocation();
const [userCount, setUserCount] = useState<number>(0);

const fetchUserCount = useCallback(async () => {
try {
const response = await getUserCount();
const serverData = response.data as any;
setUserCount(serverData?.data?.count ?? 0);
} catch {
// Silently fail — count will show 0
}
}, []);

useEffect(() => {
fetchUserCount();
}, [fetchUserCount]);

const topItems: SidebarMenuItem[] = [
{
Expand All @@ -19,6 +35,7 @@ const SuperAdminSidebar: React.FC = () => {
label: "Users",
icon: <Users size={16} strokeWidth={1.5} />,
path: "/super-admin/users",
count: userCount,
},
];

Expand Down
7 changes: 2 additions & 5 deletions Clients/src/presentation/pages/Authentication/Login/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -175,21 +175,18 @@ const Login: React.FC = () => {
localStorage.setItem("root_version", __APP_VERSION__);
logEngine({ type: "info", message: "Super-admin login successful." });

// Auto-select the first organization so super-admin sees the normal UI
// Auto-select the first organization so super-admin can view org data
try {
const orgsResponse = await getOrganizations();
const orgsData = (orgsResponse.data as any)?.data || [];
if (orgsData.length > 0) {
dispatch(setActiveOrganizationId(orgsData[0].id));
setIsSubmitting(false);
navigate("/");
return;
}
} catch (err) {
console.error("Failed to fetch organizations for auto-select:", err);
}

// No orgs available — go to super-admin panel to create one
// Always go to super-admin panel
setIsSubmitting(false);
navigate("/super-admin");
return;
Expand Down
Loading
Loading