user management ui

This commit is contained in:
yaschalew
2026-07-10 10:41:48 +03:00
parent dcb2d98503
commit 28a20923ff
595 changed files with 0 additions and 0 deletions

View File

@@ -0,0 +1,90 @@
import axios from "@/shared/services/axiosInstance";
import { DashboardStatsDto } from "@/super-admin/components/dashboard/types/dashboardStatsDto";
import axiosInstance from "../../../shared/services/axiosInstance";
import { AxiosResponse, AxiosError } from "axios";
// This is your DTO structure
export const getDashboardStats = async (): Promise<DashboardStatsDto> => {
const { data } = await axios.get("/dashboard/stats");
return data;
};
// Types for organization report data
export interface OrganizationReport {
unitsCount: number;
employeesCount: number;
positionsCount: number;
totalDocuments?: number;
recentActivities?: {
id: string;
type: string;
description: string;
timestamp: string;
}[];
}
export type UnitReport = Omit<OrganizationReport, "unitsCount"> & {
unitsCount?: number;
};
/**
* Fetches organization report data for the dashboard
* @param organizationId - The ID of the organization
* @returns Promise with the organization report data
*/
export const getOrganizationReport = async (
organizationId: string
): Promise<AxiosResponse<OrganizationReport>> => {
try {
return await axiosInstance.get(`/organizations/${organizationId}/report`);
} catch (error: unknown) {
if (error instanceof AxiosError && error.response) {
// Handle specific error cases if needed
}
throw error;
}
};
export const getUnitReport = async (
organizationId: string,
unitId: string,
): Promise<AxiosResponse<UnitReport>> => {
return axiosInstance.get(
`/organizations/${organizationId}/report/${unitId}/unit`,
);
};
/**
* Fetches total employees count for an organization
* @param organizationId - The ID of the organization
* @returns Promise with the total employees count
*/
export const getOrganizationEmployees = async (
organizationId: string
): Promise<AxiosResponse<{ total: number }>> => {
return axiosInstance.get(`/organizations/${organizationId}/employees/count`);
};
/**
* Fetches total departments count for an organization
* @param organizationId - The ID of the organization
* @returns Promise with the total departments count
*/
export const getOrganizationDepartments = async (
organizationId: string
): Promise<AxiosResponse<{ total: number }>> => {
return axiosInstance.get(
`/organizations/${organizationId}/departments/count`
);
};
/**
* Fetches total units count for an organization
* @param organizationId - The ID of the organization
* @returns Promise with the total units count
*/
export const getOrganizationUnits = async (
organizationId: string
): Promise<AxiosResponse<{ total: number }>> => {
return axiosInstance.get(`/organizations/${organizationId}/units/count`);
};

View File

@@ -0,0 +1,68 @@
import { externalParam } from "@/external-portal/services/portalOutgoingService";
import { withHeaders } from "@/record-management/services/api/withHeaders";
import recordAxiosInstance from "@/shared/services/recordAxiosInstance";
import { AdoptTemplateTypes } from "@/super-admin/components/templates/template";
import { CreateTemplateTypes } from "@/super-admin/components/templates/types/templateTypes";
export const getDelegationTemplates = async () => {
const { data } = await recordAxiosInstance.get("/record-templates/global", {
headers: withHeaders(),
});
return data;
};
export const getDelegationTemplateById = async (
id: string,
params: externalParam,
) => {
const { data } = await recordAxiosInstance.get(`/record-templates/${id}`, {
headers: withHeaders(),
...params,
});
return data;
};
export const createDelegationTemplate = async (
template: CreateTemplateTypes,
) => {
const { data } = await recordAxiosInstance.post(
`/record-templates/global/delegation`,
template,
{
headers: withHeaders(),
},
);
return data;
};
export const updateDelegationTemplate = async (
id: string,
template: CreateTemplateTypes,
) => {
const { data } = await recordAxiosInstance.patch(
`/record-templates/global/${id}`,
template,
{
headers: withHeaders(),
},
);
return data;
};
export const deleteDelegationTemplate = async (id: string) => {
const { data } = await recordAxiosInstance.delete(`/record-templates/${id}`, {
headers: withHeaders(),
});
return data;
};
export const adoptDelegationTemplate = async (item: AdoptTemplateTypes) => {
const { data } = await recordAxiosInstance.post(
`/record-templates/adopt-to-unit`,
item,
{
headers: withHeaders(),
},
);
return data;
};

View File

@@ -0,0 +1,112 @@
import { withHeaders } from "@/record-management/services/api/withHeaders";
import axiosInstance from "../../../shared/services/axiosInstance";
import { AxiosResponse } from "axios";
export interface OrgHeaders {
tenantKey: string;
unitId?: string;
}
export interface OrganizationAdminPayload {
organizationId: string;
username: string;
email: string;
name: {
am: string;
en: string;
};
phoneNumber: string;
}
export interface UnitAdminPayload {
unitId: string;
username: string;
email: string;
name: {
am: string;
en: string;
};
phoneNumber: string;
}
export interface OrganizationAdmin {
id: string;
organizationId: string;
username: string;
email: string;
name: {
am: string;
en: string;
};
status: string;
}
export interface OrgAdminQueryParams {
orderBy?: string;
take?: number;
skip?: number;
order?: string;
}
export const getOrganizationAdmins = async (
params?: OrgAdminQueryParams
): Promise<AxiosResponse> => {
return axiosInstance.get("/organizations/org-admins", {
...{ headers: withHeaders() },
params,
});
};
export const getOrganizationAdminById = async (
id: string,
params?: OrgAdminQueryParams
): Promise<AxiosResponse> => {
return axiosInstance.get(`/organizations/org-admins/${id}`, {
...{ headers: withHeaders() },
params,
});
};
export const fetchUnitAdminById = async (
id: string,
params?: OrgAdminQueryParams
): Promise<AxiosResponse> => {
return axiosInstance.get(`/units/unit-admins/${id}`, {
...{ headers: withHeaders() },
params,
});
};
export const fetchAllUnitAdminById = async (
id: string,
params?: OrgAdminQueryParams
): Promise<AxiosResponse> => {
return axiosInstance.get(`/organizations/all-admins/${id}`, {
...{ headers: withHeaders() },
params,
});
};
export const assignOrganizationAdmin = async (
data: OrganizationAdminPayload
): Promise<AxiosResponse> => {
return axiosInstance.post("/organizations/org-admin", data, {
headers: withHeaders(),
});
};
export const assignUnitAdmin = async (
data: UnitAdminPayload
): Promise<AxiosResponse> => {
return axiosInstance.post("/units/unit-admin", data, {
headers: withHeaders(),
});
};
export const updateOrganizationAdmin = async (
id: string | number,
data: OrganizationAdminPayload
): Promise<AxiosResponse> => {
return axiosInstance.put(`/organizations/org-admin/${id}`, data, {
headers: withHeaders(),
});
};

View File

@@ -0,0 +1,30 @@
import { withHeaders } from "@/record-management/services/api/withHeaders";
import axiosInstance from "../../../shared/services/axiosInstance";
import { AxiosResponse } from "axios";
export interface OrgHeaders {
tenantKey: string;
unitId?: string;
}
export interface OrgType {
id: string;
name: {
am: string;
en: string;
};
key: string;
createdAt: string;
updatedAt: string;
}
export interface OrgTypeResponse {
count: number;
items: OrgType[];
}
export const getOrganizationTypes = async (): Promise<
AxiosResponse<OrgTypeResponse>
> => {
return axiosInstance.get("/organization-types", { headers: withHeaders() });
};

View File

@@ -0,0 +1,72 @@
import axiosInstance from "@/shared/services/axiosInstance";
export interface PasswordSettings {
id?: string;
minimumPasswordLength: number;
maximumPasswordLength: number;
passwordExpiry: number;
sessionTimeout: number;
isDefaultPasswordEnabled: boolean;
defaultPassword?: string;
}
/**
* Get system password settings
*/
export const getPasswordSettings = async (): Promise<PasswordSettings | null> => {
const { data } = await axiosInstance.get("/system-configurations");
console.log("Password settings API response:", data);
// API returns an array with {count, items}
if (data && data.items && Array.isArray(data.items)) {
console.log("Found items array, returning first item:", data.items[0]);
// Return the first (latest) item if it exists
return data.items[0] || null;
}
// Fallback for direct object response
console.log("No items array, returning data as is:", data);
return data || null;
};
/**
* Update system password settings
*/
export const updatePasswordSettings = async (
payload: PasswordSettings
): Promise<PasswordSettings> => {
const { data } = await axiosInstance.put(
`/system-configurations/${payload.id}`,
payload
);
return data;
};
/**
* Create system password settings
*/
export const createPasswordSettings = async (
payload: PasswordSettings
): Promise<PasswordSettings> => {
const { data } = await axiosInstance.post(
"/system-configurations",
payload
);
return data;
};
/**
* Delete system password settings
*/
export const deletePasswordSettings = async (
id: string
): Promise<void> => {
console.log("Calling DELETE /system-configurations/" + id);
try {
const response = await axiosInstance.delete(`/system-configurations/${id}`);
console.log("Delete response:", response);
} catch (error) {
console.error("Delete API error:", error);
throw error;
}
};

View File

@@ -0,0 +1,69 @@
import axiosInstance from "@/shared/services/axiosInstance";
import { withHeaders } from "@/record-management/services/api/withHeaders";
import { AxiosResponse } from "axios";
import { SiteDto, SitePayloadDto, SiteQueryParams } from "@/super-admin/dto/SitesDto";
// Fetch all sites (supports pagination/filter params)
export const getSites = async (
params?: SiteQueryParams
): Promise<AxiosResponse<any>> => {
return axiosInstance.get("/sites", {
headers: withHeaders(),
params,
});
};
// Fetch site by ID
export const getSiteById = async (
id: string
): Promise<AxiosResponse<SiteDto>> => {
return axiosInstance.get(`/sites/${id}`, {
headers: withHeaders(),
});
};
// Create a new site
export const createSite = async (
data: SitePayloadDto
): Promise<AxiosResponse<SiteDto>> => {
return axiosInstance.post("/sites", data, {
headers: withHeaders(),
});
};
// Update an existing site
export const updateSite = async (
id: string,
data: SitePayloadDto
): Promise<AxiosResponse<SiteDto>> => {
return axiosInstance.put(`/sites/${id}`, data, {
headers: withHeaders(),
});
};
// Soft delete (archive) a site
export const softDeleteSite = async (
id: string
): Promise<AxiosResponse<void>> => {
return axiosInstance.delete(`/sites/${id}/soft`, {
headers: withHeaders(),
});
};
// Permanently delete a site
export const deleteSite = async (
id: string
): Promise<AxiosResponse<void>> => {
return axiosInstance.delete(`/sites/${id}`, {
headers: withHeaders(),
});
};
// Restore an archived site
export const restoreSite = async (
id: string
): Promise<AxiosResponse<SiteDto>> => {
return axiosInstance.patch(`/sites/${id}/restore`, null, {
headers: withHeaders(),
});
};

View File

@@ -0,0 +1,103 @@
import { withHeaders } from "@/record-management/services/api/withHeaders";
import axiosInstance from "@/shared/services/axiosInstance";
import { AxiosResponse } from "axios";
export interface UserRoleHeaders {
delegatorPositionId: string;
currentProjectId?: string;
}
export interface RemoveOrAssignUnitAdminPayload {
unitId: string;
userId: string;
}
export interface RemoveOrAssignOrgAdminPayload {
organizationId: string;
userId: string;
}
// Assign Org Admin Role
export const assignOrgAdminRole = async (
payload: RemoveOrAssignOrgAdminPayload
): Promise<AxiosResponse> =>
axiosInstance.post("/user-roles/assign-org-admin-role", payload, {
headers: withHeaders(),
});
// Remove Org Admin Role
export const removeOrgAdminRole = async (
payload: RemoveOrAssignOrgAdminPayload
): Promise<AxiosResponse> =>
axiosInstance.post("/user-roles/remove-org-admin-role", payload, {
headers: withHeaders(),
});
//Assign unit Admin Role
export const assignUnitAdminRole = async (
payload: RemoveOrAssignUnitAdminPayload
): Promise<AxiosResponse> =>
axiosInstance.post("/user-roles/assign-unit-admin-role", payload, {
headers: withHeaders(),
});
// Remove Unit Admin Role
export const removeUnitAdminRole = async (
payload: RemoveOrAssignUnitAdminPayload
): Promise<AxiosResponse> =>
axiosInstance.post("/user-roles/remove-unit-admin-role", payload, {
headers: withHeaders(),
});
// Get roles given first (e.g., user has been assigned roles)
export const getRolesGivenFirst = async (id: string): Promise<AxiosResponse> =>
axiosInstance.get(`/user-roles/given-first/${id}`, {
headers: withHeaders(),
});
// Get roles given second (e.g., entities assigned to a user)
export const getRolesGivenSecond = async (id: string): Promise<AxiosResponse> =>
axiosInstance.get(`/user-roles/given-second/${id}`, {
headers: withHeaders(),
});
// Assign firsts for second
export const assignFirstsForSecond = async (payload: {
secondId: string;
firstIds: string[];
}): Promise<AxiosResponse> =>
axiosInstance.post(`/user-roles/assign-firsts-for-second`, payload, {
headers: withHeaders(),
});
// Assign seconds for first
export const assignSecondsForFirst = async (payload: {
firstId: string;
secondIds: string[];
}): Promise<AxiosResponse> =>
axiosInstance.post(`/user-roles/assign-seconds-for-first`, payload, {
headers: withHeaders(),
});
// Delete user role by id
export const deleteUserRole = async (id: string): Promise<AxiosResponse> =>
axiosInstance.delete(`/user-roles/${id}`, { headers: withHeaders() });
// Remove firsts for second
export const removeFirstsForSecond = async (payload: {
secondId: string;
firstIds: string[];
}): Promise<AxiosResponse> =>
axiosInstance.post(`/user-roles/remove-firsts-for-second`, payload, {
headers: withHeaders(),
});
// Remove seconds for first
export const removeSecondsForFirst = async (payload: {
firstId: string;
secondIds: string[];
}): Promise<AxiosResponse> =>
axiosInstance.post(`/user-roles/remove-seconds-for-first`, payload, {
headers: withHeaders(),
});

View File

@@ -0,0 +1,103 @@
import { withHeaders } from "@/record-management/services/api/withHeaders";
import axiosInstance from "@/shared/services/axiosInstance";
import recordAxiosInstance from "@/shared/services/recordAxiosInstance";
import {
ExternalUsersResponseDto,
UserTypeDto,
} from "@/super-admin/dto/ExternalUsersDto";
import { MainDtoResponse } from "@/super-admin/dto/SuperAdminDto";
import { ExternalQueryParams } from "@/super-admin/hooks/useExternalUsers";
import { AxiosResponse } from "axios";
// 🔵 Get pending users
export const getPendingUsers = async (
params?: ExternalQueryParams
): Promise<AxiosResponse<ExternalUsersResponseDto>> =>
axiosInstance.get("/users/pending", { headers: withHeaders(), params });
// Dashboard Information
export const getUnitInfo = async (
params?: ExternalQueryParams
): Promise<AxiosResponse<UserTypeDto>> =>
recordAxiosInstance.get("/record-boxes/my-units-dashboard", {
headers: withHeaders(),
params,
});
// unit infromation from super admin side
export const getUnitInfoByUnitID = async (
UnitId: string,
params?: ExternalQueryParams
): Promise<AxiosResponse<UserTypeDto>> =>
recordAxiosInstance.get(`/record-boxes/summary/${UnitId}`, {
headers: withHeaders(),
params,
});
// 🔵 Get all users (both external_organization and employee)
export const getAllExternalUsers = async (
params?: ExternalQueryParams
): Promise<AxiosResponse<ExternalUsersResponseDto>> => {
const queryParams = {
...params,
// No userType filter - fetch both external_organization and employee users
};
return axiosInstance.get("/users/filter", {
headers: withHeaders(),
params: queryParams,
});
};
export const getExternalUsersNeesApproval = async (
params?: ExternalQueryParams
): Promise<AxiosResponse<ExternalUsersResponseDto>> => {
const queryParams = {
...params,
// No userType filter - fetch both external_organization and employee users
};
return axiosInstance.get("/users/filter", {
headers: withHeaders(),
params: queryParams,
});
};
// 🔴 Delete user
export const deleteUser = async (id: string): Promise<AxiosResponse<void>> =>
axiosInstance.delete(`/users/${id}`, { headers: withHeaders() });
export const getUserById = async (id: string): Promise<AxiosResponse<any>> =>
axiosInstance.get(`/users/${id}`, { headers: withHeaders() });
// 🟢 Activate user
export const activateUser = async (id: string): Promise<AxiosResponse<void>> =>
axiosInstance.patch(`/users/activate-user/${id}`, null, {
headers: withHeaders(),
});
export const approveUser = async (
id: string,
status: string
): Promise<AxiosResponse<void>> =>
axiosInstance.patch(
`/users/approve/${id}`,
{ status },
{
headers: withHeaders(),
}
);
// 🟠 Deactivate user
export const deactivateUser = async (
id: string
): Promise<AxiosResponse<void>> =>
axiosInstance.patch(`/users/deactivate-user/${id}`, null, {
headers: withHeaders(),
});
export const getAllRecords = async (
UnitId: string,
params?: ExternalQueryParams
): Promise<AxiosResponse<MainDtoResponse>> =>
recordAxiosInstance.get(`/record-boxes/unit-box/${UnitId}`, {
headers: withHeaders(),
params,
});