import { For, Show, createMemo, createSignal, onMount } from 'solid-js'; import AdminShell from '~/components/AdminShell'; import { ChevronDown, SlidersHorizontal, Download, MoreVertical } from 'lucide-solid'; type DesignationRecord = { id: string; name: string; code: string; department: string; level: string; description?: string; totalEmployees: number; status: 'ACTIVE' | 'INACTIVE'; createdDate: string; canManageTeam?: boolean; canApprove?: boolean; }; const FALLBACK_DESIGNATIONS: DesignationRecord[] = [ { id: 'z1', name: 'Senior Software Engineer', code: 'SSE-001', department: 'Engineering', level: 'Senior', totalEmployees: 12, status: 'ACTIVE', createdDate: '2024-01-15' }, { id: 'z2', name: 'Marketing Manager', code: 'MM-002', department: 'Marketing', level: 'Manager', totalEmployees: 8, status: 'ACTIVE', createdDate: '2024-01-20' }, { id: 'z3', name: 'Sales Executive', code: 'SE-003', department: 'Sales', level: 'Executive', totalEmployees: 15, status: 'ACTIVE', createdDate: '2024-02-01' }, { id: 'z4', name: 'HR Specialist', code: 'HRS-004', department: 'Human Resources', level: 'Specialist', totalEmployees: 5, status: 'ACTIVE', createdDate: '2024-02-10' }, { id: 'z5', name: 'Financial Analyst', code: 'FA-005', department: 'Finance', level: 'Analyst', totalEmployees: 6, status: 'ACTIVE', createdDate: '2024-02-15' }, { id: 'z6', name: 'Operations Manager', code: 'OM-006', department: 'Operations', level: 'Manager', totalEmployees: 4, status: 'INACTIVE', createdDate: '2024-03-01' }, { id: 'z7', name: 'Customer Support Lead', code: 'CSL-007', department: 'Customer Support', level: 'Lead', totalEmployees: 9, status: 'ACTIVE', createdDate: '2024-03-05' }, { id: 'z8', name: 'Product Designer', code: 'PD-008', department: 'Product', level: 'Designer', totalEmployees: 7, status: 'ACTIVE', createdDate: '2024-03-10' }, ]; const LEVELS = ['Intern', 'Junior', 'Mid-Level', 'Senior', 'Lead', 'Manager', 'Director', 'VP', 'C-Level', 'Executive', 'Specialist', 'Analyst', 'Designer']; const DEPARTMENTS = ['Engineering', 'Marketing', 'Sales', 'Human Resources', 'Finance', 'Operations', 'Product', 'Customer Support']; function levelBadge(level: string) { const map: Record = { Senior: { bg: '#EFF6FF', color: '#1D4ED8', border: '#BFDBFE' }, Manager: { bg: '#F5F3FF', color: '#7C3AED', border: '#DDD6FE' }, Executive: { bg: '#ECFDF5', color: '#059669', border: '#A7F3D0' }, Specialist: { bg: '#F0FDFA', color: '#0D9488', border: '#99F6E4' }, Analyst: { bg: '#FFF7ED', color: '#EA580C', border: '#FED7AA' }, Lead: { bg: '#EFF6FF', color: '#2563EB', border: '#BFDBFE' }, Designer: { bg: '#FDF4FF', color: '#A21CAF', border: '#F0ABFC' }, Director: { bg: '#FFF1F2', color: '#BE123C', border: '#FECDD3' }, }; const s = map[level] ?? { bg: '#F3F4F6', color: '#4B5563', border: '#D1D5DB' }; return ( {level} ); } function StatusBadge(props: { status: string }) { const active = () => props.status === 'ACTIVE'; return ( {active() ? 'Active' : 'Inactive'} ); } function Toggle(props: { on: boolean; onChange: (v: boolean) => void }) { return ( ); } function FormInput(props: { label: string; required?: boolean; value: string; onInput: (v: string) => void; placeholder?: string; type?: string }) { return ( ); } function FormSelect(props: { label: string; required?: boolean; value: string; onChange: (v: string) => void; children: any }) { return ( ); } export default function DesignationManagementPage() { const [mainTab, setMainTab] = createSignal<'all' | 'create'>('all'); const [formTab, setFormTab] = createSignal<'general' | 'settings' | 'permissions'>('general'); const [search, setSearch] = createSignal(''); const [rows, setRows] = createSignal([]); const [openMenuId, setOpenMenuId] = createSignal(null); // form state const [name, setName] = createSignal(''); const [code, setCode] = createSignal(''); const [department, setDepartment] = createSignal(''); const [level, setLevel] = createSignal(''); const [description, setDescription] = createSignal(''); const [formStatus, setFormStatus] = createSignal<'ACTIVE' | 'INACTIVE'>('ACTIVE'); const [canManageTeam, setCanManageTeam] = createSignal(false); const [canApprove, setCanApprove] = createSignal(false); // permissions toggles const [permViewEmp, setPermViewEmp] = createSignal(false); const [permCreateEmp, setPermCreateEmp] = createSignal(false); const [permEditEmp, setPermEditEmp] = createSignal(false); const [permDeleteEmp, setPermDeleteEmp] = createSignal(false); const [permAssignRoles, setPermAssignRoles] = createSignal(false); const load = async () => { try { const res = await fetch(`/api/gateway/api/admin/designations?page=1&limit=100`); if (res.ok) { const payload = await res.json().catch(() => null); const list = Array.isArray(payload) ? payload : Array.isArray(payload?.data) ? payload.data : Array.isArray(payload?.items) ? payload.items : []; if (list.length > 0) { setRows(list.map((item: any, i: number) => ({ id: String(item.id ?? `des-${i + 1}`), name: String(item.name ?? ''), code: String(item.code ?? ''), department: String(item.department ?? item.department_name ?? ''), level: String(item.level ?? ''), description: String(item.description ?? ''), totalEmployees: Number(item.totalEmployees ?? item.total_employees ?? 0), status: String(item.status ?? 'ACTIVE').toUpperCase() === 'INACTIVE' ? 'INACTIVE' : 'ACTIVE', createdDate: String(item.createdDate ?? item.created_at ?? ''), }))); return; } } } catch {} setRows(FALLBACK_DESIGNATIONS); }; onMount(() => void load()); const filteredRows = createMemo(() => { const q = search().toLowerCase(); if (!q) return rows(); return rows().filter((d) => d.name.toLowerCase().includes(q) || d.code.toLowerCase().includes(q) || d.department.toLowerCase().includes(q) ); }); const resetForm = () => { setName(''); setCode(''); setDepartment(''); setLevel(''); setDescription(''); setFormStatus('ACTIVE'); setCanManageTeam(false); setCanApprove(false); setPermViewEmp(false); setPermCreateEmp(false); setPermEditEmp(false); setPermDeleteEmp(false); setPermAssignRoles(false); setFormTab('general'); }; const handleTabChange = (tab: 'all' | 'create') => { setMainTab(tab); if (tab === 'create') resetForm(); setOpenMenuId(null); }; const formatDate = (d: string) => { if (!d) return '—'; try { return new Date(d).toLocaleDateString('en-IN', { day: '2-digit', month: 'short', year: 'numeric' }); } catch { return d; } }; return (
{/* Page header */}

Designation Management

Manage all designations and job positions

{/* Main tabs */}
{/* All Designations view */}
{/* Filter bar */}
setSearch(e.currentTarget.value)} style="height:34px;flex:1;max-width:240px;border-radius:8px;border:1px solid #E5E7EB;padding:0 12px;font-size:13px;outline:none;color:#111827;background:white" />
{/* Table */}
{(row) => ( )}
Designation Name Designation Code Department Level Total Employees Status Created Date Actions
{row.name} {row.code} {row.department} {levelBadge(row.level)} {row.totalEmployees} {formatDate(row.createdDate)}
{/* Pagination */}
Showing 1-{filteredRows().length} of {filteredRows().length} designations
{/* Create Designation view */}
{/* Form sub-tabs */}
{/* General Information tab */}
{(d) => } {(l) => }