feat: refactor department to organization and move certifications to configuration tab commit

This commit is contained in:
mengstabketemaw
2026-06-29 15:57:42 +03:00
parent 3493fbbae7
commit c46747c98e
14 changed files with 215 additions and 89 deletions

View File

@@ -1,6 +1,6 @@
import { baseApi } from '@ema-platform/api';
import type {
Department,
Organization,
Profession,
ListResponse,
CreateProfessionPayload,
@@ -9,8 +9,8 @@ import type {
const configurationApi = baseApi.injectEndpoints({
endpoints: (builder) => ({
getDepartments: builder.query<ListResponse<Department>, void>({
query: () => '/departments',
getOrganizations: builder.query<ListResponse<Organization>, void>({
query: () => '/organizations',
providesTags: ['Api'],
}),
@@ -35,11 +35,11 @@ const configurationApi = baseApi.injectEndpoints({
invalidatesTags: ['Api'],
}),
}),
overrideExisting: false,
overrideExisting: true,
});
export const {
useGetDepartmentsQuery,
useGetOrganizationsQuery,
useGetProfessionsQuery,
useCreateProfessionMutation,
useUpdateProfessionMutation,

View File

@@ -19,12 +19,13 @@ import {
} from '@mantine/core';
import { useForm } from '@mantine/form';
import { useDisclosure } from '@mantine/hooks';
import { IconEdit, IconTrash, IconPlus, IconBriefcase, IconMap, IconInfoCircle } from '@tabler/icons-react';
import { IconEdit, IconTrash, IconPlus, IconBriefcase, IconMap, IconCertificate, IconInfoCircle } from '@tabler/icons-react';
import { useTranslation } from 'react-i18next';
import { notify } from '@ema-platform/ui';
import { LocationPage } from '../../location/pages/LocationPage';
import { CertificationPage } from '../../certification/pages/CertificationPage';
import {
useGetDepartmentsQuery,
useGetOrganizationsQuery,
useGetProfessionsQuery,
useCreateProfessionMutation,
useUpdateProfessionMutation,
@@ -129,13 +130,13 @@ function ProfessionForm({ editingProf, deptOptions, isSubmitting, onSubmit, onCa
function ProfessionTab() {
const { t } = useTranslation();
const { data: deptRes } = useGetDepartmentsQuery();
const { data: deptRes } = useGetOrganizationsQuery();
const { data: profRes, isLoading, isError } = useGetProfessionsQuery();
const [createProfession, { isLoading: isCreating }] = useCreateProfessionMutation();
const [updateProfession, { isLoading: isUpdating }] = useUpdateProfessionMutation();
const [deleteProfession] = useDeleteProfessionMutation();
const departments = deptRes?.items ?? [];
const departments = Array.isArray(deptRes) ? deptRes : (deptRes?.items ?? []);
const professions = profRes?.items ?? [];
const [editingProf, setEditingProf] = useState<Profession | null>(null);
@@ -143,9 +144,9 @@ function ProfessionTab() {
const [deleteTarget, setDeleteTarget] = useState<Profession | null>(null);
const [deleteOpened, { open: openDelete, close: closeDelete }] = useDisclosure(false);
const deptOptions = departments.filter((d) => d.isActive).map((d) => ({
const deptOptions = departments.filter((d) => d?.status?.toLowerCase() === 'active').map((d) => ({
value: d.id,
label: d.name.en,
label: d.name?.en ?? d.name ?? '',
}));
const resetProfForm = useCallback(() => {
@@ -312,6 +313,9 @@ export function ConfigurationPage() {
<Tabs.Tab value="locations" leftSection={<IconMap size={16} />}>
{t('location.title')}
</Tabs.Tab>
<Tabs.Tab value="certifications" leftSection={<IconCertificate size={16} />}>
Certifications
</Tabs.Tab>
</Tabs.List>
<Tabs.Panel value="professions" pt="md">
@@ -321,6 +325,10 @@ export function ConfigurationPage() {
<Tabs.Panel value="locations" pt="md">
<LocationPage />
</Tabs.Panel>
<Tabs.Panel value="certifications" pt="md">
<CertificationPage />
</Tabs.Panel>
</Tabs>
</Stack>
);

View File

@@ -3,11 +3,15 @@ export interface NamePair {
am: string;
}
export interface Department {
export interface Organization {
id: string;
name: NamePair;
description: NamePair;
isActive: boolean;
key: string;
isSuperAdmin: boolean;
isGovernmentOrganization: boolean;
status: string;
parentId: string | null;
organizationTypeId: string;
createdAt: string;
updatedAt: string;
}
@@ -15,7 +19,7 @@ export interface Department {
export interface Profession {
id: string;
departmentId: string;
department?: Department;
department?: Organization;
name: NamePair;
description: NamePair;
isActive: boolean;

View File

@@ -20,7 +20,6 @@ import {
IconUser,
IconUsers,
IconUserShield,
IconCertificate,
IconQuestionMark,
IconClipboardList,
IconReport,
@@ -41,7 +40,6 @@ const NAV_ITEMS: NavItem[] = [
{ to: '/analytics', label: 'Analytics', icon: IconChartBar },
{ to: '/medical-verification', label: 'Medical Verification', icon: IconHeart },
{ to: '/locations', label: 'Locations', icon: IconMap },
{ to: '/certifications', label: 'Certifications', icon: IconCertificate },
{ to: '/questions', label: 'Questions', icon: IconQuestionMark },
{ to: '/exams', label: 'Examinations', icon: IconClipboardList },
{ to: '/exam-results', label: 'Exam Results', icon: IconReport },

View File

@@ -26,7 +26,6 @@ import { MedicalVerificationPage } from '../features/medical-verification/pages/
import { PaymentConfigPage } from '../features/payment-config/pages/PaymentConfigPage';
import { SeafarerRegistryPage } from '../features/seafarer-registry/pages/SeafarerRegistryPage';
import { SeamanBookQueuePage } from '../features/seaman-book-queue/pages/SeamanBookQueuePage';
import { CertificationPage } from '../features/certification/pages/CertificationPage';
import { QuestionPage } from '../features/question/pages/QuestionPage';
import { ExamPage } from '../features/exam/pages/ExamPage';
import { ExamDetailPage } from '../features/exam/pages/ExamDetailPage';
@@ -65,7 +64,6 @@ const router = createBrowserRouter([
{ path: 'payment-config', element: <PaymentConfigPage /> },
{ path: 'seafarer-registry', element: <SeafarerRegistryPage /> },
{ path: 'seaman-book-queue', element: <SeamanBookQueuePage /> },
{ path: 'certifications', element: <CertificationPage /> },
{ path: 'questions', element: <QuestionPage /> },
{ path: 'exams', element: <ExamPage /> },
{ path: 'exams/:id', element: <ExamDetailPage /> },

View File

@@ -8,7 +8,7 @@ import {
refreshAccessToken,
logout,
} from '@ema-platform/auth';
import type { AuthUser } from '@ema-platform/auth';
import type { AuthUser, CurrentProfile } from '@ema-platform/auth';
import { preferencesReducer } from './preferences.slice';
configureAuthStorage('ema-backoffice');
@@ -16,8 +16,9 @@ configureAuthStorage('ema-backoffice');
const preloadedAuth = (() => {
const token = authStorage.getToken();
const user = authStorage.getUser<AuthUser>();
const profile = authStorage.getProfile<CurrentProfile>();
if (token && user) {
return { token, user, isAuthenticated: true };
return { token, user, isAuthenticated: true, currentProfile: profile ?? null };
}
return undefined;
})();