diff --git a/.gitignore b/.gitignore index 4cbce0b01..20b771e89 100644 --- a/.gitignore +++ b/.gitignore @@ -30,4 +30,5 @@ temp_interactive_push.bat apps/backoffice/public/_um/ apps/backoffice/public/tinymce/ +local-packages/iamui-extracted/ diff --git a/.gitmodules b/.gitmodules deleted file mode 100644 index 850934ff5..000000000 --- a/.gitmodules +++ /dev/null @@ -1,3 +0,0 @@ -[submodule "user-management"] - path = user-management - url = git@github.com:Tria-plc/iamui.git diff --git a/apps/backoffice/src/app/features/configuration/api/configuration-api.ts b/apps/backoffice/src/app/features/configuration/api/configuration-api.ts index 6189684f0..13676b2a6 100644 --- a/apps/backoffice/src/app/features/configuration/api/configuration-api.ts +++ b/apps/backoffice/src/app/features/configuration/api/configuration-api.ts @@ -3,8 +3,6 @@ import type { Department, Profession, ListResponse, - CreateDepartmentPayload, - UpdateDepartmentPayload, CreateProfessionPayload, UpdateProfessionPayload, } from '../types/configuration'; @@ -15,22 +13,6 @@ const configurationApi = baseApi.injectEndpoints({ query: () => '/departments', providesTags: ['Api'], }), - createDepartment: builder.mutation({ - query: (body) => ({ url: '/departments', method: 'POST', body }), - invalidatesTags: ['Api'], - }), - updateDepartment: builder.mutation({ - query: ({ id, ...body }) => ({ - url: `/departments/${id}`, - method: 'PUT', - body, - }), - invalidatesTags: ['Api'], - }), - deleteDepartment: builder.mutation({ - query: (id) => ({ url: `/departments/${id}`, method: 'DELETE' }), - invalidatesTags: ['Api'], - }), getProfessions: builder.query, void>({ query: () => '/professions', @@ -58,9 +40,6 @@ const configurationApi = baseApi.injectEndpoints({ export const { useGetDepartmentsQuery, - useCreateDepartmentMutation, - useUpdateDepartmentMutation, - useDeleteDepartmentMutation, useGetProfessionsQuery, useCreateProfessionMutation, useUpdateProfessionMutation, diff --git a/apps/backoffice/src/app/features/configuration/pages/ConfigurationPage.tsx b/apps/backoffice/src/app/features/configuration/pages/ConfigurationPage.tsx index 83a73271e..367ef657f 100644 --- a/apps/backoffice/src/app/features/configuration/pages/ConfigurationPage.tsx +++ b/apps/backoffice/src/app/features/configuration/pages/ConfigurationPage.tsx @@ -1,4 +1,4 @@ -import { useState } from 'react'; +import { useState, useEffect, useCallback } from 'react'; import { Stack, Title, @@ -12,308 +12,208 @@ import { Modal, Text, Select, - Badge, Paper, + Loader, + Center, + Alert, } from '@mantine/core'; import { useForm } from '@mantine/form'; import { useDisclosure } from '@mantine/hooks'; -import { IconEdit, IconTrash, IconPlus, IconBuilding, IconBriefcase, IconMap } from '@tabler/icons-react'; +import { IconEdit, IconTrash, IconPlus, IconBriefcase, IconMap, IconInfoCircle } from '@tabler/icons-react'; import { useTranslation } from 'react-i18next'; import { notify } from '@ema-platform/ui'; import { LocationPage } from '../../location/pages/LocationPage'; -import type { Department, Profession } from '../types/configuration'; +import { + useGetDepartmentsQuery, + useGetProfessionsQuery, + useCreateProfessionMutation, + useUpdateProfessionMutation, + useDeleteProfessionMutation, +} from '../api/configuration-api'; +import type { Profession } from '../types/configuration'; -let nextId = 1; -const uid = () => String(nextId++); - -const MOCK_DEPARTMENTS: Department[] = [ - { id: uid(), code: 'IT', names: { en: 'Information Technology', am: 'ኢንፎርሜሽን ቴክኖሎጂ' }, description: 'Handles all IT infrastructure and systems.', createdAt: new Date().toISOString(), updatedAt: new Date().toISOString() }, - { id: uid(), code: 'HR', names: { en: 'Human Resources', am: 'የሰው ኃይል ሀብት' }, description: 'Manages personnel and recruitment.', createdAt: new Date().toISOString(), updatedAt: new Date().toISOString() }, - { id: uid(), code: 'FIN', names: { en: 'Finance', am: 'ፋይናንስ' }, description: 'Oversees budgeting and accounting.', createdAt: new Date().toISOString(), updatedAt: new Date().toISOString() }, -]; - -const MOCK_PROFESSIONS: Profession[] = [ - { id: uid(), code: 'SWE', names: { en: 'Software Engineer', am: 'የሶፍትዌር መሐንዲስ' }, description: 'Develops and maintains software applications.', departmentId: '1', createdAt: new Date().toISOString(), updatedAt: new Date().toISOString() }, - { id: uid(), code: 'SRE', names: { en: 'Site Reliability Engineer', am: 'የጣቢያ አስተማማኝነት መሐንዲስ' }, description: 'Ensures system reliability and uptime.', departmentId: '1', createdAt: new Date().toISOString(), updatedAt: new Date().toISOString() }, - { id: uid(), code: 'HRM', names: { en: 'HR Manager', am: 'የሰው ኃይል አስተዳዳሪ' }, description: 'Leads the HR team and strategy.', departmentId: '2', createdAt: new Date().toISOString(), updatedAt: new Date().toISOString() }, -]; - -function DepartmentTab() { - const { t } = useTranslation(); - const [departments, setDepartments] = useState(MOCK_DEPARTMENTS); - const [editingDept, setEditingDept] = useState(null); - const [showDeptForm, setShowDeptForm] = useState(false); - const [deleteTarget, setDeleteTarget] = useState(null); - const [deleteOpened, { open: openDelete, close: closeDelete }] = useDisclosure(false); - - const deptForm = useForm({ - initialValues: { code: '', nameEn: '', nameAm: '', description: '' }, - validate: { - code: (v) => (!v ? t('configuration.validation.codeRequired') : null), - nameEn: (v) => (!v ? t('configuration.validation.nameEnRequired') : null), - nameAm: (v) => (!v ? t('configuration.validation.nameAmRequired') : null), - }, - }); - - const resetDeptForm = () => { - deptForm.reset(); - setEditingDept(null); - setShowDeptForm(false); - }; - - const handleEditDept = (dept: Department) => { - setEditingDept(dept); - deptForm.setValues({ - code: dept.code, - nameEn: dept.names.en, - nameAm: dept.names.am, - description: dept.description, - }); - setShowDeptForm(true); - }; - - const handleDeleteDept = (dept: Department) => { - setDeleteTarget(dept); - openDelete(); - }; - - const confirmDeleteDept = () => { - if (!deleteTarget) return; - setDepartments((prev) => prev.filter((d) => d.id !== deleteTarget.id)); - notify.success(t('configuration.deleted')); - closeDelete(); - setDeleteTarget(null); - }; - - const handleDeptSubmit = deptForm.onSubmit((values) => { - const now = new Date().toISOString(); - if (editingDept) { - setDepartments((prev) => - prev.map((d) => - d.id === editingDept.id - ? { ...d, code: values.code, names: { en: values.nameEn, am: values.nameAm }, description: values.description, updatedAt: now } - : d - ) - ); - notify.success(t('configuration.updated')); - } else { - const newDept: Department = { - id: uid(), - code: values.code, - names: { en: values.nameEn, am: values.nameAm }, - description: values.description, - createdAt: now, - updatedAt: now, - }; - setDepartments((prev) => [...prev, newDept]); - notify.success(t('configuration.created')); - } - resetDeptForm(); - }); - - return ( - <> - - {t('configuration.departmentsList')} - {!showDeptForm && ( - - )} - - - {showDeptForm && ( - -
- - - - -